Re: BUG #18468: CREATE TABLE ... LIKE leaves orphaned column reference in extended statistics
Tom Lane <tgl@sss.pgh.pa.us>
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>
Date: 2024-05-16T18:45:18Z
Lists: pgsql-bugs
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
Commits
-
Fix handling of extended expression statistics in CREATE TABLE LIKE.
- 5278668d7a46 17.0 landed
- 2f3cfcf7677f 15.8 landed
- 2aa90c02dc69 16.4 landed
- 1015162c3535 14.13 landed
-
Extended statistics on expressions
- a4d75c86bf15 14.0 cited