Re: search_plan_tree(): handling of non-leaf CustomScanState nodes causes segfault
David Geier <david@swarm64.com>
From: David Geier <david@swarm64.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Date: 2021-01-18T21:32:12Z
Lists: pgsql-hackers
Attachments
- search_plan_tree_patch_2.txt (text/plain)
Hi, On 18.01.21 19:46, Tom Lane wrote: > David Geier <david@swarm64.com> writes: >> search_plan_tree() assumes that >> CustomScanState::ScanState::ss_currentRelation is never NULL. In my >> understanding that only holds for CustomScanState nodes which are at the >> bottom of the plan and actually read from a relation. CustomScanState >> nodes which are not at the bottom don't have ss_currentRelation set. I >> believe for such nodes, instead search_plan_tree() should recurse into >> CustomScanState::custom_ps. > Hm. I agree that we shouldn't simply assume that ss_currentRelation > isn't null. However, we cannot make search_plan_tree() descend > through non-leaf CustomScan nodes, because we don't know what processing > is involved there. We need to find a scan that is guaranteed to return > rows that are one-to-one with the cursor output. This is why the function > doesn't descend through join or aggregation nodes, and I see no argument > by which we should assume we know more about what a customscan node will > do than we know about those. That makes sense. Thanks for the explanation. > > So I'm inclined to think a suitable fix is just > > - if (RelationGetRelid(sstate->ss_currentRelation) == table_oid) > + if (sstate->ss_currentRelation && > + RelationGetRelid(sstate->ss_currentRelation) == table_oid) > result = sstate; > > regards, tom lane > > I updated the patch to match your proposal. Best regards, David Swarm64
Commits
-
Remove faulty support for MergeAppend plan with WHERE CURRENT OF.
- 0ab177bec1c5 9.5.25 landed
- fe8edbb8267a 9.6.21 landed
- fac54bd5e216 10.16 landed
- 794562d0770a 11.11 landed
- 6253159965d5 12.6 landed
- 188cd4f440ed 13.2 landed
- a0efda88a679 14.0 landed
-
Avoid crash with WHERE CURRENT OF and a custom scan plan.
- 33a46993f15a 9.5.25 landed
- ffbf1746354a 9.6.21 landed
- 5cd94de777e0 10.16 landed
- de622e677cfd 11.11 landed
- ba80489c66cf 12.6 landed
- f0f53195b51a 13.2 landed
- 60661bbf2dca 14.0 landed