pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Teach estimate_array_length() to use statistics where available.
Date: Thu, 04 Jan 2024 23:36:29 +0000
Message-ID: <E1rLXGG-00DXPw-Sb@gemulon.postgresql.org> (raw)

Teach estimate_array_length() to use statistics where available.

If we have DECHIST statistics about the argument expression, use
the average number of distinct elements as the array length estimate.
(It'd be better to use the average total number of elements, but
that is not currently calculated by compute_array_stats(), and
it's unclear that it'd be worth extra effort to get.)

To do this, we have to change the signature of estimate_array_length
to pass the "root" pointer.  While at it, also change its result
type to "double".  That's probably not really necessary, but it
avoids any risk of overflow of the value extracted from DECHIST.
All existing callers are going to use the result in a "double"
calculation anyway.

Paul Jungwirth, reviewed by Jian He and myself

Discussion: https://postgr.es/m/CA+renyUnM2d+SmrxKpDuAdpiq6FOM=FByvi6aS6yi__qyf6j9A@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9391f71523b6e57f1194d9f6543bc7948c16411b

Modified Files
--------------
src/backend/optimizer/path/costsize.c | 10 ++++----
src/backend/utils/adt/arrayfuncs.c    |  2 +-
src/backend/utils/adt/selfuncs.c      | 47 ++++++++++++++++++++++++++++-------
src/include/utils/selfuncs.h          |  2 +-
4 files changed, 45 insertions(+), 16 deletions(-)



Message-ID: <E1rLXGG-00DXPw-Sb@gemulon.postgresql.org>
Permalink:  ../E1rLXGG-00DXPw-Sb@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1rLXGG-00DXPw-Sb@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: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Teach estimate_array_length() to use statistics where available.
  In-Reply-To: <E1rLXGG-00DXPw-Sb@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