OSDN Git Service

Enable CHECK constraints to be declared NOT VALID
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 1 Jun 2011 22:43:50 +0000 (18:43 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 30 Jun 2011 15:24:31 +0000 (11:24 -0400)
commit897795240cfaaed724af2f53ed2c50c9862f951f
treea646222fe29936f565e715a1cce3a65016587057
parentb36927fbe922d1aac5d6e42c04eecf65bf37f5f3
Enable CHECK constraints to be declared NOT VALID

This means that they can initially be added to a large existing table
without checking its initial contents, but new tuples must comply to
them; a separate pass invoked by ALTER TABLE / VALIDATE can verify
existing data and ensure it complies with the constraint, at which point
it is marked validated and becomes a normal part of the table ecosystem.

An non-validated CHECK constraint is ignored in the planner for
constraint_exclusion purposes; when validated, cached plans are
recomputed so that partitioning starts working right away.

This patch also enables domains to have unvalidated CHECK constraints
attached to them as well by way of ALTER DOMAIN / ADD CONSTRAINT / NOT
VALID, which can later be validated with ALTER DOMAIN / VALIDATE
CONSTRAINT.

Thanks to Thom Brown, Dean Rasheed and Jaime Casanova for the various
reviews, and Robert Hass for documentation wording improvement
suggestions.

This patch was sponsored by Enova Financial.
19 files changed:
doc/src/sgml/catalogs.sgml
doc/src/sgml/ref/alter_domain.sgml
doc/src/sgml/ref/alter_table.sgml
src/backend/access/common/tupdesc.c
src/backend/catalog/heap.c
src/backend/commands/tablecmds.c
src/backend/commands/typecmds.c
src/backend/optimizer/util/plancat.c
src/backend/parser/gram.y
src/backend/tcop/utility.c
src/backend/utils/cache/relcache.c
src/include/access/tupdesc.h
src/include/catalog/heap.h
src/include/commands/typecmds.h
src/include/nodes/parsenodes.h
src/test/regress/expected/alter_table.out
src/test/regress/expected/domain.out
src/test/regress/sql/alter_table.sql
src/test/regress/sql/domain.sql