@@ -74,6 +74,7 @@ static ObjectAddress create_table_using_stmt(CreateStmt *create_stmt,
74
74
Oid relowner );
75
75
76
76
static void copy_foreign_keys (Oid parent_relid , Oid partition_oid );
77
+ static void copy_relation_attributes (Oid partition_relid , Datum reloptions );
77
78
static void postprocess_child_table_and_atts (Oid parent_relid , Oid partition_relid );
78
79
79
80
static Oid text_to_regprocedure (text * proname_args );
@@ -671,6 +672,7 @@ create_single_partition_internal(Oid parent_relid,
671
672
RangeVar * partition_rv ,
672
673
char * tablespace )
673
674
{
675
+ HeapTuple tuple = NULL ;
674
676
Relation parentrel ;
675
677
676
678
/* Value to be returned */
@@ -693,6 +695,7 @@ create_single_partition_internal(Oid parent_relid,
693
695
Oid save_userid ;
694
696
int save_sec_context ;
695
697
bool need_priv_escalation = !superuser (); /* we might be a SU */
698
+ Datum reloptions = (Datum ) 0 ;
696
699
697
700
/* Lock parent and check if it exists */
698
701
LockRelationOid (parent_relid , ShareUpdateExclusiveLock );
@@ -736,6 +739,19 @@ create_single_partition_internal(Oid parent_relid,
736
739
/* Copy attributes */
737
740
parentrel = heap_open (parent_relid , NoLock );
738
741
newrel_rv -> relpersistence = parentrel -> rd_rel -> relpersistence ;
742
+ if (parentrel -> rd_options )
743
+ {
744
+ bool isNull ;
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
+ }
739
755
heap_close (parentrel , NoLock );
740
756
741
757
/* If no 'tablespace' is provided, get parent's tablespace */
@@ -787,6 +803,10 @@ create_single_partition_internal(Oid parent_relid,
787
803
partition_relid = create_table_using_stmt ((CreateStmt * ) cur_stmt ,
788
804
child_relowner ).objectId ;
789
805
806
+ /* Copy attributes to partition */
807
+ if (reloptions )
808
+ copy_relation_attributes (partition_relid , reloptions );
809
+
790
810
/* Copy FOREIGN KEYS of the parent table */
791
811
copy_foreign_keys (parent_relid , partition_relid );
792
812
@@ -823,6 +843,9 @@ create_single_partition_internal(Oid parent_relid,
823
843
if (need_priv_escalation )
824
844
SetUserIdAndSecContext (save_userid , save_sec_context );
825
845
846
+ if (tuple != NULL )
847
+ ReleaseSysCache (tuple );
848
+
826
849
return partition_relid ;
827
850
}
828
851
@@ -1114,6 +1137,38 @@ copy_foreign_keys(Oid parent_relid, Oid partition_oid)
1114
1137
FunctionCallInvoke (& copy_fkeys_proc_fcinfo );
1115
1138
}
1116
1139
1140
+ /* Copy attributes to partition. Updates partition's tuple in pg_class */
1141
+ static void
1142
+ copy_relation_attributes (Oid partition_relid , Datum reloptions )
1143
+ {
1144
+ Relation classRel ;
1145
+ HeapTuple tuple ,
1146
+ newtuple ;
1147
+ Datum new_val [Natts_pg_class ];
1148
+ bool new_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
+
1117
1172
1118
1173
/*
1119
1174
* -----------------------------
0 commit comments