Repository navigation
Keep the PREWHERE filter column for evaluating defaults of missing columns - #117533
Conversation
…lumns
A `PREWHERE` step stores the columns it projects out, so that a later step in
the readers chain can still evaluate the `DEFAULT` expression of a column that
is missing from the part. Columns still present in the result block are
skipped, to avoid keeping and filtering them twice - but the filter column is
present in the block at that point and is erased from the result only further
down. So it was neither kept as an additional column nor available as a result
column, and it vanished.
With a single-conjunct explicit `PREWHERE` over a column that is itself the
condition, that column is exactly the one the `DEFAULT` expression needs:
CREATE TABLE ad (a UInt8) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO ad SELECT 1 FROM numbers(150);
ALTER TABLE ad ADD COLUMN b Int32 DEFAULT CAST(a % 13, 'Int32') AFTER a;
SELECT groupUniqArray(b) FROM (SELECT b FROM ad WHERE a); -- [1]
SELECT groupUniqArray(b) FROM (SELECT b FROM ad PREWHERE a); -- [0], the Int32 default
The two-conjunct spelling was already correct, because the first step then
keeps the column for the second one, which is what the fix for #111757
covered; this is the surviving single-step face of it.
Closes: #115273
Related: #111757
|
Workflow [PR], commit [36768f0] Summary: ✅
AI ReviewSummaryThis PR fixes the remaining single-step Missing context / blind spots
Final Verdict✅ No actionable review findings on the current diff. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
…where-default-column-115273
The `05099` prefix is now crowded on master; move the test to `05177`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…where-default-column-115273
…r merging master The `05177` prefix is now also used by another test on master. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…s gone since v26.9 Disabling `enable_analyzer` now throws `SETTING_CONSTRAINT_VIOLATION`, so the case can no longer run. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 CI status on head
@groeneai, investigate the failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117533&sha=747c6392cd17dd54b771d957d08be33540c2595c&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%204%2F6%29 and https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117533&sha=747c6392cd17dd54b771d957d08be33540c2595c&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%205%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The AI Review Major (the row policy |
|
Investigated both.
|
|
Follow-up on Query #0 groups by a single-type Correction to my comment above: the 594 dashboard |
Query #0 groups 5M rows by a single-type Dynamic key. For every row the
aggregation looks up the variant's default serialization in
SerializationObjectPool: a shared lock on the key's shard mutex,
weak_ptr::lock, and the release of the returned SerializationPtr. These
are atomic read-modify-writes on two cache lines that every aggregation
thread writes for every row. One key means one shard, so the pool's
sharding cannot spread the load, and the query is bound by how fast those
lines move between cores. That speed is fixed per server process.
CI data (query_metric_runs_v1, arm, 1177 runs since 2026-09-17): the 5-7
samples of one server agree within 0.7% (p50), but the per-process medians
span 0.643-0.840 s (p05-p95). Fast and slow processes do the same work
(same arena bytes, memory, two-level hash tables and page faults) and
differ only in user CPU time (9.5 vs 12.1 s). The wall time does not
depend on the thread count: arm 0.754 s with 16 threads vs 0.775 s with
12, amd 0.669 s with 16 threads on 8 pinned cores vs 0.686 s with 8. So
each A/B run compares two random draws of that per-process speed. Runs
whose new/old median moved by more than 15% (raw samples):
arm PR arm master amd PR amd master
serialization_pool_lookup #0 123/789 54/558 68/176 220/560
serialization_pool_lookup #1 41/789 11/558 5/176 20/560
serialization_pool_lookup #2 0/789 0/558 0/176 0/560
group_by_dynamic_keys #0 0/782 0/559 0/173 0/559
group_by_dynamic_keys #0 runs the same per-row lookup path with
max_threads = 1. On PR ClickHouse#117533 the performance dashboard scored #0 as a
confirmed regression (arm 5/6, 0.670 -> 0.799 s) that the shard's own
report did not flag.
Run #0 in one thread, from numbers instead of numbers_mt, so it times the
pool's hit path itself, which does not depend on the process. Queries #1
(two keys, where sharding spreads the load) and #2 (the multi-threaded
MergeTree read) keep the contention coverage.
Local check on x86 with the official 26.10.1.820 master build, perf.py,
7 runs: old #0 1.76 s with 12 threads (15.4 s user CPU per run), new #0
0.57 s (0.56 s user CPU), same result. Ten fresh servers pinned to 8
cores with max_threads = 8: old #0 per-process medians 0.68-1.08 s; new
#0 0.56-0.58 s in 8 of them and 0.72-0.73 s in the two whose table
fills were also about 25% slower (9.2-10.0 s vs 7.4-8.6 s).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…where-default-column-115273
|
🕵 Thanks @groeneai. Merged |
|
🕵 Merged
@groeneai, investigate the failures: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117533&sha=f8bb7742bfd6d0ed5571ed7cf104fa6c904748e7&name_0=PR (the |
|
Both already have fixes:
|
…where-default-column-115273
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed a column added by
ALTER TABLE ... ADD COLUMN ... DEFAULT <expression>being filled with the type default instead of the evaluated expression when it is read through a single-conjunct explicitPREWHEREon the expression's dependency.Documentation entry for user-facing changes
A
PREWHEREstep stores the columns it projects out, so that a later step in the readers chain can still evaluate theDEFAULTexpression of a column that is missing from the part. Columns still present in the result block are skipped, to avoid keeping and filtering them twice — but the filter column is present in the block at that point and is erased from the result only further down. So it was neither kept as an additional column nor available as a result column, and it vanished.With a single-conjunct explicit
PREWHEREover a column that is itself the condition, that column is exactly the one theDEFAULTexpression needs:The two-conjunct spelling was already correct, because the first step then keeps the column for the second one, which is what the fix for #111757 covered; this is the surviving single-step face of it.
Closes: #115273
Related: #111757
Workflow [PR]
Sync PR [sync-upstream/pr/117533]
Version info
26.10.1.2240-master(included in26.10and later)