Re: Bad row estimates - Mailing list pgsql-performance

From Jim C. Nasby
Subject Re: Bad row estimates
Date
Msg-id 20060304154605.GC80721@pervasive.com
Whole thread Raw
In response to Re: Bad row estimates  (Greg Stark <gsstark@mit.edu>)
List pgsql-performance
On Sat, Mar 04, 2006 at 02:01:35AM -0500, Greg Stark wrote:
> Alex Adriaanse <alex@innovacomputing.com> writes:
>
> > SELECT count(*) FROM test_table_1
> >     INNER JOIN test_table_2 ON
> >         (test_table_2.s_id = 13300613 AND test_table_1.id = test_table_2.n_id)
> >     WHERE now() BETWEEN test_table_1.start_ts AND test_table_1.end_ts
> >     AND test_table_1.id = test_table_1.g_id;

Something else that helps in cases like this is to place both an upper
and lower boundary on one (or both) fields if possible. For example, if
you know that start_ts and end_ts will always be within 1 hour of each
other, adding the following will help:

AND start_ts >= now()-'1 hour'::interval AND end_ts <= now()+'1
hour'::interval
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

pgsql-performance by date:

Previous
From: "hubert depesz lubaczewski"
Date:
Subject: Re: How to query and index for customer with lastname and city
Next
From: Tom Lane
Date:
Subject: Re: Bad row estimates