Hi Kirill
On 25/11/2026 06:05, Kirill Reshke wrote:
> I think, if patched hunks are related to frequently-used XML features,
> it's good to fix them. Otherwise it would bloat the codebase, huh?
The overhead here is negligible. At least I was unable to measure
anything significant.
create table t (doc xml);
insert into t values (('<r>' || repeat(repeat('<a>', 250) ||
repeat('</a>', 250), 4000) || '</r>')::xml);
== patched ==
postgres=# select xpath('//a', doc) is null from t;
?column?
----------
f
(1 row)
Time: 13281,557 ms (00:13,282)
== master ==
postgres=# \timing on
Timing is on.
postgres=# select xpath('//a', doc) is null from t;
?column?
----------
f
(1 row)
Time: 13260,056 ms (00:13,260)
> Not much in context here, but it looks like places can be frequently hit.
> Also, are there more places to cover? For example, can
> escape_xml/xmlelement take long?
I'd argue that it does not apply to escape_xml. In this case, it's a
linear pass over a single string, and in case the input is too large,
the 1GB limit kicks in:
postgres=# \timing on
Timing is on.
postgres=# select length(xmlelement(name a, repeat('&',
1000000000))::text);
ERROR: string buffer exceeds maximum allowed length (1073741823 bytes)
DETAIL: Cannot enlarge string buffer containing 1073741820 bytes by 5
more bytes.
Time: 5462,958 ms (00:05,463)
Arrays passed to xmlelement are a different story, since
map_sql_value_to_xml_value() loops over every element. While testing it,
I managed to get the backend killed (OOM) with a large array.. but I
suggest we look into it in a different thread, since it needs more than
a CHECK_FOR_INTERRUPTS().
WDYT?
Thanks for the review!
Best, Jim