Skip to content

Commit c9d7dba

Browse files
committed
Skip truncating ON COMMIT DELETE ROWS temp tables, if the transaction hasn't
touched any temporary tables. We could try harder, and keep track of whether we've inserted to any temp tables, rather than accessed them, and which temp tables have been inserted to. But this is dead simple, and already covers many interesting scenarios.
1 parent fd4ced5 commit c9d7dba

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/commands/tablecmds.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10124,7 +10124,13 @@ PreCommit_on_commit_actions(void)
1012410124
/* Do nothing (there shouldn't be such entries, actually) */
1012510125
break;
1012610126
case ONCOMMIT_DELETE_ROWS:
10127-
oids_to_truncate = lappend_oid(oids_to_truncate, oc->relid);
10127+
/*
10128+
* If this transaction hasn't accessed any temporary
10129+
* relations, we can skip truncating ON COMMIT DELETE ROWS
10130+
* tables, as they must still be empty.
10131+
*/
10132+
if (MyXactAccessedTempRel)
10133+
oids_to_truncate = lappend_oid(oids_to_truncate, oc->relid);
1012810134
break;
1012910135
case ONCOMMIT_DROP:
1013010136
{

0 commit comments

Comments
 (0)