Re: BUG #18885: ERROR: corrupt MVNDistinct entry - 2
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Tomas Vondra <tomas@vondra.me>
Cc: tharakan@gmail.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form <noreply@postgresql.org>,
Alexander Korotkov <aekorotkov@gmail.com>
Date: 2025-04-13T23:26:10Z
Lists: pgsql-bugs
Attachments
- v1-0001-Improve-comments-for-estimate_multivariate_ndisti.patch (application/octet-stream) patch v1-0001
On Fri, 11 Apr 2025 at 01:31, Tomas Vondra <tomas@vondra.me> wrote:
> I think estimate_multivariate_bucketsize() needs to be more careful
> about building the GroupVarInfo list - in particular, it needs to do the
> dance with examine_variable + add_unique_group_var + pull_var_clause,
> similar to estimate_num_groups() at line ~3532.
This should be documented to prevent future callers of
estimate_multivariate_ndistinct() from falling for this.
The attached aims to do this. I also couldn't resist a few other improvements.
There are a few strange goings-ons in the code itself that I didn't
adjust. For example, in the first "foreach(lc2, *varinfos)" loop after
the "if (stats)", there's a "found" variable that gets set and used
for no apparent reason. I don't see why the "found = true;" doesn't
just "continue;". The variable would only be needed if there was some
inner loop and we couldn't use "continue". I also can't make sense of
the following comment:
/*
* XXX Maybe we should allow searching the expressions even if we
* found an attribute matching the expression? That would handle
* trivial expressions like "(a)" but it seems fairly useless.
*/
Maybe it meant "matching the Var"?
The final loop to build the newlist also looks more complex than it
needs to be. The prior loop over *varinfos could have recorded the
matching GroupVarInfos in the list in a Bitmapset and that final loop
could become:
foreach(lc, *varinfos)
{
if (!bms_is_member(foreach_current_index(lc), matched_varinfos))
newlist = lappend(newlist, lfirst(lc));
}
David
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Properly prepare varinfos in estimate_multivariate_bucketsize()
- 9f404d7922e8 18.0 landed
-
Improve comments for estimate_multivariate_ndistinct()
- f3281f9f9395 18.0 landed
-
Use extended stats for precise estimation of bucket size in hash join
- 6bb6a62f3cc4 18.0 cited
-
Ignore nullingrels when looking up statistics
- e28033fe1af8 18.0 cited