Re: Additional improvements to extended statistics
Dean Rasheed <dean.a.rasheed@gmail.com>
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2020-03-23T08:21:42Z
Lists: pgsql-hackers
On Sat, 21 Mar 2020 at 21:59, Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote: > > Ah, right. Yeah, I think that should work. I thought there would be some > volatility due to groups randomly not making it into the MCV list, but > you're right it's possible to construct the data in a way to make it > perfectly deterministic. So that's what I've done in the attached patch. > Looking through those new tests, another issue occurred to me -- under some circumstances this patch can lead to extended stats being applied twice to the same clause, which is not great, because it involves quite a lot of extra work, and also because it can lead to overestimates because of the way that MCV stats are applied as a delta correction to simple_sel. The way this comes about is as follows -- if we start with an OR clause, that will be passed as a single-item implicitly AND'ed list to clauselist_selectivity(), and from there to statext_clauselist_selectivity() and then to statext_mcv_clauselist_selectivity(). This will call clauselist_selectivity_simple() to get simple_sel, before calling mcv_clauselist_selectivity(), which will recursively compute all the MCV corrections. However, the call to clauselist_selectivity_simple() will call clause_selectivity() for each clause (just a single OR clause in this example), which will now call clauselist_selectivity_or(), which will go back into statext_clauselist_selectivity() with "is_or = true", which will apply the MCV corrections to the same set of clauses that the outer call was about to process. I'm not sure what's the best way to resolve that. Perhaps statext_mcv_clauselist_selectivity() / statext_is_compatible_clause() should ignore OR clauses from an AND-list, on the basis that they will get processed recursively later. Or perhaps estimatedclauses can somehow be used to prevent this, though I'm not sure exactly how that would work. Regards, Dean
Commits
-
Improve estimation of ANDs under ORs using extended statistics.
- 4f5760d4afa9 14.0 landed
-
Improve estimation of OR clauses using multiple extended statistics.
- 88b0898fe35a 14.0 landed
-
Improve estimation of OR clauses using extended statistics.
- 25a9e54d2db3 14.0 landed
-
Prevent functional dependency estimates from exceeding column estimates.
- 87779aa47463 13.0 landed
-
Fix wording of several extended stats comments
- 6f72dbc48bf8 13.0 landed
-
Improve test coverage for multi-column MCV lists
- d8cfa82d51f8 13.0 landed
-
Improve test coverage for functional dependencies
- f9696782c701 13.0 landed