agora inbox for [email protected]  
help / color / mirror / Atom feed
From: amit <[email protected]>
Subject: [PATCH v5 1/2] Ignore partitioned tables during ON COMMIT DELETE ROWS
Date: Fri, 2 Nov 2018 15:28:57 +0900

---
 src/backend/catalog/heap.c         | 11 ++++++++---
 src/test/regress/expected/temp.out | 14 ++++++++++++++
 src/test/regress/sql/temp.sql      | 11 +++++++++++
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 064cf9dbf6..2c2d287f0e 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -3121,7 +3121,8 @@ RelationTruncateIndexes(Relation heapRelation)
 /*
  *	 heap_truncate
  *
- *	 This routine deletes all data within all the specified relations.
+ *	 This routine deletes all data within all the specified relations,
+ *	 ignoring any that don't have any storage to begin with
  *
  * This is not transaction-safe!  There is another, transaction-safe
  * implementation in commands/tablecmds.c.  We now use this only for
@@ -3151,8 +3152,12 @@ heap_truncate(List *relids)
 	{
 		Relation	rel = lfirst(cell);
 
-		/* Truncate the relation */
-		heap_truncate_one_rel(rel);
+		/*
+		 * Truncate the relation.  Regular and partitioned tables can be
+		 * temporary relations, but only regular tables have storage.
+		 */
+		if (rel->rd_rel->relkind == RELKIND_RELATION)
+			heap_truncate_one_rel(rel);
 
 		/* Close the relation, but keep exclusive lock on it until commit */
 		heap_close(rel, NoLock);
diff --git a/src/test/regress/expected/temp.out b/src/test/regress/expected/temp.out
index addf1ec444..ed2c591fc6 100644
--- a/src/test/regress/expected/temp.out
+++ b/src/test/regress/expected/temp.out
@@ -199,3 +199,17 @@ select pg_temp.whoami();
 (1 row)
 
 drop table public.whereami;
+-- for partitioned temp tables, ON COMMIT action should ignore storage-less
+-- partitioned parent table
+begin;
+create temp table temp_parted_oncommit_test (a int) partition by list (a) on commit delete rows;
+create temp table temp_parted_oncommit_test1 partition of temp_parted_oncommit_test for values in (1) on commit delete rows;
+insert into temp_parted_oncommit_test values (1);
+commit;
+-- temp_parted_oncommit_test1 must've been emptied during the commit
+select * from temp_parted_oncommit_test;
+ a 
+---
+(0 rows)
+
+drop table temp_parted_oncommit_test;
diff --git a/src/test/regress/sql/temp.sql b/src/test/regress/sql/temp.sql
index 5183c727f5..0274bdb13f 100644
--- a/src/test/regress/sql/temp.sql
+++ b/src/test/regress/sql/temp.sql
@@ -151,3 +151,14 @@ select whoami();
 select pg_temp.whoami();
 
 drop table public.whereami;
+
+-- for partitioned temp tables, ON COMMIT action should ignore storage-less
+-- partitioned parent table
+begin;
+create temp table temp_parted_oncommit_test (a int) partition by list (a) on commit delete rows;
+create temp table temp_parted_oncommit_test1 partition of temp_parted_oncommit_test for values in (1) on commit delete rows;
+insert into temp_parted_oncommit_test values (1);
+commit;
+-- temp_parted_oncommit_test1 must've been emptied during the commit
+select * from temp_parted_oncommit_test;
+drop table temp_parted_oncommit_test;
-- 
2.11.0


--------------1750D6758CB376F963B12A08--





view thread (2+ 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]
  Subject: Re: [PATCH v5 1/2] Ignore partitioned tables during ON COMMIT DELETE ROWS
  In-Reply-To: <no-message-id-237714@localhost>

* 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