pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: 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 17:19:22 -0400
Message-ID: <2510592.1758403162@sss.pgh.pa.us> (raw)
In-Reply-To: <19059-c751eed385314309@postgresql.org>
References: <19059-c751eed385314309@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> However, the optimizer fails to reorder the expressions in the WHERE clause
> for the second query. You can observe this from the second row in the plan:
> "Filter: (EXISTS(SubPlan 1) OR (c0 > 0))"
> A more optimal strategy would be for PG to use its cost model to reorder
> expressions, prioritizing the evaluation of less expensive operations first.

We do do that at the top AND level (cf. order_qual_clauses())
but we have not bothered for OR clauses.

The whole exercise is pretty questionable really, considering how weak
our cost model for expressions is.  We could easily end up pessimizing
a clause that the user had put into carefully-selected order.
While we've not gotten a huge amount of push-back about the top-level
re-ordering, there's been some complaints.  So I'm not eager to
propagate the idea further down.

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <2510592.1758403162@sss.pgh.pa.us>
Permalink:  ../2510592.1758403162@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2510592.1758403162@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, 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: <2510592.1758403162@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