jayzhan211 commented on code in PR #27019:
URL: https://github.com/apache/datafusion/pull/27019#discussion_r4650114154


##########
datafusion/sqllogictest/test_files/subquery.slt:
##########
@@ -4956,3 +4956,102 @@ statement ok
 DROP TABLE t26234;
 
 
+
+# Two equal `SubqueryAlias` nodes in one subquery share an entry in the
+# decorrelation maps, so the second `t2 AS s` would replace what the first
+# one records. These error instead of returning wrong rows.
+# See https://github.com/apache/datafusion/issues/26692
+statement ok
+CREATE TABLE t26692 (a INT, b INT) AS VALUES (1, 1), (2, 2), (3, NULL);
+
+statement ok
+CREATE TABLE t26692_2 (a INT, b INT) AS VALUES (1, 1), (3, 30), (2, NULL);
+
+query error DataFusion error: This feature is not implemented: Physical plan 
does not support logical expression Exists
+SELECT t.a FROM t26692 t, t26692_2 AS s
+WHERE EXISTS (
+  SELECT 1 FROM (SELECT * FROM t26692_2 AS s WHERE s.a = t.a) x
+  CROSS JOIN t26692_2 AS s
+);
+
+query error DataFusion error: This feature is not implemented: Physical plan 
does not support logical expression Exists
+SELECT t.a FROM t26692 t, t26692_2 AS s
+WHERE NOT EXISTS (
+  SELECT 1 FROM (SELECT * FROM t26692_2 AS s WHERE s.a = t.a) x
+  CROSS JOIN t26692_2 AS s
+);
+
+query error DataFusion error: This feature is not implemented: Physical plan 
does not support logical expression InSubquery
+SELECT t.a FROM t26692 t, t26692_2 AS s
+WHERE t.a IN (
+  SELECT x.a FROM (SELECT * FROM t26692_2 AS s WHERE s.b = t.b) x
+  CROSS JOIN t26692_2 AS s
+);

Review Comment:
   Optional: the same shape with `IN` in the select list returns wrong rows on 
main (`false, false, true` for each `t.a`, where every row should be `true`) 
and errors on this branch, but no test covers it. That form is rewritten to a 
mark join, a different path from `WHERE ... IN`:
   
   ```suggestion
   );
   
   # The same in a projection, which `decorrelate_predicate_subquery` rewrites
   # to a mark join.
   query error DataFusion error: This feature is not implemented: Physical plan 
does not support logical expression InSubquery
   SELECT t.a, t.a IN (
     SELECT x.a FROM (SELECT * FROM t26692_2 AS s WHERE s.a = t.a) x
     CROSS JOIN t26692_2 AS s
   ) FROM t26692 t, t26692_2 AS s;
   ```
   



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