Repository navigation
Extend InverseDictionaryLookupPass to support IN and notIn operators for dictionary lookups - #100001
Conversation
|
Workflow [PR], commit [1489f1d] Summary: ✅
AI ReviewSummaryExtends Final VerdictStatus: ✅ Approve |
|
Thanks for working on this! Let's also write a performance test to ensure the rewrite has performance improvements. |
Signed-off-by: noob <[email protected]>
# Conflicts: # contrib/NuRaft
Signed-off-by: noob <[email protected]>
|
There are some submodules changed which are not needed for the PR. Let's revert them. |
|
The performance comparison between this branch and master (0fe7ab9) on
|
Signed-off-by: noob <[email protected]>
Signed-off-by: noob <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only the analyzer's inverse dictionary lookup pass. It adds a rewrite for clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
Resolve the conflict in `InverseDictionaryLookupPass.cpp`: master added the `keyTypeBreaksInverseLookupEquivalence` guards (probe type and declared key types) to the code that this PR moved into `tryGetDictionaryLookup`. Apply both guards inside `tryGetDictionaryLookup`, so they cover the new `IN` / `notIn` rewrite as well.
`groupArray` over a subquery with `ORDER BY` does not guarantee the order of elements, and CI produced e.g. `[1,3,4,6,7,8,9,0]` instead of `[0,1,3,4,6,7,8,9]`. Sort the arrays explicitly instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `transform_null_in = 1`, user-written `IN` / `NOT IN` are resolved as `nullIn` / `notNullIn` before query tree passes run, so the new `IN` rewrite never fired in that mode. `rewriteIn` already requires a non-`Nullable` left-hand side and a constant set without `NULL`, where both spellings agree, and the nodes it creates already go through `getInFunctionNameForPassCreatedNode`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflict in `InverseDictionaryLookupPass.cpp`: master added key-shape and key-conversion checks (`keyExpressionMatchesDictionaryStructure`, `canCompareKeysWithoutCasts`, `convertSimpleKeyProbe`, `unwrapSingleColumnTupleKey`) inline in the comparison path, while this PR moved that part of the code into `tryGetDictionaryLookup`. The new checks are moved into `tryGetDictionaryLookup`, which now takes `DictGetFunctionInfo` by reference and updates its `key_expr_node`, so both the comparison and the `IN` rewrites use the converted probe. 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 sizes5 object files changed (+47.79 KiB total), 0 added.
719 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 units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=100001&sha=e69ba3fc1c6&name_0=PR&name_1=Integration%20tests%20(arm_binary%2C%201%2F4) ( |
|
This is fixed by #125448 (mine), merged 2026-10-13 01:47 UTC. The failed job is a re-run (attempt 2, started 02:11 UTC), and a re-run keeps the workflow's original merge ref: it tested e69ba3f merged into master af433c1 (2026-10-12 21:12 UTC), which is 37 commits behind the fix. It is the #125448 mechanism: It has not failed on any tree that contains the fix: 0 failures on master or in any PR since 2026-10-15 (1532 passing master runs since 2026-10-14), and every earlier failure tested a master behind it. The current head bdf7ba0 contains the fix, so nothing more is needed here. |
…okupPass` `IColumn::compareAt` considers `-0.0` and `+0.0` equal, but `IN` sets compare floating-point keys by their binary representation. So a `+0.0` attribute `DEFAULT` was classified as present in a list containing only `-0.0`, and the `IN` / `NOT IN` rewrite picked the wrong form for keys missing from the dictionary. Build a `Set` from the converted elements and probe it with the `DEFAULT`, like `IN` itself does. Address review: ClickHouse#100001 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Thanks @groeneai. Confirmed: the branch contains #125448. I merged the latest |
|
🕵 The only red check on f0e653c was |
|
@euvre @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
…ryLookupPass again Since `in` / `notIn` over a `dictGet` became rewritable (ClickHouse#100001), the `key IN (keys)` node that the pass creates for a comparison matching several dictionary keys is itself a rewrite candidate when the key is a `dictGet`. A shared alias node (`GROUP BY r ORDER BY r` with the identifier resolve cache) is visited once per reference, so the second visit inverted one more level of a nested `dictGet` chain and the `GROUP BY` key and the projection differed again (NOT_FOUND_COLUMN_IN_BLOCK). Register that node as final, as already done for the single-key `equals`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Extends
InverseDictionaryLookupPass(optimize_inverse_dictionary_lookup) todictGet*(...) IN (constants)andNOT IN. Before, only comparisons (=,<,LIKE, ...) were rewritten.A key missing from the dictionary makes
dictGetreturn the attributeDEFAULT. So for all missing keys the predicate has the same, known value, and the rewrite picks the form that gets it right:DEFAULTin the listdictGet(d, 'a', k) IN Lk IN (SELECT key FROM dictionary(d) WHERE a IN L)dictGet(d, 'a', k) IN Lk NOT IN (SELECT key FROM dictionary(d) WHERE a NOT IN L)dictGet(d, 'a', k) NOT IN Lk IN (SELECT key FROM dictionary(d) WHERE a NOT IN L)dictGet(d, 'a', k) NOT IN Lk NOT IN (SELECT key FROM dictionary(d) WHERE a IN L)To decide whether
DEFAULTis in the list, the pass usesgetSetElementsForConstantValue, the same conversion the planner uses to build the set. The rewrite goes through the same checks as the comparison rewrite: in-memory layouts only; attribute type must match thedictGet*type; noNullableattribute,Nullablecomplex-key component ordictGetOrNull;set_overflow_mode = 'break',rewrite_in_to_join, Cascades and a missingCREATE TEMPORARY TABLEgrant all skip it. ANULLin the list or aNullableresult also skips it.In the performance test the
IN/NOT INqueries got 20-38% faster (see the comment with measurements).Closes: #99500
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
optimize_inverse_dictionary_lookupnow also rewritesdictGet(...) IN (...)anddictGet(...) NOT IN (...)with constant lists into a lookup of the matching dictionary keys, e.g.WHERE dictGetString('dict', 'status', id) IN ('active', 'pending')intoWHERE id IN (SELECT id FROM dictionary('dict') WHERE status IN ('active', 'pending')). This lets the primary key be used for filtering.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/100001]
Version info
26.11.1.1032-master(included in26.11and later)