Repository navigation
Conversation
|
Will there be any keyword/control over ANY/ALL behavior? |
|
No, ANY/ALL is controlled by the JOIN strictness in the query itself, not by a separate LOOKUP INDEX option. |
|
Workflow [PR], commit [deabffe] Summary: ❌
|
…-as-indices Conflict in `StorageInMemoryMetadata::addImplicitIndicesForColumn`: master moved the push of the implicit min-max index into a `try` block that swallows `BAD_ARGUMENTS`. The check that rejects an implicit index name reserved by a lookup index is moved before that block so it still throws. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lookup index is rejected `RESTORE` creates the table with `SECONDARY_CREATE` and writes fresh replicated metadata into ZooKeeper, which is exactly what the guard prevents. The old comment wrongly claimed that restore from a backup is allowed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
…-as-indices Conflicts were caused by master adding `codec_declarations` to `ASTColumns` next to the `lookup_indices` added by this PR; both are kept. `IWindowFunction.h` was renamed to `IGeneralWindowFunction.h` on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r 26.11 The setting was not released in 26.10, so the style check `settings_changes_history` requires the record under the current version. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101401&sha=351154147a7bd938b32327fb8fc25c41c6d5a17e&name_0=PR&name_1=Style%20check ClickHouse#101401 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged the latest |
…cpp` The merge with master brought a second `extern const int SUPPORT_IS_DISABLED` into the `ErrorCodes` namespace, which fails the style check. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101401&sha=e0892434073aaca34cd27f19053aedcc56aca52b&name_0=PR&name_1=Style%20check ClickHouse#101401 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
|
||
| bool allowed_inner = isInner(table_join->kind()) && table_join->strictness() == JoinStrictness::All; | ||
| bool allowed_inner = isInner(table_join->kind()) && (table_join->strictness() == JoinStrictness::All | ||
| || table_join->strictness() == JoinStrictness::Any); |
There was a problem hiding this comment.
[P1] Preserve duplicate-left semantics before enabling inner ANY
With any_join_distinct_right_table_keys = 0 (the default), ANY INNER JOIN emits one row per matching key across both sides. DirectKeyValueJoin instead probes every left row independently; FirstMatch limits only the right matches and never suppresses repeated left keys.
For a left table containing (id, payload) = (1, 100), (1, 200) and a right lookup-index table containing (id, value) = (1, 10), selecting both payloads through ANY INNER JOIN ... ON f.id = d.id produces two rows with join_algorithm = 'direct,hash', versus one with hash. HashJoin enforces this through setUsedOnce. This allowance also changes existing dictionary/key-value joins without the experimental lookup setting.
Please decline inner Any in both planner paths until direct joins implement query-local, thread-safe used-key tracking across blocks. Tracking usage in the shared lookup entity would incorrectly couple separate queries.
There was a problem hiding this comment.
🕵 Addressed in 206e85bd1545: inner ANY is declined again in both tryExtractLookupJoinRightKeys and tryDirectJoin. That also restores the previous behaviour for dictionary and key-value joins. 04360 now uses ANY LEFT JOIN for its "lookup is used" check, and 05564_lookup_index_review_fixes covers your example: two left rows with the same key give one row.
There was a problem hiding this comment.
[Blocker] The fix leaves the old-analyzer entrypoint enabled: src/Interpreters/ExpressionAnalyzer.cpp:1214-1215 still accepts inner JoinStrictness::Any in tryKeyValueJoin. tryCreateJoin then selects DirectKeyValueJoin and discards the ordinary right-side plan.
With enable_analyzer = 0, any_join_distinct_right_table_keys = 0, left rows (1, 100), (1, 200), and an EmbeddedRocksDB right table keyed by id containing (1, 10), the code still emits both left rows for ANY INNER JOIN with join_algorithm = 'direct,hash'. The hash path emits one through setUsedOnce. This also affects dictionaries and requires no lookup index or experimental setting.
Please restore the All-only inner gate in tryKeyValueJoin too and cover this case with the old analyzer; 05564_lookup_index_review_fixes explicitly enables the new analyzer, so it does not exercise this remaining path.
There was a problem hiding this comment.
🕵 Addressed in 50bf5a71551f: tryKeyValueJoin in src/Interpreters/ExpressionAnalyzer.cpp accepts only All for inner joins again, so the file is identical to master. 05872_direct_join_any_inner_old_analyzer joins a table with a repeated left key to a dictionary with any_join_distinct_right_table_keys = 0 and join_algorithm = 'direct,hash' under both analyzers and expects one row.
# Conflicts: # src/Interpreters/InterpreterCreateQuery.cpp # src/Storages/AlterCommands.cpp # src/Storages/MergeTree/MergeTreeData.cpp
- Decline inner `ANY` joins for direct joins again: with `any_join_distinct_right_table_keys = 0` `HashJoin` emits one row per matching key across both sides, while `DirectKeyValueJoin` probes every left row independently. This also restores the previous behaviour for dictionary and key-value joins. - Do not replace a subquery with `LIMIT AFTER` or `LIMIT UNTIL` by the whole lookup set. - Do not use the lookup set when the plan may be serialized for remote execution: `FutureSetFromStorage` is serialized as a reference to a `StorageSet`. - Take the regular path for a lazily loaded table behind `StorageTableProxy`: its snapshot has no `MergeTreeData` parts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… entries - A lookup read inherits the query limits, and some of them (`timeout_overflow_mode = 'break'`, `read_overflow_mode = 'break'`) finish the pipeline normally after a partial read. Publish the result to the shared cache only when it has exactly the rows of the snapshot's parts. - Include the columns description in the cache signature: a non-replicated `MergeTree` does not maintain the metadata version, and an `ALTER` changing only a column default creates no mutation, so an old builder could otherwise publish an entry that matches the new snapshot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flag can come from the `clickhouse_json` dialect, so an ordinary data skipping index such as `minmax` could use it to skip the granularity check and later fail with `Attempt to write empty minmax index`. Reject the flag on a type that is not a lookup index type. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…atedMergeTree` `ATTACH TABLE ... AS REPLICATED` persisted the replicated definition before the `StorageReplicatedMergeTree` constructor rejected the lookup index, and the startup `convert_to_replicated` flag loaded the converted table with `FORCE_ATTACH` and published its metadata to Keeper. Reject the former before any side effect, and make the latter keep the table as is with an error in the log, like for `table_readonly`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged The previous red was only from |
…-as-indices Conflict resolution: - `StorageFactory`: master moved the engine feature checks into `checkEngineFeatures`; the lookup index check was moved there. - `AlterCommands`: kept the lookup index rebuild after master's text index permission check. - `MergeTreeData.h`, `Planner/Utils`: kept both sides. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ked map Master changed the type of `PreparedJoinStorage::column_mapping` to `UnorderedMapWithMemoryTracking`, so it can no longer be assigned from `TableExpressionData::getColumnIdentifierToColumnName` directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…umn default A column absent from an old part is filled on every read by evaluating its default expression, which may depend on mutable state (`dictGet`, `now`, another table). Neither the part identity nor the schema signature captures that state, so a cached `table_set` or `table_join` could keep serving values computed before, e.g., `SYSTEM RELOAD DICTIONARY`. Such snapshots are now not cacheable, both for cache hits and for publication. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`MutationsInterpreter` analyzes the mutation with `getStorageSnapshotWithoutData`, whose `SnapshotData::parts` is null, and `getLookupTableState` dereferenced it (segmentation fault found by the AST fuzzer). Decline the lookup fast path for such snapshots. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101401&sha=c904d7c3326775edb23765e4ae9745845f17a25e&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 ClickHouse#101401 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
The |
| metadata.add_minmax_index_for_block_number_column = (*storage_settings)[MergeTreeSetting::add_minmax_index_for_block_number_column] && (*storage_settings)[MergeTreeSetting::enable_block_number_column]; | ||
| metadata.add_minmax_index_for_block_offset_column = (*storage_settings)[MergeTreeSetting::add_minmax_index_for_block_offset_column] && (*storage_settings)[MergeTreeSetting::enable_block_offset_column]; | ||
| metadata.escape_index_filenames = (*storage_settings)[MergeTreeSetting::escape_index_filenames]; | ||
| metadata.lookup_indices = getLookupIndicesFromAST(args.query.columns_list ? args.query.columns_list->lookup_indices : nullptr, columns, context); |
There was a problem hiding this comment.
[Major] Lookup indexes are silently ignored when loading tables created with the old engine syntax. This assignment runs only when is_extended_storage_def is true, but isExtendedStorageDef recognizes ordinary indexes and projections without checking lookup_indices.
For example, with allow_deprecated_syntax_for_merge_tree = 1, CREATE TABLE t (d Date, id UInt64, LOOKUP INDEX s (id) TYPE table_set) ENGINE = MergeTree(d, id, 8192) passes validation but creates no runtime lookup index. An existing old-syntax table also accepts ALTER TABLE t ADD LOOKUP INDEX s (id) TYPE table_set: the old-syntax validation rejects only ADD_INDEX, so the lookup works until detach/attach or restart, when this constructor skips its persisted declaration.
Please consistently reject lookup indexes on old-syntax tables in both CREATE and ALTER, or load them correctly there. Add a focused test proving rejection or preservation across detach/attach.
There was a problem hiding this comment.
🕵 Addressed in deabffe6e3c7: lookup indexes are rejected for tables with the old engine syntax. CREATE with a LOOKUP INDEX declaration and the old syntax throws BAD_ARGUMENTS in registerStorageMergeTree.cpp, and ALTER TABLE ... ADD LOOKUP INDEX on such a table throws next to the existing ADD INDEX check in MergeTreeData::checkAlterIsPossible. 05871_lookup_index_old_syntax_rejected covers both and checks the definition after detach/attach.
…-as-indices Conflicts: - `src/Interpreters/DirectJoin.cpp`: kept the `previous_offset` loop of this branch in `selectFirstMatchForEachKey`. - `src/Planner/PlannerJoins.cpp`, `src/Planner/PlannerJoins.h`: `trySetStorageInTableJoin` was removed on master as unused; kept only `tryGetLookupJoinStorage`. - `src/Storages/MergeTree/MergeTreeData.cpp`: the invalidation of the lookup index caches moved into the new `updateCachesAfterMetadataPublish`, so both of its callers drop them. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The `arm_tidy` build failed with `readability-duplicate-include` in `InterpreterCreateQuery.cpp`: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101401&sha=ffd74d921bee038b4a1e60f7fb57c64ff0f3ca85&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29 ClickHouse#101401 Co-Authored-By: Claude Fable 5.2 <[email protected]>
…zer too `tryKeyValueJoin` still accepted `ANY INNER JOIN`, so with `enable_analyzer = 0` a direct join over a dictionary or a key-value storage emitted a row for every left row with a repeated key, while `HashJoin` emits one row per key. Restore the `All`-only gate, as on master, and cover it with a dictionary join under both analyzers. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…syntax The old `MergeTree` syntax does not read index declarations, so a lookup index in `CREATE` was silently ignored, and one added by `ALTER TABLE ... ADD LOOKUP INDEX` was lost after detach/attach or a restart. Reject both, the same way as `ADD INDEX`. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged |
This change adds table-wide
LOOKUP INDEXsupport forMergeTreetables and implements theSetandJointables as indices task from #87836. Unlike secondary data-skipping indices, these indices build reusable in-memory lookup structures for repeated key-value style queries against the right-hand side table.It introduces:
LOOKUP INDEX ... TYPE table_setforIN tablelookups and trivial key-only subqueriesLOOKUP INDEX ... TYPE table_joinfor direct-compatible equality joins withjoin_algorithm = 'direct'ALTER, andReplicatedMergeTreesupportCurrent limitations:
table_joinrequires non-nullable key columnstable_joinis only used for direct-compatible equality joinstable_joinis not always faster thanhash; the included benchmarks show win, near-parity, and lose cases depending on the relative sizes of the left and right tablesChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add
LOOKUP INDEXsupport forMergeTreetables withtable_setandtable_jointable-wide lookup indexes.Documentation entry for user-facing changes
Note
High Risk
High risk because it adds a new experimental index type that touches SQL parsing/formatting, ALTER/replication metadata, MergeTree read paths and caching, and join/set planner optimizations (including direct join behavior), which can affect query correctness and performance.
Overview
Adds experimental
LOOKUP INDEXsupport toMergeTree-family tables (gated byallow_experimental_lookup_index) with two new index types:table_setto accelerateIN table/trivial key-only subqueries andtable_jointo accelerate direct-compatible equality joins.Extends SQL/metadata plumbing end-to-end: new AST fields and parser/formatter support for
LOOKUP INDEX(includingALTER TABLE ... ADD/DROP LOOKUP INDEX), metadata storage and replication viaReplicatedMergeTreeTableMetadata, and validation to prevent misuse (e.g., noGRANULARITY, no expressions/args, and non-nullable keys fortable_join).Implements runtime lookup caches in
MergeTreeData(with invalidation on metadata/part changes) and integrates planner fast paths for sets (CollectSets) and joins (PlannerJoins/DirectKeyValueJoin) while preserving correctness by disabling the optimization when row policies or unsupported modifiers/parallel replicas are in play. Adds documentation plus new stateless/performance tests for both lookup modes.Reviewed by Cursor Bugbot for commit 6d94b00. Bugbot is set up for automated code reviews on this repo. Configure here.
Workflow [PR]
Sync PR [sync-upstream/pr/101401]