pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17879: ERROR:  unrecognized node type: 2139062143
3+ messages / 2 participants
[nested] [flat]

* BUG #17879: ERROR:  unrecognized node type: 2139062143
@ 2023-03-30 02:36  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2023-03-30 02:36 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: feichanghong@qq.com

The following bug has been logged on the website:

Bug reference:      17879
Logged by:          Fei Changhong
Email address:      feichanghong@qq.com
PostgreSQL version: 15.2
Operating system:   CentOS7 with kernel version 5.10
Description:        

We have noticed that an error "ERROR: unrecognized node type:2139062143"
occurs when creating a table with a SEQUENCE column after an event trigger
of type ddl_command_end has already been created. This error can be
reproduced using the following SQL statement, and please note that the
"--enable-cassert" option must be included during configuration.
···
-- CREATE EVENT TRIGGER
CREATE TABLE mytable (id serial primary key, name text);
CREATE OR REPLACE FUNCTION log_ddl_commands() RETURNS event_trigger AS $$
DECLARE
	obj record;
BEGIN
	FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() WHERE command_tag
<> 'SELECT' LOOP
		RAISE NOTICE 'Command: % Object: %', obj.command_tag,
obj.object_identity;
	END LOOP;
END;
$$ LANGUAGE plpgsql;
CREATE EVENT TRIGGER ddl_log_trigger ON ddl_command_end EXECUTE FUNCTION
log_ddl_commands();
-- Create a table with a SEQUENCE column
CREATE TABLE mytable1(id INT GENERATED ALWAYS AS IDENTITY (SEQUENCE NAME
test_seq));
···

We have identified the root cause as follows: 
In the generateSerialExtraStmts function, the memory space for the seqoption
list has been freed, but the options member of the Constraint still points
to that memory address, which caused an error during the copyObject
operation in the EventTriggerCollectSimpleCommand function.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17879: ERROR: unrecognized node type: 2139062143
@ 2023-03-30 10:54  David Rowley <dgrowleyml@gmail.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: David Rowley @ 2023-03-30 10:54 UTC (permalink / raw)
  To: feichanghong@qq.com; pgsql-bugs@lists.postgresql.org

On Thu, 30 Mar 2023 at 22:21, PG Bug reporting form
<noreply@postgresql.org> wrote:
> CREATE TABLE mytable1(id INT GENERATED ALWAYS AS IDENTITY (SEQUENCE NAME
> test_seq));

> We have identified the root cause as follows:
> In the generateSerialExtraStmts function, the memory space for the seqoption
> list has been freed, but the options member of the Constraint still points
> to that memory address, which caused an error during the copyObject
> operation in the EventTriggerCollectSimpleCommand function.

Thank you for the detailed report and reproducer.

The problem seems to be down to generateSerialExtraStmts() deleting a
cell out of the given seqoptions resulting in that becoming an empty
list, but the calling function does not have its list pointer set to
NIL.

I see a few ways to fix; 1) always make a list_copy() of the list
before calling generateSerialExtraStmts(), or; 2) make a copy of the
list inside generateSerialExtraStmts() unconditionally, or 3) at the
very least, just make a copy before calling list_delete_nth_cell().

#1 and #2 might be a bit more effort than is really required, so the
attached does #3.

David

Attachments:

fix_generateSerialExtraStmts.patch (application/octet-stream, 728B) download diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index 15a1dab8c5..1bd19b4730 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -423,8 +423,12 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column, snamespace = get_namespace_name(snamespaceid); } sname = rv->relname; - /* Remove the SEQUENCE NAME item from seqoptions */ - seqoptions = list_delete_nth_cell(seqoptions, nameEl_idx); + + /* + * Remove the SEQUENCE NAME item from seqoptions. We'd better make a + * copy first so as we're not modifying the passed in List. + */ + seqoptions = list_delete_nth_cell(list_copy(seqoptions), nameEl_idx); } else {
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: BUG #17879: ERROR: unrecognized node type: 2139062143
@ 2023-03-30 23:19  David Rowley <dgrowleyml@gmail.com>
  parent: David Rowley <dgrowleyml@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: David Rowley @ 2023-03-30 23:19 UTC (permalink / raw)
  To: feichanghong@qq.com; pgsql-bugs@lists.postgresql.org

On Thu, 30 Mar 2023 at 23:54, David Rowley <dgrowleyml@gmail.com> wrote:
> I see a few ways to fix; 1) always make a list_copy() of the list
> before calling generateSerialExtraStmts(), or; 2) make a copy of the
> list inside generateSerialExtraStmts() unconditionally, or 3) at the
> very least, just make a copy before calling list_delete_nth_cell().

I ended up pushing #2 as a fix. It just seems nicer to make sure that
the new command gets a completely different copy of the List in all
cases.  That seems likely to reduce the chances of any future bugs
that might be caused if we ever add future code which modifies the
input list.

The fix will appear in 15.3

Thanks again for reporting this.

David





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2023-03-30 23:19 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30 02:36 BUG #17879: ERROR:  unrecognized node type: 2139062143 PG Bug reporting form <noreply@postgresql.org>
2023-03-30 10:54 ` Re: BUG #17879: ERROR: unrecognized node type: 2139062143 David Rowley <dgrowleyml@gmail.com>
2023-03-30 23:19   ` Re: BUG #17879: ERROR: unrecognized node type: 2139062143 David Rowley <dgrowleyml@gmail.com>

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