Dandandan commented on issue #5646:
URL: 
https://github.com/apache/arrow-datafusion/issues/5646#issuecomment-1495419953

   Another observation I have is that the plan does some unnecessary casting:
   
   ```
   Projection: CAST(SUM(lineitem.l_extendedprice) AS Float64) / Float64(7) AS 
avg_yearly
     Aggregate: groupBy=[[]], aggr=[[SUM(lineitem.l_extendedprice)]]
       Projection: lineitem.l_extendedprice
         Inner Join: part.p_partkey = __scalar_sq_3.l_partkey Filter: 
CAST(lineitem.l_quantity AS Decimal128(30, 15)) < CAST(__scalar_sq_3.__value AS 
Decimal128(30, 15))
           Projection: lineitem.l_quantity, lineitem.l_extendedprice, 
part.p_partkey
             Inner Join: lineitem.l_partkey = part.p_partkey
               TableScan: lineitem projection=[l_partkey, l_quantity, 
l_extendedprice]
               Projection: part.p_partkey
                 Filter: part.p_brand = Utf8("Brand#23") AND part.p_container = 
Utf8("MED BOX")
                   TableScan: part projection=[p_partkey, p_brand, 
p_container], partial_filters=[part.p_brand = Utf8("Brand#23"), 
part.p_container = Utf8("MED BOX")]
           SubqueryAlias: __scalar_sq_3
             Projection: lineitem.l_partkey, Float64(0.2) * 
CAST(AVG(lineitem.l_quantity) AS Float64) AS __value
               Aggregate: groupBy=[[lineitem.l_partkey]], 
aggr=[[AVG(lineitem.l_quantity)]]
                 TableScan: lineitem projection=[l_partkey, l_quantity]
   ```
   
   1. inside the aggregation (in `sum_batch`)
   2. cast to float for `__scalar_sq_3.__value`
   3. cast back to decimal inside join


-- 
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]

Reply via email to