Repository navigation
Introduce Virtual Columns in Key Description - #102827
Conversation
|
Workflow [PR], commit [12e0654] Summary: ✅ AI ReviewSummaryThis PR enables virtual columns in key descriptions across storage metadata paths (for example PR Metadata
Findings
Tests
ClickHouse Rules
Final Verdict
|
| if (merging_param_key_arg) | ||
| additional_columns.emplace_back(*merging_param_key_arg, metadata.columns.getPhysical(*merging_param_key_arg).type); | ||
|
|
||
| metadata.sorting_key = KeyDescription::getKeyFromAST(args.storage_def->order_by->ptr(), metadata.columns, metadata.virtuals, context, additional_columns); |
There was a problem hiding this comment.
ORDER BY, PRIMARY KEY, SAMPLE BY), but I don't see corresponding stateless query coverage for this new behavior. Given the parser/analyzer path changed broadly (KeyDescription::getKeyFromAST now accepts virtuals), please add explicit tests for:
- positive cases: virtual columns in key description where allowed;
- negative/diagnostic cases: unsupported virtual columns in key clauses;
- compatibility cases for both extended and legacy MergeTree syntax.
Without these tests, regressions in key validation/planning for virtual columns are easy to miss.
| if (merging_param_key_arg) | ||
| additional_columns.emplace_back(*merging_param_key_arg, metadata.columns.getPhysical(*merging_param_key_arg).type); | ||
|
|
||
| metadata.sorting_key = KeyDescription::getKeyFromAST(args.storage_def->order_by->ptr(), metadata.columns, metadata.virtuals, context, additional_columns); |
There was a problem hiding this comment.
This change makes key expressions accept virtual columns (for example in ORDER BY/PRIMARY KEY/SAMPLE BY), which is user-visible SQL behavior. The PR template currently uses Not for changelog; that category does not fit this change.
Please switch to Improvement (or another user-facing category) and provide a concrete changelog entry describing the newly supported behavior and scope.
| #include <DataTypes/IDataType.h> | ||
| #include <Interpreters/Context_fwd.h> | ||
| #include <Parsers/IAST_fwd.h> | ||
| #include <Storages/VirtualColumnsDescription.h> |
There was a problem hiding this comment.
KeyDescription.h is a high-fan-out header, and this new direct include of VirtualColumnsDescription.h increases transitive parse cost for many translation units.
Because this header only needs a reference type in declarations, please prefer a forward declaration (class VirtualColumnsDescription;) in the header and move the concrete include to KeyDescription.cpp.
LLVM Coverage Report
Changed lines: 90.11% (319/354) | lost baseline coverage: 121 line(s) · Uncovered code |
…enames An expression that ALTER ... MODIFY ORDER BY adds to the sorting key may only use columns added by the same ALTER, because existing parts are not re-sorted. Two shapes broke that rule: - Retype plus subcolumn (a regression in 26.5, from ClickHouse#102827): MODIFY COLUMN x Tuple(a UInt32, b UInt32), MODIFY ORDER BY (k, x.a) was accepted, and ORDER BY k, x.a then returned the existing rows unsorted. checkProperties looks a used column up in the (name, type) difference of the column lists before and after the ALTER. Since ClickHouse#102827 those lists include subcolumns, so the new subcolumn x.a counted as added, although its storage column x (in deleted_columns) keeps its rows. 26.3 refused it. The storage column is now resolved before the existing-column test, as ClickHouse#121873 already did for the default check, so the subcolumn is as new as its storage column: subcolumns of a column the ALTER adds stay accepted. - Rename (accepted since at least 25.3): RENAME COLUMN x TO y, MODIFY ORDER BY (k, y) A rename looks like a drop plus an add in the metadata difference, so y passed. On a compact part the rename mutation then failed with the LOGICAL_ERROR "Sort order of blocks violated". Only the ALTER commands know about renames, so checkAlterEligibility, the caller that has them, now refuses a RENAME COLUMN of an existing column whose target (or a subcolumn of it) the new sorting key uses. Renaming a column of the old key is refused already, so the target can appear in the new key only in an added expression. The check is skipped on secondary replays, like the neighbouring checks added after commands.apply. Closes ClickHouse#122685. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… can run 26.3's KeyDescription::getKeyFromAST takes no `virtuals` argument (#102827 is not on 26.3), so drop the `{}` the cherry-pick carried. The test built its Delta tables with INSERT INTO FUNCTION deltaLakeLocal under allow_delta_lake_writes. On 26.3 that setting is still called allow_experimental_delta_lake_writes, and a partitioned INSERT of a NULL value fails with NOT_IMPLEMENTED (#111793 is not on 26.3). Write the same tables by hand instead, as 26.3's 05237 test does: Parquet data files through file() and one add action per file, a NULL partition value committed as a JSON null under __HIVE_DEFAULT_PARTITION__. Two cases fail on 26.3 with and without this change, so they are dropped: `ifNull(p, 0) IN (0)` prunes the NULL partition (a MergeTree table partitioned by the same Nullable column returns the same wrong rows on 26.3), and `has([NULL, 'a'], s)` throws CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN (#115647 is not on 26.3). On 26.3 the fix keeps the NULL partition's file for `has([5, 7], p)`, so that case prunes 1 file instead of 2 (rows unchanged): 26.3 builds no set index for a UInt8 array over a Nullable(Int64) key; 26.3's MergeTree partition pruning does not use that predicate on a Nullable key either. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
This patch allows the use of virtual columns in the key description
Version info
26.4.1.988