fix: guard against NULL subplan in full-path MERGE sub-case 1 (#2536) - #2546
Open
waterWang wants to merge 1 commit into
Open
fix: guard against NULL subplan in full-path MERGE sub-case 1 (#2536)#2546waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
…#2536) When MERGE is the first clause followed by WITH (Case 3, sub-case 1), the code assumes the child execution node is always a SubqueryScanState and dereferences sss->subplan to obtain the tuple descriptor for the remade scan slot. When the MERGE path pattern produces no base-relation scan (e.g. empty graph), the planner emits a plain Result plan instead of a SubqueryScan, the cast-to-SubqueryScanState reads through the wrong struct layout, sss->subplan is NULL, and ExecGetResultType(NULL) segfaults. Fix: check IsA(lefttree, SubqueryScanState) before using SubqueryScanState internals. When the child is a SubqueryScan the original code path (remake child scan slot via sss->ss + ExecGetResultType(sss->subplan)) is preserved without regression. When the child is a Result plan, use the generic PlanState API (ExecGetResultType(lefttree)) and store the remade slot in the MERGE node's own ScanState. Fixes apache#2536.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2536.
Root cause: When a full-path MERGE is the first clause followed by a
WITH (Case 3, sub-case 1, path-not-found → create path), the code assumes
node->ss.ps.lefttreeis always aSubqueryScanStateand readsExecGetResultType(sss->subplan). When the MERGE path pattern producesno base-relation scan (e.g. empty graph), the planner emits a plain
Resultplan, theSubqueryScanStatecast reads through the wrong structlayout,
sss->subplanisNULL, andExecGetResultType(NULL)segfaults.Fix: check
IsA(lefttree, SubqueryScanState)before usingSubqueryScanStateinternals. For aSubqueryScanchild the originalcode path (remake child scan slot via
sss->ss+ExecGetResultType(sss->subplan))is preserved. For a
Resultchild, use the genericPlanStateAPI(
ExecGetResultType(lefttree)) and store the remade slot in the MERGEnode's own
ScanState.Tests: 41/43 regression tests pass (age_load and age_upgrade are
pre-existing environment failures). New regression test added to
regress/sql/expr.sqlreproduces the exact query shape from #2536.