Repository navigation
Conversation
`indexHint` keeps its predicate in its own `ActionsDAG`, not in the children of the node. `ActionsDAG::serialize` wrote only the function name, so a receiver of a serialized plan (`serialize_query_plan = 1` with `process_query_plan_packet`, or `make_distributed_plan`) rebuilt the hint from `FunctionFactory` with an empty DAG. An empty hint is `ALWAYS_TRUE` for index analysis and evaluates to 1, so a query filtered by `indexHint` returned every row instead of the rows of the granules the hint selects, and the hints derived by `optimize_and_compare_chain` / `optimize_or_like_chain` stopped pruning there. `ActionsDAG::serialize` now writes the hint's DAG behind bit 8 of `column_flags`, and `deserialize` rebuilds `FunctionIndexHint` from it. The new required `IndexHintActions` parameter tells whether the stream can carry it; it is a scoped enum so that the old calls passing `input_header` do not compile silently. With `Refuse`, a hint that has a predicate throws `SUPPORT_IS_DISABLED` instead of being dropped. Lambda captures, function constants and nested hints inherit the mode. The steps that ship an `ActionsDAG` (Expression, Filter, Join, LimitRange, Filling, TotalsHaving, and the row-level filter and PREWHERE of ReadFromMergeTree) get a new step version introduced at query plan serialization version 21, which is the 26.11 bump. A build at the same global version without this change refuses those step versions up front instead of misparsing bit 8. ArrayJoin's element filter (only serialized locally), ObjectFilter (old analyzer only), `ReadFromFormatInfo` and the cluster-function schema transform keep their bytes and pass `Refuse`. Toward a peer below 21 a plan whose query contains `indexHint` (written or derived) is sent as SQL through the fallback the execution limits already use: `createLocalPlan` marks the shipped plan with `QueryPlan::setMinSerializationVersion` when its AST contains `indexHint`, and `RemoteQueryExecutor` checks it against the connections. A hint that the AST does not show (only in `additional_table_filters`) reaches the encoder and fails with `SUPPORT_IS_DISABLED` during the upgrade rather than returning wrong rows. The bump also raises `DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_PARALLEL_REPLICAS`, which is tied to the current version, so a 26.11 initiator excludes 26.10 replicas from a plan-shipping parallel-replicas query during the upgrade. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two arms run `make_distributed_plan = 1` with `distributed_plan_fallback_to_local_execution = 0`, so the query cannot silently fall back to local execution. Without the fix both return every row of the table (49695450, 100000); with it the hinted granules only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t test The stateless CI profile (tests/config/users.d/limits.yaml) sets max_rows_to_group_by to 10G. make_distributed_plan refuses an aggregation with a GROUP BY limit, and with distributed_plan_fallback_to_local_execution = 0 that refusal is thrown as SUPPORT_IS_DISABLED, so both arms failed in every stateless job. Set the limit to 0 on these two queries, as other make_distributed_plan tests do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the per-step version comments the constant names already state and a narrating line in RemoteQueryExecutor; condense the two ProtocolDefines.h entries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings over 2 runs: a full pass and a delta recheck that raised none).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261016-161600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261016-131300 |
|
cc @vdimir @davenger, could you review this? With |
|
Workflow [PR], commit [a56d349] Summary: ❌
AI ReviewSummaryThe change preserves the private predicate DAG of Findings
Tests
Missing context / blind spots
Final Verdict |
CI finish ledger - 2fa05fdEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261017-113010 |
…-serialized-plan # Conflicts: # src/Core/ProtocolDefines.h # src/Interpreters/ActionsDAG.cpp
Master now limits the nesting depth of a deserialized ActionsDAG to 1000 levels (ClickHouse#126548), counted through the recursive calls for lambda captures. The predicate of indexHint is deserialized by the same recursion, but the call did not pass the depth, so a QueryPlan packet with nested indexHint nodes was not covered by the limit (only by checkStackSize). Measured on a debug build: chains of 1001, 1500 and 3000 levels were accepted, 5000 was rejected by checkStackSize. Now every chain above 1000 levels gets TOO_DEEP_RECURSION, and 05427 has an indexHint arm at 1500 levels. Also use FunctionIndexHint::tryGet, which ClickHouse#126219 added on master, instead of the same two casts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes176 object files changed (+887.43 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1061 translation units recompiled, 10695 s compile time in total, 1061 of them have a recent master baseline. |
…-serialized-plan Conflicts: `ProtocolDefines.h` (both sides' version 21 entries kept; plan version stays 21, the 26.11 value), `ActionsDAG.cpp` (master's post-order node walk and `isConstantValueInCacheKey`, with the `IndexHintActions` parameter), `SelectQueryInfo.h` (master's `QueryPlanStepSerialization` spelling). Two new call sites of `ActionsDAG::serialize` on master need the parameter: the filter that `ReadFromCluster` sends to the replicas of a cluster table function (ClickHouse#125615) writes the predicate of `indexHint` (the replica rebuilds the filter with the same release), and the ActionsDAG deserialization gtest refuses it (the DAG has no `indexHint`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#129973 the oldest supported query-plan serialization version is 21: no plan is serialized for a peer below it (`QueryPlan::serialize` throws `NOT_IMPLEMENTED`), so such a peer can no longer receive a plan with the predicate of `indexHint` dropped. The fallback that sent a query containing `indexHint` to it as SQL protected only that case, and made those queries the one exception to the documented failure. Remove it with `QueryPlan::min_serialization_version` and the sentence in `protocol.mdx`. `Refuse` is now reached only from the call sites that never write the predicate (the array join element filter, `ObjectFilterStep`, the prewhere of a file read), so its error no longer names a version that the peer already has. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…able function The filter that a cluster table function sends to its replicas (ClickHouse#125615) is built from the conjuncts that `isSerializableFilterNode` accepts. That check walks the children of a node, but the predicate of `indexHint` is a separate DAG it does not walk. Writing the predicate there made a query fail that works on master: SELECT count() FROM icebergLocalCluster(...) AS t, (SELECT number AS k FROM numbers(1000)) AS n WHERE t.a = n.k AND t.a % 2 = 0 AND indexHint(t.a IN (SELECT number FROM numbers(10))) -- Code: 344. Cannot ship an IN-subquery set to distributed-plan worker tasks (the set is not built) On rows `indexHint` is always true, so before this PR the replicas got a hint rebuilt without its predicate that filtered nothing. Leaving the conjunct out keeps the rows each replica sends unchanged, and the filter is now serialized with `Refuse`, so a hint that reaches it fails instead of being dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The style check requires every query to system.query_log to filter on current_database = currentDatabase(). The replica queries of icebergLocalCluster are logged with current_database = 'default', so they are now selected through the query_id of the initiator, which is scoped to the test database. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A non-empty cluster_table_function_pushed_down_filter does not prove that the ordinary conjunct survived once indexHint is left out. The replicas return 500 of the 1000 rows when t.a % 2 = 0 reaches them and all 1000 when nothing pushable does, so assert sum(result_rows) < 1000, as 05394 does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| auto index_hint = std::make_shared<FunctionIndexHint>(); | ||
| index_hint->setActions(ActionsDAG::deserialize(in, registry, context, max_type_complexity, nesting_depth + 1)); | ||
| function = std::make_shared<FunctionToOverloadResolverAdaptor>(std::move(index_hint)); |
There was a problem hiding this comment.
[Major] Preserve the inferred-hint marker in the round trip
Only the predicate is restored here: the new FunctionIndexHint retains its default implied = false, even when the sender's hint came from createImplied. The receiver optimizes the received plan again, and this flag controls more than diagnostics: tryPushDownFilter permits only implied hints through GROUP BY/LIMIT BY, and ActionsDAG::mergeInplace only rebinds an implied hint's hidden inputs through an expression prefix.
Consequently, a derived hint that still needs those passes on the receiver is treated as user-written. For example, the inferred indexHint(a < 120) from HAVING a < m AND m < 120 (m = max(b)) can no longer cross the aggregation, losing the only pruning condition on a despite preserving its DAG. Alias rebinding is skipped as well.
Serialize and restore isImplied together with the predicate, and cover an inferred hint through a serialized plan with an aggregation or alias prefix; the added tests currently exercise user-written hints only.
Now that the predicate of `indexHint` is serialized with its sets, plan-based parallel replicas ship those sets too, but `dagReferencesUnshippableSubquerySet` only scanned the outer DAG, where the hint has no children. A hint holding an `IN` set that is not shippable was therefore accepted, and serializing the fragment failed: `indexHint(a IN (SELECT ... FROM generateRandom(...)))` on a key column reached `Cannot serialize FutureSetFromSubquery with no query plan` (LOGICAL_ERROR, the set was built in place by index analysis), on another column `ReadFromStorageStep serialization is implemented only for StorageSystemOne`. The same happened for such a hint inside a lambda body, and inside the subquery plan of another `IN` set (`b IN (SELECT a FROM t WHERE indexHint(a IN (...)))`), neither of which the check visited. Master keeps the fragment remote and answers all of these, since it does not ship the hint's sets at all. The check now descends into every DAG `ActionsDAG::serialize` writes inside a node (a lambda body, as a function or as a folded constant, and the predicate of `indexHint`) and into the sets referenced by a shipped set's own plan, so such a fragment stays local, while a hint whose set is shippable is still distributed. The last part also keeps local a plain nested `IN` whose inner source cannot be serialized, which failed the same way on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…an fragment
`LimitRangeStep::serialize` and `FillingStep::serialize` write their DAGs, now
with the predicate of `indexHint`, but `checkQueryPlanActionDAGs` did not visit
them. A hint holding an unshippable set there, inside an `IN` subquery of a
plan-based parallel replicas query, passed the preflight and the fragment
failed to serialize (`NOT_IMPLEMENTED` for `generateRandom`), where master
answers because it drops the hint's DAG. The same walk also keeps local a
plain such set in those steps, which failed on master too.
Example (05404 settings): `b IN (SELECT number FROM numbers(10) LIMIT 3 AFTER
indexHint(number IN (SELECT length(x) FROM generateRandom('x String', 1, 0, 1)
LIMIT 3)))` -> master 303, previous head NOT_IMPLEMENTED, now 303 (kept local);
a shippable hint there still runs on the replicas.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The planner names a hint column by its column identifier (`__table1.a`)
when the query also reads that column, and always for a non-MergeTree
source. A local read maps the identifiers back to column names before
index analysis (`SelectQueryInfo::buildNodeNameToInputNodeColumn`, from
the planner context). A read rebuilt from a serialized plan has no planner
context, so the map was empty, the hint kept `__table1.a`, `KeyCondition`
found no key column and the receiver read every granule:
`SELECT sum(a), count() FROM remote('127.0.0.2', db, t) WHERE indexHint(a < 10)`
returned `49950000 100000` with `serialize_query_plan = 1` and `4740 1024`
without it.
The sender's read steps now carry the (identifier, column name) pairs of
the local map: `ReadFromTableStep` and `ReadFromTableFunctionStep` (step
version 1, remote and Distributed tables), `ReadFromSystemNumbersStep`
(step version 1, a numbers read in a shipped join) and `ReadFromMergeTree`
(inside the unreleased step version 2, plan-based parallel replicas and
`make_distributed_plan`). The receiver keeps a pair only when its own
storage snapshot has the column, typed as stored there, and
`buildNodeNameToInputNodeColumn` returns that map when there is no
planner context, so `buildFilterActionsDAG` and both `applyFilters` stay
as they are. A hint through a subquery alias still does not prune, on any
path, as before.
05404 gains the sqp0/sqp1 pairs for a hint on a read column (WHERE and
PREWHERE) and on `remote(..., numbers(100000))`, the subquery-alias
parity pair, a `make_distributed_plan` line, and plan-based parallel
replica lines incl. a hint on the `numbers` side of a shipped join. On
the previous head every new sqp1, `make_distributed_plan` and
`parallel_replicas_local_plan = 0` line returned all rows.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`query_plan_optimize_join_order_randomize` is nonzero in 95% of randomized runs; a randomized join order can keep the `numbers` join on the initiator, and then the `JoinLogical` check of the shipped join fails (11 of 50 randomized runs, all on that one line, with the trigger isolated to that setting alone). Pin it on the two join queries only: 0 of 50 with the pin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Plan-based parallel replicas with `serialize_query_plan = 0` fuse a filter
into an `ArrayJoin` step (`tryFuseFilterIntoArrayJoin`) and can ship that
step, e.g. on the broadcast side of a shipped join. `ArrayJoinStep::serialize`
wrote the element filter with `IndexHintActions::Refuse`, so an `indexHint`
inside a lambda that captures the joined element (it stays in the lambda's
DAG, so the whole filter fuses) threw `SUPPORT_IS_DISABLED` where master
answers:
SELECT count(), sum(l.b) FROM t AS l
INNER JOIN (SELECT number AS k FROM numbers(20) ARRAY JOIN [number] AS elem
WHERE arrayExists(y -> y = elem AND indexHint(y < 10), [elem])) AS r
ON l.a = r.k
Give `ArrayJoin` step version 1 at
`DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_INDEX_HINT_ACTIONS`, which
writes hint predicates like `Filter`; the reader needs no change
(`ActionsDAG::deserialize` reads the hint flag at any step version). The
parallel-replicas preflight already walks the element filter and its nested
DAGs, so an unshippable set inside such a hint still keeps the query local.
Cache keys are unchanged: `ActionsDAG::serialize` skips the hint branch for
`for_cache_key`.
05404 gains that query and an EXPLAIN check (05138 style) that the fused
`ArrayJoin` is in the shipped fragment; both pin `serialize_query_plan = 0`
because fusion is skipped for serialized plans (the distributed-plan CI lane
sets it to 1).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The function already returns early when `planner_context` is null. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-serialized-plan # Conflicts: # src/Processors/QueryPlan/ReadFromTableStep.h # src/Storages/SelectQueryInfo.h
Master enabled `modernize-use-nodiscard` as an error, which flags the three const getters this PR adds (`ReadFromTableStep`, `ReadFromTableFunctionStep`, `SelectQueryInfo::getColumnIdentifiers`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review of this push by an independent model (engine: codex; 3 findings on the first pass, 0 on the recheck after the fix round, 1 on the recheck after the master merge).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261116-031600 |
|
cc @novikd, could you review this? indexHint keeps its predicate in its own ActionsDAG, which plan serialization dropped, so with serialize_query_plan = 1 a remote server read every granule; the DAG-carrying steps now write the hint's DAG at plan version 21, and the read steps carry the column identifiers the hint maps back to columns. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261115-231000 |
CI finish ledger - a56d349Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261116-073013 |
|
Fixing PR for the |
…me_destination The `http-False` variant of `test_async_backups_to_same_destination` runs `BACKUP TABLE tbl TO <dest> ASYNC` without `ON CLUSTER` on node1 and node2 right after the `INSERT` on node1. Such a backup contains only the parts of the local replica, and only one of the two backups to the same destination succeeds. When node2's backup won before node2 had fetched `all_0_0_0`, the successful backup held only the table metadata (`num backup entries=1` in node2's log), `RESTORE` on node1 created an empty table, and the final check failed with `assert '' == '1\n'`. Run `SYSTEM SYNC REPLICA ON CLUSTER 'cluster' tbl` after the insert, as the other tests of this file do. The two backups still race for the destination. CI reports: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126329&sha=a56d34954af566916a3978497a004b351f6e2642&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%202%2F5%29 (ClickHouse#126329) https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109453&sha=806162ffe23baed3bee142174285056d8247ab1d&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%202%2F5%29 (ClickHouse#109453) Related: ClickHouse#89141 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #126219
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
indexHintlosing its predicate when the query plan is sent serialized (serialize_query_plan = 1), which made a remote server return rows outside the granules the hint selects.Description
On 26.8.21.12,
SELECT sum(b), count() FROM remote('127.0.0.2', db, t) WHERE indexHint(a < 10) SETTINGS serialize_query_plan = 1(remote server withprocess_query_plan_packet = 1) returns every row instead of the hinted granules' rows.indexHintkeeps its predicate in its ownActionsDAG, not in the node's children.ActionsDAG::serializewrote only the function name, so the receiver rebuilt an empty hint, which selects every granule.make_distributed_planlost it the same way.The change:
ActionsDAG::serializewrites the hint's DAG behind a newcolumn_flagsbit, anddeserializerebuilds the hint from it. A requiredIndexHintActionsparameter says whether the stream can carry it;Refusethrows.ActionsDAGgets a new step version at plan serialization version 21. A peer below 21 gets no plan since Remove the binary settings serialization from the query plan #129973.indexHintout: the hint is always true on rows and may hold an unbuilt set.LIMIT ... AFTERandINTERPOLATE) cannot be shipped.numbersselects the same granules remotely.ActionsDAG.Validation: the new test fails on master and passes with the fix (also
make_distributed_planwithout local fallback, hints on a read column and onnumbers). It guards the new shipping paths: a cluster table function query that fails if its filter carries the hint, plan-based parallel replicas with unshippable sets in hints, a hint in a shippedARRAY JOINfilter.05427_query_plan_deserialize_deep_recursiongets a case with 1500 nested hints.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126329]