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: David Rowley <david.rowley@2ndquadrant.com>, Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>, Alvaro Herrera <alvherre@2ndquadrant.com>, Michael Paquier <michael@paquier.xyz>, Andres Freund <andres@anarazel.de>, Thomas Munro <thomas.munro@enterprisedb.com>, Bruce Momjian <bruce@momjian.us>, Mark Dilger <hornschnorter@gmail.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2019-03-26T15:12:35Z
Lists: pgsql-hackers
On Tue, Mar 26, 2019 at 11:59:56AM +0000, Dean Rasheed wrote: >On Mon, 25 Mar 2019 at 23:36, Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote: >> >> Attached is an updated patch, fixing all the issues pointed out so far. >> Unless there are some objections, I plan to commit the 0001 part by the >> end of this CF. Part 0002 is a matter for PG13, as previously agreed. >> > >Yes, I think that's reasonable. It looks to be in pretty good shape. I >have reviewed most of the actual code, but note that I haven't >reviewed the docs changes and I didn't spend much time reading code >comments. It might benefit from a quick once-over comment tidy up. > >I just looked through the latest set of changes and I have a couple of >additional review comments: > >In the comment about WIDTH_THRESHOLD, s/pg_statistic/pg_statistic_ext/. > >In statext_mcv_build(), I'm not convinced by the logic around keeping >the whole MCV list if it fits. Suppose there were a small number of >very common values, and then a bunch of uniformly distributed less >common values. The sample might consist of all the common values, plus >one or two instances of some of the uncommon ones, leading to a list >that would fit, but it would not be appropriate to keep the uncommon >values on the basis of having seen them only one or two times. The >fact that the list of items seen fits doesn't by itself mean that >they're all common enough to justify being kept. In the per-column >stats case, there are a bunch of other checks that have to pass, which >are intended to test not just that the list fits, but that it believes >that those are all the items in the table. For MV stats, you don't >have that, and so I think it would be best to just remove that test >(the "if (ngroups > nitems)" test) and *always* call >get_mincount_for_mcv_list() to determine how many MCV items to keep. >Otherwise there is a risk of keeping too many MCV items, with the ones >at the tail end of the list producing poor estimates. > I need to think about it a bit, but I think you're right we may not need to keep those items. The reason why I decided to keep them is that they may represent cases where the (actual frequency << base frequency). But now that I think about it, that can probably be handled as ((1 - total_sel) / ndistinct) So yeah, I think I'll just change the code to always us the mincount. 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