5982 (8, 12, 15) binder error when group by all & having clause both refer to column from correlated subquery #6163
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A Group by all with a Having clause has special behavior during binding, which makes it difficult to handle correlated subqueries. This error should fix fuzzer issues 8, 12, and 15.
In fuzzer issue 8, the column c1 in the select clause references a column from a subquery in the from clause. c1 is also grouped on using the group by all, and is then in the having clause. The
group by all
forces aggregates, which requires special handling during binding. Since the column is also in a correlated subquery, the handling should be extended to also extract the column binding from the correlated subquery, but that will be a lot of work that hopefully someone can pay us for in the future. The current solution is just to throw a binder error.Issue 8
SELECT 1 alias1 FROM (SELECT 1) t2(c1) GROUP BY ALL HAVING (SELECT c1);
Issue 12
SELECT 1 FROM (SELECT 1) t1(c0) GROUP BY ALL HAVING EXISTS (SELECT 1 FROM (SELECT 1) t0(c2) HAVING c0);
issue 12Issue 15
SELECT 0 c0 FROM t1 GROUP BY ALL HAVING c0 < ALL(SELECT 0 FROM ((SELECT 2) UNION (SELECT 2)) t2 WHERE substr('b', 1, c0) GROUP BY ALL);