pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jerry Gamache <jerry.gamache@idilia.com>
To: pgsql-performance@postgresql.org
Subject: Logarithmic data frequency distributions and the query planner
Date: Wed, 07 Jul 2010 16:54:48 -0400
Message-ID: <4C34E998.3020000@idilia.com> (raw)

On 8.1, I have a very interesting database where the distributions of 
some values in a multi-million rows table is logarithmic (i.e. the most 
frequent value is an order of magnitude more frequent than the next 
ones). If I analyze the table, the statistics become extremely skewed 
towards the most frequent values and this prevents the planner from 
giving any good results on queries that do not target these entries.

In a recent case, the planner estimated that the number of returned rows 
would be ~13% of the table size and from this bad assumption generated a 
very slow conservative plan that executed in days. If I set the 
statistics at zero for that table, the planner uses a hardcoded ratio 
(seems like 0.5%) for the number of returned rows and this helps 
generating a plan that executes in 3 minutes (still sub-optimal, but not 
as bad).

Generating partial index for the less frequent cases helps, but this 
solution is not flexible enough for our needs as the number of complex 
queries grow. We are mostly left with pre-generating a lot of temporary 
tables whenever the planner over-evaluates the number of rows generated 
by a subquery (query execution was trimmed from 3 minutes to 30 seconds 
using this technique) or using the OFFSET 0 tweak, but it would be nice 
if the planner could handle this on its own.

Am I missing something obvious? Setting the statistics for this table to 
zero seems awkward even if it gives good results.
Jerry.





view thread (2+ messages)  latest in thread

Message-ID: <4C34E998.3020000@idilia.com>
Permalink:  ../4C34E998.3020000@idilia.com/
Also on:    postgresql.org/message-id/4C34E998.3020000@idilia.com

 · 

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-performance@postgresql.org
  Cc: jerry.gamache@idilia.com
  Subject: Re: Logarithmic data frequency distributions and the query planner
  In-Reply-To: <4C34E998.3020000@idilia.com>

* 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