Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eqmTp-0005UI-Vs for pgsql-general@arkaria.postgresql.org; Tue, 27 Feb 2018 21:08:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eqmTp-0004uK-36 for pgsql-general@arkaria.postgresql.org; Tue, 27 Feb 2018 21:08:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eqmTo-0004uA-OG for pgsql-general@lists.postgresql.org; Tue, 27 Feb 2018 21:08:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eqmTm-0005Vr-0c for pgsql-general@postgresql.org; Tue, 27 Feb 2018 21:08:07 +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 w1RL84eY025620; Tue, 27 Feb 2018 16:08:04 -0500 From: Tom Lane To: Hadi Moshayedi cc: Postgres General Subject: Re: index-only-scan when there is an index on all columns In-reply-to: References: Comments: In-reply-to Hadi Moshayedi message dated "Tue, 27 Feb 2018 15:49:17 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25618.1519765684.1@sss.pgh.pa.us> Date: Tue, 27 Feb 2018 16:08:04 -0500 Message-ID: <25619.1519765684@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hadi Moshayedi writes: > I am wondering why is it not using index-only-scan (which would use the > cache better) and instead it does a bitmap scan? Never experiment on an empty table and assume that the resulting plan is the same as you'd get on a large table. In this case, not only don't you have any meaningful amount of data loaded, but the planner can see that none of the table's pages are marked all-visible, meaning that the "index-only" scan would degrade to a regular indexscan, which is how it gets costed. And on a single-page table, an indexscan is going to have a hard time beating other alternatives. regards, tom lane