perf(sql): reduce SQL planning allocations for large literal arrays #20367
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 317 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.345
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #20367"
general
weight: 0.35
GWphua
Related to #20326.
Description
Large literal arrays already contain constant Calcite values, but the existing planning path converts them into Druid expressions, formats them as text, parses that text, evaluates it, and rebuilds Calcite literals:
This round trip allocates per-element expression objects, strings, parser objects, evaluated values, and replacement Calcite nodes.
This change skips that work for already-normalized string and integer literal arrays. Expressions requiring conversion or evaluation retain the existing path.
Benchmark results
| Type | Elements | Before MB/op | After MB/op | Diff MB/op | Reduction | Before ms/op | After ms/op |
|---|---:|---:|---:|---:|---:|---:|---:|
| LONG | 100,000 | 355.87 | 226.23 | 129.63 | 36.43% | 215.95 | 153.58 |
| LONG | 1,000,000 | 3535.11 | 2216.22 | 1318.89 | 37.31% | 2899.52 | 2324.95 |
| STRING | 100,000 | 1541.08 | 1231.01 | 310.06 | 20.12% | 788.72 | 580.71 |
| STRING | 1,000,000 | 15561.88 | 12307.44 | 3254.44 | 20.91% | 8106.12 | 6150.46 |
MB is decimal; allocation means total bytes allocated per planning operation, not peak or retained heap.
Both variants use Calcite 1.42.0 with only the CALCITE-7782 fix. The benchmark isolates this Druid change using identical dependencies and harness settings.
JDK 25.0.4.1; two forks; two warmup and three measurement iterations; GC profiler. Queries are planned without execution or EXPLAIN serialization. Timing results are preliminary.
Tests
Tests cover identity reuse, NULLs, integer boundaries, type mismatches, charset/collation differences, computed operands, and SQL IN/NOT IN semantics.
Release note
Reduced SQL planning allocations for large literal string and integer arrays, including arrays generated from large IN lists.