You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem or challenge?
When running TPC-H q1 in Spark + DataFusion Comet, the expression l_extendedprice#21 * (1 - l_discount#22) appears twice in the query and currently gets evaluated twice. This could be optimized out so that it is only evaluated once. I was able to test this by manually rewriting the query.
Original Query
select
l_returnflag,
l_linestatus,
sum(l_quantity) as sum_qty,
sum(l_extendedprice) as sum_base_price,
sum(l_extendedprice * (1- l_discount)) as sum_disc_price,
sum(l_extendedprice * (1- l_discount) * (1+ l_tax)) as sum_charge,
avg(l_quantity) as avg_qty,
avg(l_extendedprice) as avg_price,
avg(l_discount) as avg_disc,
count(*) as count_order
from
lineitem
where
l_shipdate <=date'1998-12-01'- interval '68 days'group by
l_returnflag,
l_linestatus
order by
l_returnflag,
l_linestatus;
Optimized Query
select
l_returnflag,
l_linestatus,
sum(l_quantity) as sum_qty,
sum(l_extendedprice) as sum_base_price,
sum(foo) as sum_disc_price,
sum(foo * (1+ l_tax)) as sum_charge,
avg(l_quantity) as avg_qty,
avg(l_extendedprice) as avg_price,
avg(l_discount) as avg_disc,
count(*) as count_order
from (select
l_returnflag,
l_linestatus,
l_quantity,
l_extendedprice,
l_extendedprice * (1- l_discount) as foo,
l_tax,
l_discount
from lineitem
where
l_shipdate <=date'1998-12-01'- interval '68 days')
group by
l_returnflag,
l_linestatus
order by
l_returnflag,
l_linestatus;
I would like a physical optimizer rule in DataFusion for common subexpression elimination. IIRC, we already have a logical rule for doing this, but that does not help for projects that are using other query front ends and then mapping to DataFusion's physical plan.
An alternative option would be to implement this directly in Comet.
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
We have also added this issue to our todo's (though we likely won't be able to address it in the short term). It would be better to have this rule implemented directly in DataFusion.
Is your feature request related to a problem or challenge?
When running TPC-H q1 in Spark + DataFusion Comet, the expression
l_extendedprice#21 * (1 - l_discount#22)
appears twice in the query and currently gets evaluated twice. This could be optimized out so that it is only evaluated once. I was able to test this by manually rewriting the query.Original Query
Optimized Query
Timings (Original)
Timings (Optimized)
Describe the solution you'd like
I would like a physical optimizer rule in DataFusion for common subexpression elimination. IIRC, we already have a logical rule for doing this, but that does not help for projects that are using other query front ends and then mapping to DataFusion's physical plan.
An alternative option would be to implement this directly in Comet.
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: