pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: exclusion@gmail.com
Subject: BUG #18468: CREATE TABLE ... LIKE leaves orphaned column reference in extended statistics
Date: Wed, 15 May 2024 11:00:01 +0000
Message-ID: <18468-f5add190e3fa5902@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      18468
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 16.3
Operating system:   Ubuntu 22.04
Description:        

The following script:
CREATE TABLE t0 (a int, c text, b text);
CREATE STATISTICS ext_stat ON (a || b) FROM t0;
ALTER TABLE t0 DROP COLUMN c;
CREATE TABLE t1 (LIKE t0 INCLUDING ALL);

produces an invalid statistics definition:
\d+ t1
ERROR:  invalid attnum 3 for relation "t1"

SELECT stxname, stxexprs FROM pg_statistic_ext;
 ext_stat     | ({OPEXPR :opno 2780 ... {VAR :varno 1 :varattno 3 ...
 t1_expr_stat | ({OPEXPR :opno 2780 ... {VAR :varno 1 :varattno 3 ...

Though an index definition transferred correctly:
CREATE TABLE t0 (a int, c text, b text);
CREATE INDEX t_idx ON t0((a || b));
ALTER TABLE t0 DROP COLUMN c;
CREATE TABLE t1 (LIKE t0 INCLUDING ALL);
\d+ t1
...
Indexes:
    "t1_expr_idx" btree ((a || b))

SELECT relname, indexprs FROM pg_index, pg_class WHERE indexrelid = oid
  AND relname = 't1_expr_idx';
 t1_expr_idx | ({OPEXPR :opno 2780 ... {VAR :varno 1 :varattno 2 ...



view thread (7+ messages)  latest in thread

Message-ID: <18468-f5add190e3fa5902@postgresql.org>
Permalink:  ../18468-f5add190e3fa5902@postgresql.org/
Also on:    postgresql.org/message-id/18468-f5add190e3fa5902@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-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, exclusion@gmail.com
  Subject: Re: BUG #18468: CREATE TABLE ... LIKE leaves orphaned column reference in extended statistics
  In-Reply-To: <18468-f5add190e3fa5902@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox