Repository navigation
Use the adaptive aggregator for GROUP BY over Nullable keys whose hash method packs the null map into the key - #124868
Conversation
…null map into the key The admission gate rejected every Nullable key. Schema inference makes most file columns Nullable, so GROUP BY over file()/s3() data never took the adaptive path, even with no NULLs in the data. The frozen kernel probes a row with the key holder and stages a miss as the key value, which the drain emplaces straight into the bucket's submap. That is correct exactly when the key value alone identifies the group: nullable_keys128/256 write the null bitmap into the packed key, and nullable_serialized/nullable_prealloc_serialized serialize the null flag. The single-key methods keep NULL in the separate cell of AggregationDataWithNullKey and hand out the nested value as the key of a NULL row, so staging would merge NULL into the nested default's group; they stay rejected, as does LowCardinality. The admission is per method, not per key count: a single Nullable(Int128) or Nullable(UUID) key uses nullable_keys256 and is admitted. The Nullable query of the aggregation_two_level_bucket_merge perf test now inherits that file's enable_adaptive_aggregator = 0: its keys are admitted now, and the test measures the bucket merge. Measured (RelWithDebInfo, 100M rows, 16 threads, setting 0 vs 1): two Nullable number keys 1796 -> 865 ms, 10.29 -> 4.53 GiB; Nullable number + Nullable String 1820 -> 1146 ms; three keys with real NULLs 2401 -> 1161 ms. One 18.2M-group clustered-key shape uses more memory (2.06 -> 3.48 GiB), the same as the already-admitted non-Nullable path on those keys. Closes ClickHouse#124668 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (3 rounds): 2 major fixed, 2 nits fixed, 1 nit not changed; third round clean
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261009-085300 |
|
Workflow [PR], commit [6e12571] Summary: ✅
AI ReviewSummaryThis PR narrows adaptive-aggregator admission for Final Verdict✅ No findings to post on the current revision. |
Build profile diff (arm_release)Commit See the job log for details. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
CI finish ledger - c7644caEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261009-140011 |
|
Fixing PR for |
|
@groeneai, the bad test is fixed - update the branch. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
GROUP BYwith aNullablekey now uses the adaptive aggregator, except when that key is the only one and is a number of up to 8 bytes, aStringor aFixedString, or when any key isLowCardinality. Schema inference makes such keys common in CSV, JSON and Parquet files; high-cardinality aggregations over them become up to 2x faster with up to 2.2x less memory.Description
Closes #124668. Related: #111459.
AggregatingStep::adaptiveAggregatorRejectionReasonrefused the adaptive aggregator for anyNullablekey. Schema inference makes most file columnsNullable(schema_inference_make_columns_nullable), soGROUP BYover such columns offile()/s3()data never used it, even with no NULLs in the data.The frozen kernel stages a missed row under the key its method builds, then emplaces it directly into the bucket's table. That is only correct when the key value alone identifies the group. Four methods meet it and are now admitted:
nullable_keys128/nullable_keys256pack the null bitmap into the key, andnullable_serialized/nullable_prealloc_serializedserialize the null flag. The single-key methods (nullable_key8..64,nullable_key_string,nullable_key_fixed_string) keep NULL in a separate cell that the staging bypasses, so they stay rejected, and so doesLowCardinality. Admitting them would merge NULL rows into the nested default's group.Test
05340: 9 admitted and 4 rejected shapes, each with NULL next to the nested default, compared with the ordinary path, plus a staging check (it fails on master only on that check). Perf testadaptive_aggregation_nullable_keys.xml; theNullablequery ofaggregation_two_level_bucket_merge.xmlno longer re-enables the adaptive aggregator, so it still measures the bucket merge.RelWithDebInfo build, 100M rows, 16 threads,
enable_adaptive_aggregator0 vs 1 (= master vs this PR here), median of 5:Nullablenumbers,count/sum/avgNullablenumber +Nullable(String)Nullable(UInt64)(still rejected)One cost case: 18.2M groups with clustered keys run 510 -> 422 ms, but peak memory goes 2.06 -> 3.48 GiB, as on the already-admitted non-
Nullablepath (2.00 -> 3.48 GiB).Workflow [PR]
Sync PR [sync-upstream/pr/124868]
Version info
26.10.1.2108-master(included in26.10and later)