Repository navigation
Conversation
- annotate the intentional Row -> RowMapping class swap with type: ignore[assignment]; RowMapping shares BaseRow's constructor signature so the swap is runtime-safe - update test_fetch_by_key_mappings sqlite call counts to the values observed on x86_64_linux CI (mappings rows no longer construct an intermediate Row + second BaseRow, so counts drop); other-dialect entries for this test remain stale and need --write-profiles on their platforms
Member
|
@CaselIT any time to look at this one? |
Member
|
it's on my list sure |
Sanjays2402
reviewed
Jul 21, 2026
| """ | ||
| self._unique_filter_state = (set(), strategy) | ||
| if not self._real_result._source_supports_scalars: | ||
| _configure_scalar_row_shape(self) |
There was a problem hiding this comment.
_row_getter may already be memoized here if the caller consumed a row before calling unique(). In that case the new shape is ignored: a scalar custom strategy still receives an int (and can raise TypeError), while the mapping path still receives RowMapping; either invalidate the memoized getter when changing shape or keep the existing shape once fetching has started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What changed
Core .scalars() built a one-column Row per row only to unwrap it with itemgetter(0); .mappings() built a Row plus a second BaseRow (RowMapping) via attrgetter("_mapping").
New class-level _fetch_shape hint (_SHAPE_ROW / _SHAPE_SCALAR / _SHAPE_MAPPING) on BaseResultInternal; _row_getter emits direct getters: raw_row[index] with the column's result processor hoisted (scalar shape), or RowMapping constructed directly (mapping shape).
_configure_scalar_row_shape / _configure_mapping_row_shape helpers in result.py, called from init and unique() — the only pre-fetch mutation points. Mirrored in AsyncScalarResult / AsyncMappingResult.
Fast path gates OFF (legacy Row path preserved verbatim) when: _row_logging_fn present (echo="debug" must log real Rows); caller-supplied unique(strategy); metadata _create_unique_filters (scalars); any uniquing at all (mappings — RowMapping has Mapping equality, not Row-data equality). Default .scalars().unique() keeps the fast path: Row hash/eq delegate to the data tuple, so deduping raw values is equivalent.
_raw_all_tuples() now also asserts the default shape, keeping the ORM position-based path strict.
Performance (10k rows, in-memory SQLite, min-of-30, -O3 verified)
.scalars()int col.scalars()w/ processor.scalars(2)of 3 cols.scalars().unique().mappings()5 cols.all()(control)The
.unique()win comes from hashing raw values instead of Row objects.Testing
33 new unit tests (
test/base/test_result.py::RowShapeElisionTest, incl.asyncio twins) + 10 cursor-level integration tests
(
test/sql/test_resultset_elision.py) covering processors, echo="debug"fallback, uniquing fallbacks, partitions, freeze/replay. Suite green
compiled AND uncompiled (pure-python
_result_cy).Benchmark script:
bench_core_result_filters.pyChecklist
This pull request is:
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
Fixes: #<issue number>in the commit messageinclude a complete example of how the feature would look.
Fixes: #<issue number>in the commit messageHave a nice day!