pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix handling of CREATE TABLE LIKE with inheritance. 7+ messages / 1 participants [nested] [flat]
* pgsql: Fix handling of CREATE TABLE LIKE with inheritance. @ 2020-08-21 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-21 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of CREATE TABLE LIKE with inheritance. If a CREATE TABLE command uses both LIKE and traditional inheritance, Vars in CHECK constraints and expression indexes that are absorbed from a LIKE parent table tended to get mis-numbered, resulting in wrong answers and/or bizarre error messages (though probably not any actual crashes, thanks to validation occurring in the executor). In v12 and up, the same could happen to Vars in GENERATED expressions, even in cases with no LIKE clause but multiple traditional-inheritance parents. The cause of the problem for LIKE is that parse_utilcmd.c supposed it could renumber such Vars correctly during transformCreateStmt(), which it cannot since we have not yet accounted for columns added via inheritance. Fix that by postponing processing of LIKE INCLUDING CONSTRAINTS, DEFAULTS, GENERATED, INDEXES till after we've performed DefineRelation(). The error with GENERATED and multiple inheritance is a simple oversight in MergeAttributes(); it knows it has to renumber Vars in inherited CHECK constraints, but forgot to apply the same processing to inherited GENERATED expressions (a/k/a defaults). Per bug #16272 from Tom Gottfried. The non-GENERATED variants of the issue are ancient, presumably dating right back to the addition of CREATE TABLE LIKE; hence back-patch to all supported branches. Discussion: https://postgr.es/m/16272-6e32da020e9a9381@postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/50289819230d8ddad510879ee4793b04a05cf13b Modified Files -------------- src/backend/commands/tablecmds.c | 126 +++++-- src/backend/parser/parse_utilcmd.c | 381 +++++++++++++-------- src/backend/tcop/utility.c | 36 +- src/include/nodes/parsenodes.h | 1 + src/include/parser/parse_utilcmd.h | 2 + .../test_ddl_deparse/expected/create_table.out | 2 + .../modules/test_ddl_deparse/test_ddl_deparse.c | 3 + src/test/regress/expected/create_table_like.out | 40 ++- src/test/regress/sql/create_table_like.sql | 19 +- 9 files changed, 435 insertions(+), 175 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix handling of CREATE TABLE LIKE with inheritance. @ 2020-08-21 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-21 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of CREATE TABLE LIKE with inheritance. If a CREATE TABLE command uses both LIKE and traditional inheritance, Vars in CHECK constraints and expression indexes that are absorbed from a LIKE parent table tended to get mis-numbered, resulting in wrong answers and/or bizarre error messages (though probably not any actual crashes, thanks to validation occurring in the executor). In v12 and up, the same could happen to Vars in GENERATED expressions, even in cases with no LIKE clause but multiple traditional-inheritance parents. The cause of the problem for LIKE is that parse_utilcmd.c supposed it could renumber such Vars correctly during transformCreateStmt(), which it cannot since we have not yet accounted for columns added via inheritance. Fix that by postponing processing of LIKE INCLUDING CONSTRAINTS, DEFAULTS, GENERATED, INDEXES till after we've performed DefineRelation(). The error with GENERATED and multiple inheritance is a simple oversight in MergeAttributes(); it knows it has to renumber Vars in inherited CHECK constraints, but forgot to apply the same processing to inherited GENERATED expressions (a/k/a defaults). Per bug #16272 from Tom Gottfried. The non-GENERATED variants of the issue are ancient, presumably dating right back to the addition of CREATE TABLE LIKE; hence back-patch to all supported branches. Discussion: https://postgr.es/m/16272-6e32da020e9a9381@postgresql.org Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/894f5dea76e1a59fa2f3e1905c6a44f254d9d08b Modified Files -------------- src/backend/commands/tablecmds.c | 126 +++++-- src/backend/parser/parse_utilcmd.c | 381 +++++++++++++-------- src/backend/tcop/utility.c | 36 +- src/include/nodes/parsenodes.h | 1 + src/include/parser/parse_utilcmd.h | 2 + .../test_ddl_deparse/expected/create_table.out | 2 + .../modules/test_ddl_deparse/test_ddl_deparse.c | 3 + src/test/regress/expected/create_table_like.out | 40 ++- src/test/regress/sql/create_table_like.sql | 19 +- 9 files changed, 435 insertions(+), 175 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix handling of CREATE TABLE LIKE with inheritance. @ 2020-08-21 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-21 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of CREATE TABLE LIKE with inheritance. If a CREATE TABLE command uses both LIKE and traditional inheritance, Vars in CHECK constraints and expression indexes that are absorbed from a LIKE parent table tended to get mis-numbered, resulting in wrong answers and/or bizarre error messages (though probably not any actual crashes, thanks to validation occurring in the executor). In v12 and up, the same could happen to Vars in GENERATED expressions, even in cases with no LIKE clause but multiple traditional-inheritance parents. The cause of the problem for LIKE is that parse_utilcmd.c supposed it could renumber such Vars correctly during transformCreateStmt(), which it cannot since we have not yet accounted for columns added via inheritance. Fix that by postponing processing of LIKE INCLUDING CONSTRAINTS, DEFAULTS, GENERATED, INDEXES till after we've performed DefineRelation(). The error with GENERATED and multiple inheritance is a simple oversight in MergeAttributes(); it knows it has to renumber Vars in inherited CHECK constraints, but forgot to apply the same processing to inherited GENERATED expressions (a/k/a defaults). Per bug #16272 from Tom Gottfried. The non-GENERATED variants of the issue are ancient, presumably dating right back to the addition of CREATE TABLE LIKE; hence back-patch to all supported branches. Discussion: https://postgr.es/m/16272-6e32da020e9a9381@postgresql.org Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d9253df12e4c06a54e515136b115538c56eace56 Modified Files -------------- src/backend/commands/tablecmds.c | 126 +++++-- src/backend/parser/parse_utilcmd.c | 387 +++++++++++++-------- src/backend/tcop/utility.c | 36 +- src/include/nodes/parsenodes.h | 3 +- src/include/parser/parse_utilcmd.h | 2 + .../test_ddl_deparse/expected/create_table.out | 2 + .../modules/test_ddl_deparse/test_ddl_deparse.c | 3 + src/test/regress/expected/create_table_like.out | 40 ++- src/test/regress/sql/create_table_like.sql | 19 +- 9 files changed, 440 insertions(+), 178 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix handling of CREATE TABLE LIKE with inheritance. @ 2020-08-21 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-21 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of CREATE TABLE LIKE with inheritance. If a CREATE TABLE command uses both LIKE and traditional inheritance, Vars in CHECK constraints and expression indexes that are absorbed from a LIKE parent table tended to get mis-numbered, resulting in wrong answers and/or bizarre error messages (though probably not any actual crashes, thanks to validation occurring in the executor). In v12 and up, the same could happen to Vars in GENERATED expressions, even in cases with no LIKE clause but multiple traditional-inheritance parents. The cause of the problem for LIKE is that parse_utilcmd.c supposed it could renumber such Vars correctly during transformCreateStmt(), which it cannot since we have not yet accounted for columns added via inheritance. Fix that by postponing processing of LIKE INCLUDING CONSTRAINTS, DEFAULTS, GENERATED, INDEXES till after we've performed DefineRelation(). The error with GENERATED and multiple inheritance is a simple oversight in MergeAttributes(); it knows it has to renumber Vars in inherited CHECK constraints, but forgot to apply the same processing to inherited GENERATED expressions (a/k/a defaults). Per bug #16272 from Tom Gottfried. The non-GENERATED variants of the issue are ancient, presumably dating right back to the addition of CREATE TABLE LIKE; hence back-patch to all supported branches. Discussion: https://postgr.es/m/16272-6e32da020e9a9381@postgresql.org Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3737965249cdd74f94feeeb8d750723984abd361 Modified Files -------------- src/backend/parser/parse_utilcmd.c | 240 ++++++++++++++++-------- src/backend/tcop/utility.c | 36 +++- src/include/parser/parse_utilcmd.h | 2 + src/test/regress/expected/create_table_like.out | 38 +++- src/test/regress/sql/create_table_like.sql | 18 +- 5 files changed, 246 insertions(+), 88 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix handling of CREATE TABLE LIKE with inheritance. @ 2020-08-21 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-21 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of CREATE TABLE LIKE with inheritance. If a CREATE TABLE command uses both LIKE and traditional inheritance, Vars in CHECK constraints and expression indexes that are absorbed from a LIKE parent table tended to get mis-numbered, resulting in wrong answers and/or bizarre error messages (though probably not any actual crashes, thanks to validation occurring in the executor). In v12 and up, the same could happen to Vars in GENERATED expressions, even in cases with no LIKE clause but multiple traditional-inheritance parents. The cause of the problem for LIKE is that parse_utilcmd.c supposed it could renumber such Vars correctly during transformCreateStmt(), which it cannot since we have not yet accounted for columns added via inheritance. Fix that by postponing processing of LIKE INCLUDING CONSTRAINTS, DEFAULTS, GENERATED, INDEXES till after we've performed DefineRelation(). The error with GENERATED and multiple inheritance is a simple oversight in MergeAttributes(); it knows it has to renumber Vars in inherited CHECK constraints, but forgot to apply the same processing to inherited GENERATED expressions (a/k/a defaults). Per bug #16272 from Tom Gottfried. The non-GENERATED variants of the issue are ancient, presumably dating right back to the addition of CREATE TABLE LIKE; hence back-patch to all supported branches. Discussion: https://postgr.es/m/16272-6e32da020e9a9381@postgresql.org Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e22e29c258a1b10969376024027b469a8e1e1b0b Modified Files -------------- src/backend/parser/parse_utilcmd.c | 230 ++++++++++++++++-------- src/backend/tcop/utility.c | 36 +++- src/include/parser/parse_utilcmd.h | 2 + src/test/regress/expected/create_table_like.out | 38 +++- src/test/regress/sql/create_table_like.sql | 18 +- 5 files changed, 241 insertions(+), 83 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix handling of CREATE TABLE LIKE with inheritance. @ 2020-08-21 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-21 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of CREATE TABLE LIKE with inheritance. If a CREATE TABLE command uses both LIKE and traditional inheritance, Vars in CHECK constraints and expression indexes that are absorbed from a LIKE parent table tended to get mis-numbered, resulting in wrong answers and/or bizarre error messages (though probably not any actual crashes, thanks to validation occurring in the executor). In v12 and up, the same could happen to Vars in GENERATED expressions, even in cases with no LIKE clause but multiple traditional-inheritance parents. The cause of the problem for LIKE is that parse_utilcmd.c supposed it could renumber such Vars correctly during transformCreateStmt(), which it cannot since we have not yet accounted for columns added via inheritance. Fix that by postponing processing of LIKE INCLUDING CONSTRAINTS, DEFAULTS, GENERATED, INDEXES till after we've performed DefineRelation(). The error with GENERATED and multiple inheritance is a simple oversight in MergeAttributes(); it knows it has to renumber Vars in inherited CHECK constraints, but forgot to apply the same processing to inherited GENERATED expressions (a/k/a defaults). Per bug #16272 from Tom Gottfried. The non-GENERATED variants of the issue are ancient, presumably dating right back to the addition of CREATE TABLE LIKE; hence back-patch to all supported branches. Discussion: https://postgr.es/m/16272-6e32da020e9a9381@postgresql.org Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/37681d7e942e31256efdd9b562a750f1742ac111 Modified Files -------------- src/backend/parser/parse_utilcmd.c | 174 +++++++++++++++++------- src/backend/tcop/utility.c | 36 ++++- src/include/parser/parse_utilcmd.h | 2 + src/test/regress/expected/create_table_like.out | 38 +++++- src/test/regress/sql/create_table_like.sql | 18 ++- 5 files changed, 213 insertions(+), 55 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix handling of CREATE TABLE LIKE with inheritance. @ 2020-08-21 19:01 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 7+ messages in thread From: Tom Lane @ 2020-08-21 19:01 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of CREATE TABLE LIKE with inheritance. If a CREATE TABLE command uses both LIKE and traditional inheritance, Vars in CHECK constraints and expression indexes that are absorbed from a LIKE parent table tended to get mis-numbered, resulting in wrong answers and/or bizarre error messages (though probably not any actual crashes, thanks to validation occurring in the executor). In v12 and up, the same could happen to Vars in GENERATED expressions, even in cases with no LIKE clause but multiple traditional-inheritance parents. The cause of the problem for LIKE is that parse_utilcmd.c supposed it could renumber such Vars correctly during transformCreateStmt(), which it cannot since we have not yet accounted for columns added via inheritance. Fix that by postponing processing of LIKE INCLUDING CONSTRAINTS, DEFAULTS, GENERATED, INDEXES till after we've performed DefineRelation(). The error with GENERATED and multiple inheritance is a simple oversight in MergeAttributes(); it knows it has to renumber Vars in inherited CHECK constraints, but forgot to apply the same processing to inherited GENERATED expressions (a/k/a defaults). Per bug #16272 from Tom Gottfried. The non-GENERATED variants of the issue are ancient, presumably dating right back to the addition of CREATE TABLE LIKE; hence back-patch to all supported branches. Discussion: https://postgr.es/m/16272-6e32da020e9a9381@postgresql.org Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/21f8b1811ac1b61c38970c27711a7ed7fafedba6 Modified Files -------------- src/backend/parser/parse_utilcmd.c | 170 +++++++++++++++++------- src/backend/tcop/utility.c | 36 ++++- src/include/parser/parse_utilcmd.h | 2 + src/test/regress/expected/create_table_like.out | 38 +++++- src/test/regress/sql/create_table_like.sql | 18 ++- 5 files changed, 209 insertions(+), 55 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2020-08-21 19:01 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-08-21 19:01 pgsql: Fix handling of CREATE TABLE LIKE with inheritance. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-21 19:01 pgsql: Fix handling of CREATE TABLE LIKE with inheritance. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-21 19:01 pgsql: Fix handling of CREATE TABLE LIKE with inheritance. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-21 19:01 pgsql: Fix handling of CREATE TABLE LIKE with inheritance. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-21 19:01 pgsql: Fix handling of CREATE TABLE LIKE with inheritance. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-21 19:01 pgsql: Fix handling of CREATE TABLE LIKE with inheritance. Tom Lane <tgl@sss.pgh.pa.us> 2020-08-21 19:01 pgsql: Fix handling of CREATE TABLE LIKE with inheritance. Tom Lane <tgl@sss.pgh.pa.us>
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