Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1a20jB-0003D0-GP for pgsql-performance@arkaria.postgresql.org; Thu, 26 Nov 2015 17:53:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1a20jA-0006cw-Uf for pgsql-performance@arkaria.postgresql.org; Thu, 26 Nov 2015 17:53:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1a20hW-0004kk-Pt for pgsql-performance@postgresql.org; Thu, 26 Nov 2015 17:51:23 +0000 Received: from nm8-vm8.bullet.mail.ir2.yahoo.com ([212.82.96.142]) by magus.postgresql.org with esmtps (TLS1.0:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1a20hT-0002dH-Lj for pgsql-performance@postgresql.org; Thu, 26 Nov 2015 17:51:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1448560277; bh=WpX0yxUJOPsE7cGIBXYQK6OPtsbEb3FAEZLpZn4rG8Y=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject:From:Subject; b=WPhvYK3vDs0rM6KiyQUOWorpUsygeI4jvuNTuIRxJpCCfEQFm/LtZ2Y9ThEIL9yEeQWTKkNM0YWGPYrQ2z08DrsEU0ohqoaNzZJvz7BOXrzs/3xcN8rr5XtsQeWAD+/aBdu4ESXzEKHe1RCA2uLwMMXeyANPApfoJ+4BlyVS0d0Lqb1FcAtiCH/NWgq+RVRbCxQap4ENIx1RMxo33kxrgNZSrX6Da8mNDEnSBXGesYqyPNo4ZVCBlxOdqqybglFKnhAJeEXoXTkBdZJzq6cq7G+k1Je/bZt9fKUVVoepntVjjg38VCzr/OTVQFwntn4hwTkKlby+fwDBE1OiSzFOtw== Received: from [212.82.98.126] by nm8.bullet.mail.ir2.yahoo.com with NNFMP; 26 Nov 2015 17:51:17 -0000 Received: from [212.82.98.79] by tm19.bullet.mail.ir2.yahoo.com with NNFMP; 26 Nov 2015 17:51:17 -0000 Received: from [127.0.0.1] by omp1016.mail.ir2.yahoo.com with NNFMP; 26 Nov 2015 17:51:17 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 642203.52021.bm@omp1016.mail.ir2.yahoo.com X-YMail-OSG: yG39KEwVM1mw5tP2D81Bdzi0ZuMzhJHyBdtsxm_OO7ay.Va3JmOXlOjSo2ZNgT1 XmmEtzb07eQKxLPB4dFHMRXLVKSXidKVS52X6a6R1BmZPpvJn.1mVL8E8JTYHd1fsZZuJ0McVtOQ bKZhCTmooaw4DKtFy2bxyB47TVCUd6a2lJvbg8h1_7H4KFCB_I4OOpuJZLrr.yOqxjcqpgTOsXOs TnSesoCmCv9NsNcd5xhraylarZ8R9D2sotQ_psH_0P1vyGU9PC3j4NYfVkPBjegJO7vvuN5R6Kcb 4J7objzD0tJa1hYucpr0g3VeOMjP3gR7d3DaUHttpwRg1zMroAXrPwboNKmgC76Gut4YfrCZNO24 8tBVw_Lrix0MPPf2gt9kmmovVVMfvqhoUjdfiuSEsi0jjd5LPtNSmizJOpRNGRSWrzS1ekoE7D2N k_Slc_UJfyIuEqTfN.ZUYJPCBO8GUQ8YMqJH92RV64VKdyIGUNvnRo19xiwrvA5xmgvPyKtnXTDJ gQXXx5E50Tn_ko.gA Received: by 217.12.9.11; Thu, 26 Nov 2015 17:51:17 +0000 Date: Thu, 26 Nov 2015 17:50:55 +0000 (UTC) From: Glyn Astill Reply-To: Glyn Astill To: Tom Lane Cc: Pgsql-performance Message-ID: <412855216.18274544.1448560255082.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <31151.1448556291@sss.pgh.pa.us> References: <31151.1448556291@sss.pgh.pa.us> Subject: Re: Index scan cost calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Length: 2530 X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org ----- Original Message ----- > From: Tom Lane > To: Glyn Astill > Cc: Pgsql-performance > Sent: Thursday, 26 November 2015, 16:44 > Subject: Re: [PERFORM] Index scan cost calculation > > Glyn Astill writes: >> Using pg 9.4.5 I'm looking at a table set up by a 3rd party application > and trying to figure out why a particular index is being chosen over another for > updates/deletes. >> From what I can see the reason is that plans using either index have the > same exactly the same cost. So rather I'm asking if there's something > glaringly obvious I'm missing, or is there anything I can to to get better > estimates. > > I think what's happening is that it's estimating that exactly one index > tuple needs to be visited in both cases, so that the cost estimates come > out the same. That's correct in the one case but overly optimistic in the > other; the misestimate likely is a consequence of the index columns being > interdependent. For instance, if "type" can be predicted from the > other > columns then specifying it isn't really adding anything to the query > selectivity, but the planner won't know that. We can conclude from the > results you've shown that the planner thinks that show+type+best+block > is sufficient to uniquely determine a table entry, which implies that > at least some of those columns are strongly correlated with row+seat. > > The problem will probably go away by itself as your table grows, but > if you don't want to wait, you might want to reflect on which of the index > columns might be (partially?) functionally dependent on the other columns, > and whether you could redesign the key structure to avoid that. Many thanks for the explanation, is such a functional dependency assumed purely based optimistically on statistics gathered by analyze? My (ignorant) thinking was that those sorts of decisions would only be made from keys or constraints on the table. There's no way to determine a particular seat+row combination from show+type+best+block or vice versa. We need show+type+best+block+row+seat to identify an individual row, but approximately 90% of the table has just a space " " for the value of "block", and zeros for both "best" and "row", and for each of those you could say any show+type would almost certainly have row+seat combinations of 0+1, 0+2 and so on. Unfortunately it's an unnormalized legacy structure that I can't really change. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance