Re: Bug in CREATE TABLE .. LIKE .. INCLUDING STATISTICS?
Srinath Reddy Sadipiralla <srinath2133@gmail.com>
From: Srinath Reddy Sadipiralla <srinath2133@gmail.com>
To: Julien Tachoires <julien@tachoires.me>, dgrowleyml@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2026-04-16T07:44:39Z
Lists: pgsql-bugs
Hi Julien, On Wed, Apr 15, 2026 at 7:47 PM Julien Tachoires <julien@tachoires.me> wrote: > Hi, > > One of our customer is experiencing an issue when executing CREATE TABLE > .. LIKE .. INCLUDING ALL; on 14, the following kind of error happens: > ERROR: cache lookup failed for attribute X of relation ZZZZZZ > > It seems to come from generateClonedExtStatsStmt(): get_attname() > appears to be called with an attribute number (attnum) that does not > exist. > yeah, i was able to reproduce and also check the flow which is the same as you mentioned. > > Please find attached 2 patches for the master branch, the first one adds > a test that triggers the problem, the 2nd one is an attempt to fix it. > I think it's better to write a 4 column test, with this it covers both cases of lookup either returning the wrong column name or errors out when the attnum does not exist in the child, thoughts? something like this .... CREATE TABLE parent_like_stats (a int, b int, c int, d int); ALTER TABLE parent_like_stats DROP COLUMN b; CREATE STATISTICS s_parent ON a, c FROM parent_like_stats; CREATE TABLE child_like_stats (LIKE parent_like_stats INCLUDING STATISTICS); other than this patches LGTM. -- Thanks, Srinath Reddy Sadipiralla EDB: https://www.enterprisedb.com/
Commits
-
Fix attnum remapping in generateClonedExtStatsStmt()
- a0104b4474e9 17.10 landed
- 7bb519635806 16.14 landed
- 76d15a7ee9de 15.18 landed
- 81b56b47c29d 14.23 landed
- 149c875fc20b 18.4 landed
- 6cf49e804c9b 19 (unreleased) landed