Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3Siv-00041F-4I for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Aug 2019 22:16:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i3Sit-0003L4-Un for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Aug 2019 22:16:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3Sit-0003Kw-KO for pgsql-bugs@lists.postgresql.org; Thu, 29 Aug 2019 22:16:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i3Sim-0000vN-TA for pgsql-bugs@lists.postgresql.org; Thu, 29 Aug 2019 22:16:54 +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 x7TMGj39007529; Thu, 29 Aug 2019 18:16:45 -0400 From: Tom Lane To: easteregg@verfriemelt.org cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15984: order of where in() query affects query planer In-reply-to: <15984-c0a18aa262593694@postgresql.org> References: <15984-c0a18aa262593694@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 29 Aug 2019 15:48:46 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7527.1567117005.1@sss.pgh.pa.us> Date: Thu, 29 Aug 2019 18:16:45 -0400 Message-ID: <7528.1567117005@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > i have a partial index like in the following example and when reorder the > elements of the in() statement, > i get sometimes a bitmap indexscan instead of the expected index only scan. > if i remove an element, i still get the index only, > but with the wrong order, i get a bitmap heap scan. is this expected? FWIW, I get the same plan shape with either order of the IN elements. However, your example is probably going to be subject to plan instability because (1) you used vacuum full not plain vacuum. That doesn't leave the table in the all-visible condition that would favor an index-only scan. (2) you didn't analyze the table. At some point, autovacuum will come along and rectify that oversight, likely causing the plan choice to change underneath you. regards, tom lane