Re: using index or check in ALTER TABLE SET NOT NULL
От | Stephen Frost |
---|---|
Тема | Re: using index or check in ALTER TABLE SET NOT NULL |
Дата | |
Msg-id | 20180123153711.GI2416@tamriel.snowman.net обсуждение исходный текст |
Ответ на | Re: using index or check in ALTER TABLE SET NOT NULL (Sergei Kornilov <sk@zsrv.org>) |
Ответы |
Re: using index or check in ALTER TABLE SET NOT NULL
|
Список | pgsql-hackers |
Greetings Sergei, * Sergei Kornilov (sk@zsrv.org) wrote: > I update patch and also rebase to current head. I hope now it is better aligned with project style Thanks for updating it and continuing to work on it. I haven't done a full review but there were a few things below that I thought could be improved- > @@ -5863,8 +5864,11 @@ ATExecSetNotNull(AlteredTableInfo *tab, Relation rel, > > CatalogTupleUpdate(attr_rel, &tuple->t_self, tuple); > > - /* Tell Phase 3 it needs to test the constraint */ > - tab->new_notnull = true; > + if (!NotNullImpliedByRelConstraints(rel, (Form_pg_attribute) GETSTRUCT(tuple))) > + { > + /* Tell Phase 3 it needs to test the constraint */ > + tab->verify_new_notnull = true; > + } > > ObjectAddressSubSet(address, RelationRelationId, > RelationGetRelid(rel), attnum); This could really use some additional comments, imv. In particular, we need to make it clear that verify_new_notnull only moves from the initial 'false' value to 'true', since we could be asked to add multiple NOT NULL constraints and if any of them aren't already covered by an existing CHECK constraint then we need to perform the full table check. > @@ -13618,15 +13662,14 @@ ComputePartitionAttrs(Relation rel, List *partParams, AttrNumber *partattrs, > } > > /* > - * PartConstraintImpliedByRelConstraint > - * Does scanrel's existing constraints imply the partition constraint? > + * ConstraintImpliedByRelConstraint > + * Does scanrel's existing constraints imply given constraint > * > * Existing constraints includes its check constraints and column-level > * NOT NULL constraints and partConstraint describes the partition constraint. > */ > bool > -PartConstraintImpliedByRelConstraint(Relation scanrel, > - List *partConstraint) > +ConstraintImpliedByRelConstraint(Relation scanrel, List *partConstraint) > { > List *existConstraint = NIL; > TupleConstr *constr = RelationGetDescr(scanrel)->constr; I would also rename 'partConstraint' since this function is no longer, necessairly, working with a partition's constraint. This could also really use some regression tests and I'd be sure to include tests of adding multiple NOT NULL constraints, sometimes where they're all covered by existing CHECK constraints and other times when only one or the other is (and there's existing NULL values in the other column), etc. Thanks! Stephen
Вложения
В списке pgsql-hackers по дате отправления: