pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: twoflower <standa.kurik@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re:  Re: Query > 1000× slowdown after adding datetime comparison
Date: Tue, 1 Sep 2015 00:53:45 -0700 (MST)
Message-ID: <1441094025534-5864164.post@n5.nabble.com> (raw)
In-Reply-To: <CAFcOn2_1tknJ95JceZY1ikP1OURwgwuRFSQX21SJTLFF+ZzdRA@mail.gmail.com>
References: <1441037351126-5864045.post@n5.nabble.com>
	<55E47E97.1090202@2ndquadrant.com>
	<1441047830983-5864075.post@n5.nabble.com>
	<1441048763332-5864080.post@n5.nabble.com>
	<CAKFQuwbUZLWuhoaAF7mWdmRr-6LG9NdMfsyPasXo1ZY82YVRzA@mail.gmail.com>
	<1441050416677-5864088.post@n5.nabble.com>
	<CAFcOn2-u8QE-0vwkUuEQ7b1m9+YfH=vjLAaJrhAh=zU4n9Hu1w@mail.gmail.com>
	<1441053041230-5864101.post@n5.nabble.com>
	<CAFcOn2_1tknJ95JceZY1ikP1OURwgwuRFSQX21SJTLFF+ZzdRA@mail.gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Stefan Keller wrote
> So, if I'm understanding you correctly, we're talking solely about
> following clause in the query you gave initially:
> 
> WHERE doc.date_last_updated >= date(now() - '171:00:00'::interval)
> which initially was
> WHERE documenttype = 4
> and now is being replaced by a temporary (I'd say derived) column
> WHERE updated
> ?
> 
> In any case - I have to go - but run http://explain.depesz.com/ and
> give a weblink to the explain plans of your queries.

Here's the query plan for the original query I struggled with: WHERE
doc.date_last_updated >= date(now() - '171:00:00'::interval)

The original slow query with date()
<http://explain.depesz.com/d/WEy/SFfcd5esMuuI9wrLmQrZU33ma371uW2Nlh1PmeI9ZDRiAJ4wjv;  

Then, just out of curiosity, I replaced the WHERE condition with another
one: WHERE doc.documenttype = 4. documenttype is an unindexed integer
column. It's fast. Here's the query plan:

date() condition replaced with documenttype = 4
<http://explain.depesz.com/d/kHG/u1dvsDyJPBK92xnKwNT3YkQsNW6WfG9aHmWAzVSOgmXikL3hiW;  

Then, as David suggested, I tried to precompute the doc.date_last_updated >=
date(now() - '171:00:00'::interval). I created a new boolean temp_eval
column on the DOCUMENT table and updated the rows like this:

update "DOCUMENT" set temp_eval = date_last_updated >= date(now() -
'171:00:00'::interval);

Then I analyzed the table and modified the query to only have WHERE
temp_eval = TRUE. I expected this to be fast, but it took 41 minutes to
complete. Here's the query plan:

Precomputed column
<http://explain.depesz.com/d/2aFw/GLqQ8CMGDZOYx5134M8eallFluervKXDfOdnaz4nZTMXYNacji;  



--
View this message in context: http://postgresql.nabble.com/Query-1-000-000-slowdown-after-adding-datetime-comparison-tp5864045p586...
Sent from the PostgreSQL - performance mailing list archive at Nabble.com.


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



view thread (15+ messages)  latest in thread

Message-ID: <1441094025534-5864164.post@n5.nabble.com>
Permalink:  ../1441094025534-5864164.post@n5.nabble.com/
Also on:    postgresql.org/message-id/1441094025534-5864164.post@n5.nabble.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: standa.kurik@gmail.com
  Subject: Re:  Re: Query > 1000× slowdown after adding datetime comparison
  In-Reply-To: <1441094025534-5864164.post@n5.nabble.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