Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A652A1337B47 for ; Wed, 11 May 2011 12:55:38 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 41831-05 for ; Wed, 11 May 2011 15:55:29 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2.peak6.com (smtp2.peak6.com [38.98.137.9]) by mail.postgresql.org (Postfix) with ESMTP id 5009A1337BF3 for ; Wed, 11 May 2011 12:55:29 -0300 (ADT) X-AuditID: 0a02cb1e-b7b7eae000002a28-67-4dcab16f088f Message-ID: <4DCAB16F.2060300@peak6.com> Date: Wed, 11 May 2011 10:55:27 -0500 From: Shaun Thomas Reply-To: Organization: Peak6 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.7) Gecko/20100720 Lightning/1.0b2 Thunderbird/3.1.1 MIME-Version: 1.0 To: "Prodan, Andrei" CC: Subject: Re: 'Interesting' prepared statement slowdown on large table join References: In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed content-transfer-encoding: 7bit X-Originating-IP: [10.10.221.50] X-Brightmail-Tracker: AAAAAQAAAZE= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/151 X-Sequence-Number: 43660 On 05/11/2011 06:08 AM, Prodan, Andrei wrote: > Index Scan using attr_name_value on big_table (cost=0.00..22.85 > rows=4 width=7) (actual time=0.176..757.646 rows=914786 loops=1) Holy inaccurate statistics, Batman! Try increasing your statistics target for attr_name and attr_value in your big table. I know you said you set it to 300 on party_id, but what happened here is that the optimizer thought this particular name/value combo in your big table would return less rows, and it was horribly, horribly wrong. You might think about bumping up your default_statistics_target anyway to prevent problems like this in general. But definitely increase it on those two columns and reanalyze. My guess is that your big_table is big enough that each analyze gets a different random sample of the various attr_name and attr_value combinations, so occasionally it'll get too few and start badly skewing query plans. -- Shaun Thomas OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@peak6.com ______________________________________________ See http://www.peak6.com/email_disclaimer.php for terms and conditions related to this email