Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit845a6c3

Browse files
committed
Code review for domain-constraints patch. Use a new ConstraintTest node
type for runtime constraint checks, instead of misusing the parse-timeConstraint node for the purpose. Fix some damage introduced into typecoercion logic; in particular ensure that a coerced expression tree willread out the correct result type when inspected (patch had broken someRelabelType cases). Enforce domain NOT NULL constraints against columnsthat are omitted from an INSERT.
1 parent1440acd commit845a6c3

File tree

19 files changed

+334
-175
lines changed

19 files changed

+334
-175
lines changed

‎src/backend/executor/execQual.c

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.105 2002/08/3119:10:08 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.106 2002/08/3122:10:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -69,8 +69,9 @@ static Datum ExecEvalNullTest(NullTest *ntest, ExprContext *econtext,
6969
bool*isNull,ExprDoneCond*isDone);
7070
staticDatumExecEvalBooleanTest(BooleanTest*btest,ExprContext*econtext,
7171
bool*isNull,ExprDoneCond*isDone);
72-
staticDatumExecEvalConstraint(Constraint*constraint,ExprContext*econtext,
73-
bool*isNull,ExprDoneCond*isDone);
72+
staticDatumExecEvalConstraintTest(ConstraintTest*constraint,
73+
ExprContext*econtext,
74+
bool*isNull,ExprDoneCond*isDone);
7475

7576

7677
/*----------
@@ -1465,43 +1466,6 @@ ExecEvalNullTest(NullTest *ntest,
14651466
}
14661467
}
14671468

1468-
/*
1469-
* ExecEvalConstraint
1470-
*
1471-
* Test the constraint against the data provided. If the data fits
1472-
* within the constraint specifications, pass it through (return the
1473-
* datum) otherwise throw an error.
1474-
*/
1475-
staticDatum
1476-
ExecEvalConstraint(Constraint*constraint,ExprContext*econtext,
1477-
bool*isNull,ExprDoneCond*isDone)
1478-
{
1479-
Datumresult;
1480-
1481-
result=ExecEvalExpr(constraint->raw_expr,econtext,isNull,isDone);
1482-
1483-
/* Test for the constraint type */
1484-
switch(constraint->contype)
1485-
{
1486-
caseCONSTR_NOTNULL:
1487-
if (*isNull)
1488-
{
1489-
elog(ERROR,"Domain %s does not allow NULL values",constraint->name);
1490-
}
1491-
break;
1492-
caseCONSTR_CHECK:
1493-
1494-
elog(ERROR,"ExecEvalConstraint: Domain CHECK Constraints not yet implemented");
1495-
break;
1496-
default:
1497-
elog(ERROR,"ExecEvalConstraint: Constraint type unknown");
1498-
break;
1499-
}
1500-
1501-
/* If all has gone well (constraint did not fail) return the datum */
1502-
returnresult;
1503-
}
1504-
15051469
/* ----------------------------------------------------------------
15061470
*ExecEvalBooleanTest
15071471
*
@@ -1582,6 +1546,41 @@ ExecEvalBooleanTest(BooleanTest *btest,
15821546
}
15831547
}
15841548

1549+
/*
1550+
* ExecEvalConstraintTest
1551+
*
1552+
* Test the constraint against the data provided. If the data fits
1553+
* within the constraint specifications, pass it through (return the
1554+
* datum) otherwise throw an error.
1555+
*/
1556+
staticDatum
1557+
ExecEvalConstraintTest(ConstraintTest*constraint,ExprContext*econtext,
1558+
bool*isNull,ExprDoneCond*isDone)
1559+
{
1560+
Datumresult;
1561+
1562+
result=ExecEvalExpr(constraint->arg,econtext,isNull,isDone);
1563+
1564+
switch (constraint->testtype)
1565+
{
1566+
caseCONSTR_TEST_NOTNULL:
1567+
if (*isNull)
1568+
elog(ERROR,"Domain %s does not allow NULL values",
1569+
constraint->name);
1570+
break;
1571+
caseCONSTR_TEST_CHECK:
1572+
/* TODO: Add CHECK Constraints to domains */
1573+
elog(ERROR,"Domain CHECK Constraints not yet implemented");
1574+
break;
1575+
default:
1576+
elog(ERROR,"ExecEvalConstraintTest: Constraint type unknown");
1577+
break;
1578+
}
1579+
1580+
/* If all has gone well (constraint did not fail) return the datum */
1581+
returnresult;
1582+
}
1583+
15851584
/* ----------------------------------------------------------------
15861585
*ExecEvalFieldSelect
15871586
*
@@ -1749,12 +1748,6 @@ ExecEvalExpr(Node *expression,
17491748
isNull,
17501749
isDone);
17511750
break;
1752-
caseT_Constraint:
1753-
retDatum=ExecEvalConstraint((Constraint*)expression,
1754-
econtext,
1755-
isNull,
1756-
isDone);
1757-
break;
17581751
caseT_CaseExpr:
17591752
retDatum=ExecEvalCase((CaseExpr*)expression,
17601753
econtext,
@@ -1773,6 +1766,12 @@ ExecEvalExpr(Node *expression,
17731766
isNull,
17741767
isDone);
17751768
break;
1769+
caseT_ConstraintTest:
1770+
retDatum=ExecEvalConstraintTest((ConstraintTest*)expression,
1771+
econtext,
1772+
isNull,
1773+
isDone);
1774+
break;
17761775

17771776
default:
17781777
elog(ERROR,"ExecEvalExpr: unknown expression type %d",

‎src/backend/nodes/copyfuncs.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.208 2002/08/30 19:23:19 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.209 2002/08/31 22:10:43 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -973,10 +973,6 @@ _copyJoinExpr(JoinExpr *from)
973973
returnnewnode;
974974
}
975975

976-
/* ----------------
977-
*_copyCaseExpr
978-
* ----------------
979-
*/
980976
staticCaseExpr*
981977
_copyCaseExpr(CaseExpr*from)
982978
{
@@ -994,10 +990,6 @@ _copyCaseExpr(CaseExpr *from)
994990
returnnewnode;
995991
}
996992

