Skip to content

Fix window RANGE frame peer groups ignoring COLLATE - #113399

Closed
groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-window-collate-range-peers
Closed

groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-window-collate-range-peers

Conversation

@groeneai

@groeneai groeneai commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #113079

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix wrong results and a logical error in window functions when the window ORDER BY uses COLLATE. The input is sorted with the collator, but peer groups were computed with a raw byte comparison, so values equal under the collation were treated as different peers. This gave wrong rank, dense_rank, percent_rank and cume_dist values and wrong RANGE and GROUPS frames, and in debug and sanitizer builds raised Equal values are not contiguous within the range assumed to be sorted. Closes #124348.

Description

Reachable from ordinary SQL:

SELECT rank() OVER (ORDER BY x COLLATE 'en-u-ks-level2') AS r
FROM (SELECT if(number % 2, 'a', 'A') AS x FROM numbers(1000));

Under case-insensitive collation 'a' and 'A' are equal, so every row must have rank 1; ORDER BY x COLLATE 'en-u-ks-level2' LIMIT 1 WITH TIES agrees and returns all 1000 rows. On 26.8.18.2 the ranks are 1 to 1000; on master a debug build aborts on every run, found again by the AST fuzzer (STID 2508-3e4f).

Root cause: the window code re-derives peer groups with raw compareAt and getEqualRangeEndAssumeSorted, while the collated sort interleaves rows that are collation-equal but byte-different. That also breaks the contiguity precondition of the equal-range scan, hence the logical error.

The fix adds haveEqualOrderByValues and getOrderByEqualRangeEnd to WindowTransformParams, comparing ORDER BY keys the way the input was sorted, with the collator && isCollationSupported() guard of LimitTransform, FillingTransform and SortCursor. assignPeerGroupIndexes in SlidingIndexes.cpp uses them for the block-boundary check and the in-block scan; the RANGE and GROUPS frames and the peer-dependent functions all read that index. PARTITION BY cannot carry a collator and is untouched. Uncollated windows keep the inlined raw comparison; only the collated path is out of line.

Verified in both directions on current master: the test and the AST fuzzer query from #113045 abort on master and pass with the fix.


Workflow [PR]
Sync PR [sync-upstream/pr/113399]

The window input is sorted by full_sort_description, whose ORDER BY entries
carry the collator, but WindowTransform re-derived peer groups with the raw
IColumn::compareAt. Rows that are equal under the collation but differ in
bytes therefore looked unequal, so the RANGE peer group was cut short: the
frame end, and through peer_group_start the frame start, landed on the wrong
row and the query returned wrong results.

The collated sort may also interleave such rows, which violates the "equal
values are contiguous within a sorted range" precondition of the equal-range
scan, so debug and sanitizer builds raised the logical error
"Equal values are not contiguous within the range assumed to be sorted".

Compare ORDER BY keys the same way the input was sorted, at the three sites
that decide peer membership: arePeers and the reference check plus the
equal-range scan in advanceFrameEndCurrentRow. The guard shape
(collator && isCollationSupported()) matches the five existing sites in
LimitTransform, FractionalLimitTransform, NegativeLimitTransform,
FillingTransform and SortCursor. findEqualRangeEndAssumeSorted is a free
template over an arbitrary equality predicate, so no new IColumn method is
needed.

PARTITION BY sites are left alone because PARTITION BY cannot carry a
collator. A collatable type cannot reach the RANGE OFFSET comparisons, which
reject a String ORDER BY column.

Uncollated queries are bit-for-bit unchanged: a constructor flag keeps the
existing per-column equal-range scan, with its memcmp and vector fast paths,
whenever no ORDER BY key has a collator.

Found by the AST fuzzer on an unrelated PR (STID 2508-46a9) and confirmed
pre-existing on pristine master with queries containing no ranking function.
Only affects enable_analyzer = 1: the old analyzer drops COLLATE from a
window ORDER BY, so its sort and comparison are both raw and self-consistent.
@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (independent cold review + adversarial gate, 0 blockers)

