pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Speed-up build of MCV lists with many distinct values
Date: Fri, 05 Jul 2019 15:55:28 +0000
Message-ID: <E1hjQYa-0007zV-0X@gemulon.postgresql.org> (raw)

Speed-up build of MCV lists with many distinct values

When building multi-column MCV lists, we compute base frequency for each
item, i.e. a product of per-column frequencies for values from the item.
As a value may be in multiple groups, the code was scanning the whole
array of groups while adding items to the MCV list.  This works fine as
long as the number of distinct groups is small, but it's easy to trigger
trigger O(N^2) behavior, especially after increasing statistics target.

This commit precomputes frequencies for values in all columns, so that
when computing the base frequency it's enough to make a simple bsearch
lookup in the array.

Backpatch to 12, where multi-column MCV lists were introduced.

Discussion: https://postgr.es/m/20190618205920.qtlzcu73whfpfqne@development

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/57f459cf6c48e78aa321ac88418815fc65197517

Modified Files
--------------
src/backend/statistics/mcv.c | 130 ++++++++++++++++++++++++++++++++++++++++---
1 file changed, 122 insertions(+), 8 deletions(-)



view thread (2+ messages)

Message-ID: <E1hjQYa-0007zV-0X@gemulon.postgresql.org>
Permalink:  ../E1hjQYa-0007zV-0X@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hjQYa-0007zV-0X@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tomas.vondra@postgresql.org
  Subject: Re: pgsql: Speed-up build of MCV lists with many distinct values
  In-Reply-To: <E1hjQYa-0007zV-0X@gemulon.postgresql.org>
  References: <E1hjQYa-0007zV-0X@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