Repository navigation
Disable pull-up when correlated inner columns are not a subset of the PARTITION BY columns - #2274
Conversation
|
@my-ship-it , this PR fixes bug from your comment #2233 (comment) |
6891a29 to
fa68005
Compare
|
Thanks for working on this! I simulated the patch by disabling CREATE TABLE t_out AS SELECT 1 a, 2 b DISTRIBUTED BY (b);
CREATE TABLE t_in AS SELECT v.a FROM (VALUES (1),(1),(2)) v(a) DISTRIBUTED BY (a);
ANALYZE t_out, t_in;
-- expected: 1 | 2 got: 0 rows
SELECT * FROM t_out
WHERE t_out.b IN (SELECT count(*) OVER () FROM t_in WHERE t_in.a = t_out.a)
OR t_out.a = 5;
-- expected: t got: f
SELECT t_out.b IN (SELECT count(*) OVER () FROM t_in WHERE t_in.a = t_out.a)
FROM t_out;
-- expected: 1 | 2 got: 0 rows
SELECT * FROM t_out
WHERE EXISTS (SELECT 1 FROM (SELECT count(*) OVER () c FROM t_in
WHERE t_in.a = t_out.a) s
WHERE s.c = t_out.b);
-- expected: 0 rows got: 1 | 2
SELECT * FROM t_out
WHERE NOT EXISTS (SELECT 1 FROM (SELECT count(*) OVER () c FROM t_in
WHERE t_in.a = t_out.a) s
WHERE s.c = t_out.b);
-- expected: 1 | 2 got: 0 rows
SELECT * FROM t_out
WHERE t_out.b = (SELECT max(c) FROM (SELECT count(*) OVER () c FROM t_in
WHERE t_in.a = t_out.a) s);
-- expected: 2 got: 3
SELECT (SELECT max(c) FROM (SELECT count(*) OVER () c FROM t_in
WHERE t_in.a = t_out.a) s)
FROM t_out;All of these go through The new check also blocks a valid case. For example, It would also help to add |
Thanks for following up on this. I will take a look. |
@yjhjstz, fixed |
7b6a212 to
7d39952
Compare
7d39952 to
56c8bd9
Compare
56c8bd9 to
8f091f5
Compare
e250604 to
0e141eb
Compare
|
Hi @Alena0704 the PR #2261 has been in the merge pipeline and will be merged once the tests are done. Maybe you need to rebase this PR again. 😢 Before rebasing, welcome to check the status: https://github.com/apache/cloudberry/pulls?q=is%3Apr+state%3Aopen+review%3Aapproved While waiting, we also need to resolve the PR's comments. Then the |
Okay, understood. Resolved it. Thank you! |
…dow function Orca built invalid plan because it pulled up subquery which contains a window function during the CXformLeftSemiApply2LeftSemiJoin transformation. Window function could return incorrect value after the pullup because tuples number which this function was calculated over was changed after the optimization. Make CXformLeftSemiApply2LeftSemiJoin inapplicable when subquery tree contains the EopScalarWindowFunc operator. Groups are shared between alternatives in Memo. We should visit each group only once to keep the traversal linear in the number of groups. The pbsVisited variable is added to keep track of visited groups. The queries to reproduce the bug are added to tests.
0e141eb to
3eac5d9
Compare
Orca built invalid plan because it pulled up subquery which contains a window
function during the Apply to Join transformations. Window function could return
incorrect value after the pull-up because tuples number which this function was
calculated over was changed after the optimization.
The pull-up is safe when the correlated inner columns are a subset of
the PARTITION BY columns. Otherwise the pull-up is disabled.
FProcessProject processes CLogicalProject too. CLogicalProject processing is
not changed.
The queries to reproduce the bug are added to tests.