Re: Nested loop join and date range query

From: "Ian Burrell" <ianburrell(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Nested loop join and date range query
Date: 2006-05-03 17:54:04
Message-ID: d91f09cd0605031054s59984e3doa7ad3222f14b1f15@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 5/2/06, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Ian Burrell" <ianburrell(at)gmail(dot)com> writes:
> > We recently upgraded to PostgreSQL 8.1 from 7.4 and a few queries are
> > having performance problems and running for very long times. The
> > commonality seems to be PostgreSQL 8.1 is choosing to use a nested
> > loop join because it estimates there will be only be a single row.
>
> We've already noted that there's a problem with estimating zero-width
> ranges (too lazy to search the archives, but this has come up at least
> twice recently). Can you modify your app to generate something like
>
> week >= x and week < x+1
>
> instead of
>
> week >= x and week <= x
>

I am working on modifying the SQL generation code to replace the
zero-width range with an equals.

Does BETWEEN have the same bug?

> ? My recollection is that the fix will probably be complicated
> enough to not get back-patched into 8.1.
>
> BTW, AFAIK the same problem exists in 7.4. What kind of estimates/plans
> were you getting for this case in 7.4?
>

We get similar rows=1 estimates on 7.4. 7.4 doesn't choose to use the
nested loop joins so it performs fine.

We have been getting similar rows=1 estimates and nested loop joins
with some other queries. But I think those are caused by not
frequently analyzing log type tables and then searching for recent
days which it doesn't think exist.

- Ian

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2006-05-03 17:58:37 Re: Lot'sa joins - performance tip-up, please?
Previous Message Michael Stone 2006-05-03 17:06:06 Re: Slow restoration question