Repository navigation
Conversation
|
Workflow [PR], commit [bbf9d01] Summary: ✅
AI ReviewSummaryThe PR matches folded null-check constants to aggregate projection arguments and invalidates dependent projections after column replacement. One correctness blocker remains: cancelling the invalidation mutation re-enables incompatible stored states and changes query results. Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Prevent cancelled invalidation from exposing stale projection states, and cover the cancellation sequence. |
The analyzer folds functions with a constant result over non-constant arguments (e.g. isNull(string_col) -> 0), and so does the classic interpreter used to analyze projection queries. Both DAGs end up with a plain constant column, but under different names (_CAST(0_UInt8, ...) in the query vs isNull(type) in the projection), so matchTrees finds no match for the aggregate argument and the projection is rejected. With force_optimize_projection = 1 the query fails with PROJECTION_NOT_USED. Fix: in matchAggregateFunctions, when a query argument node has no match but both the query and the projection argument nodes are constant COLUMNs of the same type, compare the constant values and consider the arguments matching when they are equal. Fixes: ClickHouse#68949
083f7ab to
03b96b7
Compare
…checks Address timezone-sensitive folds and contained type loss for `Dynamic` and `Variant`. ClickHouse#126018
Exclude intermediate casts whose nullability depends on `cast_keep_nullable`, and add regression coverage. ClickHouse#126018 (comment)
|
Merged current upstream master in 672f2d0, including c14207b which fixes the |
| if (identifier) | ||
| { | ||
| const auto column = metadata_snapshot->getColumns().tryGetPhysical(identifier->name()); | ||
| if (column && !canContainNull(*column->type)) |
There was a problem hiding this comment.
❌ Check the materialization schema before equating null checks
The current table schema does not prove that existing projection states were computed over a non-nullable column. A supported drop/re-add can replace a nullable column while retaining projection states computed from its old values. This new match then reads those states for the newly folded constants and returns incorrect results.
Reproduced on a standalone server using this head's Fast test binary:
CREATE TABLE t
(
k UInt8,
x Nullable(UInt8),
PROJECTION p (SELECT countIf(x IS NULL), countIf(x IS NOT NULL))
)
ENGINE = MergeTree ORDER BY k;
INSERT INTO t VALUES (1, NULL), (2, 1);
ALTER TABLE t DROP COLUMN x, ADD COLUMN x UInt8;
SELECT countIf(x IS NULL), countIf(x IS NOT NULL)
FROM t SETTINGS optimize_use_projections = 0;
SELECT countIf(x IS NULL), countIf(x IS NOT NULL)
FROM t SETTINGS prefer_optimize_projection = 1;The results are (0, 2) and (1, 1) respectively, and EXPLAIN confirms ReadFromMergeTree (p) for the second query. Please reject or invalidate affected projection parts across schema changes before admitting this equivalence, and add a stateless regression for this DDL sequence. Checking only metadata_snapshot here cannot establish the required invariant for already stored states.
There was a problem hiding this comment.
Fixed in bbf9d01. The extra null-check constant match is disabled while metadata/alter mutations are pending. For completed column replacement, dependent projection data is invalidated by generated CLEAR PROJECTION mutations; original declaration AST dependencies are retained even when analysis folds them away. The declaration remains available for new inserts. New regression 05407_projection_null_check_drop_readd covers pending drop/readd, synchronous completion, preservation of an unrelated projection, new inserts, subsequent merges, and originally folded dependencies. Docker build passes; all 72 selected tests pass, including the original forced-projection regression.
There was a problem hiding this comment.
The stored-schema mismatch is still present at src/Processors/QueryPlan/Optimizations/optimizeUseAggregateProjection.cpp:826: cancelling the mutation makes both snapshot checks false without executing the generated CLEAR PROJECTION.
Reproduced with the Fast test binary for bbf9d012fd7e6c8704e24886228dbf67f2d2103c:
CREATE TABLE t
(
id UInt64,
x Nullable(UInt8),
PROJECTION p (SELECT countIf(isNull(x)), countIf(isNotNull(x)))
)
ENGINE = MergeTree ORDER BY id;
INSERT INTO t VALUES (1, NULL), (2, 1);
SYSTEM STOP MERGES t;
ALTER TABLE t DROP COLUMN x, ADD COLUMN x UInt8 SETTINGS alter_sync = 0;
KILL MUTATION WHERE database = currentDatabase() AND table = 't' SYNC;
SELECT countIf(isNull(x)), countIf(isNotNull(x)) FROM t
SETTINGS optimize_use_projections = 0;
SELECT countIf(isNull(x)), countIf(isNotNull(x)) FROM t
SETTINGS prefer_optimize_projection = 1;The results are (0, 2) and (1, 1) respectively; EXPLAIN confirms ReadFromMergeTree (p). Before cancellation, both queries correctly return (0, 2). StorageMergeTree::killMutation erases the pending commands and decrements their counters, while the table schema and old projection part survive.
Projection validity needs to survive cancellation, rather than depending solely on the presence of the clearing mutation. Please retain or verify sufficient validity information before admitting these stored states, and add this cancellation sequence to the regression coverage.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+29.11 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 units8 translation units recompiled, 35 s compile time in total, 8 of them have a recent master baseline. |
Disable constant null-check matching while the read snapshot has pending metadata or alter mutations; ordinary aggregate matching remains unchanged. Generate `CLEAR PROJECTION` mutations for original projection declarations depending on a dropped source column, including AST dependencies erased by folding. Reuse `DROP_PROJECTION` with `clear = true` to remove old parts without removing the declaration. Add `05407_projection_null_check_drop_readd` for pending and synchronous drop/readd, targeted invalidation, new inserts and merges, and originally folded dependencies. Preserve `05401_projection_is_null_analyzer` unchanged. Builds and tests intentionally not run yet. Related: ClickHouse#126018 Review: ClickHouse#126018 (review)
|
@groeneai, investigate the unrelated decimal failure: https://github.com/ClickHouse/ClickHouse/actions/runs/39131273659/job/117721298843 and provide a fix in a separate PR. If a fix is already in progress, link it here. |
|
Acknowledged. I'm investigating the |
|
The fix is in #126652. |
…o other servers
A `Decimal(P, S)` value is bounded only by its native integer, not by `P`:
`toDecimal64(1, 18)` is a `Decimal(18, 18)` holding 1, and
`toDecimal32(0.6, 9) + toDecimal32(0.6, 9)` is a `Decimal(9, 9)` equal to 1.2.
The analyzer printed every `Decimal` constant for another server as
`_CAST('<text>', '<type>')`, and the receiver's `String -> Decimal` conversion
(`readDecimalText`) rejects more integer digits than `P - S`, so `remote()`,
`Distributed`, parallel replicas, `IN` sets, the filter pushdown and
`serialize_query_plan = 1` failed with `ARGUMENT_OUT_OF_BOUND` where the local
query succeeded. Released 26.3 and 26.8 behave the same.
Under the ParallelReplicas CI configuration (`parallel_replicas_local_plan = 1`)
the other replicas hit this error in every run of
`05339_decimal_wide_comparison_scale_overflow`, but the coordinator usually
cancels them first, which is why the test failed only once (PR ClickHouse#126018).
A value with `|raw| >= 10^P` (exactly the condition `readDecimalText` rejects) is
now sent as its native integer reinterpreted into the type,
`_CAST(reinterpret(_CAST('<raw>', 'IntN'), T), T)`: a same-width `reinterpret`
copies the bytes, and the outer `_CAST` over constants keeps
`receivedFromInitiatorServer()` true, so the receiver names the column like the
initiator. Values within the precision keep their text form byte-for-byte.
26.3, 26.8 and 26.9 receivers evaluate the new form exactly. Same form as
ClickHouse#126262 uses for `DateTime64` ticks.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
When a query uses an aggregate projection like
SELECT countIf(type IS NULL), the analyzer foldsisNull(non_nullable_col)into a constant, so the aggregate argument in the query DAG is a constant column named_CAST(0_UInt8, 'UInt8'_String)while the projection DAG stores a constant namedisNull(type).matchTreesnever matches these nodes by name, the projection is rejected, and withforce_optimize_projection = 1the query fails withPROJECTION_NOT_USED.Fix: in
matchAggregateFunctions, when a query argument node has no match but both the query and the projection argument nodes are constantCOLUMNs of the same type, compare the constant values and consider the arguments matching when they are equal.Closes: #68949
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix aggregate projections not being used for queries with
IS NULL/IS NOT NULLover non-nullable columns under the analyzer (the query failed withPROJECTION_NOT_USEDwhenforce_optimize_projection = 1).Workflow [PR]
Sync PR [sync-upstream/pr/126018]