Fix segfault on execution of multilevel correlated queries.#204
Fix segfault on execution of multilevel correlated queries.#204Stolb27 merged 2 commits into6.16.3_arenadata22from
Conversation
Execution of multilevel correlated queries with high level of nesting can cause segfault(when using array_agg, json_agg) or can provide wrong results (when using classic aggs like sum()). Due to some GP limitations, correlated subqueries with skip-level correlations are not supported. Additional check condition is provided to prevent such queries from planning. QueryHasDistributedRelation function, used by this check, doesn't recurse over subplans and may return wrong results for distributed RTE_RELATION entries hided by RTE_SUBQUERY entries. Commit fixes such behavior by adding optional recursion to QueryHasDistributedRelation function. Additional regression test is included. Additional information can be found at issue #12054.
|
Still waiting pivotal for |
|
Got explanation and PR pre-approval from pivotal. |
…l regression test. Unnecessary space removed. (cherry picked from commit 0cc2fb5)
|
Cherry picked additional changes proposed by pivotal developer. |
darthunix
left a comment
There was a problem hiding this comment.
If we treat this PR as a hot fix, then LGTM. But I agree with @guofengrichard - we should think how to build a correct plan for correlated subqueries with SubPlans instead of InitPlans (surely, it is a separate task). @Stolb27 what do you think?
@darthunix, I've tried to reproduce the mentioned case on 6X_STABLE and got the next results. There are correlated SubPlans only. Can you explain for me mentioned problem? |
|
@Stolb27 it is legal to use nested correlated SubPlans - we have only a problem with InitPlans. It is good that Orca can build a correct plan with SubPlans instead of InitPlans (but I have no idea, does ORCA always use SubPlans instead of InitPlans where needed). Current PR fixes only Postgres optimizer. |
Execution of multilevel correlated queries with high level of nesting can cause segfault(when using array_agg, json_agg) or can provide wrong results (when using classic aggs like sum()). Due to some GP limitations, correlated subqueries with skip-level correlations are not supported. Additional check condition is provided to prevent such queries from planning. QueryHasDistributedRelation function, used by this check, doesn't recurse over subplans and may return wrong results for distributed RTE_RELATION entries hided by RTE_SUBQUERY entries. Commit fixes such behavior by adding optional recursion to QueryHasDistributedRelation function. Additional regression test is included. Additional information can be found at issue #12054. (cherry picked from commit a70454d)
…#204) (#239) Execution of multilevel correlated queries with high level of nesting can cause segfault(when using array_agg, json_agg) or can provide wrong results (when using classic aggs like sum()). Due to some GP limitations, correlated subqueries with skip-level correlations are not supported. Additional check condition is provided to prevent such queries from planning. QueryHasDistributedRelation function, used by this check, doesn't recurse over subplans and may return wrong results for distributed RTE_RELATION entries hided by RTE_SUBQUERY entries. Commit fixes such behavior by adding optional recursion to QueryHasDistributedRelation function. Additional regression test is included. Additional information can be found at issue #12054. (cherry picked from commit a70454d)
Execution of multilevel correlated queries with high level of nesting can cause segfault(when using array_agg, json_agg) or can provide wrong results (when using classic aggs like sum()). Due to some GP limitations, correlated subqueries with skip-level correlations are not supported. Additional check condition is provided to prevent such queries from planning. QueryHasDistributedRelation function, used by this check, doesn't recurse over subplans and may return wrong results for distributed RTE_RELATION entries hided by RTE_SUBQUERY entries.
Commit fixes such behavior by adding optional recursion to QueryHasDistributedRelation function. Additional regression test is included. Additional information can be found at issue #12054.