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.94.2) (envelope-from ) id 1tqEQo-001Zuw-Ci for pgsql-bugs@arkaria.postgresql.org; Thu, 06 Mar 2025 16:50:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tqEQn-000GvL-3X for pgsql-bugs@arkaria.postgresql.org; Thu, 06 Mar 2025 16:50:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tqEQm-000GvD-JZ for pgsql-bugs@lists.postgresql.org; Thu, 06 Mar 2025 16:50:44 +0000 Received: from dog.elm.relay.mailchannels.net ([23.83.212.48]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tqEQk-001KuR-12 for pgsql-bugs@lists.postgresql.org; Thu, 06 Mar 2025 16:50:43 +0000 X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id AE93542D8E; Thu, 6 Mar 2025 16:50:40 +0000 (UTC) Received: from pdx1-sub0-mail-a237.dreamhost.com (trex-1.trex.outbound.svc.cluster.local [100.115.211.97]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 4DF3643E26; Thu, 6 Mar 2025 16:50:40 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1741279840; a=rsa-sha256; cv=none; b=M/K5pZhziO+ru1m5QaF7lUzx0mHy/R17GBUMzY+y6C+4H2QwjkGhmhvd4fmA1rVLMa+BKe NsWt44LdVrKnR7AgrsdWu3DjHLludk3cdKhGSc7xWCZCF4xzKFUDhZe1BajODRuw87e8yi IbhZLsSFimBZ1dkPQGQtljacv+bSGKAR4ZbhNBzvAo6BLe5WbGHBviSTaQ9Vs6K1pa2nfI Ppq160DprCA88uz3+YzWV4vEDqDRrKXuLnygSO9DWIPI5VTW4GEfIAXe05x3m/rM86K2q8 i5S7wOm1vzrYo94QXVLjz5Gh3yRY+nZ6S7KFUvZe7izOaZgh+mye8AXAm/e+5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1741279840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yZvYSnbFSx0pSlOLBGcnIXMWf79oEOHTJA7dE8Dcnio=; b=fqlZi8ci4y23T3Z19G5LfEffWbegHz7Vn9XDBxCJTOwQj7lUlljT7T4g3PI8YepKyWkKr/ AEDV97H95EE1PeYXKCb8NErWsZGJ1EtqsKYxIeXrXXJJ6+DhUNHLEboXGbpsiri5VE4c4W ew/nr6Z+S1wyd/zyhtxnj2WnondrtTMaIMc2ldA9w/cxYiFOzUq1aPeh/GSjZfUO9niamz Sd3Y4FUt7/YvDgHd3n4nfKmxjXV2+FcTOxv0vlY4jlPBKFN6cDoTDGxhm0KtKvfMNNQ3R6 yIYWm/an9u1r6ssYwfwMdtFlg+d8z2QyQPCTEms8KfpEhG4xrG8UZX2ATBxX5w== ARC-Authentication-Results: i=1; rspamd-d464f9ccc-f9wds; auth=pass smtp.auth=dreamhost smtp.mailfrom=nico@cryptonector.com X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|nico@cryptonector.com X-MailChannels-Auth-Id: dreamhost X-Skirt-Stretch: 0fda5b323d353e72_1741279840540_487036571 X-MC-Loop-Signature: 1741279840540:2040727018 X-MC-Ingress-Time: 1741279840540 Received: from pdx1-sub0-mail-a237.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.115.211.97 (trex/7.0.2); Thu, 06 Mar 2025 16:50:40 +0000 Received: from ubby (syn-075-081-095-064.res.spectrum.com [75.81.95.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by pdx1-sub0-mail-a237.dreamhost.com (Postfix) with ESMTPSA id 4Z7wQl5Bsqzb9; Thu, 6 Mar 2025 08:50:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cryptonector.com; s=dreamhost; t=1741279840; bh=yZvYSnbFSx0pSlOLBGcnIXMWf79oEOHTJA7dE8Dcnio=; h=Date:From:To:Cc:Subject:Content-Type; b=hEYKeI5Awpi3p936ddpf5PWildVjpW4yEqv1fOJScK9yLPPRLbtOgJ2DOy73QFsPc npUYo+3KgeYKXITgZ/eCDn7awmyT0AxzHZIPLCpXPZ5vXrQWwF++himp6Qu/CoF+62 2Lb2bW1Q8E9J6UvfUrWV3wpRSOJtSa+7ZhGoAl4TEHM5Y+vxrcpb4F9dRs24jyvBJZ a3QBYxzYMC4LzHeAiCoOzkiAJoVd4Bz5r4Fg5blCAsbWRQyO4uskAYZ6MfOz0w5Vyu DwrjGc4Fkt1eMJb8LAVPOgiDi2BUfDcJqFbECHQD8Vbn3ScR+0LiTBYzybPR0CyGey p2wDqNRJq3I0A== Date: Thu, 6 Mar 2025 10:50:37 -0600 From: Nico Williams To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18825: Row value equality predicates do not use indices Message-ID: References: <18825-5c25a6ba19fa6549@postgresql.org> <1678855.1740530682@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1678855.1740530682@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Feb 25, 2025 at 07:44:42PM -0500, Tom Lane wrote: > PG Bug reporting form writes: > > DELETE FROM foo USING (SELECT dels FROM dels) AS dels > > WHERE foo = dels; -- <--- does not use indices on either table > > [ shrug... ] Works for me given the full-row indexes, although I do > have to force enable_seqscan off or reduce random_page_cost a lot, > because otherwise the planner thinks a seqscan-and-sort is cheaper. That seems like a bug, but a separate bug. > I strongly suspect it's right, because full-row indexes are going to > be bigger than the table proper. The mere fact that a plan uses > indexes does not automatically make it better than one that doesn't. If a full row index is a b-tree (or otherwise a prefix) index then one think that skip-scanning the b-tree would be much faster than scanning the table. These are tables with two or three columns, all small, and the indices are all covering indices, therefore the indices are all "bigger than the table proper", yet decomposing the row equality predicate causes indices to be used. (Again, in this example all columns are NOT NULL.) When I change the query to decompose the row equality predicate into column equality predicates then the indices are used, and the query is fast. For the reasons I give above I suspect that a full-row b-tree index would be equally fast, if only I could get the planner to try it. > Anyway, AFAICS your gripe has nothing to do with "can the planner > use these indexes", and everything to do with its cost estimates > about the value of doing it that way. I suspect that the planner doesn't know to try to decompose row equality predicates into column equality predicates to take advantage of indices on those columns. That would be a missing feature, not a bug, though I admit that it was surprising (PG is so good that this sort of thing is surprising, what can I say). As for not using the full row index, from the evidence I have the planner is indeed making a suboptimal choice here. Surely the planner can't always make the optimal choice, but I suspect row equality predicates are rare, and that when b-tree indices on full row values exist then using those should have a slightly higher weight than not using them. Nico --