pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Pavel Tavoda <pavel.tavoda@gmail.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14729: Between operator is slow when same value used for low and high margin
Date: Tue, 04 Jul 2017 01:15:09 -0400
Message-ID: <15012.1499145309@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMRASbLR2-0Q3UtRK2v6O2A5_cUkA8+9GUak7eAwN9EnebtRcQ@mail.gmail.com>
References: <20170703100923.1448.48433@wrigleys.postgresql.org>
	<CAFj8pRC85hYM=N_d-jxsq9hjMh0FPcsjjnTb3uLpTh3jM8JQsw@mail.gmail.com>
	<CAMRASbLR2-0Q3UtRK2v6O2A5_cUkA8+9GUak7eAwN9EnebtRcQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Pavel Tavoda <pavel.tavoda@gmail.com> writes:
>         ->  Seq Scan on contractportfolio cp  (cost=0.00..109171.90 rows=1 width=8) (actual time=0.009..486.918 rows=20426 loops=1)
>               Filter: ((validfor >= '2017-05-31'::date) AND (validfor <= '2017-05-31'::date))

> STUNNING!!!!

Yup, it's certainly that factor-of-20K rowcount misestimate that is
killing you here.  Given that this estimate isn't too bad:

>         ->  Seq Scan on contractportfolio cp  (cost=0.00..101496.91 rows=20197 width=8) (actual time=0.009..463.063 rows=20426 loops=1)
>               Filter: (validfor = '2017-05-31'::date)

I do not think your problem is one of out-of-date statistics.  Rather,
the issue is just that we're bad at narrow range estimates.  I did
some work on that today[1] but it won't show up in a released PG version
before next year.  In the meantime, I believe that the existing code would
arrive at a plausible answer if the value being checked were present in
the column's pg_stats.most_common_vals list.  Maybe you could fix this
by increasing the statistics target for the column or the whole table
(and re-analyzing it, of course).

			regards, tom lane

[1] https://www.postgresql.org/message-id/12232.1499140410%40sss.pgh.pa.us


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (6+ messages)  latest in thread

Message-ID: <15012.1499145309@sss.pgh.pa.us>
Permalink:  ../15012.1499145309@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15012.1499145309@sss.pgh.pa.us

 · 

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pavel.tavoda@gmail.com, pavel.stehule@gmail.com
  Subject: Re: BUG #14729: Between operator is slow when same value used for low and high margin
  In-Reply-To: <15012.1499145309@sss.pgh.pa.us>
  References: <20170703100923.1448.48433@wrigleys.postgresql.org> <CAFj8pRC85hYM=N_d-jxsq9hjMh0FPcsjjnTb3uLpTh3jM8JQsw@mail.gmail.com> <CAMRASbLR2-0Q3UtRK2v6O2A5_cUkA8+9GUak7eAwN9EnebtRcQ@mail.gmail.com> <15012.1499145309@sss.pgh.pa.us>

* 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