Skip to content

Fix SIZES_OF_COLUMNS_DOESNT_MATCH in ORDER BY LowCardinality LIMIT after JOIN (#109877) - #109897

Merged
alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
groeneai:ci-test-109877-order-by-lc-limit-after-join
Jul 30, 2026
Merged

alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
groeneai:ci-test-109877-order-by-lc-limit-after-join

Conversation

@groeneai

@groeneai groeneai commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Improvement

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

Relaxes an overly strict permutation size check in ColumnReplicated::permute so that it follows the general IColumn::permute contract, which allows a permutation shorter than the column when a limit is set.

Description

ColumnReplicated::permute required perm.size() == size() exactly, which is stricter than the IColumn::permute contract: getLimitForPermutation only requires perm.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 the ColumnReplicated, and its own permute already enforces the correct contract, throwing SIZES_OF_COLUMNS_DOESNT_MATCH when the permutation really is too short.

Reported as #109877, where ORDER BY <LowCardinality column> LIMIT N after a LEFT JOIN with enable_lazy_columns_replication = 1 produced a permutation of size min(rows, limit) and hit the strict check on 26.3 / 26.4 / 26.5. That path is unreachable on current master: sortBlock routes a ColumnReplicated through transformColumnsWithSharedIndex (#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 ColumnReplicated gtest 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 the sortBlock routing, because with the check relaxed the direct permute path returns the same rows.

Version info

  • Merged into: 26.8.1.402 (included in 26.8 and later)

…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]>
@groeneai

