Re: extended stats on partitioned tables
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: pgsql-hackers@postgresql.org
Date: 2021-09-26T20:25:50Z
Lists: pgsql-hackers
Attachments
On Sat, Sep 25, 2021 at 05:31:52PM -0500, Justin Pryzby wrote: > It seems like your patch should also check "inh" in examine_variable and > statext_expressions_load. I tried adding that - I mostly kept my patches separate. Hopefully this is more helpful than a complication. I added at: https://commitfest.postgresql.org/35/3332/ + /* create only the "stxdinherit=false", because that always exists */ + datavalues[Anum_pg_statistic_ext_data_stxdinherit - 1] = ObjectIdGetDatum(false); That'd be confusing for partitioned tables, no? They'd always have an row with no data. I guess it could be stxdinherit = BoolGetDatum(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE). (not ObjectIdGetDatum). Then, that affects the loops which delete the tuples - neither inh nor !inh is guaranteed, unless you check relkind there, too. BTW, you'd need to add an "inherited" column to \dX if you added the "built" data back. Also, I think in backbranches we should document what's being stored in pg_statistic_ext, since it's pretty unintuitive: - noninherted stats (FROM ONLY) for inheritence parents; - inherted stats (FROM *) for partitioned tables; I think the !inh decision in 859b3003de was basically backwards. I think it'd be rare for someone to put extended stats on a parent for improving plans involving FROM ONLY. But it's not worth trying to fix now, since it would change plans in irreversible ways. Also, if the stx data were already populated, users would have to run a manual analyze after upgrading to populate the catalog with the data the planner would expect in the new version, or else it would end up being the opposite of the issue I mentioned: non-inherited stats (from before the upgrade) would be applied by the planner (after the upgrade) to inherited queries.
Commits
-
Add stxdinherit flag to pg_statistic_ext_data
- 269b532aef55 15.0 landed
-
Build inherited extended stats on partitioned tables
- d6817032d26b 13.6 landed
- 20b9fa308ebf 15.0 landed
- ea212bd95fd2 14.2 landed
- 9d1bcf5dc11a 12.10 landed
- 491182e52909 11.15 landed
- 9211c2e38f09 10.20 landed
-
Ignore extended statistics for inheritance trees
- 76569ad6f423 12.10 landed
- ff0e7c7e8401 10.20 landed
- b3cac25f4d50 11.15 landed
- acfde7c5837d 13.6 landed
- 2cc007fd0359 14.2 landed
- 36c4bc6e725f 15.0 landed
-
Don't build extended statistics on inheritance trees
- 859b3003de87 10.10 cited
-
Tighten up relation kind checks for extended statistics
- 8c5cdb7f4f6e 10.0 cited
-
Avoid assuming that statistics for a parent relation reflect the properties of
- 427c6b5b9849 8.2.0 cited