Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ee0dW-0000Xs-ET for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2018 15:37:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ee0dV-0005P4-KW for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2018 15:37:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ee0dV-0005Ou-Dc for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2018 15:37:21 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ee0dN-0003Ns-Gy for pgsql-hackers@postgresql.org; Tue, 23 Jan 2018 15:37:20 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 512615F79C; Tue, 23 Jan 2018 10:37:11 -0500 (EST) Date: Tue, 23 Jan 2018 10:37:11 -0500 From: Stephen Frost To: Sergei Kornilov Cc: Robert Haas , Tom Lane , "pgsql-hackers@postgresql.org" Subject: Re: using index or check in ALTER TABLE SET NOT NULL Message-ID: <20180123153711.GI2416@tamriel.snowman.net> References: <81911511895540@web58j.yandex.ru> <20171129152135.GN4628@tamriel.snowman.net> <9878.1511970441@sss.pgh.pa.us> <370481511970756@web3j.yandex.ru> <491651511974381@web27j.yandex.ru> <369811512396584@web6o.yandex.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4etweliHmHX+n9SC" Content-Disposition: inline In-Reply-To: <369811512396584@web6o.yandex.ru> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --4etweliHmHX+n9SC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings Sergei, * Sergei Kornilov (sk@zsrv.org) wrote: > I update patch and also rebase to current head. I hope now it is better a= ligned 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 r= el, > =20 > CatalogTupleUpdate(attr_rel, &tuple->t_self, tuple); > =20 > - /* Tell Phase 3 it needs to test the constraint */ > - tab->new_notnull =3D true; > + if (!NotNullImpliedByRelConstraints(rel, (Form_pg_attribute) GETSTRUCT= (tuple))) > + { > + /* Tell Phase 3 it needs to test the constraint */ > + tab->verify_new_notnull =3D true; > + } > =20 > 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 *partP= arams, AttrNumber *partattrs, > } > =20 > /* > - * 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 const= raint. > */ > bool > -PartConstraintImpliedByRelConstraint(Relation scanrel, > - List *partConstraint) > +ConstraintImpliedByRelConstraint(Relation scanrel, List *partConstraint) > { > List *existConstraint =3D NIL; > TupleConstr *constr =3D 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 --4etweliHmHX+n9SC Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJaZ1anAAoJEO1sijiDR2RVcX0QALE01GY22Vrq5tOiH0/3pYKr 5xjYwWlB71rbxbfEZNjcwGzdSl4IU6MXJ7z+DMjdIL7DxOCGNwjeouJO/Ab/8BIn Awkn4Z/7k+HjEQebrVAHUM7H3S9VmepXs/36oiqvX1pBguxYXLdEuWMXw32tnp/a GJMyzhVa4SsRzDKskj3t1hmg5iB1Avzrxfb9DGgljU8nQBN9qZpehu3Hb7BtLhdu xkLcDaQ+4a5J990NtN5HIfZR/m51wsRLsRUh+nKTqve4+VPcrJFLCNFK3BB0WJYY EruPAe2KKoIdwHzsq6hQqgdB8pBYclLJGFf26mV4TtaUZOeAbKA3+bOqwfCPOblG l32Vq7FUfUNCeDF9874OUHLBpoKxBSXBHcoCPFqWDz6UeWyb9/6zDidcAZgyAH9G 0nc4lYktoALrAxl/4jzbhMFtknE+63bIqaqRQqktMim3lWKQyF/dzDymKivDk1X4 OVfwqUH5Cxu+mRH39/SBEiG9owOatyw3YhADAbRR19OfmOIf9IigXjEFbpkMURCm cq9LxY2BDoWUvVXupv6DWWHDBt7X8s1BjPePiLtzKN8Gtg1YaUZPZ02mnCaAOTYR 15+eX5Z2IlbsBS7zu2DxL6mOtLMmIBcQnymM8SRUX7ZQqzEZxdA4kaOQcoASm9iB 61wUyqJGLyyFx3RsHZ06 =HAWn -----END PGP SIGNATURE----- --4etweliHmHX+n9SC--