Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4bc772e

Browse files
committed
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
1 parent fa534b4 commit 4bc772e

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/backend/catalog/heap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,13 @@ heap_truncate_one_rel(Relation rel)
31813181
{
31823182
Oid toastrelid;
31833183

3184+
/*
3185+
* Truncate the relation. Partitioned tables have no storage, so there is
3186+
* nothing to do for them here.
3187+
*/
3188+
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
3189+
return;
3190+
31843191
/* Truncate the actual file (and discard buffers) */
31853192
RelationTruncate(rel, 0);
31863193

src/test/regress/expected/temp.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,20 @@ select pg_temp.whoami();
199199
(1 row)
200200

201201
drop table public.whereami;
202+
-- For partitioned temp tables, ON COMMIT actions ignore storage-less
203+
-- partitioned tables.
204+
begin;
205+
create temp table temp_parted_oncommit (a int)
206+
partition by list (a) on commit delete rows;
207+
create temp table temp_parted_oncommit_1
208+
partition of temp_parted_oncommit
209+
for values in (1) on commit delete rows;
210+
insert into temp_parted_oncommit values (1);
211+
commit;
212+
-- partitions are emptied by the previous commit
213+
select * from temp_parted_oncommit;
214+
a
215+
---
216+
(0 rows)
217+
218+
drop table temp_parted_oncommit;

src/test/regress/sql/temp.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,17 @@ select whoami();
151151
select pg_temp.whoami();
152152

153153
drop table public.whereami;
154+
155+
-- For partitioned temp tables, ON COMMIT actions ignore storage-less
156+
-- partitioned tables.
157+
begin;
158+
create temp table temp_parted_oncommit (a int)
159+
partition by list (a) on commit delete rows;
160+
create temp table temp_parted_oncommit_1
161+
partition of temp_parted_oncommit
162+
for values in (1) on commit delete rows;
163+
insert into temp_parted_oncommit values (1);
164+
commit;
165+
-- partitions are emptied by the previous commit
166+
select * from temp_parted_oncommit;
167+
drop table temp_parted_oncommit;

0 commit comments

Comments
 (0)