Re: limit + order by is slow if no rows in result set

From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Brian Cox <brian(dot)cox(at)ca(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: limit + order by is slow if no rows in result set
Date: 2007-02-12 23:26:04
Message-ID: 45D0F78C.40000@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Brian Cox wrote:
>
> There are 1.9M rows in ts_defects and indexes on b.ts_id (primary key)
> d.ts_biz_event_id and d.ts_occur_date. Both queries below return 0
> rows. The 1st runs fast and the 2nd > 400x slower. The 2nd query
> differs from the 1st only by the addition of "limit 1".
>
> Why the big difference in performance?

Please run EXPLAIN ANALYZE on both queries, and send back the results.
Also, what indexes are there on the tables involved?

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Brian Cox 2007-02-13 00:24:07 Re: limit + order by is slow if no rows in result set
Previous Message Brian Cox 2007-02-12 21:36:45 limit + order by is slow if no rows in result set