Dandandan opened a new issue #566:
URL: https://github.com/apache/arrow-datafusion/issues/566


   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   I like to support eliminating common subexpressions from a query plan.
   
   For example, this example from TCP-H query 1:
   ```sql
   select *
       sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
       sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge
   from T
   ```
   could be rewritten to reuse the result of `l_extendedprice * (1 - 
l_discount)` by moving it into another projection.
   This looks in SQL as something like:
   
   ```sql
   with temp as (
      select
          l_extendedprice * (1 - l_discount) as cs
      from t
   )
   select 
       sum(cs) as sum_disc_price,
       sum(cs * (1 + l_tax)) as sum_charge
   from temp
   ```
   
   **Describe the solution you'd like**
   Detect common subexpression in projections / group by, join conditions etc. 
and remove them by moving doing them once in a projection step. Note: this only 
makes sense when the expression includes any calculation (e.g. not a column 
reference with alias).
   
   **Describe alternatives you've considered**
   n/a
   **Additional context**
   n/a


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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to