| From: | Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Add CHECK_FOR_INTERRUPTS() to XPath result serialisation |
| Date: | 2026-11-24 14:34:25 |
| Message-ID: | 57a5a9ef-3436-4dda-8c7e-ec32813e6a84@uni-muenster.de |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi
While looking into other XML cancellation issues[1,2], I noticed that
xpath() and xmltable columns of type xml serialise every node of the
result node set without checking for interrupts. Each node is serialised
with its whple subtree, so for deeply nested documents this can take a
very long time, and during that time the backend ignores query cancel,
statement_timeout and pg_terminate_backend().
Example (with a relatively small xml doc):
create table t (doc xml);
insert into t values (('<r>' || repeat(repeat('<a>', 250) ||
repeat('</a>', 250), 4000) || '</r>')::xml);
set statement_timeout to '2s';
== master ==
postgres=# \timing on
Timing is on.
postgres=# select xpath('//a', doc) from t;
^CCancel request sent
^CCancel request sent
ERROR: canceling statement due to statement timeout
Time: 18206,080 ms (00:18,206)
== patched ==
postgres=# \timing on
Timing is on.
postgres=# select xpath('//a', doc) from t;
ERROR: canceling statement due to statement timeout
Time: 2092,112 ms (00:02,092)
0001 adds CHECK_FOR_INTERRUPTS() to the serialisation loops in xpath and
xmltable.
xpath_table() in xml2 has a similar issue. Since xml2 is deprecated, I
am not sure it's worth fixing. In case it is, 0002 adds
CHECK_FOR_INTERRUPTS() calls to its loops.
Thoughts?
Best, Jim
1 -
https://www.postgresql.org/message-id/flat/d3270e9f-4f10-4d04-8209-87e513801b05(at)uni-muenster(dot)de
2-
https://www.postgresql.org/message-id/flat/463aec1b-f833-43ca-a892-534f8b2dd65f%40uni-muenster.de
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Allow-cancelling-XPath-result-serialization.patch | text/x-patch | 1.6 KB |
| v1-0001-Allow-cancelling-xpath_table.patch | text/x-patch | 1.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrei Lepikhov | 2026-11-24 14:36:12 | Re: Use local buffer for packed numerics |
| Previous Message | David Geier | 2026-11-24 14:32:45 | Re: Numeric equality and hashing without detoasting |