possible bug - xmlconcat is badly marked as immutable

Started by Pavel Stehule19 days ago3 messageshackers
Jump to latest
#1Pavel Stehule
pavel.stehule@gmail.com

Hi

xmlexpr_is_immutable(XmlExpr *xexpr)
{
switch (xexpr->op)
{
case IS_XMLCONCAT:
case IS_XMLPARSE:
case IS_XMLPI:
case IS_XMLROOT:
case IS_XMLSERIALIZE:
case IS_DOCUMENT:
/* These variants manipulate XML text in a self-contained way */
return true;

case IS_XMLELEMENT:
case IS_XMLFOREST:

/*
* These variants invoke I/O conversion functions for a wide
range
* of data types, and have various special rules too, so in some
* cases they are only stable. In principle we could analyze
* their behavior precisely, but keeping such code in sync with
* the actual implementation seems like more maintenance risk
than
* it's worth.
*/
return false;

/* There is intentionally no default: case here */
}
/* We shouldn't get here, but if we do, say "not immutable" */
return false;
}

I don't understand why IS_XMLCONCAT is marked as immutable. In this case,
the result should depend on arguments, and arguments can be stable.

Regards

Pavel

#2Jim Jones
jim.jones@uni-muenster.de
In reply to: Pavel Stehule (#1)
Re: possible bug - xmlconcat is badly marked as immutable

Hi Pavel

On 04/11/2026 09:42, Pavel Stehule wrote:

I don't understand why IS_XMLCONCAT is marked as immutable. In this
case, the result should depend on arguments, and arguments can be stable.

I'd say that it's because it will always return the same result for the
same inputs. If any argument is not immutable, the whole expression is
not immutable either:

psql (20devel)
Type "help" for help.

postgres=# create table t1 (foo xml, bar xml generated always as
(xmlconcat(foo,'<a/>')) stored);
CREATE TABLE

postgres=# create table t2 (foo xml, bar xml generated always as
(xmlconcat(foo,now()::text::xml)) stored);
ERROR: generation expression is not immutable

Best, Jim

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Jim Jones (#2)
Re: possible bug - xmlconcat is badly marked as immutable

Hi

st 4. 11. 2026 v 13:54 odesílatel Jim Jones <jim.jones@uni-muenster.de>
napsal:

Hi Pavel

On 04/11/2026 09:42, Pavel Stehule wrote:

I don't understand why IS_XMLCONCAT is marked as immutable. In this
case, the result should depend on arguments, and arguments can be stable.

I'd say that it's because it will always return the same result for the
same inputs. If any argument is not immutable, the whole expression is
not immutable either:

psql (20devel)
Type "help" for help.

postgres=# create table t1 (foo xml, bar xml generated always as
(xmlconcat(foo,'<a/>')) stored);
CREATE TABLE

postgres=# create table t2 (foo xml, bar xml generated always as
(xmlconcat(foo,now()::text::xml)) stored);
ERROR: generation expression is not immutable

yes, it is correct. I was confused (and the name of the function is little
bit confusing)

When xmlexpr_is_immutable returns false, then it means - yes, the
expression is 100% mutable. When returned true, it means - know nothing,
check arguments - continue in node walking.

After some time it is hard to return to work with reversed logic in walker
iterators.

Regards

Pavel

Show quoted text

Best, Jim