Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C01AFB5DBE6 for ; Thu, 12 May 2011 20:28:53 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 68998-05-5 for ; Thu, 12 May 2011 23:28:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f46.google.com (mail-pz0-f46.google.com [209.85.210.46]) by mail.postgresql.org (Postfix) with ESMTP id 3DF9DB5DC0C for ; Thu, 12 May 2011 20:28:43 -0300 (ADT) Received: by pzk9 with SMTP id 9so929769pzk.19 for ; Thu, 12 May 2011 16:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=SsHPSWbrKwvMSYexehhITc3cZYPpoNODbUkM29lTcKU=; b=x5j1Apn2uIZTaqMxWNjgJJaKrJ692b95kTTRralXsUgHx4ARLalOgsnri4PmHCzY4W +IfgnehIqhHMxEQ5KiRDnbFUxJdjAS5WmP4nDnFc7ASXdyAvYE1mXs9uldoVU4rsFLyl KlEUUo6NIx0RIhnFODpRFsloDqrBdSXy/8r+Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=YbW+4iUQfJARlkpsz8e7eninCPiL2QuPX2p3kUwJkTsNtIihlkwiT5pVHmmpekCukM +YFo/kS767/4FSsuLAajFjBtWEuDyVmnpzFvvmniK23/6oBJhoKZVpzX6ADAkgNkoq2H xE7R1U0IRGnzMPZ76Iio/gzdGpMf9hzygkFkE= MIME-Version: 1.0 Received: by 10.68.65.103 with SMTP id w7mr1154955pbs.127.1305242922704; Thu, 12 May 2011 16:28:42 -0700 (PDT) Received: by 10.68.49.7 with HTTP; Thu, 12 May 2011 16:28:42 -0700 (PDT) In-Reply-To: References: Date: Thu, 12 May 2011 16:28:42 -0700 Message-ID: Subject: Re: 'Interesting' prepared statement slowdown on large table join From: Jeff Janes To: "Prodan, Andrei" Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201105/195 X-Sequence-Number: 43704 On Thu, May 12, 2011 at 8:53 AM, Prodan, Andrei wrote: > > @Jeff: thank you for the clear plan interpretation - but I'm afraid I > don't really understand the second bit: > 1) I provided the GOOD plan, so we already know what postgres thinks, > right? (Later edit: guess not. Doesn't work) > 2) There's no full table scan in any of the plans - it scans indices, > the problem seems to be that it scans them in the wrong order because it > thinks there are very few WHERE matches in big_table - which is > incorrect, as for that particular pair there is a huge amount of rows. Hi Andrei, "Explain analyze" only gives you the cost/rows for the plan components it actually executed, it doesn't give you costs for alternative rejected plans. Since the GOOD PLAN doesn't include the index scan in question, it doesn't give the estimated or actual rows for that scan under the stats/conditions that provoke the GOOD PLAN to be adopted. So to get that information, you have to design an experimental prepared query that will get executed using that particular scan, that way it will report the results I wanted to see. My concern is that the experimental query I proposed you use might instead decide to use a full table scan rather than the desired index scan. Although come to think of it, I think the same code will be used to arrive at the predicted number of rows regardless of whether it does a FTS or the desired index scan. Cheers, Jeff