1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-05 23:38:41 +03:00

Allow ALTER TABLE .. SET NOT NULL to skip provably unnecessary scans.

If existing CHECK or NOT NULL constraints preclude the presence
of nulls, we need not look to see whether any are present.

Sergei Kornilov, reviewed by Stephen Frost, Ildar Musin, David Rowley,
and by me.

Discussion: http://postgr.es/m/81911511895540@web58j.yandex.ru
This commit is contained in:
Robert Haas
2019-03-13 08:55:00 -04:00
parent 95fa9f1a13
commit bbb96c3704
4 changed files with 195 additions and 23 deletions

View File

@@ -214,8 +214,17 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<listitem>
<para>
These forms change whether a column is marked to allow null
values or to reject null values. You can only use <literal>SET
NOT NULL</literal> when the column contains no null values.
values or to reject null values.
</para>
<para>
<literal>SET NOT NULL</literal> may only be applied to a column
providing none of the records in the table contain a
<literal>NULL</literal> value for the column. Ordinarily this is
checked during the <literal>ALTER TABLE</literal> by scanning the
entire table; however, if a valid <literal>CHECK</literal> constraint is
found which proves no <literal>NULL</literal> can exist, then the
table scan is skipped.
</para>
<para>