agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Andrew Dunstan <andrew@dunslane.net>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix attnum remapping in generateClonedExtStatsStmt()
Date: Thu, 30 Apr 2026 15:17:29 +0000
Message-ID: <E1wIT8q-003TXd-1q@gemulon.postgresql.org> (raw)
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(-)
view thread (6+ messages)
Message-ID: <E1wIT8q-003TXd-1q@gemulon.postgresql.org>
Permalink: ../E1wIT8q-003TXd-1q@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1wIT8q-003TXd-1q@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: andrew@dunslane.net, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Fix attnum remapping in generateClonedExtStatsStmt()
In-Reply-To: <E1wIT8q-003TXd-1q@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox