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.96) (envelope-from ) id 1wEdBb-004E9W-13 for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Apr 2026 01:12:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEdBZ-00HDbn-1c for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Apr 2026 01:12:25 +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.96) (envelope-from ) id 1wEdBZ-00HDbe-0k for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 01:12:25 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wEdBW-00000001qZr-2qC2 for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 01:12:24 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-6841e6a5e51so1387750eaf.3 for ; Sun, 19 Apr 2026 18:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776647542; cv=none; d=google.com; s=arc-20240605; b=VS7jEWBOjxyzts56lQ19DFBnYcfhMOEcWyobIFaepXhfrdkL64qZy0mZshEd1X+is+ NOU8qg5lTjmoaoJ6mu5KUHTjF7+ARXJeaM4IFoy+6LMc+9AVTUwCAjCyHYD34h8SWfFV bo7Ue54StaOSvr8ToPH7+HSiP8tGfjnhg/dNE7osWw30MZSGXW9F2thBOHK3CRDKJd06 UdCvcmV9Oi0SGyqOLY3hh+sNxyRHwPxPpLprKb8LQnP+6odh75qOQ0M06v3PFTspxuSt Xa9431MVlKLiLCMHHV6sWzjhs8n4AwxSGuDqbQ/9uMaF91UH1aHj1hW51HjJ1kQVafxt Ar4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=kgskXO/aIk/qtPFQoGMRWvO7zg+LUrhqBbWfTejMjvg=; fh=YuPIVRfk1E2XNWZorYAjOw+FV7zC8W+xCT1BsoglDP4=; b=Issb9QDcgBLDx7sUJlf5HDd/CsPhC06TVzkaEanFtDsNTWXNwf9Te102KJf2STHAcD yaKKB6DBHVTe9Ca6/1GXZ6irLLHlSwdmeoUXli3agFtFrVAlQ4lGv4IzzSls+Kh04WuW niwh2g1BY/TwXVhdMT0OOnnBTqHUGMdidR3fQTD2jSnIZ2VPbi4BJVcAtm68vsAHXhUb kYunjo9LWHhsruefnRiecDGa8YTTNZooGQ5wUm7wjiPY42TOBw8mlyQPzAmW8wX5wWtB IBERPWEiER2lujBWemeRW2xjLJ/XanYq7jcFxycgYZe2BIdcxZnJ+UYElzLkopI9Kwgy PScg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776647542; x=1777252342; 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=kgskXO/aIk/qtPFQoGMRWvO7zg+LUrhqBbWfTejMjvg=; b=WdS+WHpyY9W2/9le+ez0GX/sBVIrktZqG4PNp77k0tIGhaPLVP4RWNybHP4YaMrn/J 5eqvRUCitux4w9x9KHvqLkoyFm2rnSfPNcu1NerIJv95V8izg724U37cece/bUPASIms 9Lv77aV+0LbuiBU45k3Lv38WdBJYt0djJysYJJKl389PY/exADTgk12dkUaHs/PF5A3q x23HsgPz1srDm+0MwiCobypeuFKEiGnLVjV6GKriOSL0IZpYCU4jkcZdqYpfh2tGqn+v RGwHpRqUhLM0EwcfLUyY1L/QtoA5Z/8JzVPK280y9+ILuiGdnpCyYC1jj/KBvDSkcVG1 H8vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776647542; x=1777252342; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kgskXO/aIk/qtPFQoGMRWvO7zg+LUrhqBbWfTejMjvg=; b=V79EZHsAcH2BgjOodQ+bgTQ1UbUcYgCw6SJqboMPkwYhNogRI7PtuYxhu4yepQAdPi sxjhdJe3t8TnqJ9pEoiuHQGEDFibaitf0U4Zj/iRvRUo2jm3g/EuYF1U/OHCLwCJfKXM be8fOMBqFgCBF3/MqMY43NDmcDJsZ7jssQ5wig1Ab8yPNn/JeJ6SIxEmrEaCXlOEsb7V Zk5rlENd0dpQw18qiZqu8q/RT4u5M/CjPp9hTvap3IEmScYWc3YRPKTYyc7S19bRbWJZ KMe0LDoKeW5vj4kYzRuGuN5TDNvs+lhBkYevWyTZGDtUF1tt40qdZwyPS0X2DHWTcOn4 rPmA== X-Forwarded-Encrypted: i=1; AFNElJ85pY+xq9IswsRtmEk/hwv/JlbZN7nbzvFQtXSj6oRcWgcyTNsd3ySZ/+2oxfUbWyyS4ypbRor9Fxlt@lists.postgresql.org X-Gm-Message-State: AOJu0YyPHMsn3sadCdFKlxWJVfj8TNvFYtrMrkQl5wlRbHtSy+zXwqwh zfzDa4johf2BYt7gYzSu4jlfgDs33bNAOOisFXOljAk8spYthcvVBnE2kCkUT/4XmlYupX24CSy /kn6NPplxybgcQuFvCINInQFvKDHCSmA= X-Gm-Gg: AeBDiesOFiBz+miDHQD7RUl2UARXerxs9oNKj9qvK66JwRzayUhn+T/GdYLMXmIJ1id yXyDMcKsv8l4y2vID16NKxiTTBrChKCPq2ZPxqM2dfPCwpnjDf2X6kj3K3WPikdus6oVxr/tVE2 eUQAEDGsNv+KLVSoiezjGamCcWJpWAplJncOlUyBa2eWWY7dHIXLwd64E8WswvB/jC9dZO8RTE5 vkssjUuYr7ZK1RNxssSXtH5c863zPgEJnBGN78UxQVHM2cJsQgYs8czLWykT7UW7J+qPejS3fSx XAUZcscj4pVvR9vLHKg= X-Received: by 2002:a05:6820:4284:b0:680:6d72:9389 with SMTP id 006d021491bc7-69462e62342mr4392007eaf.22.1776647542378; Sun, 19 Apr 2026 18:12:22 -0700 (PDT) MIME-Version: 1.0 References: <19460-5625143cef66012f@postgresql.org> <53936.1776633020@sss.pgh.pa.us> In-Reply-To: <53936.1776633020@sss.pgh.pa.us> From: Richard Guo Date: Mon, 20 Apr 2026 10:12:11 +0900 X-Gm-Features: AQROBzB8o3dXZgO7SVcB2Smgb_zQi2z3uVeVFHn3B4RVgSG_ptADF8CderUGU1g Message-ID: Subject: Re: BUG #19460: FULL JOIN rewriting issue on empty queries To: Tom Lane Cc: francois.jehl@pigment.com, pgsql-bugs@lists.postgresql.org, Robert Haas 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 Mon, Apr 20, 2026 at 6:10=E2=80=AFAM Tom Lane wrote: > This turns out to be because somebody long ago thought that outer join > removal could be lazy about how much of the planner's data structures > it needs to update. Specifically, when the lower LEFT OUTER JOIN > gets removed, we failed to remove the associated relids from the > left_relids and right_relids of the upper "ON rhs.id =3D lhs.id" clause, > and that blocks recognition of the applicability of a hash or merge > join, because clause_sides_match_join() fails. I came to the same conclusion. > The fix seems pretty trivial, as attached. (While I'm only certain > that we have to fix left_relids and right_relids, this discovery > makes it seem like it'd be pretty foolish not to fix all the relid > sets of a RestrictInfo.) I didn't make a regression test case yet, > but we need one since no existing test results change (!?). This fix LGTM. I think it'd be better to have a regression test case. How about this one: create table t (id int unique); explain (costs off) select t1.* from t t1 full join (select 1 as x from t t2 left join t t3 on t2.id =3D t3.id ) sub on t1.id =3D sub.x; ERROR: FULL JOIN is only supported with merge-joinable or hash-joinable join conditions > I'm feeling a tad nervous about pushing this into released branches. > It seems likely that it might enable quite a few join plans that were > previously not considered, and people tend not to like plan changes in > stable branches. However, (a) it's hard to argue that this isn't a > regression from pre-v16, and (b) since this change affects no existing > test, maybe the blast radius isn't as big as I fear. Fair points on both sides. I'd lean slightly toward back-patching this fix, mostly because of your points (a) and (b). Without a back-patch, users like Fran=C3=A7ois would need to adjust affected queries when upgrading from pre-v16 to v16=E2=80=93v18, which feels a bit unfortuna= te. - Richard