Re: PoC/WIP: Extended statistics on expressions
Dean Rasheed <dean.a.rasheed@gmail.com>
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: Justin Pryzby <pryzby@telsasoft.com>,
PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2021-03-25T11:35:21Z
Lists: pgsql-hackers
On Thu, 25 Mar 2021 at 00:05, Tomas Vondra <tomas.vondra@enterprisedb.com> wrote: > > Actually, I think we need that block at all - there's no point in > keeping the exact expression, because if there was a statistics matching > it it'd be matched by the examine_variable. So if we get here, we have > to just split it into the vars anyway. So the second block is entirely > useless. Good point. > That however means we don't need the processing with GroupExprInfo and > GroupVarInfo lists, i.e. we can revert back to the original simpler > processing, with a bit of extra logic to match expressions, that's all. > > The patch 0003 does this (it's a bit crude, but hopefully enough to > demonstrate). Cool. I did wonder about that, but I didn't fully think it through. I'll take a look. > 0002 is an attempt to fix an issue I noticed today - we need to handle > type changes. > > I think we have two options: > > a) Make UpdateStatisticsForTypeChange smarter to also transform and > update the expression string, and reset pg_statistics[] data. > > b) Just recreate the statistics, just like we do for indexes. Currently > this does not force analyze, so it just resets all the stats. Maybe it > should do analyze, though. I'd vote for (b) without an analyse, and I agree with getting rid of UpdateStatisticsForTypeChange(). I've always been a bit skeptical about trying to preserve extended statistics after a type change, when we don't preserve regular per-column stats. > BTW I wonder how useful the updated statistics actually is. Consider > this example: > ... > the expression now looks like this: > > ======================================================================== > "public"."s" (ndistinct) ON ((a + b)), ((((b)::numeric)::double > precision + c)) FROM t > ======================================================================== > > But we're matching it to (((b)::double precision + c)), so that fails. > > This is not specific to extended statistics - indexes have exactly the > same issue. Not sure how common this is in practice. Hmm, that's unfortunate. Maybe it's not that common in practice though. I'm not sure if there is any practical way to fix it, but if there is, I guess we'd want to apply the same fix to both stats and indexes, and that certainly seems out of scope for this patch. Regards, Dean
Commits
-
Disallow extended statistics on system columns
- 66061077155d 14.0 landed
- c9eeef2a15c0 15.0 landed
-
Identify simple column references in extended statistics
- 50ba70a957f9 14.0 landed
- 537ca68dbb24 15.0 landed
-
Don't print extra parens around expressions in extended stats
- 4d1816ec26e8 14.0 landed
- 13380e147649 15.0 landed
-
Change position of field "transformed" in struct CreateStatsStmt.
- 13a1ca160dcf 14.0 landed
-
Add transformed flag to nodes/*funcs.c for CREATE STATISTICS
- d57ecebd128c 14.0 landed
-
Stabilize stats_ext test with other collations
- 2a058e938c73 14.0 landed
-
Extended statistics on expressions
- a4d75c86bf15 14.0 landed
-
Reduce duration of stats_ext regression tests
- 98376c18f12e 14.0 landed
-
Allow composite types in catalog bootstrap
- 79f6a942bdb9 14.0 landed
-
Convert Typ from array to list in bootstrap
- e1a5e65703ce 14.0 landed
-
Disallow CREATE STATISTICS on system catalogs
- c22539756ee5 10.16 landed
- f52db969440b 11.11 landed
- 943a113bcb6f 12.6 landed
- d26d4c717dbf 13.2 landed
- c9a0dc34865f 14.0 landed