pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Floris Van Nee <florisvannee@Optiver.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: postgres reorders expressions when inlining
Date: Thu, 29 Dec 2022 10:14:32 -0500
Message-ID: <553278.1672326872@sss.pgh.pa.us> (raw)
In-Reply-To: <fe6d0843072a480c82fa48b15eea00b1@opammb0562.comp.optiver.com>
References: <fe6d0843072a480c82fa48b15eea00b1@opammb0562.comp.optiver.com>

Floris Van Nee <florisvannee@Optiver.com> writes:
> I recently ran into some behavior with inlining that seemed strange to me. 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 subqueries 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_series(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





view thread (3+ messages)

Message-ID: <553278.1672326872@sss.pgh.pa.us>
Permalink:  ../553278.1672326872@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/553278.1672326872@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, florisvannee@Optiver.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: postgres reorders expressions when inlining
  In-Reply-To: <553278.1672326872@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox