andygrove opened a new issue, #7860: URL: https://github.com/apache/datafusion-comet/issues/7860
### What is the problem the feature request solves? Several TPC-DS queries scan the same fact table many times, with each scan differing only in its filter and aggregate. In DataFlint's analysis of Onehouse's 10 TB TPC-DS runs ([part 2](https://medium.com/@menishmueli/onehouse-quanton-vs-spark-4-1-the-10-tb-tpc-ds-benchmark-analyzed-with-dataflint-f087e7864bdf)), on Spark 4.1.3: - q9 scans `store_sales` (about 2 TB) 16 times: 16 scan stages, 226,426 tasks, 17 m 31 s on Spark. Both Comet runs kept the same shape, 15 scans of 15,094 tasks each. - q88 does the same with 32 scans and q28 with 6. Onehouse Quanton merges these into one scan feeding one aggregate (q9: 1,499 tasks, 29 s). That accounts for a large share of its scan-stage savings, and no fetch or decode optimization can match it, since it removes the reads entirely. ### Describe the potential solution Two routes, which are not mutually exclusive: 1. **Spark 4.2 and later.** Spark 4.2 renames `MergeScalarSubqueries` to `MergeSubplans` and widens it to merge any one-row subplan, including bare non-grouping aggregates, which is the q88 shape. Its output is a struct-typed scalar subquery that currently takes the consuming projection off Comet (#5834). Fixing #5834 lets Comet keep the merged plan native. First check whether `MergeSubplans` merges subplans whose filters differ, which q9 and q28 need: if it does not, this route covers q88 only. 2. **A Comet optimizer rule for Spark 3.5 to 4.1**, or for the shapes `MergeSubplans` doesn't handle. Merge sibling scans of the same relation whose plans differ only in filters and aggregates into one scan, push the OR of the filters into the scan, and move each original filter into its aggregate as a `FILTER (WHERE ...)` clause. This is the transformation Spark proposed in SPARK-40193. Measure on q9, q28 and q88 at SF1000 or larger, with the task count and bytes scanned. ### Additional context Part of the 10 TB TPC-DS gap epic. Source: DataFlint's Quanton article ([part 2](https://medium.com/@menishmueli/onehouse-quanton-vs-spark-4-1-the-10-tb-tpc-ds-benchmark-analyzed-with-dataflint-f087e7864bdf)). -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