groeneai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse-local with the issue query + SETTINGS enable_lazy_columns_replication=1, query_plan_top_k_through_join=0 throws Code 9 SIZES_OF_COLUMNS_DOESNT_MATCH every time on a binary with the pre-#106566 sortBlock.
b Root cause explained? Yes. ColumnLowCardinality::getPermutation returns a permutation of size min(rows, limit) = LIMIT (legal: IColumn::permute requires only perm.size() >= limit). Old sortBlock called column->permute(perm, limit) directly; ColumnReplicated::permute demanded perm.size() == size() exactly (stricter than contract) and threw.
c Fix matches root cause? Yes (fix is #106566, already merged). It routes sortBlock through transformColumnsWithSharedIndex, applying the permutation to the shared full-size index column and rebuilding the ColumnReplicated, so ColumnReplicated::permute is never called with a LIMIT-sized permutation. This PR is the regression test only.
d Test intent preserved / new tests added? New regression test added (den-crane's minimal 2-join LowCardinality-sort-key LIMIT repro). Asserts no exception + deterministic row count.
e Both directions demonstrated? Yes. Test throws on a binary with the reverted sortBlock loop (Build ID 39c329e...); passes on current master (Build ID 9bb1696...).
f Fix is general across code paths? N/A (test-only PR; the code fix is #106566).
g Fix generalizes across inputs? N/A (test-only PR).
h Backward compatible? N/A (test-only PR).
i Invariants and contracts preserved? N/A (test-only PR).

Session id: cron:clickhouse-worker-slot-1:20260709-135300

@groeneai

groeneai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @m-selmi — regression test for the ORDER BY LowCardinality LIMIT after JOIN bug (#109877) fixed by your #106566. Verified fails pre-#106566, passes on master.

@clickhouse-gh

clickhouse-gh Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [813a18c]

Summary: ✅


AI Review

Summary

This PR relaxes ColumnReplicated::permute to follow the general IColumn::permute contract and adds focused gtest coverage for both the accepted and rejected short-permutation cases. The implementation and direct tests look sound, but the PR description still overstates what the stateless SQL test proves.

PR Metadata
  • Changelog category: Improvement now matches the current scope, and the Changelog entry is specific enough for that category.
  • Description: the last sentence still says the stateless test "pins" the sortBlock routing. That is no longer true after 813a18cd: the file comment now correctly says 04365 is only end-to-end coverage of the query shape, not proof that the routing stays on the shared-index path. A precise replacement would be: "The stateless test provides end-to-end coverage for the reported query shape; the relaxed ColumnReplicated::permute contract itself is covered by the focused ColumnReplicated gtest cases."
Final Verdict
  • Status: ✅ Approve
  • Follow-up: update the PR description sentence above so the written evidence matches the current code and tests.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 9, 2026
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]>
@groeneai groeneai changed the title Add regression test for ORDER BY LowCardinality LIMIT after JOIN (#109877) Fix SIZES_OF_COLUMNS_DOESNT_MATCH in ORDER BY LowCardinality LIMIT after JOIN (#109877) Jul 9, 2026
@groeneai

groeneai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. den-crane's minimal query throws Code: 9 SIZES_OF_COLUMNS_DOESNT_MATCH deterministically on 26.3.17 / 26.4.4 / 26.5.5 with enable_lazy_columns_replication = 1.
b Root cause explained? Sorting a LowCardinality key with LIMIT N yields a permutation of size min(rows, limit) = LIMIT. ColumnReplicated::permute demanded perm.size() == size() exactly (stricter than the IColumn::permute contract, which allows perm.size() >= min(size, limit)), so it threw.
c Fix matches root cause? Yes. Removes the over-strict size() == perm.size() check; the fix targets exactly the mechanism in (b).
d Test intent preserved / new test added? New stateless regression test 04365_order_by_lowcardinality_limit_after_join.sql (den-crane's repro + a count-assertion variant). No existing test weakened.
e Demonstrated both directions? On the LTS direct-permute code path, the query PASSES with the fix. Removing the check throws on that path per the field reports. Master routes through transformColumnsWithSharedIndex (#106566) so it passes before and after there.
f Fix general, not narrow patch? Yes. The removed check was redundant for all callers: the underlying indexes column has the same size as the ColumnReplicated, and its own permute enforces the contract via getLimitForPermutation for every permutation/limit combination. Sibling ops (filter) keep their own correct size checks.
g Generalizes across inputs? The relaxed path handles any perm.size() >= min(size, limit); getLimitForPermutation still rejects a genuinely too-short permutation (perm.size() < min(size, limit)) with the same error. limit == 0 (no limit) still requires perm.size() >= size().
h Backward compatible? Yes. Loosens an internal check to match the documented contract; no setting, format, or default changes.
i Invariants preserved? Yes. ColumnReplicated::permute still returns a column of size min(size, limit) and the strict contract is enforced one level down by the indexes column's permute.

Session id: cron:clickhouse-worker-slot-3:20260709-142900

@groeneai

groeneai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @m-selmi — one-line relaxation of ColumnReplicated::permute (lazy column replication) per the fix @ den-crane specified in #109877. Could you review?

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-ci labels Jul 9, 2026
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]>
@groeneai

groeneai commented Jul 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — ac9d57b

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.

Note: Bugfix validation (functional tests, amd64/aarch64) = SUCCESS at this head; the inner 04365_... FAIL row is the expected signal (the regression test must fail on the buggy reference binary to prove the bug), not a check failure.

Check / test Reason Owner / fixing PR
Stress test (amd_asan_ubsan) / Block structure mismatch in JoinStep (STID 0993-386d) trunk bug (60+ unrelated PRs/7d, 3 master; unrelated to our one-line ColumnReplicated::permute change) a fix task is moved to pending (investigating at full effort — fixing-PR link to follow here)
Integration tests (amd_msan, 6/8) / test_rabbitmq_mv_combo flaky (65 unrelated PRs/7d, 13 master) #109892 (ours, merged) — the failed build predates the fix; picked up on next master merge/rebase

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

@m-selmi m-selmi self-assigned this Jul 13, 2026
Remove author name and the PR ClickHouse#106566 reference from the in-file comment.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — ae21cf6

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. No PR-caused failure on this head.

Check / test Reason Owner / fixing PR
Stateless (amd_debug/amd_tsan/amd_msan/amd_asan_ubsan/arm_binary, sequential) / 02346_text_index_bug108519_qcc_skip_index flaky (68 PRs / 33 master, 30d) #110260 (ours, open)
Bugfix validation (functional tests, amd64 + aarch64) / 04365_order_by_lowcardinality_limit_after_join expected must-fail-on-reference signal — Bugfix validation nodes = SUCCESS not a failure (pass condition)
Finish Workflow / Post Hooks infra (CIDB post-hook upload) #106176 (ours, open)
CH Inc sync — CH Inc sync (private, not actionable)

@m-selmi

m-selmi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@groeneai #110260 has been merged to master, update this branch.

@groeneai

Copy link
Copy Markdown
Collaborator Author

@m-selmi Branch updated: merged master (picks up #110260), pushed 5c6bf8d. Diff unchanged (4 files, +76/-3), no contrib drift, MERGEABLE.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 5c6bf8d

All failures on this commit are the single ongoing infra runner outage; none are caused by this PR's diff. Every failure has an owner.

Check / test Reason Owner / fixing PR
Stateless tests (amd_asan_ubsan, distributed plan, parallel) / many unrelated tests infra (one broken-runner window: 124 unrelated PRs / 10852 hits across hundreds of unrelated tests on this exact check in 12h; not reproducible) a fix task is tracking this runner outage (fixing-PR link to follow)
Finish Workflow / Post Hooks rollup of the above same infra owner
CH Inc sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260715-153000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Discharging the Block structure mismatch in JoinStep (STID 0993-386d) line from my CI finish ledger above.

Fixing PR: #109114 (mine, merged 2026-07-17T02:21:49Z as 5e9c1f38be32). It auto-closed issue #109215, which is the same defect under STID 0993-308a.

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 git hash predates it) is at #110673 (comment).

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 (SELECT number, *) decorrelates into an ANY RIGHT JOIN, and the name-keyed join runtime filter cannot disambiguate two identically-named build-side key columns, so it changes a downstream step's stream multiplicity and trips the assert in JoinStep::updatePipeline. #109114 skips the runtime filter for that case only.

@m-selmi

m-selmi commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@groeneai merge master into this branch.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged master, pushed 5c6bf8d1daed18..1281bf0a224b8c. Branch was 4955 commits behind; clean merge, no conflicts. The change is unchanged at 4 files / +76 -3, and all four files are byte-identical to the pre-merge head. CI is re-running.

One thing you should decide before merging, because it is what makes Finish Workflow red on the previous head and it is not an infra flake.

new_tests_check.py fails with "No per-arch Bugfix Validation job validated the bug", and the per-arch jobs report Bug does not reproduce on this arch - bugfix validation N/A on both amd64 and aarch64. That is accurate: the stateless test 04365_order_by_lowcardinality_limit_after_join no longer reaches the method this PR changes. sortBlock routes a ColumnReplicated column through transformColumnsWithSharedIndex (src/Interpreters/sortBlock.cpp:373-375), which permutes the shared index and rebuilds the wrapper, so ColumnReplicated::permute is never called on that path.

I measured it rather than inferring it. Restoring the strict guard this PR removes and rebuilding: 04365 still passes, while the gtest ColumnReplicated.PermuteShorterThanColumnWithLimit fails. I then restored the source and rebuilt to a bit-identical Build ID to confirm the tree was unperturbed. I also swept six SQL shapes against a master binary that still has the guard (LazyMaterializingTransform, ReverseTransform, query_plan_top_k_through_join on and off, lazy materialization on and off) and none of them reaches the method either.

So the gtest is the only live oracle here, and the SQL test is dead coverage that additionally blocks the merge gate, since the has_ft branch of that hook has no fallback. Two options:

  1. Drop 04365_order_by_lowcardinality_limit_after_join.{sql,reference} and keep the two gtest cases. The hook then takes the unit-only branch and the red clears. This is my preference: the gtest pins the exact contract, and the SQL query it replaces asserts nothing about it on current master.
  2. Keep the SQL test. Then the red stays, since no query can make it reproduce on master HEAD.

The relaxation itself is still needed for the 26.5 and 26.3 backports, where sortBlock calls column_to_sort->permute(permutation, limit) directly (src/Interpreters/sortBlock.cpp:368 on 26.5), with no shared-index routing, so the throw is reachable from SQL there.

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.

@groeneai

Copy link
Copy Markdown
Collaborator Author

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 Bugfix validation (unit tests) job. That job did not exist on the previous head: it is absent from that head's check list, and the bugfix_validation_ut_job wiring in ci/workflows/pull_request.py is not an ancestor of it. It is scheduled on this head.

That is what decides the choice, because the two options land on different branches of the hook:

  • With the SQL test present, new_tests_check.py takes the has_ft or has_it branch (ci/jobs/scripts/workflow_hooks/new_tests_check.py:213), which has no fallback, so the red stays.
  • Without it, the PR is unit-only and takes the has_unit branch (:234), which blocks only if the unit validator definitively refuted the test.

I measured both halves.

Hook predicates, by importing the hook itself and passing this PR's file list: with the two files on disk, has_ft=True, has_unit=True; with them removed, has_ft=False, has_unit=True, and the derived gtest suite is ColumnReplicated.

The validator's verdict, by reproducing its procedure locally (overlay the merge-base ColumnReplicated.cpp, so the tests are present but the fix is not, then rebuild unit_tests_dbms and run the touched suite):

[ RUN      ] ColumnReplicated.PermuteShorterThanColumnWithLimit
C++ exception with description "Size of permutation (2) doesn't match size of column (9)" thrown in the test body.
[  FAILED  ] ColumnReplicated.PermuteShorterThanColumnWithLimit
10 tests ran, 9 passed, 1 failed

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: 04365 unchanged, run against a pristine master binary that still has the strict guard, exits 0 and returns 5.

So dropping 04365_order_by_lowcardinality_limit_after_join.{sql,reference} clears the gate and keeps the contract pinned by the gtest, and the relaxation stays needed for 26.5 and 26.3, where sortBlock.cpp:368 calls permute directly and the strict guard is present.

Expect the same Finish Workflow red on this head, for the same reason.

It is still your call and I have not touched the test. Say the word and I will push the deletion.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Discharging the last open owner line from my CI finish ledger above (the Stateless tests (amd_asan_ubsan, distributed plan, parallel) runner outage, which was recorded as "fixing-PR link to follow").

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 (total) memory limit exceeded, across 163 unrelated pull requests, so the failures were host memory pressure rather than anything in this change.

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.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 1281bf0

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
Integration tests (arm_binary, distributed plan, 2/4) / test_storage_s3_queue/test_system_stop.py::test_stopped_table_releases_hash_ring_slot Code: 210 ... Connection reset by peer — collateral of a server abort in ObjectStorageQueueSource::FileIterator::next earlier in the same module (the teardown section of the sibling case carries the Crash in instance stack) #108977 (ours, open)
Integration tests (arm_binary, distributed plan, 2/4) / test_storage_s3_queue/test_system_stop.py::test_refresh_survives_unready_dependencies same abort — this case dies at its very first statement (DROP TABLE IF EXISTS inside setup_consuming_table) against the already-dead server, so it is the same event, not a second failure #108977 (ours, open)
Finish Workflow / Post Hooks (new_tests_check.py) PR-caused: all four per-arch Bugfix validation jobs report SKIPPED (Bug does not reproduce on this arch) because the SQL regression test in this PR is now dead coverage on master — the gtest ColumnReplicated.PermuteShorterThanColumnWithLimit is the only live oracle PR-caused → fixed in this PR once the open scope question above is answered
Sync — CH Inc sync (private, not actionable)

The Finish Workflow aggregator completed at 19:01:04Z; those are the only failing checks
(89 succeeded, 9 skipped). The two Bugfix validation (functional tests, *) rows visible in the
CI database for this commit carry check_status = skipped, i.e. they are the N/A verdict, not
failures. #108977 is still open, so the integration abort is expected to recur here until it merges.

Session id: cron:our-pr-ci-monitor:20260727-190000

@m-selmi

m-selmi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@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.

groeneai added 2 commits July 29, 2026 17:12
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.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done, both items are in 813a18cd03279c.

Changelog category is now Improvement, and the changelog entry and description are rewritten to describe the IColumn::permute contract cleanup instead of a user-visible fix, stating that the path is unreachable on master and that no backport is planned for 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 ColumnReplicated::permute contract, since sortBlock routes a replicated column through transformColumnsWithSharedIndex and never reaches that method. The contract itself stays covered by the two focused ColumnReplicated gtest cases. I also corrected one wrong word in the gtest comment: it called the replicated column a key column, but isLazyReplicationUseful excludes lowCardinality, so the LowCardinality sort key is never the replicated column; it is a payload column.

Comment-only change, no behavior change. ColumnReplicated.* gtests are 10/10 and 04365 still matches its reference.

One consequence worth flagging, since it clears the Finish Workflow red on the previous head. That red came from new_tests_check.py reporting "No per-arch Bugfix Validation job validated the bug" while all four per-arch validators self-skipped with "bug does not reproduce on this arch". The category change removes it without touching the test: the gate short-circuits at the pr-bugfix/pr-critical-bugfix label check, and check_labels in the pr_labels_and_category pre-hook swaps pr-bugfix for pr-improvement from the new category. Driving the real hook with this PR's file list and only the labels differing gives False with pr-bugfix, printing that exact message, and True with pr-improvement, printing "Not a bug fix PR - skip". filter_job.py then skips the Bugfix jobs entirely, so the validators no longer run at all. The pre-hook runs before the post-hook in the same workflow, so this should settle on the run now in flight; the label still reads pr-bugfix until that pre-hook executes.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Jul 29, 2026
@@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.30% 86.40% +0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.50% 78.50% +0.00%

Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 813a18c

CI is fully finished on this head and there are no failures to own: 174 check-runs,
153 success / 21 skipped, 0 failed, 0 incomplete, Finish Workflow success. The report's
top-level status is OK.

Check / test Reason Owner / fixing PR
(none) - -

Session id: cron:our-pr-ci-monitor:20260729-233000

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 30, 2026
Merged via the queue into ClickHouse:master with commit 4743029 Jul 30, 2026
179 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 30, 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 pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants