Re: [HACKERS] PATCH: multivariate histograms and MCV lists
Tomas Vondra <tomas.vondra@2ndquadrant.com>
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Konstantin Knizhnik <k.knizhnik@postgrespro.ru>,
Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Bruce Momjian <bruce@momjian.us>,
Alvaro Herrera <alvherre@2ndquadrant.com>, Andres Freund
<andres@anarazel.de>, Thomas Munro <thomas.munro@enterprisedb.com>,
Mark Dilger <hornschnorter@gmail.com>,
Adrien Nayrat <adrien.nayrat@dalibo.com>,
Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2018-07-17T23:58:06Z
Lists: pgsql-hackers
On 07/18/2018 12:41 AM, Konstantin Knizhnik wrote: > ... > > Teodor Sigaev has proposed an alternative approach for calculating > selectivity of multicolumn join or compound index search. > Usually DBA creates compound indexes which can be used by optimizer to > build efficient query execution plan based on index search. > We can stores statistic for compound keys of such indexes and (as it is > done now for functional indexes) and use it to estimate selectivity > of clauses. I have implemented this idea and will publish patch in > separate thread soon. > Now I just want to share some results for the Tomas examples. > > So for Vanilla Postges without extra statistic estimated number of rows > is about 4 times smaller than real. > Can you please post plans with parallelism disabled, and perhaps without the aggregate? Both makes reading the plans unnecessarily difficult ... > postgres=# explain analyze SELECT count(*) FROM foo WHERE a=1 and (b=1 > or b=2); > QUERY PLAN > > -------------------------------------------------------------------------------------------------------------------------------------------- > > Aggregate (cost=10964.76..10964.77 rows=1 width=8) (actual > time=49.251..49.251 rows=1 loops=1) > -> Bitmap Heap Scan on foo (cost=513.60..10906.48 rows=23310 > width=0) (actual time=17.368..39.928 rows=90000 loops=1) ok, 23k vs. 90k > > If we add statistic for a and b columns: > > create statistics ab on a,b from foo; > analyze foo; > > then expected results is about 30% larger then real: 120k vs 90k: > Eh? The plan however says 9k vs. 30k ... > -> Parallel Bitmap Heap Scan on foo > (cost=2561.33..13424.24 rows=9063 width=0) (actual time=15.551..26.057 > rows=30000 loops=3) ... > With compound index statistic estimation is almost equal to real value: > > -> Bitmap Heap Scan on foo (cost=1880.20..13411.66 rows=23310 > width=0) (actual time=38.776..61.050 rows=90000 loops=1) Well, this says 23k vs. 90k. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Commits
-
Convert pre-existing stats_ext tests to new style
- dbb984128ebf 12.0 landed
-
Add support for multivariate MCV lists
- 7300a699502f 12.0 landed
-
Improve ANALYZE's strategy for finding MCVs.
- b5db1d93d2a6 11.0 cited
-
Clone extended stats in CREATE TABLE (LIKE INCLUDING ALL)
- 5564c1181548 11.0 cited
-
Try again to fix accumulation of parallel worker instrumentation.
- 8526bcb2df76 11.0 cited
-
Adjust psql \d query to avoid use of @> operator.
- 471d55859c11 11.0 cited
-
Message style fixes
- 821fb8cdbf70 11.0 cited
-
Add security checks to selectivity estimation functions
- e2d4ef8de869 10.0 cited