Skip to content

Resolve the 25.8 cherry-pick conflict of #112327 - #114814

Merged
PedroTadim merged 1 commit into
ClickHouse:25.8from
groeneai:groeneai/backport-112327-25.8
Aug 20, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:25.8from
groeneai:groeneai/backport-112327-25.8

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

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):

Fixed a use-after-free when a LEFT JOIN to a dictionary with join_algorithm = 'direct' had a join key that is serialized Sparse. getColumnVectorData returned a PaddedPODArray reference into a column owned only by a function-local ColumnPtr, so the dictionary lookup read freed memory.

Description

Backport of #112327 to 25.8. The robot cherry-pick #114796 is CONFLICTING, so the automation cannot carry it.

The conflict is in one file. getColumnVectorData materializes its key column with removeSpecialRepresentations on master and with recursiveRemoveSparse here; removeSpecialRepresentations does not exist on this branch. The resolution keeps 25.8's call and takes the fix's predicate, so the resolved change is the same 8 insertions and 7 deletions as the merged commit. On this branch the copy therefore guards Const and Sparse; ColumnReplicated does not exist here and is dropped from the comment's carrier list.

25.8 is affected. On the official 25.8.30.17 binary the repro (a 2M-row sparse probe joined to a FLAT() dictionary) segfaults in 2 of 7 runs, and with jemalloc junk filling it fails 4 of 4 with Invalid number of rows in Chunk ... expected 65409, got 0. The same data written densely passes. Comparing returned values alone cannot see this, because freed but intact memory still yields the correct numbers.

Verified in both directions with a clang-19 Debug build, this branch's pinned compiler, asserting build ids against the running server. Pristine 25.8 aborts on the first assertion of the ported test, at PODArray::operator[] inside FlatDictionary::hasKeys reached through IDictionary::getByKeys and DirectKeyValueJoin::joinBlock - the mechanism reported on master. With the fix the test passes and the repro returns the correct result in 3 of 3 runs.

One branch adaptation in the test: enable_lazy_columns_replication does not exist on 25.8 and is rejected as an unknown setting, so it is dropped from the ARRAY JOIN statement. The statement and every assertion are kept.

@clickhouse-gh

clickhouse-gh Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [bbfad95]

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (1 round, resolved) and validation detail

Gate B raised one major finding: reusing #112327's description here would promise master-only
behavior (removeSpecialRepresentations, ColumnReplicated, the lazy-replication setting) that
does not exist on 25.8. AGREED - the description above was written for this branch instead.

Validation, in full:

arm binary result
repro, plain official 25.8.30.17 SEGFAULT 2 of 7 runs
repro, jemalloc junk:true official 25.8.30.17 Code: 49 4 of 4 runs
repro, junk:true, dense probe (control) official 25.8.30.17 passes 3 of 3, correct result
repro, junk:true local pristine 25.8, clang-19 Debug aborts 3 of 3
repro, junk:true local 25.8 + fix, clang-19 Debug passes 3 of 3, correct result
04652 via tests/clickhouse-test local pristine 25.8 server aborts on the test's first assertion
04652 via tests/clickhouse-test local 25.8 + fix [ OK ]

Build ids were asserted against the running server for every arm (fix
047be5d0051a2a165df8a85bbfd2b9b4d25b9813, base 2d2eb2e03a2a57d381106585b2be89addd54c957), so no
result was taken from a stale binary.

The abort on pristine 25.8 is PODArray::operator[] (PODArray.h:386) inside
FlatDictionary::hasKeys (FlatDictionary.cpp:226), reached through IDictionary::getByKeys
(IDictionary.h:372) and DirectKeyValueJoin::joinBlock (DirectJoin.cpp:131) - the same mechanism
as the master report, so the ported test is load-bearing on this branch rather than merely present.