Two independent reviews of this change: a cold code review (reviewer never saw the author's
evidence until after writing findings), and an adversarial gate run on a different model.
Verdicts below.

# Finding Verdict
💡 Adversarial gate: 0 findings. Coverage note names all modified functions, their callers, the planner/sort paths, sibling collation comparators, the column wrappers, the range-search helper and the new test. Nothing to adjudicate. Run was cold (no prior-round state injected), so it could not echo the cold review.
💡 Cold review: the comment explaining why the collated scan cannot reuse the per-column fast paths reads as explanatory rather than as a local invariant. Dropped my own finding. It states the invariant at the spot the branch is written and is not inferable from the code. Comment budget measured: 8 comment lines against 39 added code lines, no block over 3 lines.
⚠️ Cold review: the Related: provenance line sat inside the PR template's leading HTML comment block, so the linked pull request did not render. Agreed, fixed before publishing: the line is now visible in the body.

Verified independently during review, not taken from the author's notes:

  • Carrier enumeration. Five raw comparison sites exist in WindowTransform.cpp. The two
    PARTITION BY sites cannot see a collator by construction: both builders of
    WindowDescription::partition_by construct SortColumnDescription without a collator argument
    (PlannerWindowFunctions.cpp:45-46, ExpressionAnalyzer.cpp:679-681), and structurally
    parseWindowDefinitionParts parses PARTITION BY with ParserNotEmptyExpressionList while only
    ORDER BY uses the grammar that admits COLLATE. The three ORDER BY sites are the ones fixed.
    RANGE OFFSET is not a carrier: its dispatch table covers only integer, float and Nullable of
    those, so a collatable column throws in the constructor before any row is compared.
  • Frame start and frame end move together. Both arePeers callers are live and both take the
    new comparison: the peer-group-start update (which feeds frame_start = peer_group_start and
    rank/dense_rank/percent_rank) and cume_dist's peer-group-end scan. Nothing else in src/
    computes peer groups, so the two sides cannot diverge.
  • Test liveness. Seven of the eight assertions read differently with the fix reverted; the
    eighth is the deliberate uncollated control, which reads identically on both arms and is what
    shows the change is not over-broad. The min/max oracle is required rather than a weakening:
    the collated sort permutes collation-equal rows between runs, so a per-row reference would itself
    be flaky, while the aggregate still separates correct (4 4, 1 1) from broken (2 4, 1 3,
    1 2). SET enable_analyzer = 1 is load-bearing: the old analyzer drops the collator outright
    (ExpressionAnalyzer.cpp, // Ignore collation for now.), so without it the test is vacuous.
  • Style. The real check_gaps_in_tests_numbers was executed against the live master file list
    plus the new paths: 25 gaps before, 25 after, and the one delta is an existing gap shrinking. The
    test number is free on master, in all 406 currently open pull requests by this author, and in the
    build environment.
  • The assertion was right and is untouched. checkEqualRangeEndAssumeSorted is unchanged; the
    caller was violating its contiguity precondition. No bound widened, no tag added, no assertion
    silenced.

Session id: cron:clickhouse-review-slot-11:20260804-234100

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (a-i)
# Gate Answer
a Deterministic repro? Yes. SET enable_analyzer = 1; SELECT count() OVER (ORDER BY v COLLATE 'en-u-kn-true' RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM (SELECT arrayJoin(['1','01','1','01']) AS v). On the pre-fix binary 4 of 6 runs raise Equal values are not contiguous within the range assumed to be sorted; the other 2 return 2, 2, 4, 4 where every row must be 4.
b Root cause explained? Yes. The window input is sorted by full_sort_description, whose ORDER BY entries carry the collator, but WindowTransform re-derived peer groups with the raw IColumn::compareAt. Collation-equal but byte-different rows therefore look unequal, so the peer group is cut short (wrong results) and the equal-range scan's contiguity precondition is violated (logical error in debug and sanitizer builds).
c Fix matches root cause? Yes. The comparison is made collation-aware at the three sites that decide ORDER BY peer membership. No bound widened, no test tag added, no assertion silenced: checkEqualRangeEndAssumeSorted is untouched, because it was correct and the caller was violating its precondition.
d Test intent preserved / new tests added? Yes. No existing test weakened or removed. One new stateless test, 04771_window_collation_range_peers, with 8 assertions; it aborts on pre-fix master and on both mutants.
e Demonstrated in BOTH directions? Yes. Pre-fix binary: 3 of 3 matrix runs abort. Post-fix: 3 of 3 give the correct values, and the uncollated control reads identically on both arms, so the change is not over-broad.
f General across CODE paths? Yes. All five raw comparison sites in the transform were dispositioned. The two PARTITION BY sites are safe because PARTITION BY cannot carry a collator (PARTITION BY v COLLATE 'ru' is Code: 62); all three ORDER BY sites are fixed. Both arePeers callers move together, so the RANGE frame start and frame end stay consistent, and cume_dist moves with them. A collatable type cannot reach RANGE OFFSET (Code: 48 for a String ORDER BY column). Two mutants, each disabling one half of the fix, redden disjoint assertions, so neither site is dead code.
g Generalizes across INPUTS? Yes, all covered in the new test: String, Nullable(String), LowCardinality(String), multiple ORDER BY keys with the collator on a non-first key, DESC COLLATE, and the uncollated control. LowCardinality, Const, Sparse and Replicated are already normalized before any comparison; ColumnNullable, ColumnArray and ColumnTuple all implement compareAtWithCollation.
h Backward compatible? Yes. No new setting, no default change, no SettingsChangesHistory entry owed, no serialization or on-disk format change. The only behaviour change is on collated window RANGE queries, which today return wrong results or raise a logical error.
i Invariants and contracts preserved? Yes. The invariant restored is the one that was broken: peer membership is decided with the same comparison that ordered the input, which is exactly what the equal-range scan's contiguity precondition requires. compareAtWithCollation is guarded by isCollationSupported(), matching the five existing sites (LimitTransform, FractionalLimitTransform, NegativeLimitTransform, FillingTransform, SortCursor); a non-collatable type is already rejected earlier with Code: 262. All early-return paths are preserved verbatim, and no allocation or locking is added on the uncollated path.

Additional validation: 50 of 50 randomized runs of the new test pass. The existing window and collation suite passes, including 03549_window_collation, 01591_window_functions and 01592_window_functions; the 6 remaining failures in that suite are cluster tests that fail identically on the pristine pre-fix binary in this environment (Code: 279, Code: 519), so they are unrelated to this change. Performance: a constructor flag keeps the existing per-column fast-path scan whenever no ORDER BY key has a collator, so uncollated queries take the same path as before.

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @novikd @yariks5s, could you review this? The window input is sorted with the ORDER BY collator, but WindowTransform re-derived RANGE peer groups with the raw IColumn::compareAt, so collation-equal rows that differ byte-wise were treated as separate peers: the frame is cut short (wrong results) and the equal-range scan's contiguity precondition is violated, which raises a logical error in debug and sanitizer builds.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [24effc4]

Summary: ✅


AI Review

Summary

PR #113399 makes window peer-group comparisons honor ORDER BY collations, correcting ranking results and RANGE/GROUPS frames. No actionable findings in head 24effc4046c2c0bbb52936fa86b5131e8529488d.

Missing context / blind spots
  • ⚠️ Latest-head stateless and bugfix-validation jobs are pending in the Praktika report. No local ClickHouse executable is available, so tests were not rerun locally. A passing run of 04771_window_collation_range_peers on this head would close the runtime-validation gap.
Final Verdict

Status: ✅ Approve. No code changes requested; normal CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 24effc4046c2c0bbb52936fa86b5131e8529488d was not compared: the CI logs cluster did not answer (exception 241, code 500: { "meta": [ { "name": "file", "type": "LowCardinality(String)" …).

See the job log for details.

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 69fde84

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted) / Invalid number of columns in chunk pushed to OutputPort (STID 2270-3258) trunk bug: a fuzzer-mutated count() OVER (RANGE BETWEEN ...) inside remoteSecure(view(...)) with GROUP BY ALL produces an empty output header (Expected 0, found 1). Breadth 10 rows / 9 distinct unrelated PRs / 0 master in 30 days. a fix task is created (investigating at full effort — fixing-PR link to follow on this PR)
AST fuzzer (amd_debug, targeted, old_compatibility) / Invalid number of columns in chunk pushed to OutputPort (STID 2270-3258) same signature, cluster(...)+view(...) variant of the same empty-header shape. a fix task is created (investigating at full effort — fixing-PR link to follow on this PR)
Stress test (arm_msan) / Hung check failed, possible deadlock found plan-time cancellation gap: SELECT * FROM system.one INNER JOIN merge(REGEXP('^system$'), '^') sat 632 s with is_cancelled: 1 and read_rows: 0, stuck in QueryPlan::optimize under ReadFromMerge where no cancellation checkpoint exists. a fix task is moved to pending (investigating at full effort — fixing-PR link to follow on this PR)

None is PR-caused. This PR changes RANGE-frame peer comparison in WindowTransform, and both
signatures predate it on unrelated carriers; the hung query contains no window function at all.

Session id: cron:our-pr-ci-monitor:20260805-060000

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger correction — 69fde84

Two owner-column wordings in my previous ledger were imprecise. The owners are unchanged; the
corrected phrasing is:

Check / test Owner
AST fuzzer (amd_debug, targeted) / STID 2270-3258 a fix task already owns it and is in progress (fixing-PR link to follow on this PR)
AST fuzzer (amd_debug, targeted, old_compatibility) / STID 2270-3258 same fix task, in progress

Both lines were listed as "a fix task is created". The task in question was already open and is
actively being worked, so nothing was created for them this run.

For the record, the attribution behind those two rows was re-derived rather than inherited: both
abort at RemoteSource.cpp:102 with no PlannerJoinTree frame, and the failing queries are
cluster(..., view(...)) and remoteSecure('127.0.0.{2,3}:9440', view(...)). That is the
classic-distributed empty-header carrier, which is a different producer from the parallel-replicas
shape that shares the same STID bucket, so the two rows are owned accordingly. Neither is caused by
this PR, which touches only WindowTransform.{cpp,h} and its own new test.

The Stress test (arm_msan) hung-check owner is unchanged and was stated correctly.

Session id: cron:our-pr-ci-monitor:20260805-060000

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the ReadFromMerge::createChildrenPlans plan-time cancellation hung check on my
CI finish ledger: #113415 (external, open).

I had a fix for this on a local branch, but @alexey-milovidov opened #113415 with the identical
guard at the identical call site, so I dropped mine rather than open a duplicate. My analysis and
the one coverage gap I measured are in
#113415 (comment).

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the two Invalid number of columns in chunk pushed to OutputPort rows on my CI
finish ledger (STID 2270-3258, the cluster(..., view(...)) and remoteSecure(..., view(...))
carriers): #113469.

The locus is the planner header derivation, above the transport: remoteSecure registers the same
TableFunctionRemote implementation as remote and differs only in TLS, so both ledger rows are
covered by the one change. Its test pins the cluster, remote and clusterAllReplicas forms.

Master added GROUPS frame support to WindowTransform, which rewrote
arePeers' frame-type dispatch into a switch that now also routes GROUPS
to the ORDER BY comparison. The conflict is in that dispatch:

- Dropped this branch's chassert(frame.type == RANGE): GROUPS legitimately
  reaches the comparison now, so the assertion would fire on a valid frame.
- Dropped master's `const size_t n = order_by_indices.size()`: the peer
  comparison moved into orderByEqualAt(), which iterates the indices
  itself, so the count is unused here.

The collation-aware comparison at the three ORDER BY peer sites is
unchanged and still applies.
Master's GROUPS frame support added findPeerGroupEnd(), a second
peer-group scan that compares ORDER BY keys with the raw per-column
equal-range helper. arePeers() now routes GROUPS through the collated
comparison, so the two disagreed about what a peer group is: a collated
GROUPS offset frame counted collation-equal rows as separate groups, and
tripped the equal-range sortedness check in debug builds.

Both scans now go through orderByEqualRangeEnd(), which picks the
collated or the raw probe once, so RANGE and GROUPS cannot diverge.

Also extends the regression test with the two cases it could not reach:

- cross_block: every collated case used a single-row arrayJoin source,
  which cannot span blocks, so the comparison against a reference row in
  another block was never exercised. A numbers() source with
  max_block_size = 1 does span blocks.
- groups: covers the scan above. Reverting only findPeerGroupEnd() to the
  raw helper reddens this case and leaves cross_block passing.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged master to resolve the conflict, and extended the fix to cover a site master added in the meantime.

The conflict was in arePeers: master's GROUPS frame support replaced the frame-type check with a switch that routes GROUPS to the ORDER BY comparison too, so this branch's chassert(frame.type == RANGE) had to go (it would now fire on a valid frame).

That turned up a real gap. GROUPS support also added findPeerGroupEnd, a second peer-group scan that compared keys raw. With arePeers collation-aware and that scan not, the two disagreed about what a peer group is, so a collated GROUPS offset frame split collation-equal rows into separate groups and tripped the equal-range check in debug builds:

SET enable_analyzer = 1;
SELECT count() OVER (ORDER BY v COLLATE 'en-u-kn-true' GROUPS BETWEEN CURRENT ROW AND 1 FOLLOWING)
FROM (SELECT arrayJoin(['1', '01', '1', '01']) AS v);

All four rows are one collated peer group, so each must report 4. Pristine master returns 2, 4 (min/max) and aborts 9 of 15 runs; this branch returns 4, 4 with no aborts. Both equal-range scans now go through one helper, so RANGE and GROUPS cannot diverge.

Two test cases added, each pinned by reverting one part of the fix:

  • groups, for the scan above. Reverting only findPeerGroupEnd reddens this case and leaves the rest passing.
  • cross_block. Every collated case used a single-row arrayJoin source, which cannot span blocks, so the comparison against a reference row in another block was never exercised. A numbers() source with max_block_size = 1 does.

Master's own 04416_groups_window_frame passes. The window and collation suite is unchanged at 104 pass, with 13 cluster tests failing identically on a pristine master binary (clickhouse local serves no cluster). No submodule pins moved.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e0b8fd7

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted) / Invalid number of columns in chunk pushed to OutputPort (STID 2270-3258) trunk bug: a fuzzer-mutated cume_dist() OVER () inside remoteSecure(view(...)) leaves the shard with one column where the initiator expects none (Expected 0, found 1). Breadth 52 rows / 39 distinct PRs / 2 master hits in 30 days, first seen 2026-08-03. #113469 (ours, open)
AST fuzzer (amd_debug, targeted, old_compatibility) / Invalid number of columns in chunk pushed to OutputPort (STID 2270-3258) same signature, remoteSecure(view(... rank() OVER ...)) variant of the same empty-header shape. #113469 (ours, open)
Stress test (amd_debug) / Sizes of nested column and null map of Nullable column are not equal after deserialization (STID 6726-1a46) trunk bug in SerializationNullable::deserializeBinaryBulkWithMultipleStreams (null map size 1, nested column size 0), reached here by an EXPLAIN WHATIF query from 03312_line_numbers. This is the chronic 6726 family: 336 rows / 228 PRs / 24 master hits in 30 days. #112484 (ours, open)

None is PR-caused. This PR changes only RANGE-frame peer comparison in WindowTransform plus its
own new test; both fuzzer signatures predate it on unrelated carriers, and the serialization abort
is on a query with no window function at all.

Session id: cron:our-pr-ci-monitor:20260814-200000

@groeneai groeneai added the groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect label Aug 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-window-functions Window function execution + frame handling (ROW_NUMBER/RANK/LAG/LEAD, frames, partitions, order). label Sep 4, 2026
@groeneai
groeneai requested a review from Michicosun September 29, 2026 12:17
Routing every ORDER BY peer comparison through one collation-aware helper
made `arePeers` too costly to inline into the per-row loop (inline cost 305
vs threshold 250; master was 230) and left the equal-range scan out of line
(cost 925), so every row of every RANGE/GROUPS window paid two extra calls,
with or without COLLATE. The PR's arm perf check measured it:
window_function_with_order ClickHouse#2/ClickHouse#3 +19%/+16%, window_transform ClickHouse#8 +17%.

The collated comparisons now live in NO_INLINE `...WithCollation` helpers
taking `RowNumber` by value, reached through an `unlikely` branch, so the
raw path is master's loop again and `inputAt()` is only evaluated inside it
(evaluating it up front cost 1-row partitions ~15%). `arePeers` and
`orderByEqualAt` are ALWAYS_INLINE because any collation-aware version pays
the cold call's inline penalty, which master's 20-point margin cannot absorb.

Codegen checked on the CI arm64 binaries and on local x86 ThinLTO builds:
`work()` again makes no calls to the peer helpers on the uncollated path.
Local x86 A/B (15 interleaved rounds): the PR head was 7-18% slower on the
window perf queries, this change is within noise of master on all of them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai and others added 3 commits October 7, 2026 12:26
…Params peer check

Master's window refactor (ClickHouse#122762, ClickHouse#123260, ClickHouse#123737) moved the peer comparison into
WindowTransformParams::arePeers and added SlidingIndexes, which marks peer-group starts for every
RANGE and GROUPS frame with raw compareAt / getEqualRangeEndAssumeSorted. The input is sorted with
the ORDER BY collator, so collation-equal values that differ in bytes (for example 'a' and 'A'
under 'en-u-ks-level2') are interleaved, and the raw scan either cuts a peer group short or trips
the debug check "Equal values are not contiguous within the range assumed to be sorted". Since
ClickHouse#123737 this aborts deterministically for an ordinary collated rank():

    SELECT rank() OVER (ORDER BY x COLLATE 'en-u-ks-level2')
    FROM (SELECT if(number % 2, 'a', 'A') AS x FROM numbers(1000))

The previous version of this fix lived in WindowTransform methods that the refactor removed, so
it is re-done on the new structure. WindowTransformParams gets the collation flag and two helpers,
haveEqualOrderByValues and getOrderByEqualRangeEnd, and every ORDER BY peer comparison goes
through them: arePeers (cume_dist and the GROUPS cross-block check), the SlidingIndexes block
boundary and in-block scan, the RANGE frame-end check and scan, and the GROUPS peer-group scan.
PARTITION BY keys stay raw, as PARTITION BY cannot carry COLLATE.

The helpers are inline in the header with the collated comparison in out-of-line cold functions,
so an uncollated window keeps the inlined raw comparison of master: the earlier out-of-line
version of these calls cost 15-19% on window_function_with_order in the arm performance check.

The test gains the deterministic 1000-row case above (also for GROUPS), a cume_dist case and a
one-row-per-block rank() case, so each of the six comparison sites has an assertion that fails
when only that site compares raw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-collate-range-peers

Master reworked `WindowTransform`: peer groups are now computed only in `assignPeerGroupIndexes`
in `SlidingIndexes.cpp`, and the old `arePeers`, `advanceFrameEndCurrentRow` and
`findPeerGroupEnd` code paths are gone. Took master's versions of the conflicted files and
re-applied the fix there: `WindowTransformParams` gets `has_order_by_collation`,
`haveEqualOrderByValues` and `getOrderByEqualRangeEnd`, and both ORDER BY peer comparisons in
`assignPeerGroupIndexes` (the block boundary check and the in-block scan) use them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Michicosun

Copy link
Copy Markdown
Member

I will fix it myself

@Michicosun Michicosun closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-window-functions Window function execution + frame handling (ROW_NUMBER/RANK/LAG/LEAD, frames, partitions, order). groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Peer-group index ignores COLLATE: cume_dist of last row < 1

3 participants