997-
/* ----------------
998-
*_copyCaseWhen
999-
* ----------------
1000-
*/
1001993
staticCaseWhen*
1002994
_copyCaseWhen(CaseWhen*from)
1003995
{
@@ -1012,10 +1004,6 @@ _copyCaseWhen(CaseWhen *from)
10121004
returnnewnode;
10131005
}
10141006

1015-
/* ----------------
1016-
*_copyNullTest
1017-
* ----------------
1018-
*/
10191007
staticNullTest*
10201008
_copyNullTest(NullTest*from)
10211009
{
@@ -1030,10 +1018,6 @@ _copyNullTest(NullTest *from)
10301018
returnnewnode;
10311019
}
10321020

1033-
/* ----------------
1034-
*_copyBooleanTest
1035-
* ----------------
1036-
*/
10371021
staticBooleanTest*
10381022
_copyBooleanTest(BooleanTest*from)
10391023
{
@@ -1048,6 +1032,23 @@ _copyBooleanTest(BooleanTest *from)
10481032
returnnewnode;
10491033
}
10501034

1035+
staticConstraintTest*
1036+
_copyConstraintTest(ConstraintTest*from)
1037+
{
1038+
ConstraintTest*newnode=makeNode(ConstraintTest);
1039+
1040+
/*
1041+
* copy remainder of node
1042+
*/
1043+
Node_Copy(from,newnode,arg);
1044+
newnode->testtype=from->testtype;
1045+
if (from->name)
1046+
newnode->name=pstrdup(from->name);
1047+
Node_Copy(from,newnode,check_expr);
1048+
1049+
returnnewnode;
1050+
}
1051+
10511052
staticArrayRef*
10521053
_copyArrayRef(ArrayRef*from)
10531054
{
@@ -3206,6 +3207,9 @@ copyObject(void *from)
32063207
caseT_BooleanTest:
32073208
retval=_copyBooleanTest(from);
32083209
break;
3210+
caseT_ConstraintTest:
3211+
retval=_copyConstraintTest(from);
3212+
break;
32093213
caseT_FkConstraint:
32103214
retval=_copyFkConstraint(from);
32113215
break;

‎src/backend/nodes/equalfuncs.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.156 2002/08/30 19:23:19 tgl Exp $
23+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.157 2002/08/31 22:10:43 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -1924,6 +1924,20 @@ _equalBooleanTest(BooleanTest *a, BooleanTest *b)
19241924
return true;
19251925
}
19261926

1927+
staticbool
1928+
_equalConstraintTest(ConstraintTest*a,ConstraintTest*b)
1929+
{
1930+
if (!equal(a->arg,b->arg))
1931+
return false;
1932+
if (a->testtype!=b->testtype)
1933+
return false;
1934+
if (!equalstr(a->name,b->name))
1935+
return false;
1936+
if (!equal(a->check_expr,b->check_expr))
1937+
return false;
1938+
return true;
1939+
}
1940+
19271941
/*
19281942
* Stuff from pg_list.h
19291943
*/
@@ -2380,6 +2394,9 @@ equal(void *a, void *b)
23802394
caseT_BooleanTest:
23812395
retval=_equalBooleanTest(a,b);
23822396
break;
2397+
caseT_ConstraintTest:
2398+
retval=_equalConstraintTest(a,b);
2399+
break;
23832400
caseT_FkConstraint:
23842401
retval=_equalFkConstraint(a,b);
23852402
break;

