Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T3U5f-0002rT-N2 for pgsql-performance@postgresql.org; Mon, 20 Aug 2012 15:40:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T3U5c-0000Bv-Iq for pgsql-performance@postgresql.org; Mon, 20 Aug 2012 15:40:31 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q7KFeOwQ001060; Mon, 20 Aug 2012 11:40:24 -0400 (EDT) From: Tom Lane To: Josh Berkus cc: pgsql-performance@postgresql.org Subject: Re: 7k records into Sort node, 4.5m out? In-reply-to: <50314441.6050501@agliodbs.com> References: <32B51AEA-E940-40CF-BA54-C7D4E3E1F0D7@thebuild.com> <10304.1344910305@sss.pgh.pa.us> <623F2FF3-B79D-419A-929A-41C707DD5EA3@thebuild.com> <16268.1345063872@sss.pgh.pa.us> <502C0E6B.1040402@agliodbs.com> <20520.1345067076@sss.pgh.pa.us> <502C3DE2.9060703@agliodbs.com> <2703.1345096911@sss.pgh.pa.us> <50314441.6050501@agliodbs.com> Comments: In-reply-to Josh Berkus message dated "Sun, 19 Aug 2012 12:53:37 -0700" Date: Mon, 20 Aug 2012 11:40:24 -0400 Message-ID: <1059.1345477224@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) X-Archive-Number: 201208/125 X-Sequence-Number: 47663 Josh Berkus writes: > I guess what I'm really not understanding is why it's calculating a cost > of 3.7m for the index scan, and then discarding that *entire* cost and > not including it in the total cost of the query? It isn't ... or at least, you've offered no evidence that it is. It's discounting some fraction of the cost on the (apparently correct) basis that the merge won't read that input all the way to the end. Whether it's discounted by an appropriate fraction is hard to tell from the information given. The actual rows count is about a quarter the whole-scan estimate, so a multiplier of 0.25 seems right in hindsight, and that seems to match up roughly right with the mergejoin cost estimate --- but not knowing the actual table size, there's a lot of uncertainty here. regards, tom lane