Repository navigation
Conversation
691a3c7 to
da280f8
Compare
|
Thank you for opening this pull request! Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch). Details |
Query / Computation Fusion Optimizer IdeasInspired by Athena's computation-reuse fusion paper. 1. Scalar Aggregate FusionMerge multiple scalar aggregate subqueries over the same source into one aggregate with Example query: TPC-DS Q9 Before: SELECT
(SELECT avg(x) FROM R WHERE p1),
(SELECT avg(y) FROM R WHERE p2);After: SELECT
avg(x) FILTER (WHERE p1),
avg(y) FILTER (WHERE p2)
FROM R;2. Grouped Aggregate Join To Window AggregateReplace a join back to a grouped aggregate over the same source with a window aggregate. Example query: TPC-DS Q65 Before: SELECT R.*, A.avg_v
FROM R
JOIN (
SELECT k, avg(v) AS avg_v
FROM R
GROUP BY k
) A
ON R.k = A.k;After: SELECT
R.*,
avg(v) OVER (PARTITION BY k) AS avg_v
FROM R
WHERE k IS NOT NULL;3. UNION ALL Branch FusionMerge same-source Example query: TPC-DS Q23-style shapes Before: SELECT ... FROM R WHERE p1
UNION ALL
SELECT ... FROM R WHERE p2;After: SELECT ...
FROM R
CROSS JOIN branches
WHERE (branch = 1 AND p1)
OR (branch = 2 AND p2);4. Multi-Aggregate Common-Source FusionMerge sibling aggregates over the same source and group keys into one aggregate with multiple aggregate expressions. Example queries: TPC-DS Q28 / Q88 Before: SELECT ...
FROM (
SELECT k, agg1(v) FROM R GROUP BY k
) a,
(
SELECT k, agg2(v) FROM R GROUP BY k
) b;After: SELECT
k,
agg1(v),
agg2(v)
FROM R
GROUP BY k;Note: Q28-style cases may need 5. Common Join-Input FusionDetect joins or subqueries that repeatedly consume the same source and share the common input instead of recomputing it. Example queries: TPC-DS Q64 / Q88 Before: SELECT ...
FROM (R JOIN A) x,
(R JOIN B) y;After: SELECT ...
FROM R
JOIN A
JOIN B;This should start conservatively behind a config flag and require semantic guards for |
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
Rationale for this change
Draft POC for experimenting with Athena-style computation reuse in DataFusion.
What changes are included in this PR?
Adds a disabled-by-default
query_fusionoptimizer rule with narrow POC rewrites for:UNION ALLbranches over the same source using branch tags.source JOIN Aggregate(source GROUP BY keys)shapes using window aggregates.Are these changes tested?
cargo test -p datafusion-optimizer query_fusion --libcargo fmt --allcargo clippy --all-targets --all-features -- -D warningsAre there any user-facing changes?
No default behavior change. The POC is gated behind
datafusion.optimizer.enable_query_fusion.