Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRg5p-00088E-S3 for pgsql-performance@arkaria.postgresql.org; Thu, 23 Apr 2020 17:56:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jRg5n-0000fb-Jl for pgsql-performance@arkaria.postgresql.org; Thu, 23 Apr 2020 17:56:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRg5n-0000dp-CJ for pgsql-performance@lists.postgresql.org; Thu, 23 Apr 2020 17:56:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRg5g-00066c-70 for pgsql-performance@lists.postgresql.org; Thu, 23 Apr 2020 17:56: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 03NHugFO018682; Thu, 23 Apr 2020 13:56:42 -0400 From: Tom Lane To: Stephen Frost cc: "David G. Johnston" , Thomas Kellerer , "pgsql-performance@lists.postgresql.org" Subject: Re: PostgreSQL does not choose my indexes well In-reply-to: <20200423171858.GE13712@tamriel.snowman.net> References: <35dc90d6-e0c2-13b8-3184-e3db5d854a78@gmail.com> <1bb37a19-77f6-8c49-073e-ed6251c98583@gmx.net> <4315.1587655779@sss.pgh.pa.us> <20200423171858.GE13712@tamriel.snowman.net> Comments: In-reply-to Stephen Frost message dated "Thu, 23 Apr 2020 13:18:58 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18680.1587664601.1@sss.pgh.pa.us> Date: Thu, 23 Apr 2020 13:56:41 -0400 Message-ID: <18681.1587664601@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Stephen Frost writes: > I do wonder if we are maybe missing a bet at times though, considering > that I'm pretty sure we'll always go through the index in order, and > therefore randomly, even when we don't actually need the results in > order..? Has there been much consideration for just opening an index > and sequentially scanning it in cases like this where we have to go > through all of the index anyway and don't need the results in order? As I recall, it's unsafe to do so because of consistency considerations, specifically there's a risk of missing or double-visiting some entries due to concurrent index page splits. VACUUM has some way around that, but it doesn't work for regular data-fetching cases. (nbtree/README has more about this, but I don't feel like looking it up for you.) My guess based on your results is that the OP's table *isn't* all-visible, or at least the planner doesn't know it is. regards, tom lane