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 1gwI7h-0006ze-IV for pgsql-performance@arkaria.postgresql.org; Wed, 20 Feb 2019 03:00:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwI7f-0003hx-WB for pgsql-performance@arkaria.postgresql.org; Wed, 20 Feb 2019 03:00:35 +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 1gwI7f-0003Z5-JU for pgsql-performance@lists.postgresql.org; Wed, 20 Feb 2019 03:00:35 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwI7Y-0000cF-Bz for pgsql-performance@lists.postgresql.org; Wed, 20 Feb 2019 03:00:34 +0000 Received: from [192.168.127.1] (port=56364 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1gwI7U-000A8C-Lw; Wed, 20 Feb 2019 03:00:24 +0000 Received: from [127.0.0.1] (port=51564 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gwI7T-000LVz-SN; Wed, 20 Feb 2019 03:00:23 +0000 From: Andrew Gierth To: Abi Noda Cc: pgsql-performance@lists.postgresql.org Subject: Re: Why isn't an index scan being used? In-Reply-To: (Abi Noda's message of "Tue, 19 Feb 2019 17:10:43 -0700") Message-ID: <87ftsji2tb.fsf@news-spur.riddles.org.uk> References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Wed, 20 Feb 2019 03:00:23 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Abi" == Abi Noda writes: Abi> However, when I index the closed column, a bitmap scan is used Abi> instead of an index scan, with slightly slower performance. Why Abi> isn't an index scan being used, given that the exact same number Abi> of rows are at play as in my query on the state column? Most likely difference is the correlation estimate for the conditions. The cost of an index scan includes a factor based on how well correlated the physical position of rows is with the index order, because this affects the number of random seeks in the scan. But for nulls this estimate cannot be performed, and bitmapscan is cheaper than plain indexscan on poorly correlated data. -- Andrew (irc:RhodiumToad)