| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | Rahila Syed <rahilasyed90(at)gmail(dot)com> |
| Cc: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, solai v <solai(dot)cdac(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Melanie Plageman <melanieplageman(at)gmail(dot)com> |
| Subject: | Re: Preserve statistics targets with ALTER TABLE ALTER COLUMN TYPE |
| Date: | 2026-12-04 03:50:11 |
| Message-ID: | axI4c0yR96Z6s3h9@paquier.xyz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, Dec 03, 2026 at 02:04:15PM +0800, Rahila Syed wrote:
> Why not make the target field a Node * as is done in AlterStatsStmt?
> Node *stxstattarget would hold an Integer node, with NULL as default.
> That way gram.y and parse_utilcmd.c changes won't be needed and we
> won't have to worry about whether the default of -1 is set correctly in
> various places.
Yeah, consistency sounds like it would be a good thing across all
these parse nodes.
I have read through v3-0001, and globally I like what I am reading
under it, especially the fact that a changedStatisticsTargets in
AlteredTableInfo has to hold the same number of members as the others
(err, right?). Perhaps that could be enforced as an assertion or a
run-time check, actually..
> 2. The comment says this also fixes the SET EXPRESSION case. It would
> be nice to include a test demonstrating that in the stats_ext.sql file.
> Something like this (taken from the linked bug report):
> CREATE TABLE st3 (a int, g int GENERATED ALWAYS AS (a * 2) VIRTUAL);
> CREATE STATISTICS st3_s ON g, (a + g) FROM st3;
> ALTER STATISTICS st3_s SET STATISTICS 400;
> ALTER TABLE st3 ALTER COLUMN g SET EXPRESSION AS (a * 3);
> SELECT s.stxstattarget FROM pg_statistic_ext s WHERE s.stxname = 'st3_s';
You may be able to stick that in the existing SQL sequence of v3-0002.
> 3. The fix adds a field to CreateStatsStmt, a quick search on [2] shows
> that this
> struct is being used in modules like pgpool-II, pg-stat-plans etc. In that
> case
> would this pose a problem when the fix is backported? The related commit
> 6713a6e04cb mentions that no-known third party code constructs this struct.
> It may be worth verifying this claim once.
Code using a sizeof() the structure would be a problem. A new field
could be added at the end of the structure and be safe on ABI grounds,
as long as the assumption of sizeof() not being used holds. If that
proves to be an issue, we could always drop the backport, just do it
on HEAD. Re-reading the thread I'd probably suggest to just do that..
I was pretty mild about v3-0002 after an initial read of it. But on a
second read I can see that the "Get" routine enforces a number of
members in the list (aka all should be set). I think that the patch
should be slightly improved, perhaps on the "Get" and "Set" routine
sides, by making sure that we have members assigned for all the
attributes of an index definition, just for the sake of preventing
holes if one has the idea to rework this code at some point.
--
Michael
| From | Date | Subject | |
|---|---|---|---|
| Next Message | shveta malik | 2026-12-04 03:54:30 | Re: DOC: Minor updates for logical replication conflicts |
| Previous Message | shihao zhong | 2026-12-04 03:47:44 | Re: Standby writes pages past minRecoveryPoint after crash recovery |