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

   ### Is your feature request related to a problem or challenge?
   
   After https://github.com/apache/arrow-datafusion/pull/7721 a `SortExec` with 
a limit will use a special [`TopK` 
operator](https://github.com/apache/arrow-datafusion/blob/e95a24b5a260e0e2f603d52682d36cce192676f8/datafusion/physical-plan/src/topk/mod.rs#L40-L75)
   
   However, I don't think it  is clear from the EXPLAIN plan that this will be 
used (you have to know that sort with a limit is specially optimized to not 
actually sort). 
   
   Using DataFusion CLI  and the dataset described here: 
https://github.com/apache/arrow-datafusion/pull/7721#pullrequestreview-1658084301,
 the explain plan looks like 
   
   ```
   ❯ explain select trace_id from 'traces.parquet' order by time desc limit 10;
   
+---------------+-------------------------------------------------------------------------------------------------------------------+
   | plan_type     | plan                                                       
                                                       |
   
+---------------+-------------------------------------------------------------------------------------------------------------------+
   | logical_plan  | Projection: traces.parquet.trace_id                        
                                                       |
   |               |   Limit: skip=0, fetch=10                                  
                                                       |
   |               |     Sort: traces.parquet.time DESC NULLS FIRST, fetch=10   
                                                       |
   |               |       Projection: traces.parquet.trace_id, 
traces.parquet.time                                                    |
   |               |         TableScan: traces.parquet projection=[time, 
trace_id]                                                     |
   | physical_plan | ProjectionExec: expr=[trace_id@0 as trace_id]              
                                                       |
   |               |   GlobalLimitExec: skip=0, fetch=10                        
                                                       |
   |               |     SortExec: fetch=10, expr=[time@1 DESC]         <----- 
****  this uses the TopK operator |                                             
                  
   |               |       ProjectionExec: expr=[trace_id@1 as trace_id, time@0 
as time]                                               |
   |               |         ParquetExec: file_groups={1 group: 
[[traces.parquet]]}, projection=[time, trace_id] |
   |               |                                                            
                                                       |
   
+---------------+-------------------------------------------------------------------------------------------------------------------+
   2 rows in set. Query took 0.004 seconds.
   ```
   
   ### Describe the solution you'd like
   
   
   I would like to make it clearer in the explain plan that this new operator 
is used. Perhaps something like
   
   ```
   SortExec: TopK(fetch=10), expr=[time@1 DESC]         <----- **** This is 
updated |                                                               
   ```
   
   See comment in 
https://github.com/apache/arrow-datafusion/pull/7721/files#r1343969678 for 
exactly where this code that controls the output is
   
   ### Describe alternatives you've considered
   
   We can leave the explain plans alone, but I think that is confusing
   
   ### Additional context
   
   _No response_


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