pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Don Seiler <don@seiler.us>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Odd Row Estimates in Query Plan (rows=75)
Date: Wed, 15 Aug 2018 13:31:17 -0700
Message-ID: <483d3681-5764-0e8d-a40a-d4cbd488a161@aklaver.com> (raw)
In-Reply-To: <CAHJZqBBqL0xPtz0CEG4r1J8T4X1LML=eTZaHPVw92uKcmGzHdg@mail.gmail.com>
References: <CAHJZqBA93sWR6wjmAD6Rsev+FBvfqnouVGdErOTXzhkhhT51TA@mail.gmail.com>
	<f7751be2-57f6-e75e-fbd3-8f38e51c8fbc@aklaver.com>
	<CAHJZqBBqL0xPtz0CEG4r1J8T4X1LML=eTZaHPVw92uKcmGzHdg@mail.gmail.com>

On 08/15/2018 01:03 PM, Don Seiler wrote:
> Here's the query, obfuscated manually by me:
> 
> SELECT
>          'Foo' as system_function,
> stores.name <http://stores.name; as store,
>          lt.owner,
>          lt.minute_of_day,
>          lt.records
>          FROM
>          foo.stores
>          LEFT OUTER JOIN
>              (SELECT
>                  lts.store_pkey,
>                  lts.owner,
>                  date_trunc('minute', lts.date_gifted) as minute_of_day,
>                  count(*) as records
>              FROM foo.gifts lts
>              WHERE
>                  lts.date_added  > '2017-07-14 11:13:05'
>              AND lts.date_added  < '2017-08-13 14:14:21'
>              AND lts.date_gifted >= '2017-08-13 11:13:05'
>              AND lts.date_gifted <  '2017-08-13 14:14:21'
>              GROUP BY 1,2,3
>              ORDER BY 1
>              ) lt ON lt.store_pkey = stores.pkey
>          WHERE lt.records IS NOT NULL;
> 
> The foo.gifts table is pretty much the core table of our database. It's 
> big and very active. There is an index on date_added but not yet on 
> date_gifted.
> 
> I'm working to re-write the query while the dev sees if we even need 
> this query anymore.
> 

I agree the issue seems to be in the index/filter of the dates. That 
leads me to another question:

Why in:

WHERE
	lts.date_added  > '2017-07-14 11:13:05'
AND
	lts.date_added  < '2017-08-13 14:14:21'
AND
	lts.date_gifted >= '2017-08-13 11:13:05'
AND
	lts.date_gifted <  '2017-08-13 14:14:21'

is

	lts.date_added  > '2017-07-14 11:13:05'

and
	
	lts.date_gifted >= '2017-08-13 11:13:05'
?

In other words one '>' and the other '>=' ?








-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (6+ messages)  latest in thread

Message-ID: <483d3681-5764-0e8d-a40a-d4cbd488a161@aklaver.com>
Permalink:  ../483d3681-5764-0e8d-a40a-d4cbd488a161@aklaver.com/
Also on:    postgresql.org/message-id/483d3681-5764-0e8d-a40a-d4cbd488a161@aklaver.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 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-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, don@seiler.us
  Subject: Re: Odd Row Estimates in Query Plan (rows=75)
  In-Reply-To: <483d3681-5764-0e8d-a40a-d4cbd488a161@aklaver.com>
  References: <CAHJZqBA93sWR6wjmAD6Rsev+FBvfqnouVGdErOTXzhkhhT51TA@mail.gmail.com> <f7751be2-57f6-e75e-fbd3-8f38e51c8fbc@aklaver.com> <CAHJZqBBqL0xPtz0CEG4r1J8T4X1LML=eTZaHPVw92uKcmGzHdg@mail.gmail.com> <483d3681-5764-0e8d-a40a-d4cbd488a161@aklaver.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