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 1jRdnS-0002df-TJ for pgsql-performance@arkaria.postgresql.org; Thu, 23 Apr 2020 15:29:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jRdnR-0002LV-Hc for pgsql-performance@arkaria.postgresql.org; Thu, 23 Apr 2020 15:29:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRdnR-0002LO-9k for pgsql-performance@lists.postgresql.org; Thu, 23 Apr 2020 15:29:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRdnO-0003f1-Rh for pgsql-performance@lists.postgresql.org; Thu, 23 Apr 2020 15:29:47 +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 03NFTdgx004316; Thu, 23 Apr 2020 11:29:39 -0400 From: Tom Lane To: "David G. Johnston" cc: Thomas Kellerer , "pgsql-performance@lists.postgresql.org" Subject: Re: PostgreSQL does not choose my indexes well In-reply-to: References: <35dc90d6-e0c2-13b8-3184-e3db5d854a78@gmail.com> <1bb37a19-77f6-8c49-073e-ed6251c98583@gmx.net> Comments: In-reply-to "David G. Johnston" message dated "Thu, 23 Apr 2020 06:57:29 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4314.1587655779.1@sss.pgh.pa.us> Date: Thu, 23 Apr 2020 11:29:39 -0400 Message-ID: <4315.1587655779@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Thursday, April 23, 2020, Thomas Kellerer wrote: >> Plus: scanning idx_tabla_entidad is more efficient because that index is >> smaller. > Really? The absence of 33 million rows in the partial index seems like it > would compensate fully and then some for the extra included columns. On the other hand, an indexscan is likely to end up being effectively random-access rather than the purely sequential access involved in a seqscan. (If the index was built recently, then it might not be so bad --- but the planner doesn't know that, so it assumes that the index leaf pages are laid out pretty randomly.) Moreover, unless the table is mostly marked all-visible, there will be another pile of randomized accesses into the heap to validate visibility of the index entries. Bottom line is that this choice is not nearly as open-and-shut as the OP seems to think. In fact, it's fairly likely that this is a badly designed index, not a well-designed one that the planner is unaccountably failing to use. Both covering indexes and partial indexes are easily-misused features that can make performance worse not better. regards, tom lane