Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 1A68D63619C for ; Wed, 25 Mar 2009 00:49:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 14399-06 for ; Wed, 25 Mar 2009 00:49:20 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f176.google.com (mail-gx0-f176.google.com [209.85.217.176]) by mail.postgresql.org (Postfix) with ESMTP id 0DDE9635A92 for ; Wed, 25 Mar 2009 00:49:16 -0300 (ADT) Received: by gxk24 with SMTP id 24so9762273gxk.19 for ; Tue, 24 Mar 2009 20:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=+kqjPkwDEdg5AWsdqQpGLdLqfJ0q1L7e52+vJIQ09MI=; b=VkMQIEcoHQaH4jGipreLD1k2IY0+ZxmeeYJxpQA6keWh3SugST2q2uUXCxsBw+TJSK 753gm0XpA30gum7VSivU/IQzxRnIxxLVtCIhot8pP6OTu5LxM8840sx/DZ6VBcwxBUuT lev1YHX8jtcnzom6BJLfy7j4FPl+z2tnMOd4Y= 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:content-transfer-encoding; b=LxczEsH+Q6werbvm8IhSSQuYMOCiJKBdqjQAe4j32ePJbbrjpq2MFCBJE9SobpK0Zb L2wOqyG5a8HNPETdkJkJun5gsvDT0O+njeOzZ3aa7xJfaUykl+ycQqIevsuxc0I0cRxp 5ew9M6o/EVybMO2Eglo+47u6nYLFiLTC3kFXM= MIME-Version: 1.0 Received: by 10.90.83.2 with SMTP id g2mr1395841agb.107.1237952617495; Tue, 24 Mar 2009 20:43:37 -0700 (PDT) In-Reply-To: <49C99732.8080703@agliodbs.com> References: <7fd310d10903231203r1bd37b8cn8baeadae83253f44@mail.gmail.com> <7fd310d10903241521t645462bdpb3b8aee40b4f3ae4@mail.gmail.com> <49C99732.8080703@agliodbs.com> Date: Tue, 24 Mar 2009 22:43:37 -0500 Message-ID: <7fd310d10903242043x28d24adenb729c0a77a21ce9@mail.gmail.com> Subject: Re: Help Me Understand Why I'm Getting a Bad Query Plan From: Bryan Murphy To: Josh Berkus Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/362 X-Sequence-Number: 33284 On Tue, Mar 24, 2009 at 9:30 PM, Josh Berkus wrote: > For some reason, your first post didn't make it to the list, which is why > nobody responded. Weird... I've been having problems with gmail and google reader all week. >>> I've got a query on our production system that isn't choosing a good >>> plan. =A0I can't see why it's choosing to do a sequential scan on the >>> ItemExperienceLog table. =A0That table is about 800mb and has about 2.5 >>> million records. =A0This example query only returns 4 records. =A0I've >>> tried upping the statics for ItemExperienceLog.VistorId and >>> ItemExperienceLog.ItemId to 1000 (from out default of 100) with no >>> success. > > Yes, that is kind of inexplicable. =A0For some reason, it's assigning a v= ery > high cost to the nestloops, which is why it wants to avoid them with a se= q > scan. =A0Can you try lowering cpu_index_cost to 0.001 and see how that af= fects > the plan? I'm assuming you meant cpu_index_tuple_cost. I changed that to 0.001 as you suggested, forced postgres to reload it's configuration and I'm still getting the same execution plan. Looking through our configuration one more time, I see that at some point I set random_page_cost to 2.0, but I don't see any other changes to query planner settings from their default values. Bryan