Repository navigation
Conversation
Since ClickHouse#122975 a filter pushed below AggregatingStep / MergingAggregatedStep / LimitByStep refuses every indexHint, because a user-written hint is row-level TRUE and pruning by it below a key step can drop part of a group. That also refuses the hints optimize_and_compare_chain derives (`a < b AND b < 10` adds `indexHint(a < 10)`), and since a hint blocks its ancestors, an OR holding one, so such HAVING / outer WHERE filters read the whole table. A derived hint is implied by the other conjuncts of its `and`, so the granules it prunes contain only rows of groups the filter rejects anyway. Mark such hints in FunctionIndexHint, carry the mark through the planner and buildFilterActionsDAG, and admit only marked hints at key steps. The planner deduplicates equal hints by name, so a user hint equal to a derived one clears the mark of the shared node. Closes ClickHouse#124502 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ConvertOrLikeChainPass rewrites a pure LIKE chain into `and(optimized_or, indexHint(original_or))`. The rewrite preserves results, so `optimized_or` implies the hint, which is exactly the property the implied mark stands for. Without the mark the hint was refused below GROUP BY / LIMIT BY and kept every ancestor above the step, so `HAVING (a < 10 AND (s LIKE '%1%' OR ... 4 substrings)) OR a = 500` still read the whole table. Create both derived hints through `FunctionIndexHint::createImplied`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The arm F granule line also holds when no hint exists, so assert the hint first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A factored hint is implied only if every copy was. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Arm G only checks the final count, so it passes on every build when `optimize_extract_common_expressions` does not factor `indexHint(k < 3)` out of the `OR`: each branch then keeps its own copy and the false-wins rule is never exercised. An EXPLAIN SYNTAX line before it now requires the factored `WHERE and(indexHint(...` form for the same query and settings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An `indexHint` keeps its arguments in a private DAG bound by name, and `ActionsDAG::mergeInplace` rebound only the
filter's own inputs, so below a renaming projection a derived hint kept the outer name, which in a `remote()`
local-replica plan binds to the physical column it shadows. `mergeInplace` now rebinds the private DAG of implied
hints to the outputs that compute those names (user hints are left as they are), so
`SELECT count() FROM (SELECT w AS k, v FROM remote('127.0.0.1', currentDatabase(), t_w) AS t GROUP BY w, v, t.k) WHERE k < v AND v < 3`
returns 5 instead of 0.
The 05401 test gains that query and a derived hint from an outer WHERE pruning through a GROUP BY subquery.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A derived hint lifted below ARRAY JOIN read the array under the element's name, so rebinding it made valid queries throw (J2: `ARRAY JOIN arr GROUP BY arr, v` under an outer `arr < v AND v < 3`), and such a hint is now dropped. A filter made of one hint had no identifiers for the GROUPING SETS check, so a rebound outer hint pruned rows that a set without its key needs (S: 1 row instead of 0), and the hint's own inputs now count as identifiers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`FunctionIndexHint::createImplied` and `FunctionIndexHint::tryGet` are now called from dbms (the analyzer passes, `ActionsDAG`, filter push-down), so targets that link only dbms, such as `format_fuzzer`, failed with undefined symbols. Move the file to `DBMS_FUNCTIONS` like the other helpers dbms uses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (rounds 1-7)Bounce cap reached: published as is; residual findings listed below.
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261016-051100 |
|
Workflow [PR], commit [0d0eb80] Summary: ❌
AI ReviewSummaryThis PR fixes stale bindings in derived Final VerdictStatus: ✅ Approve |
|
cc @antaljanosbenjamin @KochetovNicolai, could you review this and add |
An implied hint rebound by `mergeInplace` keeps its outer name, and it has no children, so `Node::updateHash` keyed it by that name alone. The query condition cache then served one binding's exclusions to another: after `SELECT n FROM (SELECT k AS a, max(b) AS m, count() AS n FROM t GROUP BY a) WHERE a < m AND m < 3` the same outer query over `w AS a` read only the granules where `k < 3` (n = 4 instead of 100, default settings). Only the exact hash includes the private DAG. Build-independent hashes key statistics, already drop the names that tell hints apart, and would pick up the branch-local `__tableN` names of the hint's inputs. The test is `no-parallel` because its cache-hit check, which proves the entry was written, can be evicted by a sibling test's `SYSTEM CLEAR QUERY CONDITION CACHE`, like the other query condition cache tests that assert hits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The totals row is not filtered, so it aggregates every group. An implied hint pushed below `TotalsHavingStep` then passed the aggregation and pruned granules: for `SELECT * FROM (SELECT a, max(b) AS m FROM t GROUP BY a WITH TOTALS) WHERE a < m AND m < 120` the totals row was computed over the kept granules only (`0 119` instead of `0 199`), which also depends on the part layout. `allow_index_hints` becomes `PushDownIndexHints`: all hints, implied ones only (GROUP BY, LIMIT BY), or none (totals). A user hint pushed below totals used to stop at the aggregation anyway, so only implied hints change. A query with `WITH TOTALS` keeps master's behaviour and does not prune. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 5b22d2dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261016-133003 |
|
Fixing PR for the datetime_comparison arm_release perf red: #126306 |
524cebd
|
@groeneai @fm4v — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Backport #126219 to 26.10: Fix stale argument names of derived `indexHint` and let them prune below `GROUP BY` and `LIMIT BY`
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]>
…Hint` and let them prune below `GROUP BY` and `LIMIT BY`
Since ClickHouse#126219 the GROUPING SETS check in tryPushDownFilter also counts the columns that an implied indexHint reads, so that a filter consisting only of such a hint cannot prune rows below a set that lacks its key. But the hint's own actions are built from the query tree and read the table column (`k` of key `intDiv(k, 10)`, `ts` of `toDate(ts)`), which is in no grouping set. The check then rejected the whole filter, and its other conjuncts (`v < 3`), which 26.10 pushed to the read, stopped pruning: the query from ClickHouse#128072 read 78/78 granules instead of 3/78. Collect the hint inputs separately. The filter's own identifiers still gate it as before. When a hint input is missing from some set, push the filter with PushDownIndexHints::None, so the other conjuncts go below the aggregation as on 26.10 and every hint stays above it; otherwise keep PushDownIndexHints::Implied as on master. Applies to MergingAggregated too. The existing GROUPING SETS ((a, b), (b)) case of 05401 still returns 0; with the hints pushed (Implied instead of None) it returns 1. Closes ClickHouse#128072 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`k < v AND v < 3` derives `indexHint(k < 3)`. Since ClickHouse#126219 the hint's own DAG is rebound through the projection and keeps aliases, so for `SELECT w AS k ...` it holds `k` as an alias of `w`. `getArguments` in the set index imported that DAG with `ActionsDAG::mergeNodes`, which binds every node to an existing node of the same name. When the read also references the physical `k` (`t.k < 1000`), the alias was bound to that column, and the exact per-value evaluation tested `k < 3` on `k`, dropping granules whose rows match (ClickHouse#128071). Import the hint's nodes with `ActionsDAG::unite`, which matches nothing by name. Key columns are bound by their alias-free name in `atomFromDAG`, the same way `KeyCondition` and the RPN-based skip indexes read the hint, so a hint over the key column itself still prunes. This also fixes the `remote()` local-replica shape with a set index, which still returned 0 instead of 5 on master after ClickHouse#126219. Closes ClickHouse#128071 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #124502
Related: #122975
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results when an outer
WHEREcompares columns of aremote()orDistributedsubquery that gives a column the name of another one (SELECT w AS k ...) andoptimize_and_compare_chainderives anindexHintfrom it. Such derived hints are now also used for primary key analysis belowGROUP BYandLIMIT BY.Description
On 26.9.19.9 and master, with
t ORDER BY k,SELECT count() FROM (SELECT w AS k, v FROM remote('127.0.0.1', currentDatabase(), t) AS t WHERE t.k < 1000) WHERE k < v AND v < 3returns 0 instead of 5. The chain addsindexHint(k < 3), whose argument is bound by name inside the hint. Merging actions rebinds the filter's inputs throughk := wbut not the hint, and in the local-replica plankis the physical key.Since #122975, filters pushed below
GROUP BYorLIMIT BYrefuse every hint, so withORDER BY athese read the whole table:A derived hint follows from the other conjuncts of its
and, so every row it prunes is rejected by the filter. The compare-chain and OR-LIKE rewrites now mark their hints (FunctionIndexHint::isImplied), and key steps admit only marked hints; user hints and theoptimize_append_indexhint stay refused, and a user hint merged with an equal derived one clears the mark.ActionsDAG::mergeInplacerebinds a marked hint's arguments to what the actions below compute, and drops it when a name changes type or those actions arearrayJoinor non-deterministic. TheGROUPING SETScheck counts the columns a marked hint reads. Hints stay above totals, which are not filtered. The query condition cache key now includes a hint's own DAG.Validation:
05401_index_hint_derived_below_group_by(782/782 granules without the fix, 8 to 94 with it; also theremote()alias, ARRAY JOIN,GROUPING SETSandWITH TOTALScases) and05401_index_hint_derived_query_condition_cache(4 rows instead of 100 when warm); 50/50 randomized, 10/10 Replicated database.Workflow [PR]
Sync PR [sync-upstream/pr/126219]
Version info
26.11.1.846-master(included in26.11and later)26.10.3.20