‎src/backend/nodes/outfuncs.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
*$Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.171 2002/08/30 19:23:19 tgl Exp $
8+
*$Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.172 2002/08/31 22:10:43 tgl Exp $
99
*
1010
* NOTES
1111
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -1471,7 +1471,6 @@ _outNullTest(StringInfo str, NullTest *node)
14711471
{
14721472
appendStringInfo(str," NULLTEST :arg ");
14731473
_outNode(str,node->arg);
1474-
14751474
appendStringInfo(str," :nulltesttype %d ",
14761475
(int)node->nulltesttype);
14771476
}
@@ -1484,11 +1483,25 @@ _outBooleanTest(StringInfo str, BooleanTest *node)
14841483
{
14851484
appendStringInfo(str," BOOLEANTEST :arg ");
14861485
_outNode(str,node->arg);
1487-
14881486
appendStringInfo(str," :booltesttype %d ",
14891487
(int)node->booltesttype);
14901488
}
14911489

1490+
/*
1491+
*ConstraintTest
1492+
*/
1493+
staticvoid
1494+
_outConstraintTest(StringInfostr,ConstraintTest*node)
1495+
{
1496+
appendStringInfo(str," CONSTRAINTTEST :arg ");
1497+
_outNode(str,node->arg);
1498+
appendStringInfo(str," :testtype %d :name ",
1499+
(int)node->testtype);
1500+
_outToken(str,node->name);
1501+
appendStringInfo(str," :check_expr ");
1502+
_outNode(str,node->check_expr);
1503+
}
1504+
14921505
/*
14931506
* _outNode -
14941507
* converts a Node into ascii string and append it to 'str'
@@ -1750,6 +1763,9 @@ _outNode(StringInfo str, void *obj)
17501763
caseT_BooleanTest:
17511764
_outBooleanTest(str,obj);
17521765
break;
1766+
caseT_ConstraintTest:
1767+
_outConstraintTest(str,obj);
1768+
break;
17531769
caseT_FuncCall:
17541770
_outFuncCall(str,obj);
17551771
break;

‎src/backend/nodes/readfuncs.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.130 2002/08/30 19:23:19 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.131 2002/08/31 22:10:43 tgl Exp $
1212
*
1313
* NOTES
1414
* Most of the read functions for plan nodes are tested. (In fact, they
@@ -931,6 +931,38 @@ _readBooleanTest(void)
931931
returnlocal_node;
932932
}
933933

934+
/* ----------------
935+
*_readConstraintTest
936+
*
937+
*ConstraintTest is a subclass of Node
938+
* ----------------
939+
*/
940+
staticConstraintTest*
941+
_readConstraintTest(void)
942+
{
943+
ConstraintTest*local_node;
944+
char*token;
945+
intlength;
946+
947+
local_node=makeNode(ConstraintTest);
948+
949+
token=pg_strtok(&length);/* eat :arg */
950+
local_node->arg=nodeRead(true);/* now read it */
951+
952+
token=pg_strtok(&length);/* eat :testtype */
953+
token=pg_strtok(&length);/* get testtype */
954+
local_node->testtype= (ConstraintTestType)atoi(token);
955+
956+
token=pg_strtok(&length);/* get :name */
957+
token=pg_strtok(&length);/* now read it */
958+
local_node->name=nullable_string(token,length);
959+
960+
token=pg_strtok(&length);/* eat :check_expr */
961+
local_node->check_expr=nodeRead(true);/* now read it */
962+
963+
returnlocal_node;
964+
}
965+
934966
/* ----------------
935967
*_readVar
936968
*
@@ -2222,6 +2254,8 @@ parsePlanString(void)
22222254
return_value=_readNullTest();
22232255
elseif (length==11&&strncmp(token,"BOOLEANTEST",length)==0)
22242256
return_value=_readBooleanTest();
2257+
elseif (length==14&&strncmp(token,"CONSTRAINTTEST",length)==0)
2258+
return_value=_readConstraintTest();
22252259
else
22262260
elog(ERROR,"badly formatted planstring \"%.10s\"...",token);
22272261

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp