Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Ignore partitioned tables when processing ON COMMIT DELETE ROWS
authorMichael Paquier <michael@paquier.xyz>
Mon, 5 Nov 2018 00:15:25 +0000 (09:15 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 5 Nov 2018 00:15:25 +0000 (09:15 +0900)
Those tables have no physical storage, making this option unusable with
partition trees as at commit time an actual truncation was attempted.
There are still issues with the way ON COMMIT actions are done when
mixing several action types, however this impacts as well inheritance
trees, so this issue will be dealt with later.

Reported-by: Rajkumar Raghuwanshi
Author: Amit Langote
Reviewed-by: Michael Paquier, Tom Lane
Discussion: https://postgr.es/m/CAKcux6mhgcjSiB_egqEAEFgX462QZtncU8QCAJ2HZwM-wWGVew@mail.gmail.com

src/backend/catalog/heap.c
src/test/regress/expected/temp.out
src/test/regress/sql/temp.sql

index bb21e58a454b16de0a0a30ebc2134cb333be5439..c905e7337e6b2dd742d193e36ecfaba48b636a2e 100644 (file)
@@ -2876,6 +2876,13 @@ heap_truncate_one_rel(Relation rel)
 {
    Oid         toastrelid;
 
+   /*
+    * Truncate the relation.  Partitioned tables have no storage, so there is
+    * nothing to do for them here.
+    */
+   if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
+       return;
+
    /* Truncate the actual file (and discard buffers) */
    RelationTruncate(rel, 0);
 
index addf1ec444397cbeae37d2ac1838503646d488d4..a769abe9bba51c6305f5601bea1efc1e69110d6f 100644 (file)
@@ -199,3 +199,20 @@ select pg_temp.whoami();
 (1 row)
 
 drop table public.whereami;
+-- For partitioned temp tables, ON COMMIT actions ignore storage-less
+-- partitioned tables.
+begin;
+create temp table temp_parted_oncommit (a int)
+  partition by list (a) on commit delete rows;
+create temp table temp_parted_oncommit_1
+  partition of temp_parted_oncommit
+  for values in (1) on commit delete rows;
+insert into temp_parted_oncommit values (1);
+commit;
+-- partitions are emptied by the previous commit
+select * from temp_parted_oncommit;
+ a 
+---
+(0 rows)
+
+drop table temp_parted_oncommit;
index 5183c727f5e70139d71ab345ce548f8d175baf06..1074c7cfac85f23c7eb24ab58c86544d17b67721 100644 (file)
@@ -151,3 +151,17 @@ select whoami();
 select pg_temp.whoami();
 
 drop table public.whereami;
+
+-- For partitioned temp tables, ON COMMIT actions ignore storage-less
+-- partitioned tables.
+begin;
+create temp table temp_parted_oncommit (a int)
+  partition by list (a) on commit delete rows;
+create temp table temp_parted_oncommit_1
+  partition of temp_parted_oncommit
+  for values in (1) on commit delete rows;
+insert into temp_parted_oncommit values (1);
+commit;
+-- partitions are emptied by the previous commit
+select * from temp_parted_oncommit;
+drop table temp_parted_oncommit;