Skip to content

Do not keep an IN set placeholder alive for INTERPOLATE - #118420

Merged
alexey-milovidov merged 1 commit into
masterfrom
interpolate-keeps-set-placeholder-112030
Sep 6, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
interpolate-keeps-set-placeholder-112030

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

INTERPOLATE keeps every column of the step below alive, because its expressions may name any of them. The
Set placeholder of an IN predicate is not one of those: its name is internal, no expression can name it,
and it cannot be materialized. Kept as an output it travelled past the filter that consumes it into every
step above, including ones that build rows out of the whole header:

SELECT a, k FROM coal FINAL WHERE dictGet('dict', 'val', toUInt64(k) % 500) >= 6
ORDER BY k WITH FILL FROM 0 TO 38 INTERPOLATE (a AS 7)
SETTINGS optimize_move_to_prewhere_if_final = 1;
-- Code: 246. DB::Exception: SummingSortedAlgorithm failed to read row 0 of column 1 (__set_...),
--   reason: Cannot get value from Set: While executing CoalescingSortedTransform. (CORRUPTED_DATA)

optimize_inverse_dictionary_lookup (on by default) is what turns the dictGet comparison into a membership
test against such a set, and optimize_move_to_prewhere_if_final is what puts it under the FINAL merge. The
virtual row of an in-order read hit the same placeholder from the other side (#111831, fixed in the virtual
row itself).

A Set column - and the Function column of a lambda, which is a placeholder in the same way - is no longer
kept for INTERPOLATE, so neither reaches a step that materializes rows.

Closes: #112030
Related: #111831

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 to CHANGELOG.md):

Fixed CORRUPTED_DATA ("Cannot get value from Set") for a FINAL query with ORDER BY ... WITH FILL INTERPOLATE whose filter is an IN set moved into PREWHERE: the set placeholder column is no longer kept
alive past the filter.


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

Version info

  • Merged into: 26.9.1.872 (included in 26.9 and later)

`INTERPOLATE` keeps every column of the step below alive, because its expressions may name any of
them. The `Set` placeholder of an `IN` predicate is not one of those: its name is internal, no
expression can name it, and it cannot be materialized. Kept as an output it travelled past the filter
that consumes it into every step above, including ones that build rows out of the whole header:

    SELECT a, k FROM coal FINAL WHERE dictGet('dict', 'val', toUInt64(k) % 500) >= 6
    ORDER BY k WITH FILL FROM 0 TO 38 INTERPOLATE (a AS 7)
    SETTINGS optimize_move_to_prewhere_if_final = 1;
    -- Code: 246. SummingSortedAlgorithm failed to read row 0 of column 1 (__set_...), reason:
    --   Cannot get value from Set: While executing CoalescingSortedTransform. (CORRUPTED_DATA)

`optimize_inverse_dictionary_lookup` (on by default) is what turns the `dictGet` comparison into a
membership test against such a set, and `optimize_move_to_prewhere_if_final` is what puts it under the
`FINAL` merge. The virtual row of an in-order read hit the same placeholder from the other side
(#111831, fixed in the virtual row itself).

A `Set` column - and the `Function` column of a lambda, which is a placeholder in the same way - is no
longer kept for `INTERPOLATE`, so neither reaches a step that materializes rows.

Closes: #112030

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9647d62]

Summary: ✅


AI Review

Summary

The PR fixes the new-planner INTERPOLATE path so internal Set and lambda placeholder carriers are no longer kept alive past the filter and later materialized by WITH FILL / FINAL processing. The code change itself looks targeted, but the added regression does not yet prove the DataTypeFunction half of the fix or even guarantee that the touched planner path is the one being exercised.

Tests
  • ⚠️ [tests/queries/0_stateless/05108_interpolate_keeps_set_placeholder.sql:1] The new regression never pins enable_analyzer = 1, so it does not guarantee CI hits the only changed codepath in PlannerExpressionAnalysis.cpp; the legacy path can still make it pass. It also only constructs the __set_* carrier, leaving the new isFunction() branch unproved. Please add a small analyzer-pinned higher-order-function case that brings a lambda placeholder into the rows reaching INTERPOLATE.
Final Verdict

⚠️ Needs one more focused analyzer regression before merge.

LLVM Coverage Report

Measured on commit 9647d62.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.10% 81.10% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). labels Sep 6, 2026
@@ -0,0 +1,54 @@
-- `INTERPOLATE` keeps every column of the previous step alive, which used to include the `Set`

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.

This regression file does not pin enable_analyzer = 1, so it does not guarantee that CI is exercising the only changed codepath in PlannerExpressionAnalysis.cpp; the legacy InterpreterSelectQuery path can still make the test pass. It also only constructs the __set_* carrier, while the code change adds a second contract for DataTypeFunction. Please force the analyzer here and add a tiny higher-order-function case so the isFunction() branch is covered too.

@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9647d62db with master 4a7f2f7b4 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 6, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 6, 2026
Merged via the queue into master with commit fc1d619 Sep 6, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the interpolate-keeps-set-placeholder-112030 branch September 6, 2026 21:02
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 6, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 4, 2026
`analyzeLimitRange` adds an identity actions-chain step over every column
the previous step makes available, so that columns read only by the
LIMIT AFTER/UNTIL boundary survive chain finalization. That list also holds
the `Function` column of every lambda and the `Set` placeholder of every
`IN` of the projection step, so chain finalization made the projection
output them, and they crossed into the `LimitRange` step header and, on a
shard, into the header sent to the initiator. Three failures follow:

- When the boundary repeats a lambda of the SELECT list, the boundary DAG
  takes that lambda from the header as an INPUT holding the folded
  constant. `removeUnusedActions` retyped that INPUT to a COLUMN in place
  (fixed in the previous commit) and `ExpressionActions::linearizeActions`
  aborted the server on an empty argument vector (STID 3843-5ec7, plain
  local SQL; also aborts the official 26.9.9.28 build).
- `LimitRangeTransform` cuts the chunk, and cutting a constant
  `ColumnFunction` throws NOT_IMPLEMENTED "compareAt is not implemented for
  Function" inside a debug-build assertion.
- A shard sends the lambda column, which has no serialization:
  NOT_IMPLEMENTED on the initiator or, before the previous commit, the same
  abort in `addConvertingActions` (STID 3843-4f7e, 3843-4f98).

Build the identity step over value columns only, skipping the `Set` and
`Function` types. `before_interpolate_actions` already applies this rule
for the same reason (ClickHouse#118420). A boundary expression that needs a lambda or
a set builds its own, as it already did when its lambda text differs from
the SELECT list's. Neither type can be a boundary (boundaries are boolean)
or a SELECT result, so nothing above the step loses a column it reads.

The test is renamed to 05260_limit_after_until_lambda and covers the local
LIMIT AFTER, LIMIT UNTIL and AFTER + UNTIL shapes, the debug-build shape,
the rebuilt-set path, and the two remote shapes, which now return their
rows instead of NOT_IMPLEMENTED.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

2 participants