summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2018-11-05 00:14:33 +0000
committerMichael Paquier2018-11-05 00:14:33 +0000
commit4bc772e2afa55f26734ff3fbdf27601db030b7e5 (patch)
treea7a1a993bb652b131f872d38f2e2be1f826f5ec4
parentfa534b411c86d2e7441852282ea9f1a491a090a6 (diff)
Ignore partitioned tables when processing ON COMMIT DELETE ROWS
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
-rw-r--r--src/backend/catalog/heap.c7
-rw-r--r--src/test/regress/expected/temp.out17
-rw-r--r--src/test/regress/sql/temp.sql14
3 files changed, 38 insertions, 0 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 5b8fd9bdb92..7203c86c4d4 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -3181,6 +3181,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);
diff --git a/src/test/regress/expected/temp.out b/src/test/regress/expected/temp.out
index addf1ec4443..a769abe9bba 100644
--- a/src/test/regress/expected/temp.out
+++ b/src/test/regress/expected/temp.out
@@ -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;
diff --git a/src/test/regress/sql/temp.sql b/src/test/regress/sql/temp.sql
index 5183c727f5e..1074c7cfac8 100644
--- a/src/test/regress/sql/temp.sql
+++ b/src/test/regress/sql/temp.sql
@@ -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;