Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yz5W0-0008HR-HM for pgsql-performance@arkaria.postgresql.org; Sun, 31 May 2015 15:51:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yz5W0-0003gp-2J for pgsql-performance@arkaria.postgresql.org; Sun, 31 May 2015 15:51:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yz5Vz-0003gj-BU for pgsql-performance@postgresql.org; Sun, 31 May 2015 15:51:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Yz5Vw-0001nm-7L for pgsql-performance@postgresql.org; Sun, 31 May 2015 15:51:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t4VFot96032283; Sun, 31 May 2015 11:50:56 -0400 From: Tom Lane To: "Peter J. Holzer" cc: pgsql-performance@postgresql.org Subject: Re: Different plan for very similar queries In-reply-to: <20150531110010.GA25173@hjp.at> References: <20150529085544.GA15813@hjp.at> <20150529095117.GB15813@hjp.at> <5568FAA5.3080807@2ndquadrant.com> <29819.1433012674@sss.pgh.pa.us> <20150531110010.GA25173@hjp.at> Comments: In-reply-to "Peter J. Holzer" message dated "Sun, 31 May 2015 13:00:10 +0200" Date: Sun, 31 May 2015 11:50:55 -0400 Message-ID: <32282.1433087455@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 "Peter J. Holzer" writes: >>> Merge Semi Join (cost=316864.57..319975.79 rows=1 width=81) (actual time=7703.917..30948.271 rows=2 loops=1) >>> Merge Cond: ((t.term)::text = (f.berechnungsart)::text) >>> -> Index Scan using term_term_idx on term t (cost=0.00..319880.73 rows=636 width=81) (actual time=7703.809..7703.938 rows=3 loops=1) >>> Filter: (((facttablename)::text = 'facttable_stat_fta4'::text) AND ((columnname)::text = 'berechnungsart'::text)) > Just noticed that this is a bit strange, too: > This scans the whole index term_term_idx and for every row found it > checks the table for the filter condition. So it has to read the whole > index and the whole table, right? But the planner estimates that it will > return only 636 rows (out of 6.1E6), so using > term_facttablename_columnname_idx to extract those 636 and then sorting > them should be quite a bit faster (even just a plain full table scan > and then sorting should be faster). Hm. I do not see that here with Tomas' sample data, neither on HEAD nor 9.1: I always get a scan using term_facttablename_columnname_idx. I agree your plan looks strange. Can you create some sample data that reproduces that particular misbehavior? regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance