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 1vDvH1-001Ob4-SF for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Oct 2025 01:46:51 +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 1vDvH0-00G7fA-ER for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Oct 2025 01:46:49 +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 1vDvH0-00G7f2-5n for pgsql-bugs@lists.postgresql.org; Wed, 29 Oct 2025 01:46:49 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vDvGw-004IlD-3C for pgsql-bugs@lists.postgresql.org; Wed, 29 Oct 2025 01:46:48 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-654fbeb645bso1447593eaf.2 for ; Tue, 28 Oct 2025 18:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761702406; x=1762307206; 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=qWxInQS520tAG4uVpopFnhrreTRS/prqe/oB07o7F7o=; b=Gbv5hAQkeIbsIORRGwuSIE3lp0GLJa1itzcaxqmyz42fRMacIW1oFmBbi4WBGUeiiK kKrqCfufuHQjLbYCoDkYLHPAFU1aEjv/Df07Frhm4ufSCdTyioKv5uWewTI0m9jZfHfn JopP7M/cWOGcGs/ZYiWH7mqori4gKgoRL0FYDDCjwiAQkK6SRTOVnnX9w7AB0IchYZDv eGzLD02Vp4ibzru0KaTWFghpBVNKRitUMlGkEpAGb+SJXQtBUEQmg6MBNIVPzp3Kv1Pk cYIdlJymb5Bfy/7v0mZxfaXXckudDSwPv6dXLPjPmz9Se73Y1q5O9+W+502aIBaxqitH Oozg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761702406; x=1762307206; 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=qWxInQS520tAG4uVpopFnhrreTRS/prqe/oB07o7F7o=; b=amVRKKrd7X50msCijmeuKDx8X3LpINg02GcPW6gcqsdBLjINDSQkTeUC/BDR2fBDGE vDDjla97Dd+DAkmjBh3iCy3ov/+ZNpaJXyGSLFwSjjxqbMJQf5L0fzsN50nt1fbZPUd1 QsORaWJQd3ebFTwn8HcRzZlYfZdiI/1EjUejc5pl3y5ERLS3RFzyvRluECi8yvZ3mruW b63EBlkS2HVkl+6etW1Od/AEsl8JLyRX1VMpmSs2LJd6PZ4jCo0wj+IrIDabGXf1/yE+ AP9bPwAQDVBnQz8t7FLbcSQi5HtnLnqS4qPxt72kzxOteDmRRip5qqa2gABEbGGVUcJ9 2vXA== X-Forwarded-Encrypted: i=1; AJvYcCUKloxemdzjmDJuV8lNOZWaiGHkj2IfPrpUuRdwXE9GpZ0YvDvbxB34X8Z+/Q5HnCiQS9SYmtiq8GgB@lists.postgresql.org X-Gm-Message-State: AOJu0YztAgbv7MCnUXj+uuMEIKA2AuOaefMJuxRCh+Yd+vNHdfKDKu3r XuC+Pj1TPB+pWBVWXPC6h17lETCcTBEX5t4XKY8+hWgGPIi3HGkohvxlu4YuHvvIgmQQml5L2Dm 6WeoNElA3NllmHCOzY4EtPX60jE8QWbs= X-Gm-Gg: ASbGnct1dPNsHYuGYNNpOuLDBEKa4tWATPOom7SpQVWpEHvsEXXmz278qzgfiMLkrRW 10Ey0XRe95CeyjpFioo/QLHEWVGlImJUk/EOUfDme++aqjqt1FuEyUt58sGcEivCkEyn62x6B3M ka6eViCVI9kY6Zc4i/NKZiwl+5e/bVtGgDk2LyFKQLsVbmEuVgJg+kZiqDyLaof4YCgsuN82wfm n4zVLDXM9IokTEe2Is/u1WGuA42L85AitZDeB7CUCoKiQRVfJ/MVqe2lwOXAierC/rIafLF X-Google-Smtp-Source: AGHT+IEVceeMdwyaUZyEn06gp4h1rXqELh9z8xvuTCu5u3HwFL1555UZ4M7V/SGf40oRVe8kdz2WiJDaME7fA5EdhYo= X-Received: by 2002:a05:6820:16a1:b0:654:f130:24af with SMTP id 006d021491bc7-65677e6b423mr692649eaf.1.1761702406111; Tue, 28 Oct 2025 18:46:46 -0700 (PDT) MIME-Version: 1.0 References: <19094-6ed410eb5b256abd@postgresql.org> <1970841.1761402665@sss.pgh.pa.us> <2441795.1761593103@sss.pgh.pa.us> <2447089.1761595976@sss.pgh.pa.us> <2485781.1761617055@sss.pgh.pa.us> <2626296.1761692854@sss.pgh.pa.us> In-Reply-To: <2626296.1761692854@sss.pgh.pa.us> From: Richard Guo Date: Wed, 29 Oct 2025 10:46:35 +0900 X-Gm-Features: AWmQ_bmacL2gw9R5PkMt5KpUjOsT_k-5QmSxQOErQqC0oCGKHMwSsq519W8FUhU Message-ID: Subject: Re: [EXTERNAL]Re: BUG #19094: select statement on postgres 17 vs postgres 18 is returning different/duplicate results To: Tom Lane Cc: Lori Corbani , Thomas Munro , "pgsql-bugs@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 Wed, Oct 29, 2025 at 8:07=E2=80=AFAM Tom Lane wrote: > Code changes look good, and I confirm that I can't reproduce the > failure anymore with this patch. Thanks for the review and confirmation. > I'm not convinced that the new regression test case is worth the > cycles, at least not in this form. The main thing that's annoying me > about it is creating/populating/analyzing its own large one-use table; > that approach soon leads to regression suites that take forever. Fair point. > You could answer that objection by making use of some existing > regression table, for instance this seems to work as well: > > explain select * from tenk1 t1 > where exists(select 1 from tenk1 t2 where tenthous =3D t1.tenthous); > > However, I feel like it may still not be a great test, because it only > shows that the planner *didn't* pick PRSJ, not that it *couldn't*. > The cost differential between PRSJ with these settings and the Hash > Semi Join plan that you get after applying the patch is not very > great; so it's easy to imagine future changes that'd mean we'd not > prefer PRSJ here anyway. But I'm not sure what we could do about > that, so operationally this may be as good a test as we can get > anyway. To make the right-semi join look more appealing, I wonder if we could apply a filter to t1 to make its output smaller than t2, so that the planner is more likely to choose t1 as the inner side for building the hash table. explain select * from tenk1 t1 where exists(select 1 from tenk1 t2 where fivethous =3D t1.fivethous) and t1.fivethous < 5; (I'm using fivethous instead of tenthous to avoid interference from index scan.) However, this doesn't seem to move the needle any further. The costs of PRSJ (unpatched) and PSJ (patched) are 755.67 and 777.54. The cost difference is still not very great. > Another thought is that rather than having to remember to reset all > those planner options, you could make the test a bit shorter and > more maintainable by writing something like > > begin; > set local parallel_setup_cost=3D0; > set local ... > > explain ... > > rollback; Brilliant! Thanks for the suggestion. - Richard