Appending "LIMIT" to query drastically decreases performance

From: cluster <skrald(at)amossen(dot)dk>
To: pgsql-performance(at)postgresql(dot)org
Subject: Appending "LIMIT" to query drastically decreases performance
Date: 2007-11-30 11:16:08
Message-ID: fiordm$2aev$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Can anyone explain the following odd behavior?
I have a query that completes in about 90 ms. If I append LIMIT to the
very end, eg. "LIMIT 500" the evaluation time increases to about 800 ms.
How can performance get *worse* by giving the database the option to
stop the evaluation earlier (when it reaches the output 500 rows)?

I have pasted both queries together with output from explain analyze here:
http://pastebin.com/m3c0d1896

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Matthew 2007-11-30 13:30:28 Re: Appending "LIMIT" to query drastically decreases performance
Previous Message Csaba Nagy 2007-11-30 10:29:43 Re: TB-sized databases