zhuqi-lucas commented on code in PR #16641:
URL: https://github.com/apache/datafusion/pull/16641#discussion_r2179165257


##########
datafusion/physical-optimizer/src/enforce_sorting/sort_pushdown.rs:
##########
@@ -668,6 +668,15 @@ fn handle_hash_join(
     plan: &HashJoinExec,
     parent_required: OrderingRequirements,
 ) -> Result<Option<Vec<Option<OrderingRequirements>>>> {
+    // Anti-joins (LeftAnti or RightAnti) do not preserve meaningful input 
order,
+    // so sorting beforehand cannot be relied on. Bail out early for both 
flavors:
+    match plan.join_type() {
+        JoinType::LeftAnti | JoinType::RightAnti => {
+            return Ok(None);
+        }
+        _ => {}
+    }

Review Comment:
   But we support Topk(sort with limit) pushdown for hash join:
   
   ```rust
    explain
   SELECT *
   FROM t1
   LEFT ANTI JOIN t2 ON t1.k = t2.k
   ORDER BY t1.k
   LIMIT 2;
   
+---------------+------------------------------------------------------------+
   | plan_type     | plan                                                       
|
   
+---------------+------------------------------------------------------------+
   | physical_plan | ┌───────────────────────────┐                              
|
   |               | │  SortPreservingMergeExec  │                              
|
   |               | │    --------------------   │                              
|
   |               | │   k ASC NULLS LASTlimit:  │                              
|
   |               | │             2             │                              
|
   |               | └─────────────┬─────────────┘                              
|
   |               | ┌─────────────┴─────────────┐                              
|
   |               | │    CoalesceBatchesExec    │                              
|
   |               | │    --------------------   │                              
|
   |               | │          limit: 2         │                              
|
   |               | │                           │                              
|
   |               | │     target_batch_size:    │                              
|
   |               | │            8192           │                              
|
   |               | └─────────────┬─────────────┘                              
|
   |               | ┌─────────────┴─────────────┐                              
|
   |               | │        HashJoinExec       │                              
|
   |               | │    --------------------   │                              
|
   |               | │    join_type: RightAnti   ├──────────────┐               
|
   |               | │        on: (k = k)        │              │               
|
   |               | └─────────────┬─────────────┘              │               
|
   |               | ┌─────────────┴─────────────┐┌─────────────┴─────────────┐ 
|
   |               | │       DataSourceExec      ││       SortExec(TopK)      │ 
|
   |               | │    --------------------   ││    --------------------   │ 
|
   |               | │         bytes: 224        ││     k@0 ASC NULLS LAST    │ 
|
   |               | │       format: memory      ││                           │ 
|
   |               | │          rows: 1          ││          limit: 2         │ 
|
   |               | └───────────────────────────┘└─────────────┬─────────────┘ 
|
   |               |                              ┌─────────────┴─────────────┐ 
|
   |               |                              │      RepartitionExec      │ 
|
   |               |                              │    --------------------   │ 
|
   |               |                              │ partition_count(in->out): │ 
|
   |               |                              │          1 -> 14          │ 
|
   |               |                              │                           │ 
|
   |               |                              │    partitioning_scheme:   │ 
|
   |               |                              │    RoundRobinBatch(14)    │ 
|
   |               |                              └─────────────┬─────────────┘ 
|
   |               |                              ┌─────────────┴─────────────┐ 
|
   |               |                              │       DataSourceExec      │ 
|
   |               |                              │    --------------------   │ 
|
   |               |                              │        bytes: 80384       │ 
|
   |               |                              │       format: memory      │ 
|
   |               |                              │          rows: 2          │ 
|
   |               |                              └───────────────────────────┘ 
|
   |               |                                                            
|
   
+---------------+------------------------------------------------------------+
   1 row(s) fetched.
   Elapsed 0.002 seconds.
   ```



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to