pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christophe Pettus <xof@thebuild.com>
Cc: jinhui.lai@qq.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19059: PostgreSQL fails to evaluate the cheaper expression first, leading to 45X performance degradation
Date: Sat, 20 Sep 2025 19:19:03 -0400
Message-ID: <2524033.1758410343@sss.pgh.pa.us> (raw)
In-Reply-To: <84B5D601-C007-4B07-9ECB-CDD06E47B949@thebuild.com>
References: <19059-c751eed385314309@postgresql.org>
	<2510592.1758403162@sss.pgh.pa.us>
	<84B5D601-C007-4B07-9ECB-CDD06E47B949@thebuild.com>

Christophe Pettus <xof@thebuild.com> writes:
> And tangentially, doesn't the SQL standard make it implementation-defined if OR short-circuits or not?

It looks like it says it's implementation-dependent, meaning
that not only is it not defined by the standard, but we're not
required to document it either:

    Subclause 6.3.3.3, “Rule evaluation order”:

	a) It is implementation-dependent whether expressions are
	actually evaluated from left to right when the precedence is
	not otherwise determined by the Formats or by parentheses.

	b) If evaluation of the inessential parts of an expression or
	search condition would cause an exception condition to be
	raised, then it is implementation-dependent whether or not
	that condition is raised.

	c) The declared type of a site that contains an intermediate
	result is implementation-dependent.

This is a good thing, because while we do mention boolean expression
re-ordering and short-circuiting, there's an awful lot of such details
that we've left undocumented.

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <2524033.1758410343@sss.pgh.pa.us>
Permalink:  ../2524033.1758410343@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2524033.1758410343@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, xof@thebuild.com, jinhui.lai@qq.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #19059: PostgreSQL fails to evaluate the cheaper expression first, leading to 45X performance degradation
  In-Reply-To: <2524033.1758410343@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