Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f60e1f

Browse files
committed
Fix plpgsql's handling of simple expressions in scrollable cursors.
exec_save_simple_expr did not account for the possibility thatstandard_planner would stick a Materialize node atop the planof even a simple Result, if CURSOR_OPT_SCROLL is set. This ledto an "unexpected plan node type" error.This is a very old bug, but it'd only be reached by declaring acursor for a "SELECT simple-expression" query and explicitlymarking it scrollable, which is an odd thing to do. So the lackof prior reports isn't too surprising.Bug: #18859Reported-by: Olleg Samoylov <splarv@ya.ru>Author: Andrei Lepikhov <lepihov@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/18859-0d5f28ac99a37059@postgresql.orgBackpatch-through: 13
1 parentc600265 commit0f60e1f

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

‎src/pl/plpgsql/src/expected/plpgsql_simple.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,14 @@ select simplecaller();
118118
44
119119
(1 row)
120120

121+
-- Check handling of simple expression in a scrollable cursor (bug #18859)
122+
do $$
123+
declare
124+
p_CurData refcursor;
125+
val int;
126+
begin
127+
open p_CurData scroll for select 42;
128+
fetch p_CurData into val;
129+
raise notice 'val = %', val;
130+
end; $$;
131+
NOTICE: val = 42

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8282,10 +8282,12 @@ exec_save_simple_expr(PLpgSQL_expr *expr, CachedPlan *cplan)
82828282
/*
82838283
* Ordinarily, the plan node should be a simple Result. However, if
82848284
* force_parallel_mode is on, the planner might've stuck a Gather node
8285-
* atop that. The simplest way to deal with this is to look through the
8286-
* Gather node. The Gather node's tlist would normally contain a Var
8287-
* referencing the child node's output, but it could also be a Param, or
8288-
* it could be a Const that setrefs.c copied as-is.
8285+
* atop that; and/or if this plan is for a scrollable cursor, the planner
8286+
* might've stuck a Material node atop it. The simplest way to deal with
8287+
* this is to look through the Gather and/or Material nodes. The upper
8288+
* node's tlist would normally contain a Var referencing the child node's
8289+
* output, but it could also be a Param, or it could be a Const that
8290+
* setrefs.c copied as-is.
82898291
*/
82908292
plan=stmt->planTree;
82918293
for (;;)
@@ -8303,7 +8305,7 @@ exec_save_simple_expr(PLpgSQL_expr *expr, CachedPlan *cplan)
83038305
((Result*)plan)->resconstantqual==NULL);
83048306
break;
83058307
}
8306-
elseif (IsA(plan,Gather))
8308+
elseif (IsA(plan,Gather)||IsA(plan,Material))
83078309
{
83088310
Assert(plan->lefttree!=NULL&&
83098311
plan->righttree==NULL&&

‎src/pl/plpgsql/src/sql/plpgsql_simple.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,15 @@ as $$select 22 + 22$$;
102102
select simplecaller();
103103

104104
select simplecaller();
105+
106+
-- Check handling of simple expression in a scrollable cursor (bug #18859)
107+
108+
do $$
109+
declare
110+
p_CurData refcursor;
111+
valint;
112+
begin
113+
open p_CurData scroll forselect42;
114+
fetch p_CurData into val;
115+
raise notice'val = %', val;
116+
end; $$;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp