]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix order of operations in ExecEvalFieldStoreDeForm().
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 29 Jun 2023 14:19:10 +0000 (10:19 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 29 Jun 2023 14:19:10 +0000 (10:19 -0400)
commit0789b82a97924cec14f651f678eebc56c09da17f
treed30ba38acaba8dbfa8b36c92db134fc57a863ca7
parent6bc7873da1c3e9f1d870fa2d671eb450ea6c9753
Fix order of operations in ExecEvalFieldStoreDeForm().

If the given composite datum is toasted out-of-line,
DatumGetHeapTupleHeader will perform database accesses to detoast it.
That can invalidate the result of get_cached_rowtype, as documented
(perhaps not plainly enough) in that function's API spec; which leads
to strange errors or crashes when we try to use the TupleDesc to read
the tuple.  In short then, trying to update a field of a composite
column could fail intermittently if the overall column value is wide
enough to require toasting.

We can fix the bug at no cost by just changing the order of
operations, since we don't need the TupleDesc until after detoasting.
(Other callers of get_cached_rowtype appear to get this right already,
so there's only one bug.)

Note that the added regression test case reveals this bug reliably
only with debug_discard_caches/CLOBBER_CACHE_ALWAYS.

Per bug #17994 from Alexander Lakhin.  Sadly, this patch does not fix
the missing-values issue revealed in the bug discussion; we'll need
some more work to cover that.

Discussion: https://postgr.es/m/17994-5c7100b51b4790e9@postgresql.org
src/backend/executor/execExprInterp.c
src/test/regress/expected/rowtypes.out
src/test/regress/sql/rowtypes.sql