pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Szűcs Gábor <surrano@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: fake condition causes far better plan
Date: Tue, 23 Aug 2005 11:14:19 -0400
Message-ID: <2638.1124810059@sss.pgh.pa.us> (raw)
In-Reply-To: <430B379A.7090204@gmail.com>
References: <430B379A.7090204@gmail.com>

=?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= <surrano@gmail.com> writes:
> [ bad query plan ]

Most of the problem is here:

>                       ->  Index Scan using muvelet_vonalkod_ny_idopont on 
> muvelet_vonalkod_ny ny  (cost=0.00..1351.88 rows=24649 width=4) (actual 
> time=0.161..10.735 rows=3943 loops=1)
>                             Index Cond: (idopont >= (now() - 
> ('00:00:00'::interval + ('1 days'::text)::interval)))

(BTW, you lied about the query, because this index condition doesn't
match anything in the given query text.)

Pre-8.0 releases aren't capable of making useful statistical estimates
for conditions involving nonconstant subexpressions, so you get a
badly-mistaken row count estimate that leads to a poor choice of plan.

If you can't update to 8.0, the best answer is to do the date arithmetic
on the client side.  Another way is to create an allegedly-immutable
function along the lines of "ago(interval) returns timestamptz" to hide
the now() call --- this is dangerous but sometimes it's the easiest answer.
See the archives.

			regards, tom lane



view thread (2+ messages)

Message-ID: <2638.1124810059@sss.pgh.pa.us>
Permalink:  ../2638.1124810059@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2638.1124810059@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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, surrano@gmail.com
  Subject: Re: fake condition causes far better plan
  In-Reply-To: <2638.1124810059@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