Обсуждение: BUG #17879: ERROR: unrecognized node type: 2139062143
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.
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
Вложения
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