agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Fix attnum remapping in generateClonedExtStatsStmt() 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix attnum remapping in generateClonedExtStatsStmt() @ 2026-04-30 15:17 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 6+ messages in thread From: Andrew Dunstan @ 2026-04-30 15:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix attnum remapping in generateClonedExtStatsStmt() When cloning extended statistics via CREATE TABLE ... LIKE ... INCLUDING STATISTICS, stxkeys holds attribute numbers from the source (parent) table, but get_attname() was being called with the child relation's OID. If the parent has dropped columns, the child's attribute numbers are renumbered sequentially and no longer match, so the lookup either returns the wrong column name (silent corruption) or errors out when the attnum does not exist in the child. Fix it by remapping the parent attnum through attmap before the lookup, consistent with how expression statistics are already handled a few lines below. Add a regression test covering both manifestations: a 3-column parent where the stale attnum refers to no child column (cache-lookup error), and a 4-column parent where the stale attnum silently refers to the wrong child column. Author: Julien Tachoires <julmon@gmail.com> Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Discussion: https://postgr.es/m/20260415105718.tomuncfbmlt67oel@poseidon.home.virt Backpatch-through: 14 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/7bb5196358063c61a554052a1ea0ee82b61efabb Modified Files -------------- src/backend/parser/parse_utilcmd.c | 8 +++++-- src/test/regress/expected/create_table_like.out | 31 +++++++++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 26 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix attnum remapping in generateClonedExtStatsStmt() @ 2026-04-30 15:17 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 6+ messages in thread From: Andrew Dunstan @ 2026-04-30 15:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix attnum remapping in generateClonedExtStatsStmt() When cloning extended statistics via CREATE TABLE ... LIKE ... INCLUDING STATISTICS, stxkeys holds attribute numbers from the source (parent) table, but get_attname() was being called with the child relation's OID. If the parent has dropped columns, the child's attribute numbers are renumbered sequentially and no longer match, so the lookup either returns the wrong column name (silent corruption) or errors out when the attnum does not exist in the child. Fix it by remapping the parent attnum through attmap before the lookup, consistent with how expression statistics are already handled a few lines below. Add a regression test covering both manifestations: a 3-column parent where the stale attnum refers to no child column (cache-lookup error), and a 4-column parent where the stale attnum silently refers to the wrong child column. Author: Julien Tachoires <julmon@gmail.com> Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Discussion: https://postgr.es/m/20260415105718.tomuncfbmlt67oel@poseidon.home.virt Backpatch-through: 14 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/149c875fc20b2025608a2b3e4a0eb2821a879894 Modified Files -------------- src/backend/parser/parse_utilcmd.c | 8 +++++-- src/test/regress/expected/create_table_like.out | 31 +++++++++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 26 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix attnum remapping in generateClonedExtStatsStmt() @ 2026-04-30 15:17 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 6+ messages in thread From: Andrew Dunstan @ 2026-04-30 15:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix attnum remapping in generateClonedExtStatsStmt() When cloning extended statistics via CREATE TABLE ... LIKE ... INCLUDING STATISTICS, stxkeys holds attribute numbers from the source (parent) table, but get_attname() was being called with the child relation's OID. If the parent has dropped columns, the child's attribute numbers are renumbered sequentially and no longer match, so the lookup either returns the wrong column name (silent corruption) or errors out when the attnum does not exist in the child. Fix it by remapping the parent attnum through attmap before the lookup, consistent with how expression statistics are already handled a few lines below. Add a regression test covering both manifestations: a 3-column parent where the stale attnum refers to no child column (cache-lookup error), and a 4-column parent where the stale attnum silently refers to the wrong child column. Author: Julien Tachoires <julmon@gmail.com> Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Discussion: https://postgr.es/m/20260415105718.tomuncfbmlt67oel@poseidon.home.virt Backpatch-through: 14 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/76d15a7ee9de91afda672cd7ed56cdcd9909f4ef Modified Files -------------- src/backend/parser/parse_utilcmd.c | 8 +++++-- src/test/regress/expected/create_table_like.out | 31 +++++++++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 26 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix attnum remapping in generateClonedExtStatsStmt() @ 2026-04-30 15:17 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 6+ messages in thread From: Andrew Dunstan @ 2026-04-30 15:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix attnum remapping in generateClonedExtStatsStmt() When cloning extended statistics via CREATE TABLE ... LIKE ... INCLUDING STATISTICS, stxkeys holds attribute numbers from the source (parent) table, but get_attname() was being called with the child relation's OID. If the parent has dropped columns, the child's attribute numbers are renumbered sequentially and no longer match, so the lookup either returns the wrong column name (silent corruption) or errors out when the attnum does not exist in the child. Fix it by remapping the parent attnum through attmap before the lookup, consistent with how expression statistics are already handled a few lines below. Add a regression test covering both manifestations: a 3-column parent where the stale attnum refers to no child column (cache-lookup error), and a 4-column parent where the stale attnum silently refers to the wrong child column. Author: Julien Tachoires <julmon@gmail.com> Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Discussion: https://postgr.es/m/20260415105718.tomuncfbmlt67oel@poseidon.home.virt Backpatch-through: 14 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/a0104b4474e92a130c742dfa36da1aa8e221fa61 Modified Files -------------- src/backend/parser/parse_utilcmd.c | 8 +++++-- src/test/regress/expected/create_table_like.out | 31 +++++++++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 26 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix attnum remapping in generateClonedExtStatsStmt() @ 2026-04-30 15:17 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 6+ messages in thread From: Andrew Dunstan @ 2026-04-30 15:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix attnum remapping in generateClonedExtStatsStmt() When cloning extended statistics via CREATE TABLE ... LIKE ... INCLUDING STATISTICS, stxkeys holds attribute numbers from the source (parent) table, but get_attname() was being called with the child relation's OID. If the parent has dropped columns, the child's attribute numbers are renumbered sequentially and no longer match, so the lookup either returns the wrong column name (silent corruption) or errors out when the attnum does not exist in the child. Fix it by remapping the parent attnum through attmap before the lookup, consistent with how expression statistics are already handled a few lines below. Add a regression test covering both manifestations: a 3-column parent where the stale attnum refers to no child column (cache-lookup error), and a 4-column parent where the stale attnum silently refers to the wrong child column. Author: Julien Tachoires <julmon@gmail.com> Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Discussion: https://postgr.es/m/20260415105718.tomuncfbmlt67oel@poseidon.home.virt Backpatch-through: 14 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/6cf49e804c9b4ac24046a48541810d1fed33fec3 Modified Files -------------- src/backend/parser/parse_utilcmd.c | 8 +++++-- src/test/regress/expected/create_table_like.out | 31 +++++++++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 26 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix attnum remapping in generateClonedExtStatsStmt() @ 2026-04-30 15:17 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 6+ messages in thread From: Andrew Dunstan @ 2026-04-30 15:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix attnum remapping in generateClonedExtStatsStmt() When cloning extended statistics via CREATE TABLE ... LIKE ... INCLUDING STATISTICS, stxkeys holds attribute numbers from the source (parent) table, but get_attname() was being called with the child relation's OID. If the parent has dropped columns, the child's attribute numbers are renumbered sequentially and no longer match, so the lookup either returns the wrong column name (silent corruption) or errors out when the attnum does not exist in the child. Fix it by remapping the parent attnum through attmap before the lookup, consistent with how expression statistics are already handled a few lines below. Add a regression test covering both manifestations: a 3-column parent where the stale attnum refers to no child column (cache-lookup error), and a 4-column parent where the stale attnum silently refers to the wrong child column. Author: Julien Tachoires <julmon@gmail.com> Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Discussion: https://postgr.es/m/20260415105718.tomuncfbmlt67oel@poseidon.home.virt Backpatch-through: 14 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/81b56b47c29d28f6041c94be5c5345f974d09f68 Modified Files -------------- src/backend/parser/parse_utilcmd.c | 8 +++++-- src/test/regress/expected/create_table_like.out | 31 +++++++++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 26 +++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2026-04-30 15:17 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-04-30 15:17 pgsql: Fix attnum remapping in generateClonedExtStatsStmt() Andrew Dunstan <andrew@dunslane.net> 2026-04-30 15:17 pgsql: Fix attnum remapping in generateClonedExtStatsStmt() Andrew Dunstan <andrew@dunslane.net> 2026-04-30 15:17 pgsql: Fix attnum remapping in generateClonedExtStatsStmt() Andrew Dunstan <andrew@dunslane.net> 2026-04-30 15:17 pgsql: Fix attnum remapping in generateClonedExtStatsStmt() Andrew Dunstan <andrew@dunslane.net> 2026-04-30 15:17 pgsql: Fix attnum remapping in generateClonedExtStatsStmt() Andrew Dunstan <andrew@dunslane.net> 2026-04-30 15:17 pgsql: Fix attnum remapping in generateClonedExtStatsStmt() Andrew Dunstan <andrew@dunslane.net>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox