Re: not null constraints, again

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Tender Wang <tndrwang@gmail.com>, Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-10-01T08:14:18Z
Lists: pgsql-hackers
CREATE TABLE a (aa TEXT);
CREATE TEMP TABLE z (b TEXT, UNIQUE(aa, b)) inherits (a);

\d+ z
                                         Table "pg_temp_0.z"
 Column | Type | Collation | Nullable | Default | Storage  |
Compression | Stats target | Description
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
 aa     | text |           | not null |         | extended |
  |              |
 b      | text |           |          |         | extended |
  |              |
Indexes:
    "z_aa_b_key" UNIQUE CONSTRAINT, btree (aa, b)
Not-null constraints:
    "z_aa_not_null" NOT NULL "aa"
Inherits: a
Access method: heap



that means in transformIndexConstraint,
the following part only apply to CONSTR_PRIMARY

                        if (strcmp(key, inhname) == 0)
                        {
                            found = true;
                            typid = inhattr->atttypid;
                            cxt->nnconstraints =
                                lappend(cxt->nnconstraints,

makeNotNullConstraint(makeString(pstrdup(inhname))));
                            break;
                        }



Commits

  1. Suppress "may be used uninitialized" warnings from older compilers.

  2. Elide not-null constraint checks on child tables during PK creation

  3. Remove unnecessary code to handle CONSTR_NOTNULL

  4. Silence compilers about extractNotNullColumn()

  5. Add pg_constraint rows for not-null constraints