Re: creating CHECK constraints as NOT VALID

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: creating CHECK constraints as NOT VALID
Date: 2011-06-01 22:47:26
Message-ID: 1306968328-sup-6164@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Here's a complete patch with all this stuff, plus doc additions and
simple regression tests for the new ALTER DOMAIN commands.

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.

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.

This patch was sponsored by Enova Financial.

doc/src/sgml/catalogs.sgml | 2 +-
doc/src/sgml/ref/alter_domain.sgml | 39 +++++-
doc/src/sgml/ref/alter_table.sgml | 4 +-
src/backend/catalog/heap.c | 13 +-
src/backend/commands/tablecmds.c | 227 ++++++++++++++++++++++++-----
src/backend/commands/typecmds.c | 140 ++++++++++++++++--
src/backend/parser/gram.y | 22 +++
src/backend/tcop/utility.c | 4 +
src/include/catalog/heap.h | 1 +
src/include/commands/typecmds.h | 1 +
src/include/nodes/parsenodes.h | 3 +
src/test/regress/expected/alter_table.out | 36 +++++
src/test/regress/expected/domain.out | 11 ++
src/test/regress/sql/alter_table.sql | 29 ++++
src/test/regress/sql/domain.sql | 10 ++
15 files changed, 480 insertions(+), 62 deletions(-)

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Attachment Content-Type Size
not-valid-check.patch application/octet-stream 40.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message panam 2011-06-01 22:49:31 Re: [PERFORM] Hash Anti Join performance degradation
Previous Message Tom Lane 2011-06-01 22:42:52 Re: vacuum and row type