Replies: 3 comments 4 replies
-
In the meantime I've found duckdb/duckdb#8445 which is similar to what we're trying to accomplish. In this DuckDB proposal the scan sharing is not explicit in the query plan. Instead the planner/optimizer would detect the duplicate execution plan portions and rearranges things accordingly. |
Beta Was this translation helpful? Give feedback.
-
This is a great feature, and I also believe it'll speed up tpch: https://github.com/dragansah/tpch-dbgen/blob/master/tpch-queries/21.sql, https://github.com/dragansah/tpch-dbgen/blob/master/tpch-queries/15.sql |
Beta Was this translation helpful? Give feedback.
-
There is some additional discussion on a similar sounding feature here: Another potential approach is to fully materialize the input ( Basically the tricky bit with an approach to share the scan is that in the general case the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In the system I'm working on I want to perform multiple aggregates using different group by criteria over large data sets.
I don't think grouping sets are an option since those support computing a single set of aggregates over multiple groupings. What I'm trying to achieve instead is one multiple sets of aggregates that each have their own group by strategy.
A simple way to do this is to just run multiple queries of course. That works but requires scanning through the data multiple times. That becomes prohibitive pretty quickly as the number of sets of aggregates increases.
While I was experimenting with the multiple query approach and combining those into a single query using 'union all' I started wondering if I couldn't write an operator to have my cake and eat it. So rather than this:
which results in a logical plan that sort of looks like this (edited for brevity/clarity)
what I would want to do instead is something like this
CommonInputPlaceholder
is a stub node that has the same schema as theCommonInput
child.The Unify operator works by setting up queues for each
CommonInputPlaceholder
. It polls theCommonInput
child, and places a duplicate of each record batch it receives onto each queue. This is kind of similar to how RepartitionExec does its thing but instead of assigning each record batch once, we duplicate and assign it multiple times.With quite some trial and error I've been able to get something up and running, but I have a feeling I'm going against the grain of the framework. Getting the optimizer to do the right thing for instance proved to be a challenge since it expects plans to be trees rather than DAGs.
My question for the group is if someone else has tried to implement something like this before? Or if what I'm trying to accomplish can be done in some other way? Perhaps someone has advice on how to best go about implementing this?
I realize this colors outside the lines of what you can express in SQL (as far as I know at least). I'm creating my queries by directly instantiating logical plans so for now that's not an issue for the system I'm working on.
Edit: I accidentally ended up writing an example that can be done with grouping sets since the sets of aggregates were identical. Update example to use different aggregates.
Beta Was this translation helpful? Give feedback.
All reactions