Repository navigation
Reduce double-copy of data on Map functions - #111749
Conversation
|
Workflow [PR], commit [5880712] Summary: ✅
AI ReviewSummaryThis PR threads Final Verdict✅ No review findings in the current diff. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 36/37 (97.30%) · Uncovered code |
Build profile diff (arm_release)No arm_release build profile data for commit 5880712 - the build was skipped, reused from cache, or predates profile upload. |
|
📊 Cloud Performance Report ✅ AI verdict: This change makes mapLike functions (mapContainsKeyLike, mapExtractKeyLike, etc.) capture their pattern column lazily to cut peak memory, and adds optional ContextPtr construction to the LowCardinality FastPath mixin. ClickBench Q17 is a GROUP BY aggregation over hits and does not exercise any mapLike function or the changed capture path, so the flagged -10.1% improvement cannot plausibly be attributed to this PR and is downgraded to not_sure as run-to-run variance. The remaining diff (comment edits and the constructor plumbing) is behavior-neutral for existing functions. No cross-query pattern emerged from a single flagged query. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
451e003
Part 2 of avoiding multiple copies of data in higher-order functions (Depends on Part 1: #111581, arrays).
mapContainsKeyLike,mapContainsValueLike,mapExtractKeyLikeandmapExtractValueLikehave no SQL lambda, but are implemented through the same machinery:
MapLikeAdaptersynthesizes a lambda-like
ColumnFunctionthat captures the pattern column, and the arrayimplementation replicates it by the map offsets before appending the keys/values.
That synthetic ColumnFunction was created without allow_lazy_replicated_captures, so a non-constant pattern was physically replicated once per map entry at capture time and the expanded column stayed alive through the whole arrayExists/arrayFilter pipeline, even with enable_lazy_columns_replication enabled.
With this change the capture stays lazy (ColumnReplicated) until the synthetic lambda is executed. The pattern is still materialized in full at that point: IExecutableFunction::execute falls back to full materialization because the lambda receives a mix of replicated (pattern) and full (keys/values) arguments.
Related: #111581
Related: #54967
Performance Test:
enable_lazy_columns_replication = 0)enable_lazy_columns_replication = 1)mapContainsKeyLike, 100 KB patternmapContainsKeyLike, 100 KB patternmapContainsKeyLike, 100 KB patternmapExtractValueLike, 100 KB patternmapContainsKeyLike, tiny pattern, 200k rowsChanges
FunctionMapToArrayAdaptertakesContextPtrand readsenable_lazy_columns_replicationat function creation time.
Adapter::extractNestedTypesAndColumnsvia arequires-clausedispatch.
MapLikeAdapterpasses the flag to ColumnFunction::create for the captured pattern, so ColumnFunction::replicate wraps it in ColumnReplicated instead of copying at capture time. The full copy still happens when the lambda executes, but it is deferred and shorter-lived.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Functions mapContainsKeyLike, mapContainsValueLike, mapExtractKeyLike and mapExtractValueLike with a non-constant pattern use less memory and time when enable_lazy_columns_replication is enabled. The pattern is no longer eagerly copied per map entry at capture time; the copy is deferred to the execution of the internal lambda and is freed sooner, so one fewer expanded copy of the pattern exists at peak.
Version info
26.8.1.1164(included in26.8and later)