alamb commented on code in PR #11066:
URL: https://github.com/apache/datafusion/pull/11066#discussion_r1650081511


##########
datafusion/optimizer/src/propagate_empty_relation.rs:
##########
@@ -142,13 +146,19 @@ impl OptimizerRule for PropagateEmptyRelation {
                             schema: join.schema.clone(),
                         }),
                     )),
+                    JoinType::LeftAnti if right_empty => {

Review Comment:
   I double checked that an ANTI join (e.g. a `NOT IN`) is true when there are 
no tuples (aka the right side is emprt)
   
   ```sql
   postgres=# select * from foo;
     x
   -----
      1
      2
    NaN
   (3 rows)
   
   postgres=# select * from bar;
    y
   ---
   (0 rows)
   
   postgres=# select x NOT IN (SELECT y from bar) from foo;
    ?column?
   ----------
    t
    t
    t
   (3 rows)
   postgres=# select x from foo where NOT EXISTS (SELECT y from bar);
     x
   -----
      1
      2
    NaN
   (3 rows)
   ```
   
   Thus I think this is a valid rewrite



##########
datafusion/optimizer/src/propagate_empty_relation.rs:
##########
@@ -142,13 +146,19 @@ impl OptimizerRule for PropagateEmptyRelation {
                             schema: join.schema.clone(),
                         }),
                     )),
+                    JoinType::LeftAnti if right_empty => {

Review Comment:
   I double checked that an ANTI join (e.g. a `NOT IN`) is true when there are 
no tuples (aka the right side is emprt)
   
   ```sql
   postgres=# select * from foo;
     x
   -----
      1
      2
    NaN
   (3 rows)
   
   postgres=# select * from bar;
    y
   ---
   (0 rows)
   
   postgres=# select x NOT IN (SELECT y from bar) from foo;
    ?column?
   ----------
    t
    t
    t
   (3 rows)
   
   postgres=# select x from foo where NOT EXISTS (SELECT y from bar);
     x
   -----
      1
      2
    NaN
   (3 rows)
   ```
   
   Thus I think this is a valid rewrite



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to