pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Properly prepare varinfos in estimate_multivariate_bucketsize()
Date: Wed, 23 Apr 2025 17:27:39 +0000
Message-ID: <E1u7dsp-001RGf-1g@gemulon.postgresql.org> (raw)

Properly prepare varinfos in estimate_multivariate_bucketsize()

To estimate with extended statistics, we need to clear the varnullingrels
field in the expression, and duplicates are not allowed in the GroupVarInfo
list.  We might re-use add_unique_group_var(), but we don't do so for two
reasons.

  1) We must keep the origin_rinfos list ordered exactly the same way as
     varinfos.
  2) add_unique_group_var() is designed for estimate_num_groups(), where a
     larger number of groups is worse.   While estimating the number of hash
     buckets, we have the opposite: a lesser number of groups is worse.
     Therefore, we don't have to remove "known equal" vars: the removed var
     may valuably contribute to the multivariate statistics to grow the number
     of groups.

This commit adds custom code to estimate_multivariate_bucketsize() to
initialize varinfos properly.

Reported-by: Robins Tharakan <tharakan@gmail.com>
Discussion: https://postgr.es/m/18885-da51324078588253%40postgresql.org
Author: Andrei Lepikhov <lepihov@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9f404d7922e8831dc49bfa225530ba5309900e4e

Modified Files
--------------
src/backend/utils/adt/selfuncs.c        | 60 +++++++++++++++++++++++++++++++--
src/test/regress/expected/stats_ext.out | 28 +++++++++++++++
src/test/regress/sql/stats_ext.sql      | 11 ++++++
3 files changed, 96 insertions(+), 3 deletions(-)



Message-ID: <E1u7dsp-001RGf-1g@gemulon.postgresql.org>
Permalink:  ../E1u7dsp-001RGf-1g@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1u7dsp-001RGf-1g@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Properly prepare varinfos in estimate_multivariate_bucketsize()
  In-Reply-To: <E1u7dsp-001RGf-1g@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox