Re: ALTER TABLE ADD COLUMN fast default

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Zhihong Yu <zyu@yugabyte.com>
Cc: Andrew Dunstan <andrew@dunslane.net>, Andrew Gierth <andrew@tao11.riddles.org.uk>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2021-04-05T16:21:36Z
Lists: pgsql-hackers
Zhihong Yu <zyu@yugabyte.com> writes:
>>     if (found != ncheck)

> Since there is check on found being smaller than ncheck inside the loop,
> the if condition can be written as:
>     if (found < ncheck)

Doesn't really seem like an improvement?  Nor am I excited about renaming
these "found" variables, considering that those names can be traced back
more than twenty years.

> +   if (found != ndef)
> +       elog(WARNING, "%d attrdef record(s) missing for rel %s",
> +            ndef - found, RelationGetRelationName(relation));

> Since only warning is logged, there seems to be some wasted space in
> attrdef. Would such space accumulate, resulting in some memory leak ?

No, it's just one palloc chunk either way.  I do not think there is
any value in adding more code to reclaim the unused array slots a
bit sooner.  (Because of aset.c's power-of-two allocation practices,
it's likely there would be zero actual space savings anyway.)

			regards, tom lane



Commits

  1. Clean up treatment of missing default and CHECK-constraint records.

  2. Fast ALTER TABLE ADD COLUMN with a non-NULL default

  3. Fix application of identity values in some cases