Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5WtG-00042a-77 for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Sep 2018 14:03:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5WtE-0008H1-Fr for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Sep 2018 14:03:36 +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.89) (envelope-from ) id 1g5WtE-0008Gu-9p for pgsql-bugs@lists.postgresql.org; Thu, 27 Sep 2018 14:03:36 +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.89) (envelope-from ) id 1g5WtC-0007OU-7o for pgsql-bugs@lists.postgresql.org; Thu, 27 Sep 2018 14:03:35 +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 w8RE3VXv001819; Thu, 27 Sep 2018 10:03:31 -0400 From: Tom Lane To: acamargo@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15408: Postgresql bad planning with multicolumn gist and search with empty results In-reply-to: <15408-18cb801b3a5b21a5@postgresql.org> References: <15408-18cb801b3a5b21a5@postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Thu, 27 Sep 2018 11:59:23 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1817.1538057011.1@sss.pgh.pa.us> Date: Thu, 27 Sep 2018 10:03:31 -0400 Message-ID: <1818.1538057011@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?utf-8?q?PG_Bug_reporting_form?= writes: > As seen in the explain results, when I search for non-existent values of n2, > the plan changes on Index condition used, giving poor plans. None of this > plan differences appear if the index is btree. It seems something gist > related, and I need to use gist due to PostGIS functions. I don't have time to dig in the code right now, but my recollection is that btcostestimate() has fairly detailed modeling of the behavior of queries that constrain only some columns of an index, eg it understands that "col1 = constant" is much cheaper to scan than "col2 = constant". On the other hand, gistcostestimate() has no such modeling and assumes that a constraint on a lower-order column is worth the same as one on the first column. This is partially due to lack of effort put into that function, but I seem to recall being told that GIST was not as sensitive to column ordering as btree, too. Your results indicate otherwise :-( Depending on what other queries you use, maybe an adequate workaround would be to switch the two columns of the index. regards, tom lane