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 1thFyh-000UcB-Pl for pgsql-performance@arkaria.postgresql.org; Sun, 09 Feb 2025 22:40:39 +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 1thFyf-00HM0l-DU for pgsql-performance@arkaria.postgresql.org; Sun, 09 Feb 2025 22:40:37 +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 1thFyf-00HM0c-3T for pgsql-performance@lists.postgresql.org; Sun, 09 Feb 2025 22:40:37 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1thFyc-004Dwh-2p for pgsql-performance@lists.postgresql.org; Sun, 09 Feb 2025 22:40:36 +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 519MeXqC2065761; Sun, 9 Feb 2025 17:40:33 -0500 From: Tom Lane To: Jon Emord cc: Greg Sabino Mullane , "pgsql-performance@lists.postgresql.org" Subject: Re: Poor performance with row wise comparisons In-reply-to: References: Comments: In-reply-to Jon Emord message dated "Fri, 07 Feb 2025 16:16:27 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2065759.1739140833.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 09 Feb 2025 17:40:33 -0500 Message-ID: <2065760.1739140833@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jon Emord writes: > -> Index Only Scan using entity_data_model_id_primary_key_uniq on en= tity (cost=3D0.70..873753.60 rows=3D15581254 width=3D31) (actual time=3D0= .093..2712.836 rows=3D100 loops=3D1) > Index Cond: ((ROW(data_model_id, primary_key) >=3D ROW(123, 'AB= C'::text)) AND (ROW(data_model_id, primary_key) <=3D ROW(123, 'DEF'::text)= )) > Heap Fetches: 4 > Buffers: shared hit=3D97259 > 2. > data_model_id =3D 123 is the 15 most common value of data_model_id with = 10.8 million records Hm. I think your answer is in this comment in nbtree's key-preprocessing logic: * Row comparison keys are currently also treated without any smarts: * we just transfer them into the preprocessed array without any * editorialization. We can treat them the same as an ordinary inequality * comparison on the row's first index column, for the purposes of the log= ic * about required keys. That is, for the purposes of deciding when the index scan can stop, the "<=3D ROW" condition acts like "data_model_id <=3D 123". So it will run through all of the data_model_id =3D 123 entries before stopping. regards, tom lane