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

Commit 1c7f585

Browse files
committed
Fix catalog insertion order for ATTACH PARTITION
Commit 2fbdf1b changed the order in which we inserted catalog rows when creating partitions, so that we could remove an unsightly hack required for untimely relcache invalidations. However, that commit only changed the ordering for CREATE TABLE PARTITION OF, and left ALTER TABLE ATTACH PARTITION unchanged, so the latter can be affected when catalog invalidations occur, for instance when the partition key involves an SQL function. Reported-by: Rajkumar Raghuwanshi Author: Amit Langote Reviewed-by: Michaël Paquier Discussion: https://postgr.es/m/CAKcux6=nTz9KSfTr_6Z2mpzLJ_09JN-rK6=dWic6gGyTSWueyQ@mail.gmail.com
1 parent 1a852f7 commit 1c7f585

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/backend/commands/tablecmds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14191,9 +14191,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1419114191
trigger_name, RelationGetRelationName(attachrel)),
1419214192
errdetail("ROW triggers with transition tables are not supported on partitions")));
1419314193

14194-
/* OK to create inheritance. Rest of the checks performed there */
14195-
CreateInheritance(attachrel, rel);
14196-
1419714194
/*
1419814195
* Check that the new partition's bound is valid and does not overlap any
1419914196
* of existing partitions of the parent - note that it does not return on
@@ -14202,6 +14199,9 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1420214199
check_new_partition_bound(RelationGetRelationName(attachrel), rel,
1420314200
cmd->bound);
1420414201

14202+
/* OK to create inheritance. Rest of the checks performed there */
14203+
CreateInheritance(attachrel, rel);
14204+
1420514205
/* Update the pg_class entry. */
1420614206
StorePartitionBound(attachrel, rel, cmd->bound);
1420714207

src/test/regress/expected/alter_table.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3960,3 +3960,18 @@ ERROR: cannot attach a temporary relation as partition of permanent relation "p
39603960
alter table temp_part_parent attach partition temp_part_child default; -- ok
39613961
drop table perm_part_parent cascade;
39623962
drop table temp_part_parent cascade;
3963+
-- test case where the partitioning operator is a SQL function whose
3964+
-- evaluation results in the table's relcache being rebuilt partway through
3965+
-- the execution of an ATTACH PARTITION command
3966+
create function at_test_sql_partop (int4, int4) returns int language sql
3967+
as $$ select case when $1 = $2 then 0 when $1 > $2 then 1 else -1 end; $$;
3968+
create operator class at_test_sql_partop for type int4 using btree as
3969+
operator 1 < (int4, int4), operator 2 <= (int4, int4),
3970+
operator 3 = (int4, int4), operator 4 >= (int4, int4),
3971+
operator 5 > (int4, int4), function 1 at_test_sql_partop(int4, int4);
3972+
create table at_test_sql_partop (a int) partition by range (a at_test_sql_partop);
3973+
create table at_test_sql_partop_1 (a int);
3974+
alter table at_test_sql_partop attach partition at_test_sql_partop_1 for values from (0) to (10);
3975+
drop table at_test_sql_partop;
3976+
drop operator class at_test_sql_partop using btree;
3977+
drop function at_test_sql_partop;

src/test/regress/sql/alter_table.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,3 +2618,19 @@ alter table perm_part_parent attach partition temp_part_child default; -- error
26182618
alter table temp_part_parent attach partition temp_part_child default; -- ok
26192619
drop table perm_part_parent cascade;
26202620
drop table temp_part_parent cascade;
2621+
2622+
-- test case where the partitioning operator is a SQL function whose
2623+
-- evaluation results in the table's relcache being rebuilt partway through
2624+
-- the execution of an ATTACH PARTITION command
2625+
create function at_test_sql_partop (int4, int4) returns int language sql
2626+
as $$ select case when $1 = $2 then 0 when $1 > $2 then 1 else -1 end; $$;
2627+
create operator class at_test_sql_partop for type int4 using btree as
2628+
operator 1 < (int4, int4), operator 2 <= (int4, int4),
2629+
operator 3 = (int4, int4), operator 4 >= (int4, int4),
2630+
operator 5 > (int4, int4), function 1 at_test_sql_partop(int4, int4);
2631+
create table at_test_sql_partop (a int) partition by range (a at_test_sql_partop);
2632+
create table at_test_sql_partop_1 (a int);
2633+
alter table at_test_sql_partop attach partition at_test_sql_partop_1 for values from (0) to (10);
2634+
drop table at_test_sql_partop;
2635+
drop operator class at_test_sql_partop using btree;
2636+
drop function at_test_sql_partop;

0 commit comments

Comments
 (0)