Re: PoC/WIP: Extended statistics on expressions
Tomas Vondra <tomas.vondra@enterprisedb.com>
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2020-11-16T15:27:46Z
Lists: pgsql-hackers
On 11/16/20 2:49 PM, Tomas Vondra wrote: > Hi, > > ... > > 4) apply the statistics > > This is the hard part, really, and the exact state of the support > depends on type of statistics. > > For ndistinct coefficients, it generally works. I'm sure there may be > bugs in estimate_num_groups, etc. but in principle it works. > > For MCV lists, it generally works too - you can define statistics on > the expressions and the estimates should improve. The main downside > here is that it requires at least two expressions, otherwise we can't > build/apply the extended statistics. So for example > > SELECT * FROM t WHERE mod(a,100) = 10 AND mod(b,11) = 0 > > may be estimated "correctly", once you drop any of the conditions it > gets much worse as we don't have stats for individual expressions. > That's rather annoying - it does not break the extended MCV, but the > behavior will certainly cause confusion. > > For functional dependencies, the estimation does not work yet. Also, > the missing per-column statistics have bigger impact than on MCV, > because while MCV can work fine without it, the dependencies heavily > rely on the per-column estimates. We only apply "corrections" based > on the dependency degree, so we still need (good) per-column > estimates, which does not quite work with the expressions. > > > Of course, the lack of per-expression statistics may be somewhat > fixed by adding indexes on expressions, but that's kinda expensive. > FWIW after re-reading [1], I think the plan to build pg_statistic rows for expressions and stash them in pg_statistic_ext_data is the way to go. I was thinking that maybe we'll need some new statistics type to request this, e.g. CREATE STATISTICS s (expressions) ON ... but on second thought I think we should just build this whenever there are expressions in the definition. It'll require some changes (e.g. we require at least two items in the list, but we'll want to allow building stats on a single expression too, I guess), but that's doable. Of course, we don't have any catalogs with composite types yet, so it's not 100% sure this will work, but it's worth a try. regards [1] https://www.postgresql.org/message-id/flat/6331.1579041473%40sss.pgh.pa.us#5ec6af7583e84cef2ca6a9e8a713511e -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
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