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

Commit96376f1

Browse files
committed
Copy WITH options to partitions
1 parent07a9c88 commit96376f1

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

‎expected/pathman_basic.out‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,34 @@ NOTICE: 1000 rows copied from test.num_range_rel_3
13391339
DROP TABLE test.num_range_rel CASCADE;
13401340
DROP TABLE test.range_rel CASCADE;
13411341
NOTICE: drop cascades to 10 other objects
1342+
/* Test attributes copying */
1343+
CREATE UNLOGGED TABLE test.range_rel (
1344+
idSERIAL PRIMARY KEY,
1345+
dtDATE NOT NULL)
1346+
WITH (fillfactor = 70);
1347+
INSERT INTO test.range_rel (dt)
1348+
SELECT g FROM generate_series('2015-01-01', '2015-02-15', '1 month'::interval) AS g;
1349+
SELECT pathman.create_range_partitions('test.range_rel', 'dt',
1350+
'2015-01-01'::date, '1 month'::interval);
1351+
create_range_partitions
1352+
-------------------------
1353+
2
1354+
(1 row)
1355+
1356+
SELECT reloptions, relpersistence FROM pg_class WHERE oid='test.range_rel'::REGCLASS;
1357+
reloptions | relpersistence
1358+
-----------------+----------------
1359+
{fillfactor=70} | u
1360+
(1 row)
1361+
1362+
SELECT reloptions, relpersistence FROM pg_class WHERE oid='test.range_rel_1'::REGCLASS;
1363+
reloptions | relpersistence
1364+
-----------------+----------------
1365+
{fillfactor=70} | u
1366+
(1 row)
1367+
1368+
DROP TABLE test.range_rel CASCADE;
1369+
NOTICE: drop cascades to 3 other objects
13421370
/* Test automatic partition creation */
13431371
CREATE TABLE test.range_rel (
13441372
idSERIAL PRIMARY KEY,

‎sql/pathman_basic.sql‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,19 @@ DROP TABLE test.num_range_rel CASCADE;
390390

391391
DROPTABLEtest.range_rel CASCADE;
392392

393+
/* Test attributes copying*/
394+
CREATE UNLOGGED TABLEtest.range_rel (
395+
idSERIALPRIMARY KEY,
396+
dtDATENOT NULL)
397+
WITH (fillfactor=70);
398+
INSERT INTOtest.range_rel (dt)
399+
SELECT gFROM generate_series('2015-01-01','2015-02-15','1 month'::interval)AS g;
400+
SELECTpathman.create_range_partitions('test.range_rel','dt',
401+
'2015-01-01'::date,'1 month'::interval);
402+
SELECT reloptions, relpersistenceFROM pg_classWHEREoid='test.range_rel'::REGCLASS;
403+
SELECT reloptions, relpersistenceFROM pg_classWHEREoid='test.range_rel_1'::REGCLASS;
404+
DROPTABLEtest.range_rel CASCADE;
405+
393406
/* Test automatic partition creation*/
394407
CREATETABLEtest.range_rel (
395408
idSERIALPRIMARY KEY,

‎src/partition_creation.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static ObjectAddress create_table_using_stmt(CreateStmt *create_stmt,
7474
Oidrelowner);
7575

7676
staticvoidcopy_foreign_keys(Oidparent_relid,Oidpartition_oid);
77+
staticvoidcopy_relation_attributes(Oidpartition_relid,Datumreloptions);
7778
staticvoidpostprocess_child_table_and_atts(Oidparent_relid,Oidpartition_relid);
7879

7980
staticOidtext_to_regprocedure(text*proname_args);
@@ -671,6 +672,7 @@ create_single_partition_internal(Oid parent_relid,
671672
RangeVar*partition_rv,
672673
char*tablespace)
673674
{
675+
HeapTupletuple=NULL;
674676
Relationparentrel;
675677

676678
/* Value to be returned */
@@ -693,6 +695,7 @@ create_single_partition_internal(Oid parent_relid,
693695
Oidsave_userid;
694696
intsave_sec_context;
695697
boolneed_priv_escalation= !superuser();/* we might be a SU */
698+
Datumreloptions= (Datum)0;
696699

697700
/* Lock parent and check if it exists */
698701
LockRelationOid(parent_relid,ShareUpdateExclusiveLock);
@@ -736,6 +739,19 @@ create_single_partition_internal(Oid parent_relid,
736739
/* Copy attributes */
737740
parentrel=heap_open(parent_relid,NoLock);
738741
newrel_rv->relpersistence=parentrel->rd_rel->relpersistence;
742+
if (parentrel->rd_options)
743+
{
744+
boolisNull;
745+
746+
tuple=SearchSysCache1(RELOID,ObjectIdGetDatum(parent_relid));
747+
if (!HeapTupleIsValid(tuple))
748+
elog(ERROR,"cache lookup failed for relation %u",parent_relid);
749+
750+
reloptions=SysCacheGetAttr(RELOID,tuple,Anum_pg_class_reloptions,
751+
&isNull);
752+
if (isNull)
753+
reloptions= (Datum)0;
754+
}
739755
heap_close(parentrel,NoLock);
740756

741757
/* If no 'tablespace' is provided, get parent's tablespace */
@@ -787,6 +803,10 @@ create_single_partition_internal(Oid parent_relid,
787803
partition_relid=create_table_using_stmt((CreateStmt*)cur_stmt,
788804
child_relowner).objectId;
789805

806+
/* Copy attributes to partition */
807+
if (reloptions)
808+
copy_relation_attributes(partition_relid,reloptions);
809+
790810
/* Copy FOREIGN KEYS of the parent table */
791811
copy_foreign_keys(parent_relid,partition_relid);
792812

@@ -823,6 +843,9 @@ create_single_partition_internal(Oid parent_relid,
823843
if (need_priv_escalation)
824844
SetUserIdAndSecContext(save_userid,save_sec_context);
825845

846+
if (tuple!=NULL)
847+
ReleaseSysCache(tuple);
848+
826849
returnpartition_relid;
827850
}
828851

@@ -1114,6 +1137,38 @@ copy_foreign_keys(Oid parent_relid, Oid partition_oid)
11141137
FunctionCallInvoke(&copy_fkeys_proc_fcinfo);
11151138
}
11161139

1140+
/* Copy attributes to partition. Updates partition's tuple in pg_class */
1141+
staticvoid
1142+
copy_relation_attributes(Oidpartition_relid,Datumreloptions)
1143+
{
1144+
RelationclassRel;
1145+
HeapTupletuple,
1146+
newtuple;
1147+
Datumnew_val[Natts_pg_class];
1148+
boolnew_null[Natts_pg_class],
1149+
new_repl[Natts_pg_class];
1150+
1151+
classRel=heap_open(RelationRelationId,RowExclusiveLock);
1152+
tuple=SearchSysCacheCopy1(RELOID,
1153+
ObjectIdGetDatum(partition_relid));
1154+
if (!HeapTupleIsValid(tuple))
1155+
elog(ERROR,"cache lookup failed for relation %u",
1156+
partition_relid);
1157+
1158+
/* Fill in relpartbound value */
1159+
memset(new_val,0,sizeof(new_val));
1160+
memset(new_null, false,sizeof(new_null));
1161+
memset(new_repl, false,sizeof(new_repl));
1162+
new_val[Anum_pg_class_reloptions-1]=reloptions;
1163+
new_null[Anum_pg_class_reloptions-1]= false;
1164+
new_repl[Anum_pg_class_reloptions-1]= true;
1165+
newtuple=heap_modify_tuple(tuple,RelationGetDescr(classRel),
1166+
new_val,new_null,new_repl);
1167+
CatalogTupleUpdate(classRel,&newtuple->t_self,newtuple);
1168+
heap_freetuple(newtuple);
1169+
heap_close(classRel,RowExclusiveLock);
1170+
}
1171+
11171172

11181173
/*
11191174
* -----------------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp