Skip site navigation (1) Skip section navigation (2)

Re: fake condition causes far better plan

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Szűcs Gábor <surrano(at)gmail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: fake condition causes far better plan
Date: 2005-08-23 15:14:19
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
=?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= <surrano(at)gmail(dot)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

In response to

pgsql-performance by date

Next:From: gokulnathbabu manoharanDate: 2005-08-23 17:10:45
Subject: Caching by Postgres
Previous:From: Chris BrowneDate: 2005-08-23 15:12:51
Subject: Re: Performance for relative large DB

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group