ygf11 opened a new issue, #5344:
URL: https://github.com/apache/arrow-datafusion/issues/5344

   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   
   After #5264, we support rewriting more `where-exists` to join, but do not 
add back the `Distinct`.
   For query:
   ```sql
   SELECT t1.t1_id
   FROM   t1
   WHERE  EXISTS(SELECT DISTINCT t2_int
                 FROM   t2
                 WHERE  t2.t2_id > t1.t1_id); 
   
   # current logical plan:
   Projection: t1.t1_id                                                         
                                                       
     LeftSemi Join:  Filter: t2.t2_id > t1.t1_id                                
                                                                               
       TableScan: t1 projection=[t1_id]                                         
                                                              
       Projection: t2.t2_id # DISTINCT is not added back                        
                                                                                
                            
         TableScan: t2 projection=[t2_id]
   ```
   Although the execution result is correct, we should add back the `DISTINCT`.
   In some cases, `DISTINCT` can filter a lot rows before join, we should let 
`user` choose.  
   
   **Describe the solution you'd like**
   Add back `Distinct` if the subquery is a `DISTINCT`.
   
   **Describe alternatives you've considered**
   A clear and concise description of any alternative solutions or features 
you've considered.
   
   **Additional context**
   Add any other context or screenshots about the feature request here.
   


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