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

Commit1666970

Browse files
committed
I've fixed up the way domain constraints (not null and type length)
are managed as per request.Moved from merging with table attributes to applying themselves duringcoerce_type() and coerce_type_typmod.Regression tests altered to test the cast() scenarios.Rod Taylor
1 parent5af6e0a commit1666970

File tree

11 files changed

+263
-112
lines changed

11 files changed

+263
-112
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.18 2002/07/01 15:27:46 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.19 2002/07/06 20:16:35 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -48,7 +48,6 @@
4848
#include"utils/relcache.h"
4949

5050

51-
staticList*MergeDomainAttributes(List*schema);
5251
staticList*MergeAttributes(List*schema,List*supers,boolistemp,
5352
List**supOids,List**supconstr,bool*supHasOids);
5453
staticboolchange_varattnos_of_a_node(Node*node,constAttrNumber*newattno);
@@ -122,13 +121,6 @@ DefineRelation(CreateStmt *stmt, char relkind)
122121
aclcheck_error(aclresult,get_namespace_name(namespaceId));
123122
}
124123

125-
/*
126-
* Merge domain attributes into the known columns before processing table
127-
* inheritance. Otherwise we risk adding double constraints to a
128-
* domain-type column that's inherited.
129-
*/
130-
schema=MergeDomainAttributes(schema);
131-
132124
/*
133125
* Look up inheritance ancestors and generate relation schema,
134126
* including inherited attributes.
@@ -328,49 +320,6 @@ TruncateRelation(const RangeVar *relation)
328320
heap_truncate(relid);
329321
}
330322

331-
332-
/*
333-
* MergeDomainAttributes
334-
* Returns a new table schema with the constraints, types, and other
335-
* attributes of domains resolved for fields using a domain as
336-
* their type.
337-
*/
338-
staticList*
339-
MergeDomainAttributes(List*schema)
340-
{
341-
List*entry;
342-
343-
/*
344-
* Loop through the table elements supplied. These should
345-
* never include inherited domains else they'll be
346-
* double (or more) processed.
347-
*/
348-
foreach(entry,schema)
349-
{
350-
ColumnDef*coldef=lfirst(entry);
351-
HeapTupletuple;
352-
Form_pg_typetypeTup;
353-
354-
tuple=typenameType(coldef->typename);
355-
typeTup= (Form_pg_type)GETSTRUCT(tuple);
356-
357-
if (typeTup->typtype=='d')
358-
{
359-
/* Force the column to have the correct typmod. */
360-
coldef->typename->typmod=typeTup->typtypmod;
361-
/* XXX more to do here? */
362-
}
363-
364-
/* Enforce type NOT NULL || column definition NOT NULL -> NOT NULL */
365-
/* Currently only used for domains, but could be valid for all */
366-
coldef->is_not_null |=typeTup->typnotnull;
367-
368-
ReleaseSysCache(tuple);
369-
}
370-
371-
returnschema;
372-
}
373-
374323
/*----------
375324
* MergeAttributes
376325
*Returns new schema given initial schema and superclasses.

‎src/backend/executor/execQual.c

Lines changed: 46 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/executor/execQual.c,v 1.96 2002/07/0416:44:08 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.97 2002/07/06 20:16:35 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -66,6 +66,8 @@ static Datum ExecEvalNullTest(NullTest *ntest, ExprContext *econtext,
6666
bool*isNull,ExprDoneCond*isDone);
6767
staticDatumExecEvalBooleanTest(BooleanTest*btest,ExprContext*econtext,
6868
bool*isNull,ExprDoneCond*isDone);
69+
staticDatumExecEvalConstraint(Constraint*constraint,ExprContext*econtext,
70+
bool*isNull,ExprDoneCond*isDone);
6971

7072

7173
/*----------
@@ -1226,6 +1228,43 @@ ExecEvalNullTest(NullTest *ntest,
12261228
}
12271229
}
12281230

1231+
/*
1232+
* ExecEvalConstraint
1233+
*
1234+
* Test the constraint against the data provided. If the data fits
1235+
* within the constraint specifications, pass it through (return the
1236+
* datum) otherwise throw an error.
1237+
*/
1238+
staticDatum
1239+
ExecEvalConstraint(Constraint*constraint,ExprContext*econtext,
1240+
bool*isNull,ExprDoneCond*isDone)
1241+
{
1242+
Datumresult;
1243+
1244+
result=ExecEvalExpr(constraint->raw_expr,econtext,isNull,isDone);
1245+
1246+
/* Test for the constraint type */
1247+
switch(constraint->contype)
1248+
{
1249+
caseCONSTR_NOTNULL:
1250+
if (*isNull)
1251+
{
1252+
elog(ERROR,"Domain %s does not allow NULL values",constraint->name);
1253+
}
1254+
break;
1255+
caseCONSTR_CHECK:
1256+
1257+
elog(ERROR,"ExecEvalConstraint: Domain CHECK Constraints not yet implemented");
1258+
break;
1259+
default:
1260+
elog(ERROR,"ExecEvalConstraint: Constraint type unknown");
1261+
break;
1262+
}
1263+
1264+
/* If all has gone well (constraint did not fail) return the datum */
1265+
returnresult;
1266+
}
1267+
12291268
/* ----------------------------------------------------------------
12301269
*ExecEvalBooleanTest
12311270
*
@@ -1473,6 +1512,12 @@ ExecEvalExpr(Node *expression,
14731512
isNull,
14741513
isDone);
14751514
break;
1515+
caseT_Constraint:
1516+
retDatum=ExecEvalConstraint((Constraint*)expression,
1517+
econtext,
1518+
isNull,
1519+
isDone);
1520+
break;
14761521
caseT_CaseExpr:
14771522
retDatum=ExecEvalCase((CaseExpr*)expression,
14781523
econtext,

‎src/backend/optimizer/util/clauses.c

Lines changed: 17 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/optimizer/util/clauses.c,v 1.102 2002/07/04 15:23:58 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.103 2002/07/06 20:16:35 momjian Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -1882,6 +1882,8 @@ expression_tree_walker(Node *node,
18821882
return true;
18831883
}
18841884
break;
1885+
caseT_Constraint:
1886+
returnwalker(((Constraint*)node)->raw_expr,context);
18851887
caseT_NullTest:
18861888
returnwalker(((NullTest*)node)->arg,context);
18871889
caseT_BooleanTest:
@@ -2236,6 +2238,20 @@ expression_tree_mutator(Node *node,
22362238
return (Node*)newnode;
22372239
}
22382240
break;
2241+
caseT_Constraint:
2242+
{
2243+
/*
2244+
* Used for confirming domains. Only needed fields
2245+
* within the executor are the name, raw expression
2246+
* and constraint type.
2247+
*/
2248+
Constraint*con= (Constraint*)node;
2249+
Constraint*newnode;
2250+
2251+
FLATCOPY(newnode,con,Constraint);
2252+
MUTATE(newnode->raw_expr,con->raw_expr,Node*);
2253+
return (Node*)newnode;
2254+
}
22392255
caseT_NullTest:
22402256
{
22412257
NullTest*ntest= (NullTest*)node;

‎src/backend/parser/gram.y

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.336 2002/07/04 15:23:59 thomas Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.337 2002/07/06 20:16:35 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -6968,24 +6968,16 @@ static Node *
69686968
makeTypeCast(Node *arg, TypeName *typename)
69696969
{
69706970
/*
6971-
* If arg is an A_Const, just stick the typename into the
6972-
* field reserved for it --- unless there's something there already!
6973-
* (We don't want to collapse x::type1::type2 into just x::type2.)
6974-
* Otherwise, generate a TypeCast node.
6971+
* Simply generate a TypeCast node.
6972+
*
6973+
* Earlier we would determine whether an A_Const would
6974+
* be acceptable, however Domains require coerce_type()
6975+
* to process them -- applying constraints as required.
69756976
*/
6976-
if (IsA(arg, A_Const) &&
6977-
((A_Const *) arg)->typename == NULL)
6978-
{
6979-
((A_Const *) arg)->typename = typename;
6980-
return arg;
6981-
}
6982-
else
6983-
{
6984-
TypeCast *n = makeNode(TypeCast);
6985-
n->arg = arg;
6986-
n->typename = typename;
6987-
return (Node *) n;
6988-
}
6977+
TypeCast *n = makeNode(TypeCast);
6978+
n->arg = arg;
6979+
n->typename = typename;
6980+
return (Node *) n;
69896981
}
69906982

69916983
static Node *

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp