pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Frost <sfrost@snowman.net>
To: Sergei Kornilov <sk@zsrv.org>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: using index or check in ALTER TABLE SET NOT NULL
Date: Tue, 23 Jan 2018 10:37:11 -0500
Message-ID: <20180123153711.GI2416@tamriel.snowman.net> (raw)
In-Reply-To: <369811512396584@web6o.yandex.ru>
References: <81911511895540@web58j.yandex.ru>
	<CA+TgmoZKR4dTR7KyoM4jfJN2J-eNoBRG2_XHdZa1f0VUbK1xXQ@mail.gmail.com>
	<20171129152135.GN4628@tamriel.snowman.net>
	<9878.1511970441@sss.pgh.pa.us>
	<370481511970756@web3j.yandex.ru>
	<491651511974381@web27j.yandex.ru>
	<CA+TgmoahVfu0dUmvM1bO3csn=DtFp1fG92995rjYD9u_kO-Y1g@mail.gmail.com>
	<369811512396584@web6o.yandex.ru>

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

Attachments:

  [application/pgp-signature] signature.asc (818B, ../20180123153711.GI2416@tamriel.snowman.net/2-signature.asc)
  download

view thread (73+ messages)  latest in thread

Message-ID: <20180123153711.GI2416@tamriel.snowman.net>
Permalink:  ../20180123153711.GI2416@tamriel.snowman.net/
Also on:    postgresql.org/message-id/20180123153711.GI2416@tamriel.snowman.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: sfrost@snowman.net, sk@zsrv.org, robertmhaas@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: using index or check in ALTER TABLE SET NOT NULL
  In-Reply-To: <20180123153711.GI2416@tamriel.snowman.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox