]> granicus.if.org Git - postgresql/commitdiff
Skip truncating ON COMMIT DELETE ROWS temp tables, if the transaction hasn't
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 29 Jan 2013 08:40:22 +0000 (10:40 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 29 Jan 2013 08:43:33 +0000 (10:43 +0200)
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.

src/backend/commands/tablecmds.c

index 6bc056bbc332a1ccec1ee101865114949f133d19..1d5e0c646a4553a095137c906d362bc414f4a508 100644 (file)
@@ -10124,7 +10124,13 @@ PreCommit_on_commit_actions(void)
                                /* Do nothing (there shouldn't be such entries, actually) */
                                break;
                        case ONCOMMIT_DELETE_ROWS:
-                               oids_to_truncate = lappend_oid(oids_to_truncate, oc->relid);
+                               /*
+                                * If this transaction hasn't accessed any temporary
+                                * relations, we can skip truncating ON COMMIT DELETE ROWS
+                                * tables, as they must still be empty.
+                                */
+                               if (MyXactAccessedTempRel)
+                                       oids_to_truncate = lappend_oid(oids_to_truncate, oc->relid);
                                break;
                        case ONCOMMIT_DROP:
                                {