mirror of
https://github.com/postgres/postgres.git
synced 2025-08-22 21:53:06 +03:00
Code review for domain-constraints patch. Use a new ConstraintTest node
type for runtime constraint checks, instead of misusing the parse-time Constraint node for the purpose. Fix some damage introduced into type coercion logic; in particular ensure that a coerced expression tree will read out the correct result type when inspected (patch had broken some RelabelType cases). Enforce domain NOT NULL constraints against columns that are omitted from an INSERT.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.208 2002/08/30 19:23:19 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.209 2002/08/31 22:10:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -973,10 +973,6 @@ _copyJoinExpr(JoinExpr *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _copyCaseExpr
|
||||
* ----------------
|
||||
*/
|
||||
static CaseExpr *
|
||||
_copyCaseExpr(CaseExpr *from)
|
||||
{
|
||||
@@ -994,10 +990,6 @@ _copyCaseExpr(CaseExpr *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _copyCaseWhen
|
||||
* ----------------
|
||||
*/
|
||||
static CaseWhen *
|
||||
_copyCaseWhen(CaseWhen *from)
|
||||
{
|
||||
@@ -1012,10 +1004,6 @@ _copyCaseWhen(CaseWhen *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _copyNullTest
|
||||
* ----------------
|
||||
*/
|
||||
static NullTest *
|
||||
_copyNullTest(NullTest *from)
|
||||
{
|
||||
@@ -1030,10 +1018,6 @@ _copyNullTest(NullTest *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _copyBooleanTest
|
||||
* ----------------
|
||||
*/
|
||||
static BooleanTest *
|
||||
_copyBooleanTest(BooleanTest *from)
|
||||
{
|
||||
@@ -1048,6 +1032,23 @@ _copyBooleanTest(BooleanTest *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static ConstraintTest *
|
||||
_copyConstraintTest(ConstraintTest *from)
|
||||
{
|
||||
ConstraintTest *newnode = makeNode(ConstraintTest);
|
||||
|
||||
/*
|
||||
* copy remainder of node
|
||||
*/
|
||||
Node_Copy(from, newnode, arg);
|
||||
newnode->testtype = from->testtype;
|
||||
if (from->name)
|
||||
newnode->name = pstrdup(from->name);
|
||||
Node_Copy(from, newnode, check_expr);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
static ArrayRef *
|
||||
_copyArrayRef(ArrayRef *from)
|
||||
{
|
||||
@@ -3206,6 +3207,9 @@ copyObject(void *from)
|
||||
case T_BooleanTest:
|
||||
retval = _copyBooleanTest(from);
|
||||
break;
|
||||
case T_ConstraintTest:
|
||||
retval = _copyConstraintTest(from);
|
||||
break;
|
||||
case T_FkConstraint:
|
||||
retval = _copyFkConstraint(from);
|
||||
break;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.156 2002/08/30 19:23:19 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.157 2002/08/31 22:10:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1924,6 +1924,20 @@ _equalBooleanTest(BooleanTest *a, BooleanTest *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalConstraintTest(ConstraintTest *a, ConstraintTest *b)
|
||||
{
|
||||
if (!equal(a->arg, b->arg))
|
||||
return false;
|
||||
if (a->testtype != b->testtype)
|
||||
return false;
|
||||
if (!equalstr(a->name, b->name))
|
||||
return false;
|
||||
if (!equal(a->check_expr, b->check_expr))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stuff from pg_list.h
|
||||
*/
|
||||
@@ -2380,6 +2394,9 @@ equal(void *a, void *b)
|
||||
case T_BooleanTest:
|
||||
retval = _equalBooleanTest(a, b);
|
||||
break;
|
||||
case T_ConstraintTest:
|
||||
retval = _equalConstraintTest(a, b);
|
||||
break;
|
||||
case T_FkConstraint:
|
||||
retval = _equalFkConstraint(a, b);
|
||||
break;
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.171 2002/08/30 19:23:19 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.172 2002/08/31 22:10:43 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every (plan) node in POSTGRES has an associated "out" routine which
|
||||
@@ -1471,7 +1471,6 @@ _outNullTest(StringInfo str, NullTest *node)
|
||||
{
|
||||
appendStringInfo(str, " NULLTEST :arg ");
|
||||
_outNode(str, node->arg);
|
||||
|
||||
appendStringInfo(str, " :nulltesttype %d ",
|
||||
(int) node->nulltesttype);
|
||||
}
|
||||
@@ -1484,11 +1483,25 @@ _outBooleanTest(StringInfo str, BooleanTest *node)
|
||||
{
|
||||
appendStringInfo(str, " BOOLEANTEST :arg ");
|
||||
_outNode(str, node->arg);
|
||||
|
||||
appendStringInfo(str, " :booltesttype %d ",
|
||||
(int) node->booltesttype);
|
||||
}
|
||||
|
||||
/*
|
||||
* ConstraintTest
|
||||
*/
|
||||
static void
|
||||
_outConstraintTest(StringInfo str, ConstraintTest *node)
|
||||
{
|
||||
appendStringInfo(str, " CONSTRAINTTEST :arg ");
|
||||
_outNode(str, node->arg);
|
||||
appendStringInfo(str, " :testtype %d :name ",
|
||||
(int) node->testtype);
|
||||
_outToken(str, node->name);
|
||||
appendStringInfo(str, " :check_expr ");
|
||||
_outNode(str, node->check_expr);
|
||||
}
|
||||
|
||||
/*
|
||||
* _outNode -
|
||||
* converts a Node into ascii string and append it to 'str'
|
||||
@@ -1750,6 +1763,9 @@ _outNode(StringInfo str, void *obj)
|
||||
case T_BooleanTest:
|
||||
_outBooleanTest(str, obj);
|
||||
break;
|
||||
case T_ConstraintTest:
|
||||
_outConstraintTest(str, obj);
|
||||
break;
|
||||
case T_FuncCall:
|
||||
_outFuncCall(str, obj);
|
||||
break;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.130 2002/08/30 19:23:19 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.131 2002/08/31 22:10:43 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Most of the read functions for plan nodes are tested. (In fact, they
|
||||
@@ -931,6 +931,38 @@ _readBooleanTest(void)
|
||||
return local_node;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _readConstraintTest
|
||||
*
|
||||
* ConstraintTest is a subclass of Node
|
||||
* ----------------
|
||||
*/
|
||||
static ConstraintTest *
|
||||
_readConstraintTest(void)
|
||||
{
|
||||
ConstraintTest *local_node;
|
||||
char *token;
|
||||
int length;
|
||||
|
||||
local_node = makeNode(ConstraintTest);
|
||||
|
||||
token = pg_strtok(&length); /* eat :arg */
|
||||
local_node->arg = nodeRead(true); /* now read it */
|
||||
|
||||
token = pg_strtok(&length); /* eat :testtype */
|
||||
token = pg_strtok(&length); /* get testtype */
|
||||
local_node->testtype = (ConstraintTestType) atoi(token);
|
||||
|
||||
token = pg_strtok(&length); /* get :name */
|
||||
token = pg_strtok(&length); /* now read it */
|
||||
local_node->name = nullable_string(token, length);
|
||||
|
||||
token = pg_strtok(&length); /* eat :check_expr */
|
||||
local_node->check_expr = nodeRead(true); /* now read it */
|
||||
|
||||
return local_node;
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* _readVar
|
||||
*
|
||||
@@ -2222,6 +2254,8 @@ parsePlanString(void)
|
||||
return_value = _readNullTest();
|
||||
else if (length == 11 && strncmp(token, "BOOLEANTEST", length) == 0)
|
||||
return_value = _readBooleanTest();
|
||||
else if (length == 14 && strncmp(token, "CONSTRAINTTEST", length) == 0)
|
||||
return_value = _readConstraintTest();
|
||||
else
|
||||
elog(ERROR, "badly formatted planstring \"%.10s\"...", token);
|
||||
|
||||
|
Reference in New Issue
Block a user