Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 79EC91288B2F for ; Wed, 1 Feb 2012 16:20:13 -0400 (AST) Received: from postman.sesda2.com ([63.68.157.115] helo=sesda2.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rsgf5-0000zk-26 for pgsql-bugs@postgresql.org; Wed, 01 Feb 2012 20:20:12 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by sesda2.com (Postfix) with ESMTP id A29EE8E4083; Wed, 1 Feb 2012 15:19:47 -0500 (EST) X-Virus-Scanned: amavisd-new at sesda2.com Received: from sesda2.com ([127.0.0.1]) by localhost (postman.sesda2.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id LVYTWLLwUEQy; Wed, 1 Feb 2012 15:19:47 -0500 (EST) Received: from [192.168.200.162] (unknown [192.168.200.162]) by sesda2.com (Postfix) with ESMTP id 859C58E407F; Wed, 1 Feb 2012 15:19:47 -0500 (EST) Message-ID: <4F299E69.4080605@sesda2.com> Date: Wed, 01 Feb 2012 15:19:53 -0500 From: Alex Lai User-Agent: Thunderbird 2.0.0.24 (X11/20111109) MIME-Version: 1.0 To: Andrew Schetinin CC: pgsql-bugs@postgresql.org Subject: Re: BUG #6426: Complex query runs 10 times longer with "LIMIT 20" References: <4F2995BB.6050708@sesda2.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/17 X-Sequence-Number: 32360 Andrew Schetinin wrote: > Hi Alex, > > Thank you. I played with subqueries, but in this case I did not see a > good enough improvement. > > In my specific case, what I've seen from the query execution plans, is > that without LIMIT the query uses Hash Joins, but once I add LIMIT, it > starts using Nested Loop Joins almost everywhere. > > Regards, > > Andrew > > On Wed, Feb 1, 2012 at 9:42 PM, Alex Lai > wrote: > > Hi Andrew, > I posted for another post, its may give you a workaround. > I still not fully understand how PG choose execute plan that slow > down so much. > > I had the same situation in one of my query. > Use the subquery can speed up almost by 100 times faster. > > .......... > > > > Hope this help. > > > Best Regards, > Alex Lai > > -- > Best regards, > > > Alex Lai > OMI SIPS DBA ADNET Systems , Inc. 7515 Mission Drive, Suite A100 > Lanham, MD 20706 301-352-4657 (phone) 301-352-0437 (fax) > alai@sesda2.com > > > > > -- > -- > Andrew Schetinin Hi Andrew, I am interested in see your query. -- Best regards, Alex Lai OMI SIPS DBA ADNET Systems , Inc. 7515 Mission Drive, Suite A100 Lanham, MD 20706 301-352-4657 (phone) 301-352-0437 (fax) alai@sesda2.com