public inbox for [email protected]
help / color / mirror / Atom feedFrom: Kyotaro Horiguchi <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Re: TRAP: FailedAssertion("HaveRegisteredOrActiveSnapshot()", File: "toast_internals.c", Line: 670, PID: 19403)
Date: Tue, 29 Mar 2022 17:06:21 +0900 (JST)
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
At Mon, 28 Mar 2022 18:36:46 +0900 (JST), Kyotaro Horiguchi <[email protected]> wrote in
> Inserting EnsurePortalSnapshotExists() to RunFromStore fixes this but
> I'm not sure where is the right place to do this..
Then, I found that portal->holdSnapshot is that. I came up with the
attached. It does the follows:
1. Teach PlannedStmtRequiresSnapshot() to return true for FetchStmt.
2. Use holdSnapshot in RunFromStore if any.
The rerpducer is reduced to as small as the following.
CREATE TABLE t (a text);
INSERT INTO t VALUES('some random text');
BEGIN;
DECLARE c CURSOR FOR SELECT * FROM t;
FETCH ALL IN c;
But I haven't come up with a reasonable way to generate the 'some
random text' yet.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
[text/x-patch] use_holdsnapshot_to_read_cursor.patch (1.4K, ../[email protected]/2-use_holdsnapshot_to_read_cursor.patch)
download | inline diff:
diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
index 5aa5a350f3..8354029f2a 100644
--- a/src/backend/tcop/pquery.c
+++ b/src/backend/tcop/pquery.c
@@ -1068,6 +1068,18 @@ RunFromStore(Portal portal, ScanDirection direction, uint64 count,
dest->rStartup(dest, CMD_SELECT, portal->tupDesc);
+ /*
+ * If holdSnapshot is set, that means we should use the snapshot to read
+ * this store.
+ */
+ if (portal->holdSnapshot)
+ {
+ Assert(portal->portalSnapshot == 0);
+ PushActiveSnapshotWithLevel(portal->holdSnapshot,
+ portal->createLevel);
+ portal->portalSnapshot = GetActiveSnapshot();
+ }
+
if (ScanDirectionIsNoMovement(direction))
{
/* do nothing except start/stop the destination */
@@ -1114,6 +1126,13 @@ RunFromStore(Portal portal, ScanDirection direction, uint64 count,
dest->rShutdown(dest);
+ if (portal->holdSnapshot)
+ {
+ Assert(portal->portalSnapshot == GetActiveSnapshot());
+ PopActiveSnapshot();
+ portal->portalSnapshot = NULL;
+ }
+
ExecDropSingleTupleTableSlot(slot);
return current_tuple_count;
@@ -1756,7 +1775,6 @@ PlannedStmtRequiresSnapshot(PlannedStmt *pstmt)
IsA(utilityStmt, VariableShowStmt) ||
IsA(utilityStmt, ConstraintsSetStmt) ||
/* efficiency hacks from here down */
- IsA(utilityStmt, FetchStmt) ||
IsA(utilityStmt, ListenStmt) ||
IsA(utilityStmt, NotifyStmt) ||
IsA(utilityStmt, UnlistenStmt) ||
view thread (9+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: TRAP: FailedAssertion("HaveRegisteredOrActiveSnapshot()", File: "toast_internals.c", Line: 670, PID: 19403)
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox