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 1siH2J-001Uf4-ST for pgsql-hackers@arkaria.postgresql.org; Sun, 25 Aug 2024 17:28:19 +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 1siH2G-00HNXm-Ty for pgsql-hackers@arkaria.postgresql.org; Sun, 25 Aug 2024 17:28:17 +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 1siH2G-00HNV9-JU for pgsql-hackers@lists.postgresql.org; Sun, 25 Aug 2024 17:28:17 +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.94.2) (envelope-from ) id 1siH2F-001OMb-07 for pgsql-hackers@postgresql.org; Sun, 25 Aug 2024 17:28:15 +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 47PHSD4Q2592658; Sun, 25 Aug 2024 13:28:13 -0400 From: Tom Lane To: Tobias Hoffmann cc: "David G. Johnston" , "pgsql-hackers@postgresql.org" Subject: Re: Non-trivial condition is only propagated to one side of JOIN In-reply-to: <13ebf00f-2991-43c5-5d11-a8216cb3217a@thax.hardliners.org> References: <8520950a-272c-9cc6-de29-2993b4227bf3@thax.hardliners.org> <13ebf00f-2991-43c5-5d11-a8216cb3217a@thax.hardliners.org> Comments: In-reply-to Tobias Hoffmann message dated "Sun, 25 Aug 2024 19:04:32 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2592656.1724606893.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Sun, 25 Aug 2024 13:28:13 -0400 Message-ID: <2592657.1724606893@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tobias Hoffmann writes: > A more complete example might look more like this: > CREATE VIEW "subview1" AS >   SELECT tbl1.site_id, ... JOIN ... ON tbl1.site_id = tbl2.site_id > WHERE ...; > CREATE VIEW "view1" AS >   SELECT site_id, ... FROM subview1  -- maybe even: WHERE site_id IS > NOT NULL >   UNION ALL >   SELECT null, ...; > SELECT * FROM view1 WHERE (site_id = 1 OR site_id IS NULL); For this particular case, you could probably get somewhere by writing SELECT * FROM view1 WHERE site_id = 1 UNION ALL SELECT * FROM view1 WHERE site_id IS NULL; since the sets of rows satisfying those two WHERE conditions must be disjoint. (I recall working on a patch that essentially tried to do that transformation automatically, but it eventually failed because things get too messy if the row sets might not be disjoint.) regards, tom lane