Repository navigation
Fix SIZES_OF_COLUMNS_DOESNT_MATCH in ORDER BY LowCardinality LIMIT after JOIN (#109877) - #109897
Conversation
…ckHouse#109877) ORDER BY a LowCardinality column with LIMIT below the row count, after a LEFT JOIN using lazy column replication, produced a permutation of size min(rows, limit) that ColumnReplicated::permute rejected with SIZES_OF_COLUMNS_DOESNT_MATCH. Fixed on master by ClickHouse#106566, which routes sortBlock through transformColumnsWithSharedIndex. This adds den-crane's minimal repro from the issue as a stateless regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260709-135300 |
|
Workflow [PR], commit [813a18c] Summary: ✅
AI ReviewSummaryThis PR relaxes PR Metadata
Final Verdict
|
ColumnReplicated::permute required perm.size() == size() exactly, which is stricter than the general IColumn::permute contract. ORDER BY <LowCardinality column> LIMIT N after a LEFT JOIN with lazy column replication passes a permutation of size min(rows, limit) = LIMIT, so the check threw SIZES_OF_COLUMNS_DOESNT_MATCH (Code 9) on 26.5 and 26.3 LTS. Remove the redundant check: the underlying indexes column has the same size as the ColumnReplicated, and its permute already enforces the correct contract via getLimitForPermutation (throws when perm.size() < min(size, limit)). Master already avoids the throw by routing sortBlock through transformColumnsWithSharedIndex (ClickHouse#106566), so this is a minimal, backportable fix for the LTS branches. Regression test pins the query on master. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260709-142900 |
The stateless SQL test does not exercise the relaxed permute contract on master: sortBlock routes replicated columns through transformColumnsWithSharedIndex, so it stays green even if the permute hunk is reverted. Add two focused unit cases that verify the contract directly: a positive case where perm.size() < size() with limit == perm.size() (permute succeeds), and a negative case where perm.size() < min(size(), limit) (permute still throws). Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI finish ledger — ac9d57bEvery 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 Note:
Session id: cron:our-pr-ci-monitor:20260709-200000 |
Remove author name and the PR ClickHouse#106566 reference from the in-file comment. Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI finish ledger — ae21cf6Every 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
|
…r-by-lc-limit-after-join
CI finish ledger — 5c6bf8dAll failures on this commit are the single ongoing infra runner outage; none are caused by this PR's diff. Every failure has an owner.
Session id: cron:our-pr-ci-monitor:20260715-153000 |
|
Discharging the Fixing PR: #109114 (mine, merged 2026-07-17T02:21:49Z as This PR's head does not yet contain that merge, so the failure recorded above is expected for the build that ran; merging master picks the fix up. Full analysis, including the message-keyed cutoff (435 occurrences before the merge, 3 after, all three on binaries whose own Correcting my own reason column while I am here: I labelled it a "trunk fuzzer bug" with no owner, but the mechanism was specific and fixable, not generic fuzzer noise. A correlated subquery over a relation whose header carries the same column name twice ( |
|
@groeneai merge master into this branch. |
…r-by-lc-limit-after-join
|
Merged master, pushed One thing you should decide before merging, because it is what makes
I measured it rather than inferring it. Restoring the strict guard this PR removes and rebuilding: So the gtest is the only live oracle here, and the SQL test is dead coverage that additionally blocks the merge gate, since the
The relaxation itself is still needed for the 26.5 and 26.3 backports, where Say which you prefer and I will push it. I did not delete the test in this push since you have already approved the PR and that is a scope change. |
|
Follow-up on my previous comment: option (1) is now measurably safe, and I checked it rather than assuming it. The master merge pulled in #108827 ("Add bugfix check for unit tests", merged 2026-07-20), which adds a That is what decides the choice, because the two options land on different branches of the hook:
I measured both halves. Hook predicates, by importing the hook itself and passing this PR's file list: with the two files on disk, The validator's verdict, by reproducing its procedure locally (overlay the merge-base Restoring the fix rebuilds to a bit-identical Build ID and the suite is 10/10. So the gtest reproduces the bug on the before-binary, which is the outcome that passes, not the definitive FAIL that blocks. One difference worth stating: I built debug and the CI job builds amd_asan_ubsan. The check being removed is a plain compile-time size comparison, so the flavour does not change the result, but I did not run it under that build. I also re-confirmed the dead coverage without needing a mutation this time: So dropping Expect the same It is still your call and I have not touched the test. Say the word and I will push the deletion. |
|
Discharging the last open owner line from my CI finish ledger above (the Fixing PR: #111789 (Max Kainov, merged 2026-07-25). It moves that job from a 32 vCPU / 64 GiB runner to one with 128 GiB, so the sanitizer memory cap sits above the job's aggregate RSS at full concurrency. That is the right owner for what my ledger recorded: on the day of that run, 13260 of the 14133 failing rows on this exact check carried The earlier ledger line called it an infra runner outage without naming a cause. The more precise statement is that the runner was correctly sized for the job's concurrency but not for the accumulated ASan RSS, which is the term that PR fixes. That merge is now an ancestor of this branch, so it should not recur on this head. |
CI finish ledger — 1281bf0Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20260727-190000 |
|
@groeneai This bug is unreachable on master and will not be backported for now. Reframe the PR as improvement: update the Changelog category and rephrase the comment in the stateless test. |
The reported query no longer reaches ColumnReplicated::permute on master: sortBlock routes a replicated column through transformColumnsWithSharedIndex, so the change is an internal contract cleanup rather than a user-visible bug fix, and no backport is planned for now. Rephrase the stateless test comment accordingly (state what the test pins today instead of describing a failure that master cannot produce), and call the replicated column in the gtest a payload column, which is what it is: isLazyReplicationUseful excludes lowCardinality, so the LowCardinality sort key is never the replicated column. Comment-only change; no behavior change.
It does not: with the relaxed ColumnReplicated::permute a routing regression that called permute directly would still pass. Say plainly that the test is end-to-end coverage and is not a regression test for the permute contract.
|
Done, both items are in Changelog category is now The stateless test comment no longer describes a failure master cannot produce. It now says what the test actually is: end-to-end coverage of the reported query, explicitly not a regression test for the relaxed Comment-only change, no behavior change. One consequence worth flagging, since it clears the |
| @@ -0,0 +1,45 @@ | |||
| -- End-to-end coverage for ORDER BY <LowCardinality column> LIMIT N after a | |||
| -- LEFT JOIN with lazy column replication: the query must return its rows. | |||
| -- This does not exercise the relaxed ColumnReplicated::permute contract, and | |||
There was a problem hiding this comment.
These file comments are accurate now, but the PR description still ends with The stateless test pins the reported query so the sortBlock routing keeps holding. That is the exact claim the last commit backed out here: after the ColumnReplicated::permute relaxation, a routing regression back to the direct permute path would still keep 04365 green. Please rephrase the PR body to match these lines and describe this SQL test only as end-to-end coverage of the query shape, not as proof that the sortBlock routing stays in place.
There was a problem hiding this comment.
Agreed, and the situation is stronger than described. I have rephrased the PR body; that sentence is gone.
I checked this by simulating the regression rather than by reading the code. Replacing the transformColumnsWithSharedIndex call in sortBlock with a direct per-column col->permute(permutation, limit) loop leaves 04365 green (rc 0, output matches the reference), so the test indeed cannot detect a routing regression once the size check is relaxed.
While confirming that, I found the test is even further from the contract than the direct-permute framing suggests. A cerr probe inside ColumnReplicated::permute records zero calls for this query on both the real routing and the regressed loop. Lazy replication is active, and transformColumnsWithSharedIndex does see a Replicated(String) column, but the LowCardinality(String) sort key is never the replicated one, since isLazyReplicationUseful excludes lowCardinality (src/Columns/ColumnReplicated.cpp:713). A probe in sortBlock also shows is_identity_permutation true on 12 of 14 calls at limit = 5, so the transform takes the col->cut branch rather than the col->permute branch.
So the SQL test is end-to-end coverage of the query shape only, and the body now says exactly that. The two ColumnReplicated gtest cases remain the only regression tests for the relaxed contract.
I have not deleted the SQL test: keeping it and rephrasing its comment is the disposition the PR assignee ruled on, and the body wording was the part that was out of date. No source file changed in this round.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code |
CI finish ledger - 813a18cCI is fully finished on this head and there are no failures to own: 174 check-runs,
Session id: cron:our-pr-ci-monitor:20260729-233000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Relaxes an overly strict permutation size check in
ColumnReplicated::permuteso that it follows the generalIColumn::permutecontract, which allows a permutation shorter than the column when a limit is set.Description
ColumnReplicated::permuterequiredperm.size() == size()exactly, which is stricter than theIColumn::permutecontract:getLimitForPermutationonly requiresperm.size() >= min(size(), limit), so a shorter permutation is legal when a limit is set. This removes the redundant check. The underlying indexes column has the same size as theColumnReplicated, and its ownpermutealready enforces the correct contract, throwingSIZES_OF_COLUMNS_DOESNT_MATCHwhen the permutation really is too short.Reported as #109877, where
ORDER BY <LowCardinality column> LIMIT Nafter aLEFT JOINwithenable_lazy_columns_replication = 1produced a permutation of sizemin(rows, limit)and hit the strict check on 26.3 / 26.4 / 26.5. That path is unreachable on current master:sortBlockroutes aColumnReplicatedthroughtransformColumnsWithSharedIndex(#106566, first in v26.6.1), permuting the shared index instead. The method is still reachable from C++, so this is an internal contract cleanup rather than a user-visible bug fix, and no backport is planned for now.Covered by two focused
ColumnReplicatedgtest cases pinning both directions of the contract (a shorter permutation with a matching limit succeeds; a permutation shorter than the limit still throws). Those gtests are the only regression tests for the relaxed contract. The stateless test is end-to-end coverage of the reported query shape only: it does not exercise the contract and would not detect a regression in thesortBlockrouting, because with the check relaxed the directpermutepath returns the same rows.Version info
26.8.1.402(included in26.8and later)