Commit 6ebc90b0 authored by Tom Lane's avatar Tom Lane

Remove Ident nodetype in favor of using String nodes; this fixes some

latent wrong-struct-type bugs and makes the coding style more uniform,
since the majority of places working with lists of column names were
already using Strings not Idents.  While at it, remove vestigial
support for Stream node type, and otherwise-unreferenced nodes.h entries
for T_TupleCount and T_BaseNode.
NB: full recompile is recommended due to changes of Node type numbers.
This shouldn't force an initdb though.
parent 10b374ae
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.164 2002/08/19 00:40:14 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.165 2002/08/19 15:08:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1513,7 +1513,7 @@ CopyGetAttnums(Relation rel, List *attnamelist) ...@@ -1513,7 +1513,7 @@ CopyGetAttnums(Relation rel, List *attnamelist)
foreach(l, attnamelist) foreach(l, attnamelist)
{ {
char *name = ((Ident *) lfirst(l))->name; char *name = strVal(lfirst(l));
int attnum; int attnum;
/* Lookup column name, elog on failure */ /* Lookup column name, elog on failure */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.29 2002/08/15 16:36:02 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.30 2002/08/19 15:08:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2677,17 +2677,17 @@ validateForeignKeyConstraint(FkConstraint *fkconstraint, ...@@ -2677,17 +2677,17 @@ validateForeignKeyConstraint(FkConstraint *fkconstraint,
count = 4; count = 4;
foreach(list, fkconstraint->fk_attrs) foreach(list, fkconstraint->fk_attrs)
{ {
Ident *fk_at = lfirst(list); char *fk_at = strVal(lfirst(list));
trig.tgargs[count] = fk_at->name; trig.tgargs[count] = fk_at;
count += 2; count += 2;
} }
count = 5; count = 5;
foreach(list, fkconstraint->pk_attrs) foreach(list, fkconstraint->pk_attrs)
{ {
Ident *pk_at = lfirst(list); char *pk_at = strVal(lfirst(list));
trig.tgargs[count] = pk_at->name; trig.tgargs[count] = pk_at;
count += 2; count += 2;
} }
trig.tgnargs = count - 1; trig.tgnargs = count - 1;
...@@ -2746,13 +2746,13 @@ createForeignKeyConstraint(Relation rel, Relation pkrel, ...@@ -2746,13 +2746,13 @@ createForeignKeyConstraint(Relation rel, Relation pkrel,
i = 0; i = 0;
foreach(l, fkconstraint->fk_attrs) foreach(l, fkconstraint->fk_attrs)
{ {
Ident *id = (Ident *) lfirst(l); char *id = strVal(lfirst(l));
AttrNumber attno; AttrNumber attno;
attno = get_attnum(RelationGetRelid(rel), id->name); attno = get_attnum(RelationGetRelid(rel), id);
if (attno == InvalidAttrNumber) if (attno == InvalidAttrNumber)
elog(ERROR, "Relation \"%s\" has no column \"%s\"", elog(ERROR, "Relation \"%s\" has no column \"%s\"",
RelationGetRelationName(rel), id->name); RelationGetRelationName(rel), id);
fkattr[i++] = attno; fkattr[i++] = attno;
} }
...@@ -2762,13 +2762,13 @@ createForeignKeyConstraint(Relation rel, Relation pkrel, ...@@ -2762,13 +2762,13 @@ createForeignKeyConstraint(Relation rel, Relation pkrel,
i = 0; i = 0;
foreach(l, fkconstraint->pk_attrs) foreach(l, fkconstraint->pk_attrs)
{ {
Ident *id = (Ident *) lfirst(l); char *id = strVal(lfirst(l));
AttrNumber attno; AttrNumber attno;
attno = get_attnum(RelationGetRelid(pkrel), id->name); attno = get_attnum(RelationGetRelid(pkrel), id);
if (attno == InvalidAttrNumber) if (attno == InvalidAttrNumber)
elog(ERROR, "Relation \"%s\" has no column \"%s\"", elog(ERROR, "Relation \"%s\" has no column \"%s\"",
RelationGetRelationName(pkrel), id->name); RelationGetRelationName(pkrel), id);
pkattr[i++] = attno; pkattr[i++] = attno;
} }
...@@ -2804,7 +2804,6 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, ...@@ -2804,7 +2804,6 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint,
CreateTrigStmt *fk_trigger; CreateTrigStmt *fk_trigger;
List *fk_attr; List *fk_attr;
List *pk_attr; List *pk_attr;
Ident *id;
ObjectAddress trigobj, ObjectAddress trigobj,
constrobj; constrobj;
...@@ -2867,12 +2866,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, ...@@ -2867,12 +2866,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint,
while (fk_attr != NIL) while (fk_attr != NIL)
{ {
id = (Ident *) lfirst(fk_attr); fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr));
fk_trigger->args = lappend(fk_trigger->args, makeString(id->name)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, makeString(id->name));
fk_attr = lnext(fk_attr); fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr); pk_attr = lnext(pk_attr);
} }
...@@ -2942,12 +2937,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, ...@@ -2942,12 +2937,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint,
pk_attr = fkconstraint->pk_attrs; pk_attr = fkconstraint->pk_attrs;
while (fk_attr != NIL) while (fk_attr != NIL)
{ {
id = (Ident *) lfirst(fk_attr); fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr));
fk_trigger->args = lappend(fk_trigger->args, makeString(id->name)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, makeString(id->name));
fk_attr = lnext(fk_attr); fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr); pk_attr = lnext(pk_attr);
} }
...@@ -3017,12 +3008,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, ...@@ -3017,12 +3008,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint,
pk_attr = fkconstraint->pk_attrs; pk_attr = fkconstraint->pk_attrs;
while (fk_attr != NIL) while (fk_attr != NIL)
{ {
id = (Ident *) lfirst(fk_attr); fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr));
fk_trigger->args = lappend(fk_trigger->args, makeString(id->name)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr));
id = (Ident *) lfirst(pk_attr);
fk_trigger->args = lappend(fk_trigger->args, makeString(id->name));
fk_attr = lnext(fk_attr); fk_attr = lnext(fk_attr);
pk_attr = lnext(pk_attr); pk_attr = lnext(pk_attr);
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.203 2002/08/19 00:40:14 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.204 2002/08/19 15:08:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1435,28 +1435,6 @@ _copyJoinInfo(JoinInfo *from) ...@@ -1435,28 +1435,6 @@ _copyJoinInfo(JoinInfo *from)
return newnode; return newnode;
} }
static Stream *
_copyStream(Stream *from)
{
Stream *newnode = makeNode(Stream);
newnode->pathptr = from->pathptr;
newnode->cinfo = from->cinfo;
newnode->clausetype = from->clausetype;
newnode->upstream = (StreamPtr) NULL; /* only copy nodes
* downwards! */
Node_Copy(from, newnode, downstream);
if (newnode->downstream)
((Stream *) newnode->downstream)->upstream = (Stream *) newnode;
newnode->groupup = from->groupup;
newnode->groupcost = from->groupcost;
newnode->groupsel = from->groupsel;
return newnode;
}
/* **************************************************************** /* ****************************************************************
* parsenodes.h copy functions * parsenodes.h copy functions
* **************************************************************** * ****************************************************************
...@@ -1593,16 +1571,6 @@ _copyAConst(A_Const *from) ...@@ -1593,16 +1571,6 @@ _copyAConst(A_Const *from)
return newnode; return newnode;
} }
static Ident *
_copyIdent(Ident *from)
{
Ident *newnode = makeNode(Ident);
newnode->name = pstrdup(from->name);
return newnode;
}
static FuncCall * static FuncCall *
_copyFuncCall(FuncCall *from) _copyFuncCall(FuncCall *from)
{ {
...@@ -2890,9 +2858,6 @@ copyObject(void *from) ...@@ -2890,9 +2858,6 @@ copyObject(void *from)
case T_JoinInfo: case T_JoinInfo:
retval = _copyJoinInfo(from); retval = _copyJoinInfo(from);
break; break;
case T_Stream:
retval = _copyStream(from);
break;
case T_IndexOptInfo: case T_IndexOptInfo:
retval = _copyIndexOptInfo(from); retval = _copyIndexOptInfo(from);
break; break;
...@@ -3131,9 +3096,6 @@ copyObject(void *from) ...@@ -3131,9 +3096,6 @@ copyObject(void *from)
case T_A_Const: case T_A_Const:
retval = _copyAConst(from); retval = _copyAConst(from);
break; break;
case T_Ident:
retval = _copyIdent(from);
break;
case T_FuncCall: case T_FuncCall:
retval = _copyFuncCall(from); retval = _copyFuncCall(from);
break; break;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.152 2002/08/19 00:40:14 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.153 2002/08/19 15:08:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -543,26 +543,6 @@ _equalJoinInfo(JoinInfo *a, JoinInfo *b) ...@@ -543,26 +543,6 @@ _equalJoinInfo(JoinInfo *a, JoinInfo *b)
return true; return true;
} }
static bool
_equalStream(Stream *a, Stream *b)
{
if (a->clausetype != b->clausetype)
return false;
if (a->groupup != b->groupup)
return false;
if (a->groupcost != b->groupcost)
return false;
if (a->groupsel != b->groupsel)
return false;
if (!equal(a->pathptr, b->pathptr))
return false;
if (!equal(a->cinfo, b->cinfo))
return false;
if (!equal(a->upstream, b->upstream))
return false;
return equal(a->downstream, b->downstream);
}
/* /*
* Stuff from parsenodes.h * Stuff from parsenodes.h
*/ */
...@@ -1556,15 +1536,6 @@ _equalAConst(A_Const *a, A_Const *b) ...@@ -1556,15 +1536,6 @@ _equalAConst(A_Const *a, A_Const *b)
return true; return true;
} }
static bool
_equalIdent(Ident *a, Ident *b)
{
if (!equalstr(a->name, b->name))
return false;
return true;
}
static bool static bool
_equalFuncCall(FuncCall *a, FuncCall *b) _equalFuncCall(FuncCall *a, FuncCall *b)
{ {
...@@ -2045,9 +2016,6 @@ equal(void *a, void *b) ...@@ -2045,9 +2016,6 @@ equal(void *a, void *b)
case T_JoinInfo: case T_JoinInfo:
retval = _equalJoinInfo(a, b); retval = _equalJoinInfo(a, b);
break; break;
case T_Stream:
retval = _equalStream(a, b);
break;
case T_TidPath: case T_TidPath:
retval = _equalTidPath(a, b); retval = _equalTidPath(a, b);
break; break;
...@@ -2290,9 +2258,6 @@ equal(void *a, void *b) ...@@ -2290,9 +2258,6 @@ equal(void *a, void *b)
case T_A_Const: case T_A_Const:
retval = _equalAConst(a, b); retval = _equalAConst(a, b);
break; break;
case T_Ident:
retval = _equalIdent(a, b);
break;
case T_FuncCall: case T_FuncCall:
retval = _equalFuncCall(a, b); retval = _equalFuncCall(a, b);
break; break;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.167 2002/08/10 20:44:48 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.168 2002/08/19 15:08:46 tgl Exp $
* *
* NOTES * NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which * Every (plan) node in POSTGRES has an associated "out" routine which
...@@ -1257,24 +1257,6 @@ _outDatum(StringInfo str, Datum value, int typlen, bool typbyval) ...@@ -1257,24 +1257,6 @@ _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
} }
} }
static void
_outStream(StringInfo str, Stream *node)
{
appendStringInfo(str,
" STREAM :pathptr @ %p :cinfo @ %p :clausetype %p :upstream @ %p ",
node->pathptr,
node->cinfo,
node->clausetype,
node->upstream);
appendStringInfo(str,
" :downstream @ %p :groupup %d :groupcost %f :groupsel %f ",
node->downstream,
node->groupup,
node->groupcost,
node->groupsel);
}
static void static void
_outAExpr(StringInfo str, A_Expr *node) _outAExpr(StringInfo str, A_Expr *node)
{ {
...@@ -1371,13 +1353,6 @@ _outParamRef(StringInfo str, ParamRef *node) ...@@ -1371,13 +1353,6 @@ _outParamRef(StringInfo str, ParamRef *node)
_outNode(str, node->indirection); _outNode(str, node->indirection);
} }
static void
_outIdent(StringInfo str, Ident *node)
{
appendStringInfo(str, " IDENT ");
_outToken(str, node->name);
}
static void static void
_outAConst(StringInfo str, A_Const *node) _outAConst(StringInfo str, A_Const *node)
{ {
...@@ -1736,9 +1711,6 @@ _outNode(StringInfo str, void *obj) ...@@ -1736,9 +1711,6 @@ _outNode(StringInfo str, void *obj)
case T_JoinInfo: case T_JoinInfo:
_outJoinInfo(str, obj); _outJoinInfo(str, obj);
break; break;
case T_Stream:
_outStream(str, obj);
break;
case T_A_Expr: case T_A_Expr:
_outAExpr(str, obj); _outAExpr(str, obj);
break; break;
...@@ -1751,9 +1723,6 @@ _outNode(StringInfo str, void *obj) ...@@ -1751,9 +1723,6 @@ _outNode(StringInfo str, void *obj)
case T_ParamRef: case T_ParamRef:
_outParamRef(str, obj); _outParamRef(str, obj);
break; break;
case T_Ident:
_outIdent(str, obj);
break;
case T_A_Const: case T_A_Const:
_outAConst(str, obj); _outAConst(str, obj);
break; break;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.240 2002/08/02 18:15:06 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.241 2002/08/19 15:08:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -238,17 +238,14 @@ transformStmt(ParseState *pstate, Node *parseTree, ...@@ -238,17 +238,14 @@ transformStmt(ParseState *pstate, Node *parseTree,
{ {
TargetEntry *te = (TargetEntry *) lfirst(targetList); TargetEntry *te = (TargetEntry *) lfirst(targetList);
Resdom *rd; Resdom *rd;
Ident *id;
Assert(IsA(te, TargetEntry)); Assert(IsA(te, TargetEntry));
rd = te->resdom; rd = te->resdom;
Assert(IsA(rd, Resdom)); Assert(IsA(rd, Resdom));
if (rd->resjunk) /* junk columns don't get /* junk columns don't get aliases */
* aliases */ if (rd->resjunk)
continue; continue;
id = (Ident *) lfirst(aliaslist); rd->resname = pstrdup(strVal(lfirst(aliaslist)));
Assert(IsA(id, Ident));
rd->resname = pstrdup(id->name);
aliaslist = lnext(aliaslist); aliaslist = lnext(aliaslist);
if (aliaslist == NIL) if (aliaslist == NIL)
break; /* done assigning aliases */ break; /* done assigning aliases */
...@@ -788,7 +785,6 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, ...@@ -788,7 +785,6 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
bool saw_nullable; bool saw_nullable;
Constraint *constraint; Constraint *constraint;
List *clist; List *clist;
Ident *key;
cxt->columns = lappend(cxt->columns, column); cxt->columns = lappend(cxt->columns, column);
...@@ -901,17 +897,14 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, ...@@ -901,17 +897,14 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
/* /*
* If this column constraint is a FOREIGN KEY constraint, then we * If this column constraint is a FOREIGN KEY constraint, then we
* fill in the current attributes name and throw it into the list * fill in the current attribute's name and throw it into the list
* of FK constraints to be processed later. * of FK constraints to be processed later.
*/ */
if (IsA(constraint, FkConstraint)) if (IsA(constraint, FkConstraint))
{ {
FkConstraint *fkconstraint = (FkConstraint *) constraint; FkConstraint *fkconstraint = (FkConstraint *) constraint;
Ident *id = makeNode(Ident);
id->name = column->colname;
fkconstraint->fk_attrs = makeList1(id);
fkconstraint->fk_attrs = makeList1(makeString(column->colname));
cxt->fkconstraints = lappend(cxt->fkconstraints, fkconstraint); cxt->fkconstraints = lappend(cxt->fkconstraints, fkconstraint);
continue; continue;
} }
...@@ -923,7 +916,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, ...@@ -923,7 +916,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
case CONSTR_NULL: case CONSTR_NULL:
if (saw_nullable && column->is_not_null) if (saw_nullable && column->is_not_null)
elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'", elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'",
cxt->stmtType, (cxt->relation)->relname, column->colname); cxt->stmtType, cxt->relation->relname, column->colname);
column->is_not_null = FALSE; column->is_not_null = FALSE;
saw_nullable = true; saw_nullable = true;
break; break;
...@@ -931,7 +924,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, ...@@ -931,7 +924,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
case CONSTR_NOTNULL: case CONSTR_NOTNULL:
if (saw_nullable && !column->is_not_null) if (saw_nullable && !column->is_not_null)
elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'", elog(ERROR, "%s/(NOT) NULL conflicting declaration for '%s.%s'",
cxt->stmtType, (cxt->relation)->relname, column->colname); cxt->stmtType, cxt->relation->relname, column->colname);
column->is_not_null = TRUE; column->is_not_null = TRUE;
saw_nullable = true; saw_nullable = true;
break; break;
...@@ -939,42 +932,34 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, ...@@ -939,42 +932,34 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
case CONSTR_DEFAULT: case CONSTR_DEFAULT:
if (column->raw_default != NULL) if (column->raw_default != NULL)
elog(ERROR, "%s/DEFAULT multiple values specified for '%s.%s'", elog(ERROR, "%s/DEFAULT multiple values specified for '%s.%s'",
cxt->stmtType, (cxt->relation)->relname, column->colname); cxt->stmtType, cxt->relation->relname, column->colname);
column->raw_default = constraint->raw_expr; column->raw_default = constraint->raw_expr;
Assert(constraint->cooked_expr == NULL); Assert(constraint->cooked_expr == NULL);
break; break;
case CONSTR_PRIMARY: case CONSTR_PRIMARY:
if (constraint->name == NULL) if (constraint->name == NULL)
constraint->name = makeObjectName((cxt->relation)->relname, constraint->name = makeObjectName(cxt->relation->relname,
NULL, NULL,
"pkey"); "pkey");
if (constraint->keys == NIL) if (constraint->keys == NIL)
{ constraint->keys = makeList1(makeString(column->colname));
key = makeNode(Ident);
key->name = pstrdup(column->colname);
constraint->keys = makeList1(key);
}
cxt->ixconstraints = lappend(cxt->ixconstraints, constraint); cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
break; break;
case CONSTR_UNIQUE: case CONSTR_UNIQUE:
if (constraint->name == NULL) if (constraint->name == NULL)
constraint->name = makeObjectName((cxt->relation)->relname, constraint->name = makeObjectName(cxt->relation->relname,
column->colname, column->colname,
"key"); "key");
if (constraint->keys == NIL) if (constraint->keys == NIL)
{ constraint->keys = makeList1(makeString(column->colname));
key = makeNode(Ident);
key->name = pstrdup(column->colname);
constraint->keys = makeList1(key);
}
cxt->ixconstraints = lappend(cxt->ixconstraints, constraint); cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
break; break;
case CONSTR_CHECK: case CONSTR_CHECK:
if (constraint->name == NULL) if (constraint->name == NULL)
constraint->name = makeObjectName((cxt->relation)->relname, constraint->name = makeObjectName(cxt->relation->relname,
column->colname, column->colname,
NULL); NULL);
cxt->ckconstraints = lappend(cxt->ckconstraints, constraint); cxt->ckconstraints = lappend(cxt->ckconstraints, constraint);
...@@ -1002,7 +987,7 @@ transformTableConstraint(ParseState *pstate, CreateStmtContext *cxt, ...@@ -1002,7 +987,7 @@ transformTableConstraint(ParseState *pstate, CreateStmtContext *cxt,
{ {
case CONSTR_PRIMARY: case CONSTR_PRIMARY:
if (constraint->name == NULL) if (constraint->name == NULL)
constraint->name = makeObjectName((cxt->relation)->relname, constraint->name = makeObjectName(cxt->relation->relname,
NULL, NULL,
"pkey"); "pkey");
cxt->ixconstraints = lappend(cxt->ixconstraints, constraint); cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
...@@ -1069,7 +1054,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1069,7 +1054,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
relationHasPrimaryKey(cxt->relOid))) relationHasPrimaryKey(cxt->relOid)))
elog(ERROR, "%s / PRIMARY KEY multiple primary keys" elog(ERROR, "%s / PRIMARY KEY multiple primary keys"
" for table '%s' are not allowed", " for table '%s' are not allowed",
cxt->stmtType, (cxt->relation)->relname); cxt->stmtType, cxt->relation->relname);
cxt->pkey = index; cxt->pkey = index;
} }
index->isconstraint = true; index->isconstraint = true;
...@@ -1077,7 +1062,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1077,7 +1062,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
if (constraint->name != NULL) if (constraint->name != NULL)
index->idxname = pstrdup(constraint->name); index->idxname = pstrdup(constraint->name);
else if (constraint->contype == CONSTR_PRIMARY) else if (constraint->contype == CONSTR_PRIMARY)
index->idxname = makeObjectName((cxt->relation)->relname, NULL, "pkey"); index->idxname = makeObjectName(cxt->relation->relname, NULL, "pkey");
else else
index->idxname = NULL; /* will set it later */ index->idxname = NULL; /* will set it later */
...@@ -1092,16 +1077,15 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1092,16 +1077,15 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
*/ */
foreach(keys, constraint->keys) foreach(keys, constraint->keys)
{ {
Ident *key = (Ident *) lfirst(keys); char *key = strVal(lfirst(keys));
bool found = false; bool found = false;
Assert(IsA(key, Ident));
column = NULL; column = NULL;
foreach(columns, cxt->columns) foreach(columns, cxt->columns)
{ {
column = lfirst(columns); column = lfirst(columns);
Assert(IsA(column, ColumnDef)); Assert(IsA(column, ColumnDef));
if (strcmp(column->colname, key->name) == 0) if (strcmp(column->colname, key) == 0)
{ {
found = true; found = true;
break; break;
...@@ -1113,7 +1097,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1113,7 +1097,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
if (constraint->contype == CONSTR_PRIMARY) if (constraint->contype == CONSTR_PRIMARY)
column->is_not_null = TRUE; column->is_not_null = TRUE;
} }
else if (SystemAttributeByName(key->name, cxt->hasoids) != NULL) else if (SystemAttributeByName(key, cxt->hasoids) != NULL)
{ {
/* /*
* column will be a system column in the new table, so * column will be a system column in the new table, so
...@@ -1145,7 +1129,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1145,7 +1129,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
if (inhattr->attisdropped) if (inhattr->attisdropped)
continue; continue;
if (strcmp(key->name, inhname) == 0) if (strcmp(key, inhname) == 0)
{ {
found = true; found = true;
...@@ -1180,7 +1164,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1180,7 +1164,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
/* ALTER TABLE case: does column already exist? */ /* ALTER TABLE case: does column already exist? */
HeapTuple atttuple; HeapTuple atttuple;
atttuple = SearchSysCacheAttName(cxt->relOid, key->name); atttuple = SearchSysCacheAttName(cxt->relOid, key);
if (HeapTupleIsValid(atttuple)) if (HeapTupleIsValid(atttuple))
{ {
found = true; found = true;
...@@ -1192,28 +1176,28 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1192,28 +1176,28 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
if (constraint->contype == CONSTR_PRIMARY && if (constraint->contype == CONSTR_PRIMARY &&
!((Form_pg_attribute) GETSTRUCT(atttuple))->attnotnull) !((Form_pg_attribute) GETSTRUCT(atttuple))->attnotnull)
elog(ERROR, "Existing attribute \"%s\" cannot be a PRIMARY KEY because it is not marked NOT NULL", elog(ERROR, "Existing attribute \"%s\" cannot be a PRIMARY KEY because it is not marked NOT NULL",
key->name); key);
ReleaseSysCache(atttuple); ReleaseSysCache(atttuple);
} }
} }
if (!found) if (!found)
elog(ERROR, "%s: column \"%s\" named in key does not exist", elog(ERROR, "%s: column \"%s\" named in key does not exist",
cxt->stmtType, key->name); cxt->stmtType, key);
/* Check for PRIMARY KEY(foo, foo) */ /* Check for PRIMARY KEY(foo, foo) */
foreach(columns, index->indexParams) foreach(columns, index->indexParams)
{ {
iparam = (IndexElem *) lfirst(columns); iparam = (IndexElem *) lfirst(columns);
if (iparam->name && strcmp(key->name, iparam->name) == 0) if (iparam->name && strcmp(key, iparam->name) == 0)
elog(ERROR, "%s: column \"%s\" appears twice in %s constraint", elog(ERROR, "%s: column \"%s\" appears twice in %s constraint",
cxt->stmtType, key->name, cxt->stmtType, key,
index->primary ? "PRIMARY KEY" : "UNIQUE"); index->primary ? "PRIMARY KEY" : "UNIQUE");
} }
/* OK, add it to the index definition */ /* OK, add it to the index definition */
iparam = makeNode(IndexElem); iparam = makeNode(IndexElem);
iparam->name = pstrdup(key->name); iparam->name = pstrdup(key);
iparam->funcname = NIL; iparam->funcname = NIL;
iparam->args = NIL; iparam->args = NIL;
iparam->opclass = NIL; iparam->opclass = NIL;
...@@ -1338,13 +1322,12 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1338,13 +1322,12 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
attnum = 0; attnum = 0;
foreach(fkattrs, fkconstraint->fk_attrs) foreach(fkattrs, fkconstraint->fk_attrs)
{ {
Ident *fkattr = lfirst(fkattrs); char *fkattr = strVal(lfirst(fkattrs));
if (attnum >= INDEX_MAX_KEYS) if (attnum >= INDEX_MAX_KEYS)
elog(ERROR, "Can only have %d keys in a foreign key", elog(ERROR, "Can only have %d keys in a foreign key",
INDEX_MAX_KEYS); INDEX_MAX_KEYS);
fktypoid[attnum++] = transformFkeyGetColType(cxt, fktypoid[attnum++] = transformFkeyGetColType(cxt, fkattr);
fkattr->name);
} }
/* /*
...@@ -1353,7 +1336,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1353,7 +1336,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
*/ */
if (fkconstraint->pk_attrs == NIL) if (fkconstraint->pk_attrs == NIL)
{ {
if (strcmp(fkconstraint->pktable->relname, (cxt->relation)->relname) != 0) if (strcmp(fkconstraint->pktable->relname, cxt->relation->relname) != 0)
transformFkeyGetPrimaryKey(fkconstraint, pktypoid); transformFkeyGetPrimaryKey(fkconstraint, pktypoid);
else if (cxt->pkey != NULL) else if (cxt->pkey != NULL)
{ {
...@@ -1364,17 +1347,16 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1364,17 +1347,16 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
foreach(attr, cxt->pkey->indexParams) foreach(attr, cxt->pkey->indexParams)
{ {
IndexElem *ielem = lfirst(attr); IndexElem *ielem = lfirst(attr);
Ident *pkattr = (Ident *) makeNode(Ident); char *iname = ielem->name;
Assert(ielem->name); /* no func index here */ Assert(iname); /* no func index here */
pkattr->name = pstrdup(ielem->name);
fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs, fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs,
pkattr); makeString(iname));
if (attnum >= INDEX_MAX_KEYS) if (attnum >= INDEX_MAX_KEYS)
elog(ERROR, "Can only have %d keys in a foreign key", elog(ERROR, "Can only have %d keys in a foreign key",
INDEX_MAX_KEYS); INDEX_MAX_KEYS);
pktypoid[attnum++] = transformFkeyGetColType(cxt, pktypoid[attnum++] = transformFkeyGetColType(cxt,
ielem->name); iname);
} }
} }
else else
...@@ -1390,7 +1372,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1390,7 +1372,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
else else
{ {
/* Validate the specified referenced key list */ /* Validate the specified referenced key list */
if (strcmp(fkconstraint->pktable->relname, (cxt->relation)->relname) != 0) if (strcmp(fkconstraint->pktable->relname, cxt->relation->relname) != 0)
transformFkeyCheckAttrs(fkconstraint, pktypoid); transformFkeyCheckAttrs(fkconstraint, pktypoid);
else else
{ {
...@@ -1411,7 +1393,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1411,7 +1393,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
attnum = 0; attnum = 0;
foreach(pkattrs, fkconstraint->pk_attrs) foreach(pkattrs, fkconstraint->pk_attrs)
{ {
Ident *pkattr = lfirst(pkattrs); char *pkattr = strVal(lfirst(pkattrs));
List *indparms; List *indparms;
found = false; found = false;
...@@ -1420,7 +1402,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1420,7 +1402,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
IndexElem *indparm = lfirst(indparms); IndexElem *indparm = lfirst(indparms);
if (indparm->name && if (indparm->name &&
strcmp(indparm->name, pkattr->name) == 0) strcmp(indparm->name, pkattr) == 0)
{ {
found = true; found = true;
break; break;
...@@ -1432,7 +1414,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) ...@@ -1432,7 +1414,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
elog(ERROR, "Can only have %d keys in a foreign key", elog(ERROR, "Can only have %d keys in a foreign key",
INDEX_MAX_KEYS); INDEX_MAX_KEYS);
pktypoid[attnum++] = transformFkeyGetColType(cxt, pktypoid[attnum++] = transformFkeyGetColType(cxt,
pkattr->name); pkattr);
} }
if (found) if (found)
break; break;
...@@ -2621,7 +2603,7 @@ transformFkeyCheckAttrs(FkConstraint *fkconstraint, Oid *pktypoid) ...@@ -2621,7 +2603,7 @@ transformFkeyCheckAttrs(FkConstraint *fkconstraint, Oid *pktypoid)
foreach(attrl, fkconstraint->pk_attrs) foreach(attrl, fkconstraint->pk_attrs)
{ {
Ident *attr = lfirst(attrl); char *attrname = strVal(lfirst(attrl));
found = false; found = false;
for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++) for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++)
...@@ -2629,7 +2611,7 @@ transformFkeyCheckAttrs(FkConstraint *fkconstraint, Oid *pktypoid) ...@@ -2629,7 +2611,7 @@ transformFkeyCheckAttrs(FkConstraint *fkconstraint, Oid *pktypoid)
int pkattno = indexStruct->indkey[i]; int pkattno = indexStruct->indkey[i];
if (namestrcmp(attnumAttName(pkrel, pkattno), if (namestrcmp(attnumAttName(pkrel, pkattno),
attr->name) == 0) attrname) == 0)
{ {
pktypoid[attnum++] = attnumTypeId(pkrel, pkattno); pktypoid[attnum++] = attnumTypeId(pkrel, pkattno);
found = true; found = true;
...@@ -2720,12 +2702,10 @@ transformFkeyGetPrimaryKey(FkConstraint *fkconstraint, Oid *pktypoid) ...@@ -2720,12 +2702,10 @@ transformFkeyGetPrimaryKey(FkConstraint *fkconstraint, Oid *pktypoid)
for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++) for (i = 0; i < INDEX_MAX_KEYS && indexStruct->indkey[i] != 0; i++)
{ {
int pkattno = indexStruct->indkey[i]; int pkattno = indexStruct->indkey[i];
Ident *pkattr = makeNode(Ident);
pkattr->name = pstrdup(NameStr(*attnumAttName(pkrel, pkattno)));
pktypoid[attnum++] = attnumTypeId(pkrel, pkattno); pktypoid[attnum++] = attnumTypeId(pkrel, pkattno);
fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs,
fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs, pkattr); makeString(pstrdup(NameStr(*attnumAttName(pkrel, pkattno)))));
} }
ReleaseSysCache(indexTuple); ReleaseSysCache(indexTuple);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.359 2002/08/15 16:36:03 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.360 2002/08/19 15:08:47 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -1724,9 +1724,7 @@ columnList: ...@@ -1724,9 +1724,7 @@ columnList:
columnElem: ColId columnElem: ColId
{ {
Ident *id = makeNode(Ident); $$ = (Node *) makeString($1);
id->name = $1;
$$ = (Node *)id;
} }
; ;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.87 2002/08/08 01:44:31 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.88 2002/08/19 15:08:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -501,9 +501,6 @@ FigureColnameInternal(Node *node, char **name) ...@@ -501,9 +501,6 @@ FigureColnameInternal(Node *node, char **name)
switch (nodeTag(node)) switch (nodeTag(node))
{ {
case T_Ident:
*name = ((Ident *) node)->name;
return 2;
case T_ColumnRef: case T_ColumnRef:
{ {
char *cname = strVal(llast(((ColumnRef *) node)->fields)); char *cname = strVal(llast(((ColumnRef *) node)->fields));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: nodes.h,v 1.115 2002/08/15 16:36:07 momjian Exp $ * $Id: nodes.h,v 1.116 2002/08/19 15:08:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -85,7 +85,6 @@ typedef enum NodeTag ...@@ -85,7 +85,6 @@ typedef enum NodeTag
T_PathKeyItem, T_PathKeyItem,
T_RestrictInfo, T_RestrictInfo,
T_JoinInfo, T_JoinInfo,
T_Stream,
T_IndexOptInfo, T_IndexOptInfo,
/* /*
...@@ -93,13 +92,11 @@ typedef enum NodeTag ...@@ -93,13 +92,11 @@ typedef enum NodeTag
*/ */
T_IndexInfo = 300, T_IndexInfo = 300,
T_ResultRelInfo, T_ResultRelInfo,
T_TupleCount,
T_TupleTableSlot, T_TupleTableSlot,
T_ExprContext, T_ExprContext,
T_ProjectionInfo, T_ProjectionInfo,
T_JunkFilter, T_JunkFilter,
T_EState, T_EState,
T_BaseNode,
T_CommonState, T_CommonState,
T_ResultState, T_ResultState,
T_AppendState, T_AppendState,
...@@ -207,7 +204,6 @@ typedef enum NodeTag ...@@ -207,7 +204,6 @@ typedef enum NodeTag
T_A_Expr = 700, T_A_Expr = 700,
T_ColumnRef, T_ColumnRef,
T_ParamRef, T_ParamRef,
T_Ident,
T_A_Const, T_A_Const,
T_FuncCall, T_FuncCall,
T_A_Indices, T_A_Indices,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: parsenodes.h,v 1.200 2002/08/19 00:40:15 tgl Exp $ * $Id: parsenodes.h,v 1.201 2002/08/19 15:08:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -287,17 +287,6 @@ typedef struct ColumnDef ...@@ -287,17 +287,6 @@ typedef struct ColumnDef
RangeVar *support; /* supporting relation, if any */ RangeVar *support; /* supporting relation, if any */
} ColumnDef; } ColumnDef;
/*
* Ident -
* an unqualified identifier. This is currently used only in the context
* of column name lists.
*/
typedef struct Ident
{
NodeTag type;
char *name; /* its name */
} Ident;
/* /*
* FuncCall - a function or aggregate invocation * FuncCall - a function or aggregate invocation
* *
...@@ -869,7 +858,8 @@ typedef struct CopyStmt ...@@ -869,7 +858,8 @@ typedef struct CopyStmt
{ {
NodeTag type; NodeTag type;
RangeVar *relation; /* the relation to copy */ RangeVar *relation; /* the relation to copy */
List *attlist; /* List of Ident nodes, or NIL for all */ List *attlist; /* List of column names (as Strings),
* or NIL for all columns */
bool is_from; /* TO or FROM */ bool is_from; /* TO or FROM */
char *filename; /* if NULL, use stdin/stdout */ char *filename; /* if NULL, use stdin/stdout */
List *options; /* List of DefElem nodes */ List *options; /* List of DefElem nodes */
...@@ -936,7 +926,7 @@ typedef struct Constraint ...@@ -936,7 +926,7 @@ typedef struct Constraint
char *name; /* name, or NULL if unnamed */ char *name; /* name, or NULL if unnamed */
Node *raw_expr; /* expr, as untransformed parse tree */ Node *raw_expr; /* expr, as untransformed parse tree */
char *cooked_expr; /* expr, as nodeToString representation */ char *cooked_expr; /* expr, as nodeToString representation */
List *keys; /* Ident nodes naming referenced column(s) */ List *keys; /* String nodes naming referenced column(s) */
} Constraint; } Constraint;
/* ---------- /* ----------
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: relation.h,v 1.65 2002/06/20 20:29:51 momjian Exp $ * $Id: relation.h,v 1.66 2002/08/19 15:08:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -603,42 +603,4 @@ typedef struct JoinInfo ...@@ -603,42 +603,4 @@ typedef struct JoinInfo
List *jinfo_restrictinfo; /* relevant RestrictInfos */ List *jinfo_restrictinfo; /* relevant RestrictInfos */
} JoinInfo; } JoinInfo;
/*
* Stream:
* A stream represents a root-to-leaf path in a plan tree (i.e. a tree of
* JoinPaths and Paths). The stream includes pointers to all Path nodes,
* as well as to any clauses that reside above Path nodes. This structure
* is used to make Path nodes and clauses look similar, so that Predicate
* Migration can run.
*
* XXX currently, Predicate Migration is dead code, and so is this node type.
* Probably should remove support for it.
*
* pathptr -- pointer to the current path node
* cinfo -- if NULL, this stream node referes to the path node.
* Otherwise this is a pointer to the current clause.
* clausetype -- whether cinfo is in loc_restrictinfo or pathinfo in the
* path node (XXX this is now used only by dead code, which is
* good because the distinction no longer exists...)
* upstream -- linked list pointer upwards
* downstream -- ditto, downwards
* groupup -- whether or not this node is in a group with the node upstream
* groupcost -- total cost of the group that node is in
* groupsel -- total selectivity of the group that node is in
*/
typedef struct Stream *StreamPtr;
typedef struct Stream
{
NodeTag type;
Path *pathptr;
RestrictInfo *cinfo;
int *clausetype;
StreamPtr upstream;
StreamPtr downstream;
bool groupup;
Cost groupcost;
Selectivity groupsel;
} Stream;
#endif /* RELATION_H */ #endif /* RELATION_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment