Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pAuc9-0000EA-HX for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Dec 2022 15:14:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pAuc8-0004BT-EX for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Dec 2022 15:14:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pAuc8-0004BK-66 for pgsql-bugs@lists.postgresql.org; Thu, 29 Dec 2022 15:14:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pAuc5-0003mP-Ts for pgsql-bugs@lists.postgresql.org; Thu, 29 Dec 2022 15:14:35 +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 2BTFEW8W553279; Thu, 29 Dec 2022 10:14:32 -0500 From: Tom Lane To: Floris Van Nee cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: postgres reorders expressions when inlining In-reply-to: References: Comments: In-reply-to Floris Van Nee message dated "Thu, 29 Dec 2022 10:58:35 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <553277.1672326872.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 29 Dec 2022 10:14:32 -0500 Message-ID: <553278.1672326872@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Floris Van Nee writes: > I recently ran into some behavior with inlining that seemed strange to m= e. I managed to break it down into a small reproducible example that I've = added. I originally ran into it in more complicated queries that involved = inlining of SQL functions instead of subqueries, but it reproduces with su= bqueries too so that's the example I've added. Tested on v15. > create table t1 as select a, b from generate_series(0, 5) a, generate_se= ries(0, 10) b; > select * from ( > select a, b, c > from t1 > left join lateral > ( > select 1 / b as c > ) c on true > where b <> 0 > ) as o > where o.c is not null > The SELECT query leads to a division by zero. Plan: This is not a bug. We make no ordering guarantees about WHERE clause execution; if we did, it would cripple the planner's ability to optimize. regards, tom lane