Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39808e8

Browse files
committed
Fix catalog insertion order for ATTACH PARTITION
Commit2fbdf1b changed the order in which we inserted catalog rowswhen creating partitions, so that we could remove an unsightly hackrequired for untimely relcache invalidations. However, that commit onlychanged the ordering for CREATE TABLE PARTITION OF, and left ALTER TABLEATTACH PARTITION unchanged, so the latter can be affected when cataloginvalidations occur, for instance when the partition key involves an SQLfunction.Reported-by: Rajkumar RaghuwanshiAuthor: Amit LangoteReviewed-by: Michaël PaquierDiscussion:https://postgr.es/m/CAKcux6=nTz9KSfTr_6Z2mpzLJ_09JN-rK6=dWic6gGyTSWueyQ@mail.gmail.com
1 parentad08006 commit39808e8

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
@@ -14247,9 +14247,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1424714247
trigger_name,RelationGetRelationName(attachrel)),
1424814248
errdetail("ROW triggers with transition tables are not supported on partitions")));
1424914249

14250-
/* OK to create inheritance. Rest of the checks performed there */
14251-
CreateInheritance(attachrel,rel);
14252-
1425314250
/*
1425414251
* Check that the new partition's bound is valid and does not overlap any
1425514252
* of existing partitions of the parent - note that it does not return on
@@ -14258,6 +14255,9 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1425814255
check_new_partition_bound(RelationGetRelationName(attachrel),rel,
1425914256
cmd->bound);
1426014257

14258+
/* OK to create inheritance. Rest of the checks performed there */
14259+
CreateInheritance(attachrel,rel);
14260+
1426114261
/* Update the pg_class entry. */
1426214262
StorePartitionBound(attachrel,rel,cmd->bound);
1426314263

‎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
altertable temp_part_parent attach partition temp_part_child default;-- ok
26192619
droptable perm_part_parent cascade;
26202620
droptable 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+
createfunctionat_test_sql_partop (int4, int4) returnsint language sql
2626+
as $$select case when $1= $2 then0 when $1> $2 then1 else-1 end; $$;
2627+
createoperator classat_test_sql_partop for type int4 using btreeas
2628+
operator1< (int4, int4), operator2<= (int4, int4),
2629+
operator3= (int4, int4), operator4>= (int4, int4),
2630+
operator5> (int4, int4), function1 at_test_sql_partop(int4, int4);
2631+
createtableat_test_sql_partop (aint) partition by range (a at_test_sql_partop);
2632+
createtableat_test_sql_partop_1 (aint);
2633+
altertable at_test_sql_partop attach partition at_test_sql_partop_1 forvaluesfrom (0) to (10);
2634+
droptable at_test_sql_partop;
2635+
dropoperator class at_test_sql_partop using btree;
2636+
dropfunction at_test_sql_partop;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp