Re: [HACKERS] PATCH: multivariate histograms and MCV lists
Tomas Vondra <tomas.vondra@2ndquadrant.com>
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: 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-15T13:29:16Z
Lists: pgsql-hackers
On 07/15/2018 11:36 AM, Dean Rasheed wrote: > ... > > What I'm considering is an algorithm where we simultaneously compute 3 things: > > simple_sel - The result we would get without multivariate stats (*) > mcv_sel - The multivariate MCV result > hist_sel - The multivariate histogram result > > (*) except that at each stage where we add a new clause to the > simple_sel value, we improve upon that estimate by factoring in a > lower bound from the multivariate stats so far, so that even if the > multivariate stats fail to generate anything at the end, we've managed > to account for some of the non-independence of the columns. > > If the MCV matches represented all the matches, then at the end we > would have simple_sel = mcv_sel, and hist_sel = 0, and we'd be done. > It's quite unclear to me how this algorithm could reliably end up with hist_sel=0 (in cases where we already don't end up with that). I mean, if a bucket matches the conditions, then the only way to eliminate is by deducing that MCV already contains all the matches - and that's rather difficult for complex clauses ... > Otherwise, we'd have simple_sel >= mcv_sel, and a possibly non-zero > hist_sel, but if we had managed to factor in both mcv_sel and hist_sel > to simple_sel at each stage as we went along, then simple_sel is the > best overall estimate we can return. > Hmm. I may not be understanding the algorithm yet, but I find it hard to believe applying the stats incrementally is going to produce reliably better estimates that looking at all clauses at once. I understand deducing upper/lower boundaries is useful, but I wonder if we could do that somehow with the current algorithm. > Perhaps this is not so very different from what you're currently > doing, except that with this approach we might also end up with > mcv_sel = 0 and hist_sel = 0, but still have an improved simple_sel > estimate that had accounted for some the multivariate stats available > along the way. > I don't know, really. I'll have to try hacking on this a bit I guess. But there's one obvious question - in what order should we add the clauses? Does it matter at all, or what is the optimal order? We don't need to worry about it now, because we simply consider all clauses at once, but I guess the proposed algorithm is more sensitive to this. 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