Re: BUG #15990: PROCEDURE throws "SQL Error [XX000]: ERROR: no known snapshots" with PostGIS geometries
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Robert Haas <robertmhaas@gmail.com>, Andres Freund <andres@anarazel.de>,
a.wicht@gmail.com, pgsql-bugs@lists.postgresql.org,
Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Date: 2021-05-12T15:37:46Z
Lists: pgsql-bugs
Attachments
- toastbug2.sql (text/plain)
... okay, now I'm roping Alvaro into this thread, because the attached
test case (extracted from [1]) shows that there's still a problem,
and this time it seems like we are dropping the ball on snapshot
management.
The sequence of events here is that after the first COMMIT inside the
loop, we call _SPI_execute_plan to execute the "select txt into t from
test2 where i=r.i;". It does what it's supposed to, i.e.
PushActiveSnapshot(GetTransactionSnapshot());
... run query ...
PopActiveSnapshot();
and then hands back a tuple that includes a toasted datum. plpgsql
knows it must detoast that value before storing it into "t", but
when it calls the toaster, GetOldestSnapshot returns NULL because
we have neither any "active" nor any "registered" snapshots.
ISTM there are two ways we could look at this:
1. COMMIT is dropping the ball by not forcing there to be any
registered transaction-level snapshot afterward. (Maybe it's
not exactly COMMIT that must do this, but in any case the
snapshot situation after COMMIT is clearly different from
normal running, and that seems highly bug-prone.)
2. GetOldestSnapshot ought to be willing to fall back to
CurrentSnapshot if FirstSnapshotSet is true but there are
no active or registered snapshots. But it's not clear how
its promises about returning the "oldest" snapshot would apply.
Thoughts?
regards, tom lane
[1] https://www.postgresql.org/message-id/65424747-42ed-43d5-4cca-6b03481409a4%40perfexpert.ch
Commits
-
Remove plpgsql's special-case code paths for SET/RESET.
- 30168be8f75b 14.0 landed
-
Restore the portal-level snapshot after procedure COMMIT/ROLLBACK.
- 84f5c2908dad 14.0 landed
- ef9480509622 11.13 landed
- d18ee6f92d9a 13.4 landed
- 41c6a5bec25e 12.8 landed
-
Avoid detoasting failure after COMMIT inside a plpgsql FOR loop.
- f21fadafaf0f 14.0 landed
- c64183f234e8 13.4 landed
- 8d341d6cb6c9 12.8 landed
- 0c1b2cb17c25 11.13 landed