pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrei Lepikhov <lepihov@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: splarv@ya.ru
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18859: ERROR: unexpected plan node type: 356
Date: Fri, 21 Mar 2025 15:49:40 +0100
Message-ID: <ee51b44b-8759-4600-a3af-c0565c9bea12@gmail.com> (raw)
In-Reply-To: <1243263.1742562053@sss.pgh.pa.us>
References: <18859-0d5f28ac99a37059@postgresql.org>
	<72c3c1f4-9ed1-4d1c-ae67-eb04b8e50cd1@gmail.com>
	<1243263.1742562053@sss.pgh.pa.us>

On 21/3/2025 14:00, Tom Lane wrote:
> Andrei Lepikhov <lepihov@gmail.com> writes:
>> The problem here is in the scrollable cursors code which inserts
>> Material node:
> 
> Yeah, I'd just come to the same conclusion.  I guess we can make
> this code look through a Material node as well as Gather.
Yes, as I see there are no additional corner cases. See the code in 
attachment.

-- 
regards, Andrei Lepikhov

Attachments:

scrollable-fix.diff (text/plain, 2.1K) download diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index d4377ceecbf..f3691eb2f58 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -8306,6 +8306,8 @@ exec_save_simple_expr(PLpgSQL_expr *expr, CachedPlan *cplan) * Gather node. The Gather node's tlist would normally contain a Var * referencing the child node's output, but it could also be a Param, or * it could be a Const that setrefs.c copied as-is. + * Also, in case of scrollable cursor it contains Material node at the top + * of the plan tree. */ plan = stmt->planTree; for (;;) @@ -8338,6 +8340,15 @@ exec_save_simple_expr(PLpgSQL_expr *expr, CachedPlan *cplan) /* Descend to the child node */ plan = plan->lefttree; } + else if (IsA(plan, Material)) + { + Assert(plan->lefttree != NULL && + plan->righttree == NULL && + plan->initPlan == NULL && + plan->qual == NULL); + Assert(plan == stmt->planTree); + plan = plan->lefttree; + } else elog(ERROR, "unexpected plan node type: %d", (int) nodeTag(plan)); diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index d8ce39dba3c..0e5435ebdfc 100644 --- a/src/test/regress/expected/plpgsql.out +++ b/src/test/regress/expected/plpgsql.out @@ -3656,6 +3656,13 @@ $$ language plpgsql; ERROR: cursor FOR loop must use a bound cursor variable LINE 5: for r in c loop ^ +-- Test scrollable cursor and simple expression optimisation +DO $$ +DECLARE + p_CurData refcursor; +BEGIN + OPEN p_CurData SCROLL FOR SELECT NULL; +END; $$; -- test RETURN QUERY EXECUTE create or replace function return_dquery() returns setof int as $$ diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql index d413d995d17..7797beb6e03 100644 --- a/src/test/regress/sql/plpgsql.sql +++ b/src/test/regress/sql/plpgsql.sql @@ -3034,6 +3034,14 @@ begin end; $$ language plpgsql; +-- Test scrollable cursor and simple expression optimisation +DO $$ +DECLARE + p_CurData refcursor; +BEGIN + OPEN p_CurData SCROLL FOR SELECT NULL; +END; $$; + -- test RETURN QUERY EXECUTE create or replace function return_dquery()

view thread (7+ messages)  latest in thread

Message-ID: <ee51b44b-8759-4600-a3af-c0565c9bea12@gmail.com>
Permalink:  ../ee51b44b-8759-4600-a3af-c0565c9bea12@gmail.com/
Also on:    postgresql.org/message-id/ee51b44b-8759-4600-a3af-c0565c9bea12@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: lepihov@gmail.com, tgl@sss.pgh.pa.us, splarv@ya.ru, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18859: ERROR: unexpected plan node type: 356
  In-Reply-To: <ee51b44b-8759-4600-a3af-c0565c9bea12@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox