Avoid syscache lookup while building a WAIT FOR tuple descriptor

Use TupleDescInitBuiltinEntry instead of TupleDescInitEntry when building
the result tuple descriptor for the WAIT FOR command. This avoids a syscache
access that could re-establish a catalog snapshot after we've explicitly
released all snapshots before the wait.

Discussion: https://postgr.es/m/CABPTF7U%2BSUnJX_woQYGe%3D%3DR9Oz%2B-V6X0VO2stBLPGfJmH_LEhw%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
This commit is contained in:
Alexander Korotkov 2026-04-06 22:27:36 +03:00
parent 775fe51daa
commit 834038c1f8

View file

@ -335,10 +335,17 @@ WaitStmtResultDesc(WaitStmt *stmt)
{
TupleDesc tupdesc;
/* Need a tuple descriptor representing a single TEXT column */
/*
* Need a tuple descriptor representing a single TEXT column.
*
* We use TupleDescInitBuiltinEntry instead of TupleDescInitEntry to avoid
* syscache access. This is important because WaitStmtResultDesc may be
* called after snapshots have been released, and we must not re-establish
* a catalog snapshot which could cause recovery conflicts on a standby.
*/
tupdesc = CreateTemplateTupleDesc(1);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
TEXTOID, -1, 0);
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 1, "status",
TEXTOID, -1, 0);
TupleDescFinalize(tupdesc);
return tupdesc;
}