Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vOTFT-008qCp-1z for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Nov 2025 04:04:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vOTFR-003E64-0g for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Nov 2025 04:04:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vOTFQ-003E5v-2w for pgsql-hackers@lists.postgresql.org; Thu, 27 Nov 2025 04:04:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vOTFP-001ieE-0E for pgsql-hackers@lists.postgresql.org; Thu, 27 Nov 2025 04:04:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5AR44hxk036828; Wed, 26 Nov 2025 23:04:43 -0500 From: Tom Lane To: David Rowley cc: Sergei Glukhov , pgsql-hackers@lists.postgresql.org Subject: Re: Partial hash index is not used for implied qual. In-reply-to: References: <1106189.1764033798@sss.pgh.pa.us> <1112416.1764036072@sss.pgh.pa.us> <1615744.1764181557@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Thu, 27 Nov 2025 16:01:14 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <36826.1764216283.1@sss.pgh.pa.us> Date: Wed, 26 Nov 2025 23:04:43 -0500 Message-ID: <36827.1764216283@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Thu, 27 Nov 2025 at 07:26, Tom Lane wrote: >> I checked the costing calculations and it's basically that >> genericcostestimate doesn't understand about hash buckets. > I assume you must mean using your "x % 100" case rather than Sergei's case. Right. >> ... tuples in the index, so it supposes that that means we'll visit >> 1/100th of the index's pages (rounded up to 1). > I'm not so clear on why this is bad. The index has 1000 tuples on 6 > pages and we want to scan 1% of the rows in the index. As a result, > genericcostestimate() calculates that's 1 page. How many pages would > you expect to scan? To be clear, neither of genericcostestimate's estimates are bad as a generic estimate. And I'm not even sure that we could do better with a hash-aware estimate implemented in hashcostestimate. I think the key thing about this test case is that the partial index ends up with all its entries in one hash bucket. I'm not sure that we could reasonably expect to know that in the cost estimator. Even if we could, should we really expend a lot of effort on the case? It's a textbook example of when you should not use a hash index. I'm interested in fixing this can't-generate-this-plan-shape bug because it probably impacts more-realistic use-cases. But I think the cost estimation problem is probably specific to cases where you shouldn't have used a hash index, so I'm okay with ignoring that part. Until more evidence arrives, anyway. regards, tom lane