Re: Bad row estimates

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Alex Adriaanse <alex(at)innovacomputing(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Bad row estimates
Date: 2006-03-04 15:46:05
Message-ID: 20060304154605.GC80721@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Sat, Mar 04, 2006 at 02:01:35AM -0500, Greg Stark wrote:
> Alex Adriaanse <alex(at)innovacomputing(dot)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(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2006-03-04 16:09:59 Re: Bad row estimates
Previous Message hubert depesz lubaczewski 2006-03-04 14:23:08 Re: How to query and index for customer with lastname and city