Re: BUG #18984: Empty prepared statement from psql \parse triggers assert in PortalRunMulti
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ãlvaro Herrera <alvherre@kurilemu.de>
Cc: Michael Paquier <michael@paquier.xyz>, exclusion@gmail.com,
pgsql-bugs@lists.postgresql.org
Date: 2025-07-15T16:05:34Z
Lists: pgsql-bugs
I wrote: > BTW, with Asserts disabled it works fine: > ... > (I did not look into how come that works... the correct > command tag must be getting filled in later, but where?) I traced through this, and the answer is that there are two levels of Portal, an outer one that holds the EXECUTE command (and has portal->qc.commandTag = CMDTAG_EXECUTE) and an inner one that runs the prepared statement's list (and has portal->qc.commandTag = CMDTAG_UNKNOWN, because that list is empty). But ExecuteQuery passes down the outer "qc" parameter to the inner recursion level. So without the Assert, the inner invocation of PortalRunMulti leaves qc->commandTag = CMDTAG_UNKNOWN, and then the very same stanza of PortalRunMulti replaces that with CMDTAG_EXECUTE in the outer recursion level. So it's just wrong for PortalRunMulti to assert that the computation of qc->commandTag is necessarily complete. If we wanted to replace that, it might be appropriate to have an assertion at the top level (exec_simple_query) but I'm not very sure what that would buy us. It'll be apparent enough what happened from the reported "???" command tag, and the top-level assertion would contribute exactly nada to identifying where we'd missed setting it. In short, Alvaro's patch definitely seems like the right one, modulo quibbles about rewriting the comment. Perhaps we should add something about the possibility that an outer Portal level can supply a default command tag if we lack one now? regards, tom lane
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Minor cosmetic tweaks
- e76221bd95f0 19 (unreleased) landed
-
Simplify coding in ProcessQuery
- a27c40bfe8ab 19 (unreleased) landed
-
Remove assertion from PortalRunMulti
- e0d3f3cfb6f2 18.0 landed
- c2720ac6010a 15.14 landed
- b9a89682846f 14.19 landed
- b8926a5b4bb8 19 (unreleased) landed
- 4871c1e9cb6e 16.10 landed
- 43cd85962755 13.22 landed
- 0c466f5e0b34 17.6 landed
-
Represent command completion tags as structs
- 2f9661311b83 13.0 cited