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 1v7iZc-006o0Q-V8 for pgsql-performance@arkaria.postgresql.org; Sat, 11 Oct 2025 23:00:25 +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 1v7iZa-00HH9y-PS for pgsql-performance@arkaria.postgresql.org; Sat, 11 Oct 2025 23:00:23 +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 1v74d4-009xoC-OK for pgsql-performance@lists.postgresql.org; Fri, 10 Oct 2025 04:21:20 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v74d2-000ya5-18 for pgsql-performance@lists.postgresql.org; Fri, 10 Oct 2025 04:21:18 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-78af3fe5b17so1363751b3a.2 for ; Thu, 09 Oct 2025 21:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=empays.com; s=google; t=1760070076; x=1760674876; darn=lists.postgresql.org; h=content-transfer-encoding:date:to:in-reply-to:references:message-id :subject:mime-version:from:from:to:cc:subject:date:message-id :reply-to; bh=uCp7LLIsiiv4OLuyqyibEUdCVNSfP+xr1165+r1433Y=; b=G0I6vjDfc5MOTjDYEZS1MrzW/rVLKiMOvLVWcVOd7/J5GwHcIJPfZUUi3yorQ+RqS2 ERFPP5JxDl52YmV7+pyhrVitwG+z0Q+wIEtzvSKSCGQojctCdWkOsQIyay1be0z+rJYQ Pw50MOaBsLt6xSK3DqyitJuQD83Tn5BuA+3Yg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760070076; x=1760674876; h=content-transfer-encoding:date:to:in-reply-to:references:message-id :subject:mime-version:from:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=uCp7LLIsiiv4OLuyqyibEUdCVNSfP+xr1165+r1433Y=; b=s46hAY3QCVk1p49RhQNXUvpVFveVfUI0V0uUdV+mAI5R50qBJuAhbyB+LsGord9D+6 qtsF+WV+29eKGwa5VidHCWnHdfDUe6dVvK6YfkEkQl6cxKdgR6BrIsWSRkr4M7Q42l4b hEd/2I13SpG0osnCBZNqOR6z23A5UgbTbDYz8aVfqYucPKq58e+HtFgBvBvHiVopbkfK fER7gVX3hHB2nuu1xWO3QpE7zXHLaqi8XSHexZ/nKEkQDemHsxxpqg1muzGr4GSw+hDV /6igtTqIpGi9dech11hJGGhdrdUDcAAlelmj42QuwKO0KoOuuGjyTn6Bdx28TsLMyQ7j xzpQ== X-Gm-Message-State: AOJu0YyfownKJKKikC9V7z7n8kXfqO/rSPDbirlS8avr1ln07G5VyP2x BpzOdGpbbY5Z0szqvHK+8MkaB8jLNCLJulRNud+y752MI4y/OAPdhtuOa1WJGENd3xnnFoTh68X 0x8z2wnPGVpMzih2TjJ3LngoCeDaKaHs9rugm+6SqnKE0wZ2pxJ6+szxfRHivyNKhulJgUmn7 X-Gm-Gg: ASbGncsvpQs4jjqXc1NjoKgbKS/WthO+2zKx/puUQA8AQzed+PlFzqCRCe6FTqiLFfe 9CiOtOOXxJkSC9zeCamfYcN1JAQv4akqWM/Kp6u41apV7M5HD+mgg3MFz4Vd2PUJHapxSNw3zB3 cf7dT/DTfgHcTK5V9Lwo+n+uEBuP1qm8EuIYbcL0Hl824Sm4FhtPYaSDgH32YBpVwRua0IyMn23 2nvmLqkLh8YbN9IH7ROOsDbwYEX6JHucfeU+ULqrz7aanruEldNMzSBo57A723ao31larEsDna6 e12v5RR9/TrWsfGdkBrvKjPodAdviJK0Nz1wcbof52s8Z7YUVZMXlqvnwwq70ECIqJegXDhQEyH 0mZrC1p2FF1PxP5vm6rACQE9HWajwK1vHnfTRAiAvfHcsPvmOIalso0E= X-Google-Smtp-Source: AGHT+IFb3y9OhdW+RHd6hTs/zogLPiZhiDOFL65QWNyecLqYI2Phd40P8+p5PcnF7gUF3LRJoIbEsg== X-Received: by 2002:a05:6a00:4b04:b0:781:1d38:d571 with SMTP id d2e1a72fcca58-793878286b9mr13494170b3a.17.1760070076104; Thu, 09 Oct 2025 21:21:16 -0700 (PDT) Received: from smtpclient.apple ([206.84.236.205]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7992b060bc2sm1437544b3a.3.2025.10.09.21.21.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Oct 2025 21:21:15 -0700 (PDT) From: lokesh@empays.com Mime-Version: 1.0 (1.0) Subject: Re: Poor performance with row wise comparisons Message-Id: <5EBECECB-EDF2-4309-B985-680D75E8FE17@empays.com> References: In-Reply-To: To: pgsql-performance@lists.postgresql.org Date: Fri, 10 Oct 2025 09:51:01 +0530 X-Mailer: iPhone Mail (22G100) Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Looking for help on storing and retrieving the personal data as masked. Any= references and implementation details would help > On 10 Oct 2025, at 3:24=E2=80=AFAM, Peter Geoghegan wrote: >=20 > =EF=BB=BFOn Fri, Feb 7, 2025 at 2:05=E2=80=AFAM Jon Emord wrote: >> My expectation is that the following two queries would have roughly the = same performance. >> They both use the same index only scans and return the same 100 rows of = data. >> The main difference I see in the explain output is that the row wise com= parison has 3,000 times >> the shared buffer hits, but it is unclear why there would need to be mor= e hits. >=20 > I agree that this doesn't make sense. >=20 > The problem here is that the row compare condition that terminates the > scan (namely "(ROW(data_model_id, primary_key) <=3D ROW(123, > 'DEF'::text))") was unable to recognize that we've reached the end of > all matching tuples upon reaching the first tuple that's > "(123, > 'DEF')". The scan would only terminate upon reaching the first tuple > whose data_model_id was > 123. Which (in this particular case) meant > that the scan read far more index leaf pages than necessary. Note that > this wouldn't have mattered very much if there weren't so many > irrelevant tuples that were "data_model_id =3D 123 AND > '(123, 'DEF')'" > -- but there were. >=20 > I fixed this problem in passing, in the context of a bug fix that went > into Postgres 18 (see commit bd3f59fd, in particular the part about > marking lower-order subkeys as required to continue the scan, > described towards the end of the commit message). You should look into > upgrading to Postgres 18 if this issue is important to you. >=20 > -- > Peter Geoghegan >=20 >=20 --=20 ________________________________________________________________ Note:=20 Privileged/Confidential information may be contained in this=20 message and=20 may be subject to legal privilege. Access to this e-mail by=20 anyone other=20 than the intended is unauthorised. If you are not the=20 intended recipient=20 (or responsible for delivery of the message to such=20 person), you may not=20 use, copy, distribute or deliver to anyone this=20 message (or any part of=20 its contents ) or take any action in reliance on it. In such case, you=20 should destroy this message, and notify us=20 immediately. If you have=20 received this email in error, please notify us=20 immediately by e-mail or=20 telephone and delete the e-mail from any=20 computer.=C2=A0The integrity and=20 security of e-mail communication cannot be guaranteed via the public=20 Internet as information can be intercepted, corrupted, lost, destroyed,=20 arrive late or contain viruses. Boson Systems Pvt. Ltd. hereby disclaims=20 any liability for the correct and complete transmission of information=20 contained in e-mail messages or for any delay in its receipt. If=20 verification of the content of any e-mail communication is required, please= =20 request a hard copy version of the e-mail from the original sender. If you= =20 or your employer does not consent to internet e-mail=20 messages of this=20 kind, please notify us immediately. All reasonable=20 precautions have been=20 taken to ensure no viruses are present in this=20 e-mail. As our company=20 cannot accept responsibility for any loss or=20 damage arising from the use=20 of this e-mail or attachments we recommend=20 that you subject these to your=20 virus checking procedures prior to use.=20 The views, opinions, conclusions=20 and other informations expressed in=20 this electronic mail are not given or=20 endorsed by the company unless=20 otherwise indicated by an authorized=20 representative independent of this=20 message.