pgsql: Handle XmlExpr more honestly in clauses.c.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Handle XmlExpr more honestly in clauses.c.
Date: 2026-09-01 16:17:20
Message-ID: E1x1RAl-000000033jT-0Dao@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Handle XmlExpr more honestly in clauses.c.

eval_const_expressions() didn't constant-fold XmlExpr. In some cases
it cannot, but often it can. Failure to do so can cause visible
regressions in SQL-language function behavior compared to pre-v18,
though only in a rather narrow set of contexts: basically, if you're
trying to use a CASE to prevent evaluation of a failure-prone XML
function.

While we're at it, make contain_mutable_functions() handle XmlExpr
more precisely, and adjust some comments that justify not treating
XmlExpr explicitly.

This seems worth sneaking into v19, but I'm hesitant to put it into
v18. It's not really a bug fix, because we disclaim the safety of
using CASE this way, and it carries some risk of de-optimizing queries
that worked satisfactorily before.

Bug: #19487
Reported-by: Ilya Portnov <i(dot)portnov(at)compassplus(dot)com>
Author: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
Co-authored-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/19487-367258bc497b923a@postgresql.org
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/14dbc85985357c0d6485dab8dd64fac02c91d207

Modified Files
--------------
src/backend/optimizer/util/clauses.c | 83 +++++++++++++++++++++++++++++++-----
src/test/regress/expected/xml.out | 11 +++++
src/test/regress/sql/xml.sql | 7 +++
3 files changed, 90 insertions(+), 11 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2026-09-01 16:26:36 pgsql: pg_dump: Remove some dead code.
Previous Message Fujii Masao 2026-09-01 13:53:35 pgsql: doc: clarify aliasing of VALUES in FROM clauses