The other four automated backports (#114797 26.3, #114798 26.5, #114799 26.6, #114800 26.7)
are MERGEABLE and need nothing; only the 25.8 cherry-pick conflicted.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b1962e7

CI is fully finished on this head: 32 leaves, 28 success, 2 skipped (reused from cache),
0 dropped jobs, and one test failing in two shards. Every failure below has an owner.

Check / test Reason Owner / fixing PR
Integration tests (amd_asan, old analyzer, 6/6) and (amd_tsan, 6/6) / test_storage_s3_queue/test_parallel_inserts.py::test_batch_set_processing_failure_does_not_crash flaky on 25.8 only, unrelated to this diff ready fix in #113728, closed on @ PedroTadim's instruction to leave 25.8 alone

The failure is a 25.8 branch property, not this backport's. Over the last 14 days every
branch-side hit is on 25.8 (24 rows across 13 integration shards, latest 2026-08-14 13:23Z) and
master has none. This diff is src/Dictionaries/DictionaryHelpers.h plus
04652_direct_join_dictionary_sparse_key, which the test does not reach.

Root cause is in the test: on 25.8 the processing-node directory is chosen at runtime from
use_persistent_processing_nodes, which the shared test helper randomizes, so the test plants its
Keeper conflict node in the wrong directory about half the time and times out. #113728 pins that
setting and was closed unmerged on 2026-08-07 after "dont be concerned about the 25.8 branch for
now". That ruling stands, so I am not reopening it or re-deriving the fix; reopening #113728 is all
that is needed if the red should go away.

Coverage on this head is real: 8567 stateless tests passed with 0 failures across the three
amd_asan, distributed plan jobs, Stress test (amd_tsan) reported no errors, and the ten other
integration shards passed 7372 tests with 0 failures.

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

@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexbakharew this is the 25.8 half of #112327, which you merged on master. 25.8 still has the bug on today's tip (8ca297db): getColumnVectorData returns vector_col->getData() from the local recursiveRemoveSparse result, so the dangling reference is unchanged there. 26.7 landed as #114800; 26.3, 26.5 and 26.6 are the robot's #114797, #114798 and #114799, all still open.

The robot could not carry 25.8 because removeSpecialRepresentations does not exist on that branch. The resolution keeps 25.8's recursiveRemoveSparse call and takes the fix's pointer-identity predicate, so the source change is the same 8 insertions and 7 deletions as the commit you merged. CI here has finished; the only failure is a 25.8-only test_storage_s3_queue flake unreachable from this diff, with its owner linked in the ledger above.

Two things worth knowing. This PR carries no pr-backport label, unlike the four robot backports, so it sits outside that bookkeeping. And when the robot cherry-pick #114796 closes for inactivity, cherry_pick.py:273-280 sets _backported and stops retrying 25.8, so this PR becomes the only carrier.

Could you review it, or point me at the right person?

Backport of ClickHouse#112327 to 25.8. The robot cherry-pick (ClickHouse#114796) conflicts in
src/Dictionaries/DictionaryHelpers.h because the materializing call in
getColumnVectorData is removeSpecialRepresentations on master and
recursiveRemoveSparse here; removeSpecialRepresentations does not exist on this
branch. The resolution keeps 25.8's call and takes the fix's predicate, so the
resolved change is the same 8 insertions and 7 deletions as the merged commit.

25.8 is affected. On the official 25.8.30.17 binary the amplified repro (a 2M-row
sparse probe joined to a FLAT dictionary with join_algorithm = 'direct')
segfaults in 2 of 7 runs, and with jemalloc junk filling it fails 4 of 4 with
"Invalid number of rows in Chunk ... expected 65409, got 0". Writing the same
data densely passes. A value comparison alone cannot see this: freed but intact
memory still returns the right numbers, which is why both arms agreed until the
freed page was poisoned.

Verified in both directions with a clang-19 Debug build, 25.8's pinned compiler,
build ids asserted against the running server. The pristine branch aborts on the
first assertion of the ported test, at PODArray::operator[] inside
FlatDictionary::hasKeys reached through IDictionary::getByKeys and
DirectKeyValueJoin::joinBlock, which is the mechanism reported on master. With
the fix the test passes and the repro returns the correct result 3 of 3 runs.

The test carries one branch adaptation: enable_lazy_columns_replication does not
exist on 25.8 and is rejected as an unknown setting, so it is dropped from the
ARRAY JOIN statement. The statement and every assertion are kept. The comment
drops ColumnReplicated from the carrier list because that class does not exist
here.

Co-Authored-By: Claude Opus 5 <[email protected]>
The test comments describe what each statement asserts at the SQL level and no longer
name C++ functions or classes, per the review of the master commit. The statements
and the reference are unchanged: stripping comments from both revisions yields
byte-identical SQL (md5 5a88d22c5d3f4aedbdeb8befef6c0ef9), and both format to the
same AST.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

groeneai-origin-request PR origin: a maintainer pinged or directed groeneai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants