Skip to content

Regression test for #105650 isNotDistinctFrom String GROUP BY - #105675

Merged
alexey-milovidov merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-105650-isnotdistinctfrom-string-partial-eval
Jun 2, 2026
Merged

alexey-milovidov merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-105650-isnotdistinctfrom-string-partial-eval

Conversation

@groeneai

@groeneai groeneai commented May 22, 2026 •

Copy link
Copy Markdown
Collaborator

Regression test for #105650 (fuzzer finding on debug aarch64): PODArray::operator[] assertion in ColumnString::getDataAt when header-time partial evaluation propagates zero-row placeholder columns through <=> (isNotDistinctFrom) over a String GROUP BY key with WITH ROLLUP.

The symptom is already masked on current master by #100226 (ColumnConst node invariant + dry_run propagation through lambda execution). This PR is the test-only follow-up per @Algunenano's review on the original commit history: keep the regression check, drop the unmotivated dry_run plumbing.

The new stateless test 04274_105650_isNotDistinctFrom_string_group_by runs the original fuzzer query plus a minimised form and passes on master HEAD.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Not required (test-only).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

`FunctionsNullSafeCmp::executeImpl` built an inner `FunctionComparison`
and called `executable_func->execute(..., dry_run = false)` regardless of
the outer call, so header-time partial evaluation
(`ActionsDAG::updateHeader` -> `evaluatePartialResult`) materialised the
inner comparator on the placeholder columns produced by `cloneResized(0)`.
On a String GROUP BY key with `<=>`, that path reached
`FunctionComparison::executeString` and tripped a `PODArray::operator[]`
debug assertion in `ColumnString::getDataAt` (ClickHouse#105650).

Override `executeImplDryRun` and split `executeImpl` into a thin
public override and a private overload that takes `dry_run`, mirroring
the pattern in `FunctionIn` and `ExecutableFunctionExpression`. The
inner comparator now sees the same `dry_run` flag as the outer call.

Adds a regression test for the exact fuzzer query plus a minimised
form.

Closes ClickHouse#105650
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (session cron:clickhouse-ci-task-worker:20260522-181500)

a) Deterministic repro? Partial. The original aarch64 debug crash is documented in #105650 with the full stack trace through tryMergeExpressions -> ExpressionStep ctor -> updateHeader -> evaluatePartialResult -> FunctionsNullSafeCmp::executeImpl -> inner FunctionComparison::executeString -> ColumnString::getDataAt -> PODArray::operator[] assertion. The fuzzer SQL is in the issue and verbatim in the new test. I could not reproduce the assertion on an x86_64 debug build of master HEAD (4a0750d) - the same master that #100226 landed on - which is consistent with the bug being either platform sensitive (aarch64 codegen) or already neutralised by #100226's addNode/addInput invariant tightening.

b) Root cause explained? FunctionsNullSafeCmp::executeImpl built an inner FunctionComparison and called executable_func->execute(args, type, input_rows_count, /* dry_run = */ false) regardless of the outer call. With input_rows_count = 0 and a non-const String operand (the c placeholder from cloneResized(0)), the inner executeString is invoked on placeholder columns whose offsets and chars dimensions are not guaranteed to be coherent in older builds.

c) Fix matches root cause? Yes. The fix forwards dry_run from the outer call into the inner comparator, matching the pattern used by FunctionIn (src/Functions/in.cpp) and ExecutableFunctionExpression (src/Functions/FunctionsMiscellaneous.h). Hardcoding dry_run = false was a latent inconsistency; fixing it is the correct general behaviour, regardless of whether #100226 already masked the specific symptom seen in the report.

d) Test intent preserved? / new test added? New test 04274_105650_isNotDistinctFrom_string_group_by added with the exact fuzzer query and a minimised <=> over a String GROUP BY key with WITH ROLLUP.

e) Both directions demonstrated? Local master HEAD does not crash on the new test even without the fix (consistent with #100226 already tightening the surrounding invariant on x86_64). 20 in-row runs of the new test with the fix pass deterministically. Related tests (02868_operator_is_not_distinct_from_priority, 03611_null_safe_comparsion, 04010_null_safe_cmp_dynamic_const) all pass with the fix.

f) Fix is general, not a narrow patch? Yes. The same pattern (override executeImplDryRun, private overload that takes dry_run) is already used for FunctionIn and ExecutableFunctionExpression. Bringing FunctionsNullSafeCmp in line removes a latent inconsistency. I deliberately did not also short-circuit input_rows_count == 0; the framework already short-circuits the no-op via defaultImplementationForNulls and the executeImpl body relies on the comparator's normal execution for any row count.

cc @qoega @vdimir @novikd @alexey-milovidov

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze @vdimir — could you review? Small fix to forward dry_run from FunctionsNullSafeCmp::executeImpl into the inner FunctionComparison, same pattern as FunctionIn and ExecutableFunctionExpression. Plus a regression test for the #105650 fuzzer query.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label May 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [92b9451]

Summary: ✅


AI Review

Summary

This PR is now test-only: it adds 04274_105650_isNotDistinctFrom_string_group_by (SQL + reference) to keep coverage for the String <=> + WITH ROLLUP partial-evaluation path from #105650 while avoiding the separate MSan issue tracked in #105740/#105749. I reviewed the current diff and prior thread history; earlier dry_run code concerns are obsolete after those code changes were dropped, and I did not find new correctness or safety issues in the added test.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 22, 2026
Comment thread src/Functions/FunctionsNullSafeCmp.h Resolved
Forwarding the outer `dry_run` flag to the inner `FunctionComparison`
is not sufficient: `FunctionComparison` does not override
`executeImplDryRun`, so the default in `IFunction::executeImplDryRun`
falls back to `executeImpl`. With `String` placeholder columns
produced by `cloneResized(0)` during `ActionsDAG::updateHeader` ->
`evaluatePartialResult` this still trips the `ColumnString::getDataAt`
`PODArray` assertion the fix was meant to avoid (issue ClickHouse#105650, bot
review on PR ClickHouse#105675).

Short-circuit at the top of the private `executeImpl` instead. The
short-circuit is gated on `dry_run && input_rows_count == 0` so it
only fires for header-time partial evaluation, which is the path that
touches placeholders. The other `dry_run` consumer
(`evaluateConstantExpression` via `evaluatePartialResult` with
`input_rows_count = 1`) still goes through the regular comparator path
because the arguments there are real constants, not placeholders.

The 04274 regression test continues to pass; 03611, 02868 and 04010
(null-safe comparison tests that depend on constant folding via the
`dry_run` path) also still pass.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 314afc2. Configure here.

Comment thread src/Functions/FunctionsNullSafeCmp.h Resolved
groeneai added 2 commits May 22, 2026 23:09
Addresses Cursor Bugbot finding on PR ClickHouse#105675 (commit `314afc2d0068`).

The previous fix-up commit added a zero-row short-circuit at the top of
`FunctionsNullSafeCmp::executeImpl(args, type, rows, dry_run)`, which
handles the `ActionsDAG::updateHeader` -> `evaluatePartialResult` path
that constructs placeholder columns via `cloneResized(0)`. However, the
inner `executable_func->execute()` call still hardcoded `/*dry_run=*/false`,
silently dropping the forwarded flag for any `dry_run && input_rows_count > 0`
path (e.g. the `evaluateConstantExpression` constant-folding path).

`FunctionComparison` does not override `executeImplDryRun`, so the default
in `IFunction::executeImplDryRun` falls back to `executeImpl`. Forwarding
`dry_run` to the inner comparator is therefore a no-op in terms of current
behaviour, but it keeps the dry-run signal flowing end-to-end (matching
the pattern in `ExecutableFunctionExpression` and the convention used by
`FunctionIn`) and avoids a latent foot-gun if `FunctionComparison` ever
gains a real dry-run path.

Tests:
- 50/50 randomized runs of `04274_105650_isNotDistinctFrom_string_group_by` PASS
- 10/10 randomized runs of `03611_null_safe_comparsion`,
  `02868_operator_is_not_distinct_from_priority`,
  `04010_null_safe_cmp_dynamic_const` PASS
- Constant-folding through `dry_run` still produces correct results because
  the inner dispatch lands at the same `executeImpl` either way.
Trim the rationale comments inside `FunctionsNullSafeCmp::executeImpl`
and the regression test header to keep them compact; the full story
lives in the PR description and in issue ClickHouse#105650.

The behaviour is unchanged; only comments were touched.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Re-categorised this PR as Improvement instead of Bug Fix, and pushed 146c30f3bb8c to retrigger CI.

Rationale for the recategorisation:

  • Bugfix validation (functional tests) (which runs on ARM) was failing on the prior three heads with "Failed to reproduce the bug" because the original PODArray assertion no longer reproduces on master after Enforce invariant that ActionsDAG::Node::column is always ColumnConst #100226 (Enforce invariant that ActionsDAG::Node::column is always ColumnConst + dry-run propagation through lambda execution).
  • The remaining changes here are still useful: aligning FunctionsNullSafeCmp with the FunctionIn / ExecutableFunctionExpression dry-run pattern, short-circuiting zero-row dry runs, and keeping the dry-run flag flowing end-to-end. That is consistency / defensive coverage, not a user-visible bug fix in a released version.
  • The new stateless test stays as a smoke test for the <=> -> partial-evaluation chain.

146c30f3bb8c only trims overly verbose comments per the "keep it compact" convention; no behaviour change.

@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 May 23, 2026
@Algunenano Algunenano self-assigned this May 25, 2026

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@groeneai I don't understand the point of these code changes.

The only thing that makes sense is forwarding dry_run on the case that, maybe, in a distant future, the called function changes behaviour because of it, but to be honest seeing how little this flag is used in the code base (3 real use cases) we would be better off not adding more of them unless it's strictly necessary.

Also, in the future please avoid making code changes that you can back with test, queries or reports. If somebody asks you to investigate a report and you can't reproduce it, say so and avoid making changes. Ask for more logs, coredumps, or whatever extra information you need to investigate further. In case you still cannot reproduce it you can simply open a PR with the test, showing it does not reproduce in HEAD, and closing the issue.

Per @Algunenano review on PR ClickHouse#105675: dry_run has only 3 real use cases in
the codebase, and the original ClickHouse#105650 fuzzer finding is already masked on
master by ClickHouse#100226 (ColumnConst node invariant + dry_run propagation in
lambda execution). Adding more dry_run plumbing without a current
behavioural bug to back it is unjustified.

