pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Revise attribute handling code on partition creation 3+ messages / 1 participants [nested] [flat]
* pgsql: Revise attribute handling code on partition creation @ 2018-11-08 19:35 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 3+ messages in thread From: Alvaro Herrera @ 2018-11-08 19:35 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Revise attribute handling code on partition creation The original code to propagate NOT NULL and default expressions specified when creating a partition was mostly copy-pasted from typed-tables creation, but not being a great match it contained some duplicity, inefficiency and bugs. This commit fixes the bug that NOT NULL constraints declared in the parent table would not be honored in the partition. One reported issue that is not fixed is that a DEFAULT declared in the child is not used when inserting through the parent. That would amount to a behavioral change that's better not back-patched. This rewrite makes the code simpler: 1. instead of checking for duplicate column names in its own block, reuse the original one that already did that; 2. instead of concatenating the list of columns from parent and the one declared in the partition and scanning the result to (incorrectly) propagate defaults and not-null constraints, just scan the latter searching the former for a match, and merging sensibly. This works because we know the list in the parent is already correct and there can only be one parent. This rewrite makes ColumnDef->is_from_parent unused, so it's removed on branch master; on released branches, it's kept as an unused field in order not to cause ABI incompatibilities. This commit also adds a test case for creating partitions with collations mismatching that on the parent table, something that is closely related to the code being patched. No code change is introduced though, since that'd be a behavior change that could break some (broken) working applications. Amit Langote wrote a less invasive fix for the original NOT NULL/defaults bug, but while I kept the tests he added, I ended up not using his original code. Ashutosh Bapat reviewed Amit's fix. Amit reviewed mine. Author: Álvaro Herrera, Amit Langote Reviewed-by: Ashutosh Bapat, Amit Langote Reported-by: Jürgen Strobel (bug #15212) Discussion: https://postgr.es/m/152746742177.1291.9847032632907407358@wrigleys.postgresql.org Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/21c9e4973cec9c3f0bb7a3f3c1649c4e4a0b9127 Modified Files -------------- src/backend/commands/sequence.c | 1 - src/backend/commands/tablecmds.c | 99 ++++++++++++++---------------- src/backend/nodes/equalfuncs.c | 1 - src/backend/nodes/makefuncs.c | 1 - src/backend/parser/gram.y | 4 -- src/backend/parser/parse_utilcmd.c | 2 - src/include/nodes/parsenodes.h | 2 +- src/test/regress/expected/create_table.out | 26 ++++++++ src/test/regress/sql/create_table.sql | 19 ++++++ 9 files changed, 92 insertions(+), 63 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Revise attribute handling code on partition creation @ 2018-11-08 19:35 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 3+ messages in thread From: Alvaro Herrera @ 2018-11-08 19:35 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Revise attribute handling code on partition creation The original code to propagate NOT NULL and default expressions specified when creating a partition was mostly copy-pasted from typed-tables creation, but not being a great match it contained some duplicity, inefficiency and bugs. This commit fixes the bug that NOT NULL constraints declared in the parent table would not be honored in the partition. One reported issue that is not fixed is that a DEFAULT declared in the child is not used when inserting through the parent. That would amount to a behavioral change that's better not back-patched. This rewrite makes the code simpler: 1. instead of checking for duplicate column names in its own block, reuse the original one that already did that; 2. instead of concatenating the list of columns from parent and the one declared in the partition and scanning the result to (incorrectly) propagate defaults and not-null constraints, just scan the latter searching the former for a match, and merging sensibly. This works because we know the list in the parent is already correct and there can only be one parent. This rewrite makes ColumnDef->is_from_parent unused, so it's removed on branch master; on released branches, it's kept as an unused field in order not to cause ABI incompatibilities. This commit also adds a test case for creating partitions with collations mismatching that on the parent table, something that is closely related to the code being patched. No code change is introduced though, since that'd be a behavior change that could break some (broken) working applications. Amit Langote wrote a less invasive fix for the original NOT NULL/defaults bug, but while I kept the tests he added, I ended up not using his original code. Ashutosh Bapat reviewed Amit's fix. Amit reviewed mine. Author: Álvaro Herrera, Amit Langote Reviewed-by: Ashutosh Bapat, Amit Langote Reported-by: Jürgen Strobel (bug #15212) Discussion: https://postgr.es/m/152746742177.1291.9847032632907407358@wrigleys.postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/705d433fd5e29ac173ef46a5acd4a2d7336f5573 Modified Files -------------- src/backend/commands/sequence.c | 1 - src/backend/commands/tablecmds.c | 99 ++++++++++++++---------------- src/backend/nodes/copyfuncs.c | 1 - src/backend/nodes/equalfuncs.c | 1 - src/backend/nodes/makefuncs.c | 1 - src/backend/nodes/outfuncs.c | 1 - src/backend/parser/gram.y | 4 -- src/backend/parser/parse_utilcmd.c | 2 - src/include/nodes/parsenodes.h | 1 - src/test/regress/expected/create_table.out | 26 ++++++++ src/test/regress/sql/create_table.sql | 19 ++++++ 11 files changed, 91 insertions(+), 65 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Revise attribute handling code on partition creation @ 2018-11-08 19:35 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 3+ messages in thread From: Alvaro Herrera @ 2018-11-08 19:35 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Revise attribute handling code on partition creation The original code to propagate NOT NULL and default expressions specified when creating a partition was mostly copy-pasted from typed-tables creation, but not being a great match it contained some duplicity, inefficiency and bugs. This commit fixes the bug that NOT NULL constraints declared in the parent table would not be honored in the partition. One reported issue that is not fixed is that a DEFAULT declared in the child is not used when inserting through the parent. That would amount to a behavioral change that's better not back-patched. This rewrite makes the code simpler: 1. instead of checking for duplicate column names in its own block, reuse the original one that already did that; 2. instead of concatenating the list of columns from parent and the one declared in the partition and scanning the result to (incorrectly) propagate defaults and not-null constraints, just scan the latter searching the former for a match, and merging sensibly. This works because we know the list in the parent is already correct and there can only be one parent. This rewrite makes ColumnDef->is_from_parent unused, so it's removed on branch master; on released branches, it's kept as an unused field in order not to cause ABI incompatibilities. This commit also adds a test case for creating partitions with collations mismatching that on the parent table, something that is closely related to the code being patched. No code change is introduced though, since that'd be a behavior change that could break some (broken) working applications. Amit Langote wrote a less invasive fix for the original NOT NULL/defaults bug, but while I kept the tests he added, I ended up not using his original code. Ashutosh Bapat reviewed Amit's fix. Amit reviewed mine. Author: Álvaro Herrera, Amit Langote Reviewed-by: Ashutosh Bapat, Amit Langote Reported-by: Jürgen Strobel (bug #15212) Discussion: https://postgr.es/m/152746742177.1291.9847032632907407358@wrigleys.postgresql.org Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e0c05bf4a7e6b6327d02da4ca67fc2a41d9e6548 Modified Files -------------- src/backend/commands/sequence.c | 1 - src/backend/commands/tablecmds.c | 99 ++++++++++++++---------------- src/backend/nodes/equalfuncs.c | 1 - src/backend/nodes/makefuncs.c | 1 - src/backend/parser/gram.y | 4 -- src/backend/parser/parse_utilcmd.c | 2 - src/include/nodes/parsenodes.h | 2 +- src/test/regress/expected/create_table.out | 26 ++++++++ src/test/regress/sql/create_table.sql | 19 ++++++ 9 files changed, 92 insertions(+), 63 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2018-11-08 19:35 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2018-11-08 19:35 pgsql: Revise attribute handling code on partition creation Alvaro Herrera <alvherre@alvh.no-ip.org> 2018-11-08 19:35 pgsql: Revise attribute handling code on partition creation Alvaro Herrera <alvherre@alvh.no-ip.org> 2018-11-08 19:35 pgsql: Revise attribute handling code on partition creation Alvaro Herrera <alvherre@alvh.no-ip.org>
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