Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f0f5319

Browse files
committed
Avoid crash with WHERE CURRENT OF and a custom scan plan.
execCurrent.c's search_plan_tree() assumed that ForeignScanStates and CustomScanStates necessarily have a valid ss_currentRelation. This is demonstrably untrue for postgres_fdw's remote join and remote aggregation plans, and non-leaf custom scans might not have an identifiable scan relation either. Avoid crashing by ignoring such nodes when the field is null. This solution will lead to errors like 'cursor "foo" is not a simply updatable scan of table "bar"' in cases where maybe we could have allowed WHERE CURRENT OF to work. That's not an issue for postgres_fdw's usages, since joins or aggregations would render WHERE CURRENT OF invalid anyway. But an otherwise-transparent upper level custom scan node might find this annoying. When and if someone cares to expend work on such a scenario, we could invent a custom-scan-provider callback to determine what's safe. Report and patch by David Geier, commentary by me. It's been like this for awhile, so back-patch to all supported branches. Discussion: https://postgr.es/m/0253344d-9bdd-11c4-7f0d-d88c02cd7991@swarm64.com
1 parent b8daf89 commit f0f5319

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/executor/execCurrent.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,12 @@ search_plan_tree(PlanState *node, Oid table_oid,
317317
switch (nodeTag(node))
318318
{
319319
/*
320-
* Relation scan nodes can all be treated alike
320+
* Relation scan nodes can all be treated alike. Note that
321+
* ForeignScan and CustomScan might not have a currentRelation, in
322+
* which case we just ignore them. (We dare not descend to any
323+
* child plan nodes they might have, since we do not know the
324+
* relationship of such a node's current output tuple to the
325+
* children's current outputs.)
321326
*/
322327
case T_SeqScanState:
323328
case T_SampleScanState:
@@ -330,7 +335,8 @@ search_plan_tree(PlanState *node, Oid table_oid,
330335
{
331336
ScanState *sstate = (ScanState *) node;
332337

333-
if (RelationGetRelid(sstate->ss_currentRelation) == table_oid)
338+
if (sstate->ss_currentRelation &&
339+
RelationGetRelid(sstate->ss_currentRelation) == table_oid)
334340
result = sstate;
335341
break;
336342
}

0 commit comments

Comments
 (0)