Unix Technical Forum

Appending "LIMIT" to query drastically decreases performance

This is a discussion on Appending "LIMIT" to query drastically decreases performance within the Pgsql Performance forums, part of the PostgreSQL category; --> Can anyone explain the following odd behavior? I have a query that completes in about 90 ms. If I ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 11:42 AM
cluster
 
Posts: n/a
Default Appending "LIMIT" to query drastically decreases 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 11:42 AM
Matthew
 
Posts: n/a
Default Re: Appending "LIMIT" to query drastically decreasesperformance

On Fri, 30 Nov 2007, cluster wrote:
> 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)?


The planner doesn't always get it right. Simple.

Have you done a "VACUUM FULL ANALYSE" recently?

Matthew

--
It is better to keep your mouth closed and let people think you are a fool
than to open it and remove all doubt. -- Mark Twain

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 11:42 AM
Bill Moran
 
Posts: n/a
Default Re: Appending "LIMIT" to query drastically decreasesperformance

In response to Matthew <matthew@flymine.org>:

> On Fri, 30 Nov 2007, cluster wrote:
> > 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)?

>
> The planner doesn't always get it right. Simple.
>
> Have you done a "VACUUM FULL ANALYSE" recently?


I don't know about the "FULL" part ... but certainly an ANALYZE.

Please post EXPLAIN ANALYZE output for the two queries.

--
Bill Moran
Collaborative Fusion Inc.
http://people.collaborativefusion.com/~wmoran/

wmoran@collaborativefusion.com
Phone: 412-422-3463x4023

************************************************** **************
IMPORTANT: This message contains confidential information and is
intended only for the individual named. If the reader of this
message is not an intended recipient (or the individual
responsible for the delivery of this message to an intended
recipient), please be advised that any re-use, dissemination,
distribution or copying of this message is prohibited. Please
notify the sender immediately by e-mail if you have received
this e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or
error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The
sender therefore does not accept liability for any errors or
omissions in the contents of this message, which arise as a
result of e-mail transmission.
************************************************** **************

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 11:42 AM
cluster
 
Posts: n/a
Default Re: Appending "LIMIT" to query drastically decreases performance

> Please post EXPLAIN ANALYZE output for the two queries.

As I wrote in my first post, I pasted this together with the two queries
at pastebin.com:
http://pastebin.com/m3c0d1896
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:27 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com