Report
With JIT inlining, building a named-composite ROW() that contains an external TOAST value fails with "tupdesc reference ... is not owned by resource owner Portal"
- Severity
- 40
- Blamed commit
- b8bff07daa85c837a2747b4d35cd5a27e73fb7b2 REL_17_STABLE, REL_18_STABLE, REL_19_STABLE, master
Summary
With JIT inlining enabled, building a named-composite ROW(...) value that contains an external (out-of-line) TOAST value fails with
ERROR: tupdesc reference ... is not owned by resource owner Portal
The reporter saw it on 17.12 and 18.7 with LLVM 19. It goes away when JIT inlining or optimization is disabled.
Reproduction
Create a partitioned table p with 100k rows, plus one incompressible jsonb value over 2 kB stored out of line. In a new session:
SET jit = on;
SET jit_above_cost = 0;
SET jit_inline_above_cost = 0;
SET jit_optimize_above_cost = 0;
SELECT sum(hashtextextended(ROW(p.id, p.a, p.b, p.c)::p::text, 0)) FROM p;
The full script is in the pgsql-bugs post linked below.
Analysis
Inlining copies tupdesc.c's file-local constant tupdesc_resowner_desc into the JIT module. The inlined HeapTupleHeaderGetDatum() -> lookup_rowtype_tupdesc() path then registers or forgets the tuple descriptor using the copy's address. ResourceOwnerForget() matches entries by the kind pointer, so a register and forget that use different copies of the descriptor do not match, and the forget fails.
Blame is not confirmed. The candidate is b8bff07daa85c837a2747b4d35cd5a27e73fb7b2 ("Make ResourceOwners more easily extensible"), which introduced matching by kind pointer; it interacts with llvmjit_inline.cpp cloning file-local constant globals. That commit is in REL_17_STABLE and later, which matches the versions the reporter saw.
Notes
Reported on pgsql-bugs: https://postgr.es/m/CAKrZDnX+fU5Wo4Umd7zyoN+zUahFXxV568C7FKTWggthLZBK1g@mail.gmail.com. Not independently reproduced by the bots yet.