tlfua opened a new issue, #27830:
URL: https://github.com/apache/datafusion/issues/27830
### Describe the bug
The same `EXISTS` query over two nested filters on a correlated `count(*)`
fails with a schema error in some runs and returns the correct rows in others.
### To Reproduce
```sql
CREATE TABLE t (a INT) AS VALUES (1), (2), (4);
CREATE TABLE i (a INT) AS VALUES (1), (2), (2), (3);
SELECT o.a FROM t o WHERE EXISTS (
SELECT 1 FROM (
SELECT v FROM (
SELECT v FROM (SELECT count(*) AS v FROM i WHERE i.a = o.a) w WHERE v
>= 0
) w WHERE v >= 0
) e
) ORDER BY o.a;
```
Running this query 20 times in one `sqllogictest` file (DataFusion main at
25da21b69703fad181f08f64568b90ebb963e0e0) gives the error 10 times:
```text
Optimizer rule 'decorrelate_predicate_subquery' failed
caused by
Schema error: No field named w.v. Did you mean 'e.v'?
Valid fields are e.v, e.a, e.__always_true.
```
The other 10 runs return `1, 2, 4`. I reproduced it only with
`sqllogictest`, not with `datafusion-cli`.
### Expected behavior
Always `1, 2, 4` (DuckDB 2.0.1 returns `1, 2, 4`).
### Additional context
It also happens when the two derived tables have different aliases (`w1`,
`w2`: 11 errors in 20 runs). I have not found the source of the nondeterminism.
--
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]