From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tender Wang <tndrwang@gmail.com>
Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org, Tomas Vondra <tomas.vondra@enterprisedb.com>
Subject: Re: BUG #18468: CREATE TABLE ... LIKE leaves orphaned column reference in extended statistics
Date: Thu, 16 May 2024 14:45:18 -0400
Message-ID: <2135832.1715885118@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHewXNkng5jG472hh+icVT_g8BT5Gv4tNFjBP_X5cK1aqiH=ag@mail.gmail.com>
References: <18468-f5add190e3fa5902@postgresql.org>
<CAHewXNnbUZ1=ezBPtuc6iv8kwzJBsPXkv=XPwrEYg-CXerPEFQ@mail.gmail.com>
<CAHewXNkng5jG472hh+icVT_g8BT5Gv4tNFjBP_X5cK1aqiH=ag@mail.gmail.com>
Tender Wang <tndrwang@gmail.com> writes:
> generateClonedExtStatsStmt just copy t0's ext_stat info to t1.
So this is a complete mess. The fundamental problem is that
transformTableLikeClause believes it can process LIKE_STATISTICS
requests immediately, because:
* We may copy extended statistics if requested, since the representation
* of CreateStatsStmt doesn't depend on column numbers.
That was true apparently in the original, limited implementation
where we only supported CREATE STATISTICS on plain columns.
It's completely wrong for statistics on expressions. IMO what we
need to do is make LIKE_STATISTICS work more like LIKE_INDEXES:
postpone the transformation until expandTableLikeClause when we know
the mapping from source columns to destination columns, and have a
chance at converting the expression trees properly, comparably to
generateClonedIndexStmt.
> Right now, there is nothing to do in transformExtendedStatistics.
> Can we update the varattno to the right value here?
We don't know the column mapping there, either. What we need to have
our hands on is the "attmap" computed in expandTableLikeClause, and
then we can pass the stats expressions through map_variable_attnos().
I think this might not need to be a really large patch, but it
definitely has to change where generateClonedExtStatsStmt is
called from. I can have a go at it if Tomas doesn't want to.
regards, tom lane
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: tgl@sss.pgh.pa.us, tndrwang@gmail.com, tomas.vondra@enterprisedb.com
Subject: Re: BUG #18468: CREATE TABLE ... LIKE leaves orphaned column reference in extended statistics
In-Reply-To: <2135832.1715885118@sss.pgh.pa.us>
* 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