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 1v6yaf-00Csny-9c for pgsql-performance@arkaria.postgresql.org; Thu, 09 Oct 2025 21:54: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 1v6yac-008oe0-S4 for pgsql-performance@arkaria.postgresql.org; Thu, 09 Oct 2025 21:54: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 1v6yac-008odp-Dv for pgsql-performance@lists.postgresql.org; Thu, 09 Oct 2025 21:54:23 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v6yaZ-000vlG-0u for pgsql-performance@lists.postgresql.org; Thu, 09 Oct 2025 21:54:22 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-46e6ba26c50so8164455e9.2 for ; Thu, 09 Oct 2025 14:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bowt-ie.20230601.gappssmtp.com; s=20230601; t=1760046856; x=1760651656; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6HfnjzGuqMH4F2a2RP5xshztahARAnJMUn8/nGOLC54=; b=Vnx4ZD5LkfVpeWhno4M3wRPu0PgBUdAXHFYPsDDmB3Nou8ZzA4qJoL61F3au8dAtHO znO9WVuTEz8AM4+xORCopM3y8YbNnevkBnRS6nQUybgyZowBvav60mJcuaKa1fnNbICC D/B9ajOw2EjvIUnonyr6fyBj2YacHjspHs4nIqyXAcEmSo0DkpIfPZNlKwuh6Eld58yo sRRmwbxZCKxZMB1jJbjUoX8AwzclMOK6PySBqm0pqCKH2n2GLRHL6xk1p9WHPQlEWow5 Fs4bCz7k+V1TVYmKay7BZqDZsTYDn1EN/GEWg6W91rQ9pey7fJK5oDgxwwUeodLWUHm5 G8fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760046856; x=1760651656; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6HfnjzGuqMH4F2a2RP5xshztahARAnJMUn8/nGOLC54=; b=tBTjWxK4nVcbD3lZPnanbkD7fZ5sP7aSxf80199xq1ZWKzm2c1C5uUmz9+18HYrnyx nKkPh7hf2BiXS5KwMLlocB5gi0zRNv08OhcTbgb96oddCr9BhviqfC8CMyh1+EO1Ae+w MuPVyGqu6PsEcGUBQ03p1oGPGHaNrBoxbnO7Ep1+N/3ToobNDYqC6hqK04OzTt46nGZu nGeHhOFJ3+sfJm8qJCn06jEt1NmtaVerokywuc6Hv7RhsokZqCSZuCKIaEzyMdymGyRf isU7s1VPuvsefSz0ZnpII13YX69JkNsRCaQw1BiutaDjqifK/9uilOXOJr3AnnTdLCrh oEmQ== X-Gm-Message-State: AOJu0YyfunH/RUOUWmq+6XHi78KDOyGBYg0FVSJoiKjXPVv9Rz5PPSqg n7gPo72UqmvUFIlC98vbPCU2sPLpbNNM/c2zmZBubmhP1B98sWyAtrklW9p5SJnX7kpe7u3k9/1 e5kcajN4a8M0bVmf96nQQfelCE07tKpTjUSj/JTPmPqvLancsyHQ2K6idiQ== X-Gm-Gg: ASbGncsXAsw9u3U/aOuAzbT2LI8qWXQzx2lmOeDYyEYNdSUeEe2u3ExRngr0RGvZnMQ mxj6zWn6N1iO6rsPD1zNCURg3hmCzKmVLXZ65qKhIBfEPCsNRNcXJ1+Hvg662GONt7ho6FnR9FD A5qpHvA1WE9lykb2pEjM1ZAe/SqCksSgUTZVHH7ygrnJibeLMUQi/XP4khqDySTsRAmGvhItxwG uwP6RHJQNqOtln1zAgzIkKGVXVaHOk= X-Google-Smtp-Source: AGHT+IHm0vz0X2qMNSA6Nobpgwwlyd6VDwzmGcGLTp2MHRAqx/ovt0h+Ly5OQGDTSesPX/6mLN2NepB6HGe/ZAKYzPw= X-Received: by 2002:a05:600d:416b:b0:46e:3dc3:b645 with SMTP id 5b1f17b1804b1-46fa9a87f3emr64737815e9.3.1760046856432; Thu, 09 Oct 2025 14:54:16 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Geoghegan Date: Thu, 9 Oct 2025 17:53:49 -0400 X-Gm-Features: AS18NWAJsQGasT8TYgpFKB_O5vC-Qz6DkfOhV1lSt5FCGdpc8G7PQn7UXn0lyoc Message-ID: Subject: Re: Poor performance with row wise comparisons To: Jon Emord Cc: "pgsql-performance@lists.postgresql.org" 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 On 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 s= ame performance. > They both use the same index only scans and return the same 100 rows of d= ata. > The main difference I see in the explain output is that the row wise comp= arison has 3,000 times > the shared buffer hits, but it is unclear why there would need to be more= hits. I agree that this doesn't make sense. 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. 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