You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "nathanb9 (via GitHub)" <gi...@apache.org> on 2026/06/26 22:35:59 UTC

[I] Fuse multiple scalar-aggregate subqueries over the same source into a single scan [datafusion]

nathanb9 opened a new issue, #23213:
URL: https://github.com/apache/datafusion/issues/23213

   **Problem**
   
   When a query computes several uncorrelated scalar-aggregate subqueries over the same table, DataFusion scans that table once per subquery.
   
   **Proposed rewrite**
   
   When 2 or more such subqueries share one source, fuse them into a single scan + aggregate, pushing each subquery's predicate into a `FILTER (WHERE ...)` clause:
   
   ```sql
   -- Before: two scans of t
   SELECT (SELECT count(*) FROM t WHERE a < 10),
          (SELECT avg(x)   FROM t WHERE a >= 10);
   
   -- After: one scan of t
   SELECT count(*) FILTER (WHERE a < 10),
          avg(x)   FILTER (WHERE a >= 10)
   FROM t;
   ```
   
   The source filter becomes the OR of the branch predicates, and each scalar subquery is replaced by a reference to the merged aggregate.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Fuse multiple scalar-aggregate subqueries over the same source into a single scan [datafusion]

Posted by "nathanb9 (via GitHub)" <gi...@apache.org>.
nathanb9 commented on issue #23213:
URL: https://github.com/apache/datafusion/issues/23213#issuecomment-4813880905

   take


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org