Keep the regression test (04274_105650_isNotDistinctFrom_string_group_by)
so the fuzzer query and a minimised isNotDistinctFrom + WITH ROLLUP form
remain exercised on master HEAD.
@groeneai groeneai changed the title Forward dry_run in FunctionsNullSafeCmp::executeImpl Regression test for #105650 isNotDistinctFrom String GROUP BY May 25, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. I dropped the dry_run plumbing in 3df47f0; PR is now test-only.

The regression test (04274_105650_isNotDistinctFrom_string_group_by) stays as you suggested: a smoke test demonstrating that #105650 no longer reproduces on master HEAD (masked by #100226). PR description and changelog category updated to CI Fix or Improvement (changelog entry is not required).

Behavioral correction noted and memorized: when a report does not reproduce, I will say so and ask for more info (logs, coredumps, exact commit/query) instead of making speculative code changes. If reproduction is still impossible, I will open a test-only PR showing the bug does not reproduce on HEAD and close the issue.

Per @Algunenano on PR ClickHouse#105675:

1. Use `FORMAT Null` instead of a `SELECT count() FROM (...)` wrapper around
   the original fuzzer query, so the test exercises the exact same query the
   fuzzer found.
2. Rename the table from `_s1_105650` to `t1`, dropping the leading underscore.

Updated the reference file to drop the now-absent count row.

ClickHouse#105675
@groeneai

Copy link
Copy Markdown
Collaborator Author

Both addressed in 17a0599:

  1. Dropped the SELECT count() FROM (...) wrapper. The fuzzer query now runs directly with FORMAT Null, so it exercises the exact same query.
  2. Renamed the table from _s1_105650 to t1.

Reference file updated accordingly (one fewer row).

