@@ -127,7 +127,8 @@ static char *domainAddConstraint(Oid domainOid, Oid domainNamespace,
127
127
const char * domainName , ObjectAddress * constrAddr );
128
128
static Node * replace_domain_constraint_value (ParseState * pstate ,
129
129
ColumnRef * cref );
130
- static void AlterTypeRecurse (Oid typeOid , HeapTuple tup , Relation catalog ,
130
+ static void AlterTypeRecurse (Oid typeOid , bool isImplicitArray ,
131
+ HeapTuple tup , Relation catalog ,
131
132
AlterTypeRecurseParams * atparams );
132
133
133
134
@@ -3853,8 +3854,8 @@ AlterType(AlterTypeStmt *stmt)
3853
3854
errmsg ("%s is not a base type" ,
3854
3855
format_type_be (typeOid ))));
3855
3856
3856
- /* OK, recursively update this type and any domains over it */
3857
- AlterTypeRecurse (typeOid , tup , catalog , & atparams );
3857
+ /* OK, recursively update this type and any arrays/ domains over it */
3858
+ AlterTypeRecurse (typeOid , false, tup , catalog , & atparams );
3858
3859
3859
3860
/* Clean up */
3860
3861
ReleaseSysCache (tup );
@@ -3870,13 +3871,15 @@ AlterType(AlterTypeStmt *stmt)
3870
3871
* AlterTypeRecurse: one recursion step for AlterType()
3871
3872
*
3872
3873
* Apply the changes specified by "atparams" to the type identified by
3873
- * "typeOid", whose existing pg_type tuple is "tup". Then search for any
3874
- * domains over this type, and recursively apply (most of) the same changes
3875
- * to those domains.
3874
+ * "typeOid", whose existing pg_type tuple is "tup". If necessary,
3875
+ * recursively update its array type as well. Then search for any domains
3876
+ * over this type, and recursively apply (most of) the same changes to those
3877
+ * domains.
3876
3878
*
3877
3879
* We need this because the system generally assumes that a domain inherits
3878
3880
* many properties from its base type. See DefineDomain() above for details
3879
- * of what is inherited.
3881
+ * of what is inherited. Arrays inherit a smaller number of properties,
3882
+ * but not none.
3880
3883
*
3881
3884
* There's a race condition here, in that some other transaction could
3882
3885
* concurrently add another domain atop this base type; we'd miss updating
@@ -3888,7 +3891,8 @@ AlterType(AlterTypeStmt *stmt)
3888
3891
* committed.
3889
3892
*/
3890
3893
static void
3891
- AlterTypeRecurse (Oid typeOid , HeapTuple tup , Relation catalog ,
3894
+ AlterTypeRecurse (Oid typeOid , bool isImplicitArray ,
3895
+ HeapTuple tup , Relation catalog ,
3892
3896
AlterTypeRecurseParams * atparams )
3893
3897
{
3894
3898
Datum values [Natts_pg_type ];
@@ -3949,12 +3953,43 @@ AlterTypeRecurse(Oid typeOid, HeapTuple tup, Relation catalog,
3949
3953
NULL , /* don't have defaultExpr handy */
3950
3954
NULL , /* don't have typacl handy */
3951
3955
0 , /* we rejected composite types above */
3952
- false, /* and we rejected implicit arrays above */
3953
- false, /* so it can't be a dependent type */
3956
+ isImplicitArray , /* it might be an array */
3957
+ isImplicitArray , /* dependent iff it's array */
3954
3958
true);
3955
3959
3956
3960
InvokeObjectPostAlterHook (TypeRelationId , typeOid , 0 );
3957
3961
3962
+ /*
3963
+ * Arrays inherit their base type's typmodin and typmodout, but none of
3964
+ * the other properties we're concerned with here. Recurse to the array
3965
+ * type if needed.
3966
+ */
3967
+ if (!isImplicitArray &&
3968
+ (atparams -> updateTypmodin || atparams -> updateTypmodout ))
3969
+ {
3970
+ Oid arrtypoid = ((Form_pg_type ) GETSTRUCT (newtup ))-> typarray ;
3971
+
3972
+ if (OidIsValid (arrtypoid ))
3973
+ {
3974
+ HeapTuple arrtup ;
3975
+ AlterTypeRecurseParams arrparams ;
3976
+
3977
+ arrtup = SearchSysCache1 (TYPEOID , ObjectIdGetDatum (arrtypoid ));
3978
+ if (!HeapTupleIsValid (arrtup ))
3979
+ elog (ERROR , "cache lookup failed for type %u" , arrtypoid );
3980
+
3981
+ memset (& arrparams , 0 , sizeof (arrparams ));
3982
+ arrparams .updateTypmodin = atparams -> updateTypmodin ;
3983
+ arrparams .updateTypmodout = atparams -> updateTypmodout ;
3984
+ arrparams .typmodinOid = atparams -> typmodinOid ;
3985
+ arrparams .typmodoutOid = atparams -> typmodoutOid ;
3986
+
3987
+ AlterTypeRecurse (arrtypoid , true, arrtup , catalog , & arrparams );
3988
+
3989
+ ReleaseSysCache (arrtup );
3990
+ }
3991
+ }
3992
+
3958
3993
/*
3959
3994
* Now we need to recurse to domains. However, some properties are not
3960
3995
* inherited by domains, so clear the update flags for those.
@@ -3963,6 +3998,12 @@ AlterTypeRecurse(Oid typeOid, HeapTuple tup, Relation catalog,
3963
3998
atparams -> updateTypmodin = false; /* domains don't have typmods */
3964
3999
atparams -> updateTypmodout = false;
3965
4000
4001
+ /* Skip the scan if nothing remains to be done */
4002
+ if (!(atparams -> updateStorage ||
4003
+ atparams -> updateSend ||
4004
+ atparams -> updateAnalyze ))
4005
+ return ;
4006
+
3966
4007
/* Search pg_type for possible domains over this type */
3967
4008
ScanKeyInit (& key [0 ],
3968
4009
Anum_pg_type_typbasetype ,
@@ -3983,7 +4024,7 @@ AlterTypeRecurse(Oid typeOid, HeapTuple tup, Relation catalog,
3983
4024
if (domainForm -> typtype != TYPTYPE_DOMAIN )
3984
4025
continue ;
3985
4026
3986
- AlterTypeRecurse (domainForm -> oid , domainTup , catalog , atparams );
4027
+ AlterTypeRecurse (domainForm -> oid , false, domainTup , catalog , atparams );
3987
4028
}
3988
4029
3989
4030
systable_endscan (scan );
0 commit comments