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

Re: Yet another slow nested loop

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexander Staubo <alex(at)bengler(dot)no>
Cc: pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Yet another slow nested loop
Date: 2009-06-16 14:36:57
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
Alexander Staubo <alex(at)bengler(dot)no> writes:
> Here's the query:
> select photos.*
> from photos
> inner join event_participations on
>   event_participations.user_id = photos.creator_id and
>   event_participations.attend = true
> inner join event_instances on
> = event_participations.event_instance_id
> where (
>   (event_instances.venue_id = 1290) and
>   (photos.taken_at > (event_instances.time + interval '-3600 seconds')) and
>   (photos.taken_at < (event_instances.time + interval '25200 seconds'))
> )
> order by taken_at desc
> limit 20

> It occasionally takes four minutes to run:

Actually the easiest way to fix that is to get rid of the LIMIT.
(Maybe use a cursor instead, and fetch only twenty rows.)  LIMIT
magnifies the risks from any estimation error, and you've got a lot
of that here ...

			regards, tom lane

In response to


pgsql-performance by date

Next:From: Alberto DalmasoDate: 2009-06-16 14:45:53
Subject: Re: performance with query
Previous:From: Kevin GrittnerDate: 2009-06-16 14:21:18
Subject: Re: performance with query

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