aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2011-06-01 18:43:50 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2011-06-30 11:24:31 -0400
commit897795240cfaaed724af2f53ed2c50c9862f951f (patch)
treea646222fe29936f565e715a1cce3a65016587057 /src/backend/parser
parentb36927fbe922d1aac5d6e42c04eecf65bf37f5f3 (diff)
downloadpostgresql-897795240cfaaed724af2f53ed2c50c9862f951f.tar.gz
postgresql-897795240cfaaed724af2f53ed2c50c9862f951f.zip
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.
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 62cff8a7de3..72260320c38 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2759,8 +2759,9 @@ ConstraintElem:
n->raw_expr = $3;
n->cooked_expr = NULL;
processCASbits($5, @5, "CHECK",
- NULL, NULL, NULL,
+ NULL, NULL, &n->skip_validation,
yyscanner);
+ n->initially_valid = !n->skip_validation;
$$ = (Node *)n;
}
| UNIQUE '(' columnList ')' opt_definition OptConsTableSpace
@@ -7559,6 +7560,15 @@ AlterDomainStmt:
n->behavior = $7;
$$ = (Node *)n;
}
+ /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
+ | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
+ {
+ AlterDomainStmt *n = makeNode(AlterDomainStmt);
+ n->subtype = 'V';
+ n->typeName = $3;
+ n->name = $6;
+ $$ = (Node *)n;
+ }
;
opt_as: AS {}