pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: pgsql-hackers@postgresql.org
To: pgsql-performance@postgresql.org
Subject: BETWEEN optimizer problems with single-value range
Date: Wed, 15 Mar 2006 11:56:53 -0600
Message-ID: <44180105.EE98.0025.0@wicourts.gov> (raw)

Attached is a simplified example of a performance problem we have seen,
with a workaround and a suggestion for enhancement (hence both the
performance and hackers lists).

Our software is allowing users to specify the start and end dates for a
query.  When they enter the same date for both, the optimizer makes a
very bad choice.  We can work around it in application code by using an
equality test if both dates match.  I think the planner should be able
to make a better choice here.  (One obvious way to fix it would be to
rewrite "BETWEEN a AND b" as "= a" when a is equal to b, but it seems
like there is some underlying problem which should be fixed instead (or
in addition to) this.

The first query uses BETWEEN with the same date for both min and max
values.  The second query uses an equality test for the same date.  The
third query uses BETWEEN with a two-day range.  In all queries, there
are less than 4,600 rows for the specified cotfcNo value out of over 18
million rows in the table.  We tried boosting the statistics samples for
the columns in the selection, which made the estimates of rows more
accurate, but didn't change the choice of plans.

-Kevin

Attachments:

  between-optimization-problem.txt (application/octet-stream, 4.4K) download

view thread (20+ messages)  latest in thread

Message-ID: <44180105.EE98.0025.0@wicourts.gov>
Permalink:  ../44180105.EE98.0025.0@wicourts.gov/
Also on:    postgresql.org/message-id/44180105.EE98.0025.0@wicourts.gov

 · 

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: Kevin.Grittner@wicourts.gov, pgsql-hackers@postgresql.org
  Subject: Re: BETWEEN optimizer problems with single-value range
  In-Reply-To: <44180105.EE98.0025.0@wicourts.gov>

* 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