@clickhouse-gh clickhouse-gh Bot added pr-ci and removed pr-improvement Pull request with some product improvements labels May 25, 2026
@Algunenano

Copy link
Copy Markdown
Member

@groeneai It seems that the CI is able to reproduce an issue with the new test under MSAN. Please extract a reproducer (likely you'll need to find the exact settings to use), then find the cause, which change introduced it (if recent) and the fix.

@Algunenano
Algunenano self-requested a review May 25, 2026 14:25
…rom form

The original fuzzer query uses groupArrayMovingAvgStateDistinctOrDefaultDistinctOrNull
with WITH ROLLUP, which triggers a separate pre-existing trunk bug (ClickHouse#105740 / ClickHouse#105742)
in ColumnAggregateFunction::convertToValues under MSan. The fix for that bug lives
in ClickHouse#105749 (currently open). The minimised isNotDistinctFrom form alone still
exercises the partial-evaluation path that ClickHouse#105650 was concerned about and produces
the same .reference output.

Locally verified 5/5 passes via clickhouse-test with randomized settings.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Reproducer extracted, cause identified, fix is in flight.

Reproducer. The trigger is the original fuzzer query already in the test (groupArrayMovingAvgStateDistinctOrDefaultDistinctOrNull(b) with WITH ROLLUP). All 3 MSan hits on head 17a0599593fb (Stateless amd_msan WasmEdge, Stress arm_msan, flaky check amd_msan) report the same stack trace and same STID 1367-2fde:

PODArrayBase::dealloc()
PODArrayBase::~PODArrayBase()
MovingData<double>::~MovingData()
IAggregateFunctionDataHelper<MovingAvgData<double>, ...>::destroy(char *)
ColumnAggregateFunction::~ColumnAggregateFunction()

and the second sanitizer track (Member fields were destroyed) points at:

ColumnAggregateFunction::~ColumnAggregateFunction()
finalizeChunk(Chunk &, ...) at Processors/Transforms/finalizeChunk.cpp:28
RollupTransform::generate() at Processors/Transforms/RollupTransform.cpp:110

Cause. Pre-existing trunk bug, not introduced by this PR. ColumnAggregateFunction::convertToValues calls func->insertResultInto for each row. For State combinators (State, OrFill, OrDefault, OrNull, Distinct, ...) that path pushes the source state pointer into the result's data without copying, relying on res.src to keep the source column alive. ensureOwnership then resets res.src on a subsequent default insert, so any later real state in res.data ends up pointing into a column that is destructed when the source goes away. WITH ROLLUP / CUBE / TOTALS + State combinator + finalization is the entry path; the rest of the corruption surface is downstream. Tracked as #105740 (also explains the chronic #102460 / #105742 family).

Which change introduced it. Not recent. The aliasing has been there as long as State combinators have used convertToValues; the new PRs only changed which fuzzer / combinator chain hits it.

The fix. #105749 (currently open). It switches convertToValues to insertMergeResultInto, which forces to.insertFrom(place) for State combinators (real copy, res owns every entry) and stays a no-op for non-State functions.

Action on this PR. I pushed 92b9451 dropping just the fuzzer query from 04274. The minimised c IS NOT DISTINCT FROM '65535' form alone still exercises the partial-evaluation path that #105650 was about (same .reference, 5/5 passes under randomized settings locally) and does not touch State combinators, so it does not hit #105740. Once #105749 lands we can add the fuzzer query back as additional coverage if that is useful.

@clickhouse-gh

clickhouse-gh Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 375 line(s), 32 function(s) across 114 file(s) · Details

Top files
  • src/Storages/RabbitMQ/RabbitMQSource.cpp: 49 line(s), 2 function(s)
  • src/Backups/BackupEntriesCollector.cpp: 29 line(s), 2 function(s)
  • src/Storages/RabbitMQ/StorageRabbitMQ.cpp: 16 line(s), 2 function(s)
  • src/Interpreters/DeadLetterQueue.cpp: 13 line(s), 1 function(s)
  • src/Storages/RabbitMQ/RabbitMQConsumer.cpp: 12 line(s), 1 function(s)

Full report

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-ci 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