From 2c482cdbf20854f75b36fdf15b9e68403473228f Mon Sep 17 00:00:00 2001 From: Bruce Momjian <bruce@momjian.us> Date: Tue, 10 Feb 1998 04:02:59 +0000 Subject: [PATCH] Pass attypmod through to executor by adding to Var and Resdom. --- src/backend/access/common/printtup.c | 8 ++-- src/backend/access/common/tupdesc.c | 15 +++++--- src/backend/commands/creatinh.c | 3 +- src/backend/commands/recipe.c | 12 +++--- src/backend/commands/view.c | 4 +- src/backend/executor/execMain.c | 4 +- src/backend/executor/execTuples.c | 11 ++++-- src/backend/executor/execUtils.c | 45 +--------------------- src/backend/executor/nodeGroup.c | 8 ++-- src/backend/executor/nodeUnique.c | 10 +++-- src/backend/executor/spi.c | 4 +- src/backend/libpq/be-dumpdata.c | 6 ++- src/backend/nodes/copyfuncs.c | 5 ++- src/backend/nodes/equalfuncs.c | 6 ++- src/backend/nodes/makefuncs.c | 8 ++-- src/backend/nodes/outfuncs.c | 6 ++- src/backend/nodes/readfuncs.c | 12 ++++-- src/backend/optimizer/plan/createplan.c | 3 +- src/backend/optimizer/plan/initsplan.c | 4 +- src/backend/optimizer/plan/planmain.c | 3 +- src/backend/optimizer/plan/setrefs.c | 5 ++- src/backend/optimizer/prep/preptlist.c | 27 +++++++------ src/backend/optimizer/util/tlist.c | 9 +++-- src/backend/optimizer/util/var.c | 3 +- src/backend/parser/analyze.c | 4 +- src/backend/parser/gram.y | 31 ++++++++++++++- src/backend/parser/parse_func.c | 22 +++++------ src/backend/parser/parse_node.c | 10 +++-- src/backend/parser/parse_relation.c | 12 ++---- src/backend/parser/parse_target.c | 44 +++++++++++---------- src/backend/rewrite/rewriteManip.c | 4 +- src/backend/storage/large_object/inv_api.c | 11 +++--- src/include/access/tupdesc.h | 5 ++- src/include/catalog/pg_attribute.h | 4 +- src/include/catalog/pg_type.h | 4 +- src/include/executor/executor.h | 18 +-------- src/include/nodes/makefuncs.h | 5 ++- src/include/nodes/primnodes.h | 8 ++-- src/include/parser/parse_node.h | 4 +- src/man/explain.l | 6 +-- 40 files changed, 212 insertions(+), 201 deletions(-) diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index fcedc3adf29..8181b17401a 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.23 1998/01/31 04:38:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.24 1998/02/10 04:00:12 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -123,7 +123,8 @@ printtup(HeapTuple tuple, TupleDesc typeinfo) if (!isnull && OidIsValid(typoutput)) { outputstr = fmgr(typoutput, attr, - gettypelem(typeinfo->attrs[i]->atttypid)); + gettypelem(typeinfo->attrs[i]->atttypid), + (int)typeinfo->attrs[i]->atttypmod); pq_putint(strlen(outputstr) + VARHDRSZ, VARHDRSZ); pq_putnchar(outputstr, strlen(outputstr)); pfree(outputstr); @@ -189,7 +190,8 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo) if (!isnull && OidIsValid(typoutput)) { value = fmgr(typoutput, attr, - gettypelem(typeinfo->attrs[i]->atttypid)); + gettypelem(typeinfo->attrs[i]->atttypid), + (int)typeinfo->attrs[i]->atttypmod); printatt((unsigned) i + 1, typeinfo->attrs[i], value); pfree(value); } diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c index e3f719a0f3b..440084062b6 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.33 1998/02/07 06:10:30 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.34 1998/02/10 04:00:14 momjian Exp $ * * NOTES * some of the executor utility code such as "ExecTypeFromTL" should be @@ -254,7 +254,8 @@ bool TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, char *attributeName, - char *typeName, + Oid typeid, + int typmod, int attdim, bool attisset) { @@ -274,7 +275,6 @@ TupleDescInitEntry(TupleDesc desc, * why that is, though -- Jolly */ /* AssertArg(NameIsValid(attributeName));*/ -/* AssertArg(NameIsValid(typeName));*/ AssertArg(!PointerIsValid(desc->attrs[attributeNumber - 1])); @@ -301,7 +301,7 @@ TupleDescInitEntry(TupleDesc desc, att->attdisbursion = 0; /* dummy value */ att->attcacheoff = -1; - att->atttypmod = -1; + att->atttypmod = typmod; att->attnum = attributeNumber; att->attnelems = attdim; @@ -327,7 +327,7 @@ TupleDescInitEntry(TupleDesc desc, * -cim 6/14/90 * ---------------- */ - tuple = SearchSysCacheTuple(TYPNAME, PointerGetDatum(typeName), + tuple = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(typeid), 0, 0, 0); if (!HeapTupleIsValid(tuple)) { @@ -448,6 +448,7 @@ BuildDescForRelation(List *schema, char *relname) TupleConstr *constr = (TupleConstr *) palloc(sizeof(TupleConstr)); char *attname; char *typename; + int atttypmod; int attdim; int ndef = 0; bool attisset; @@ -481,6 +482,7 @@ BuildDescForRelation(List *schema, char *relname) attname = entry->colname; arry = entry->typename->arrayBounds; attisset = entry->typename->setof; + atttypmod = entry->typename->typmod; if (arry != NIL) { @@ -495,7 +497,8 @@ BuildDescForRelation(List *schema, char *relname) } if (!TupleDescInitEntry(desc, attnum, attname, - typename, attdim, attisset)) + typeTypeId(typenameType(typename)), + atttypmod, attdim, attisset)) { /* ---------------- * if TupleDescInitEntry() fails, it means there is diff --git a/src/backend/commands/creatinh.c b/src/backend/commands/creatinh.c index 8e60f2b450b..13f43d7a75c 100644 --- a/src/backend/commands/creatinh.c +++ b/src/backend/commands/creatinh.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.24 1998/01/05 16:38:49 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.25 1998/02/10 04:00:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -304,6 +304,7 @@ MergeAttributes(List *schema, List *supers, List **supconstr) typename = makeNode(TypeName); def->colname = pstrdup(attributeName); typename->name = pstrdup(attributeType); + typename->typmod = attribute->atttypmod; def->typename = typename; def->is_not_null = attribute->attnotnull; def->defval = NULL; diff --git a/src/backend/commands/recipe.c b/src/backend/commands/recipe.c index 96808a6e311..a95913392ca 100644 --- a/src/backend/commands/recipe.c +++ b/src/backend/commands/recipe.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/recipe.c,v 1.18 1998/01/20 22:10:53 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/recipe.c,v 1.19 1998/02/10 04:00:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -493,7 +493,8 @@ tg_replaceNumberedParam(Node *expression, { newVar = makeVar(rt_ind, 0, /* the whole tuple */ - TypeGet(teeRelName, &defined), + TypeGet(teeRelName, &defined), + -1, 0, rt_ind, 0); @@ -503,7 +504,8 @@ tg_replaceNumberedParam(Node *expression, newVar = makeVar(rt_ind, 1, /* just the first field, * which is 'result' */ - TypeGet(teeRelName, &defined), + TypeGet(teeRelName, &defined), + -1, 0, rt_ind, 0); @@ -1067,8 +1069,8 @@ tg_parseSubQuery(TgRecipe * r, TgNode * n, TeeInfo * teeInfo) if (!TupleDescInitEntry(tupdesc, 1, "result", - NULL, - 0, false)) + InvalidOid, + -1, 0, false)) { elog(NOTICE, "tg_parseSubQuery: unexpected result from TupleDescInitEntry"); } diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index c7f54749883..38a39ed3923 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/view.c,v 1.19 1998/01/05 16:39:08 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/view.c,v 1.20 1998/02/10 04:00:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -77,6 +77,8 @@ DefineVirtualRelation(char *relname, List *tlist) typename = makeNode(TypeName); typename->name = pstrdup(restypename); + typename->typmod = res->restypmod; + def->colname = pstrdup(resname); def->typename = typename; diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index ba3275f346a..c4bea118db6 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.40 1998/01/19 02:37:32 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.41 1998/02/10 04:00:45 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -563,8 +563,6 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) */ tupdesc = CreateTupleDescCopy(tupType); - setAtttypmodForCreateTable(tupdesc, targetList, rangeTable); - intoRelationId = heap_create_with_catalog(intoName, tupdesc); FreeTupleDesc(tupdesc); diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index e8787efd6ce..5f2336ce19d 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.15 1998/01/07 21:02:48 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.16 1998/02/10 04:00:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -986,7 +986,8 @@ ExecTypeFromTL(List *targetList) resdom->resno, resdom->resname, /* fix for SELECT NULL ... */ - typeidTypeName(restype ? restype : UNKNOWNOID), + (restype ? restype : UNKNOWNOID), + resdom->restypmod, 0, false); @@ -1019,7 +1020,8 @@ ExecTypeFromTL(List *targetList) TupleDescInitEntry(typeInfo, fjRes->resno, fjRes->resname, - typeidTypeName(restype), + restype, + fjRes->restypmod, 0, false); /* @@ -1042,7 +1044,8 @@ ExecTypeFromTL(List *targetList) TupleDescInitEntry(typeInfo, fjRes->resno, fjRes->resname, - typeidTypeName(restype), + restype, + fjRes->restypmod, 0, false); diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 244bfdaa401..e02205828ae 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.27 1998/02/07 06:11:21 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.28 1998/02/10 04:00:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1179,46 +1179,3 @@ ExecInsertIndexTuples(TupleTableSlot *slot, if (econtext != NULL) pfree(econtext); } - -/* ---------------------------------------------------------------- - * setAtttyplenForCreateTable - - * called when we do a SELECT * INTO TABLE tab - * needed for attributes that have atttypmod like bpchar and - * varchar - * ---------------------------------------------------------------- - */ -void -setAtttypmodForCreateTable(TupleDesc tupType, List *targetList, - List *rangeTable) -{ - List *tl; - TargetEntry *tle; - Node *expr; - int varno; - - tl = targetList; - - for (varno = 0; varno < tupType->natts; varno++) - { - tle = lfirst(tl); - - if (USE_ATTTYPMOD(tupType->attrs[varno]->atttypid)) - { - expr = tle->expr; - if (expr && IsA(expr, Var)) - { - Var *var; - RangeTblEntry *rtentry; - - var = (Var *) expr; - rtentry = rt_fetch(var->varnoold, rangeTable); - tupType->attrs[varno]->atttypmod = - get_atttypmod(rtentry->relid, var->varoattno); - } - else - elog(ERROR, "setAtttypmodForCreateTable: can't get atttypmod for field (for length, etc.)"); - } - tl = lnext(tl); - } -} - diff --git a/src/backend/executor/nodeGroup.c b/src/backend/executor/nodeGroup.c index 516cd624bfc..da9f8c06a1a 100644 --- a/src/backend/executor/nodeGroup.c +++ b/src/backend/executor/nodeGroup.c @@ -13,7 +13,7 @@ * columns. (ie. tuples from the same group are consecutive) * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeGroup.c,v 1.14 1998/01/31 04:38:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeGroup.c,v 1.15 1998/02/10 04:00:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -417,9 +417,11 @@ sameGroup(TupleTableSlot *oldslot, continue; val1 = fmgr(typoutput, attr1, - gettypelem(tupdesc->attrs[att - 1]->atttypid)); + gettypelem(tupdesc->attrs[att - 1]->atttypid), + (int)tupdesc->attrs[att - 1]->atttypmod); val2 = fmgr(typoutput, attr2, - gettypelem(tupdesc->attrs[att - 1]->atttypid)); + gettypelem(tupdesc->attrs[att - 1]->atttypid), + (int)tupdesc->attrs[att - 1]->atttypmod); /* * now, val1 and val2 are ascii representations so we can use diff --git a/src/backend/executor/nodeUnique.c b/src/backend/executor/nodeUnique.c index ddb8d6ea660..52f3f247c9b 100644 --- a/src/backend/executor/nodeUnique.c +++ b/src/backend/executor/nodeUnique.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeUnique.c,v 1.12 1998/01/31 04:38:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeUnique.c,v 1.13 1998/02/10 04:00:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -196,8 +196,12 @@ ExecUnique(Unique *node) { if (isNull1) /* both are null, they are equal */ continue; - val1 = fmgr(typoutput, attr1, gettypelem(tupDesc->attrs[uniqueAttrNum - 1]->atttypid)); - val2 = fmgr(typoutput, attr2, gettypelem(tupDesc->attrs[uniqueAttrNum - 1]->atttypid)); + val1 = fmgr(typoutput, attr1, + gettypelem(tupDesc->attrs[uniqueAttrNum - 1]->atttypid), + (int)tupDesc->attrs[uniqueAttrNum - 1]->atttypmod); + val2 = fmgr(typoutput, attr2, + gettypelem(tupDesc->attrs[uniqueAttrNum - 1]->atttypid), + (int)tupDesc->attrs[uniqueAttrNum - 1]->atttypmod); /* * now, val1 and val2 are ascii representations so we can diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index cd898a1c209..103f40ac9f2 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -430,7 +430,9 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber) return (NULL); } - return (fmgr(foutoid, val, gettypelem(tupdesc->attrs[fnumber - 1]->atttypid))); + return (fmgr(foutoid, val, + gettypelem(tupdesc->attrs[fnumber - 1]->atttypid), + (int)tupdesc->attrs[fnumber - 1]->atttypmod)); } Datum diff --git a/src/backend/libpq/be-dumpdata.c b/src/backend/libpq/be-dumpdata.c index 13c826cb078..212ec397a96 100644 --- a/src/backend/libpq/be-dumpdata.c +++ b/src/backend/libpq/be-dumpdata.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-dumpdata.c,v 1.11 1998/01/31 04:38:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-dumpdata.c,v 1.12 1998/02/10 04:00:58 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -312,7 +312,9 @@ be_printtup(HeapTuple tuple, TupleDesc typeinfo) if (!isnull && OidIsValid(typoutput)) { - values[i] = fmgr(typoutput, attr, gettypelem(typeinfo->attrs[i]->atttypid)); + values[i] = fmgr(typoutput, attr, + gettypelem(typeinfo->attrs[i]->atttypid), + (int)typeinfo->attrs[i]->atttypmod); } else values[i] = NULL; diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index ce3ffb9f335..7cd00218c0a 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.36 1998/01/21 23:42:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.37 1998/02/10 04:00:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -591,7 +591,7 @@ _copyResdom(Resdom *from) newnode->resno = from->resno; newnode->restype = from->restype; - newnode->reslen = from->reslen; + newnode->restypmod = from->restypmod; if (from->resname != NULL) newnode->resname = pstrdup(from->resname); @@ -671,6 +671,7 @@ _copyVar(Var *from) newnode->varno = from->varno; newnode->varattno = from->varattno; newnode->vartype = from->vartype; + newnode->vartypmod = from->vartypmod; newnode->varlevelsup = from->varlevelsup; newnode->varnoold = from->varnoold; diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index bfed02b5e56..254b62c9fd6 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.13 1998/01/20 22:11:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.14 1998/02/10 04:00:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -42,7 +42,7 @@ _equalResdom(Resdom *a, Resdom *b) return (false); if (a->restype != b->restype) return (false); - if (a->reslen != b->reslen) + if (a->restypmod != b->restypmod) return (false); if (strcmp(a->resname, b->resname) != 0) return (false); @@ -129,6 +129,8 @@ _equalVar(Var *a, Var *b) return (false); if (a->vartype != b->vartype) return (false); + if (a->vartypmod != b->vartypmod) + return (false); if (a->varlevelsup != b->varlevelsup) return (false); if (a->varnoold != b->varnoold) diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index af5003e8773..8dcfdd8e364 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.5 1998/01/20 22:11:05 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.6 1998/02/10 04:00:50 momjian Exp $ * * NOTES * Creator functions in POSTGRES 4.2 are generated automatically. Most of @@ -53,6 +53,7 @@ Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, + int vartypmod, Index varlevelsup, Index varnoold, AttrNumber varoattno) @@ -62,6 +63,7 @@ makeVar(Index varno, var->varno = varno; var->varattno = varattno; var->vartype = vartype; + var->vartypmod = vartypmod; var->varlevelsup = varlevelsup; var->varnoold = varnoold; var->varoattno = varoattno; @@ -76,7 +78,7 @@ makeVar(Index varno, Resdom * makeResdom(AttrNumber resno, Oid restype, - int reslen, + int restypmod, char *resname, Index reskey, Oid reskeyop, @@ -86,7 +88,7 @@ makeResdom(AttrNumber resno, resdom->resno = resno; resdom->restype = restype; - resdom->reslen = reslen; + resdom->restypmod = restypmod; resdom->resname = resname; resdom->reskey = reskey; resdom->reskeyop = reskeyop; diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 2f72b2de66e..48ed8cfd383 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.27 1998/01/25 04:07:52 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.28 1998/02/10 04:00:57 momjian Exp $ * * NOTES * Every (plan) node in POSTGRES has an associated "out" routine which @@ -606,7 +606,7 @@ _outResdom(StringInfo str, Resdom *node) appendStringInfo(str, buf); sprintf(buf, " :restype %u ", node->restype); appendStringInfo(str, buf); - sprintf(buf, " :reslen %d ", node->reslen); + sprintf(buf, " :restypmod %d ", node->restypmod); appendStringInfo(str, buf); appendStringInfo(str, " :resname "); appendStringInfo(str, node->resname); @@ -698,6 +698,8 @@ _outVar(StringInfo str, Var *node) appendStringInfo(str, buf); sprintf(buf, " :vartype %u ", node->vartype); appendStringInfo(str, buf); + sprintf(buf, " :vartypmod %u ", node->vartypmod); + appendStringInfo(str, buf); sprintf(buf, " :varlevelsup %u ", node->varlevelsup); appendStringInfo(str, buf); sprintf(buf, " :varnoold %d ", node->varnoold); diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index d0bcf13875f..4406d9e89d8 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.22 1998/01/20 22:11:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.23 1998/02/10 04:01:03 momjian Exp $ * * NOTES * Most of the read functions for plan nodes are tested. (In fact, they @@ -706,9 +706,9 @@ _readResdom() token = lsptok(NULL, &length); /* get restype */ local_node->restype = atol(token); - token = lsptok(NULL, &length); /* eat :reslen */ - token = lsptok(NULL, &length); /* get reslen */ - local_node->reslen = atoi(token); + token = lsptok(NULL, &length); /* eat :restypmod */ + token = lsptok(NULL, &length); /* get restypmod */ + local_node->restypmod = atoi(token); token = lsptok(NULL, &length); /* eat :resname */ token = lsptok(NULL, &length); /* get the name */ @@ -814,6 +814,10 @@ _readVar() token = lsptok(NULL, &length); /* get vartype */ local_node->vartype = (Oid) atol(token); + token = lsptok(NULL, &length); /* eat :vartypmod */ + token = lsptok(NULL, &length); /* get vartypmod */ + local_node->vartypmod = (Oid) atol(token); + token = lsptok(NULL, &length); /* eat :varlevelsup */ token = lsptok(NULL, &length); /* get varlevelsup */ local_node->varlevelsup = (Oid) atol(token); diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 2b53f1875fe..f6a1470be8e 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.24 1998/01/20 22:11:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.25 1998/02/10 04:01:09 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -701,6 +701,7 @@ fix_indxqual_references(Node *clause, Path *index_path) makeVar((Index) lfirsti(index_path->parent->relids), 1, /* func indices have one key */ ((Func *) ((Expr *) clause)->oper)->functype, + -1, 0, (Index) lfirsti(index_path->parent->relids), 0); diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index cb0bd085875..322c272e752 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.9 1998/01/20 22:11:27 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.10 1998/02/10 04:01:11 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -116,7 +116,7 @@ add_missing_vars_to_base_rels(Query *root, List *tlist) !rel_member(relids, root->base_relation_list_)) { - var = makeVar(varno, -2, 26, 0, varno, -2); + var = makeVar(varno, -2, -1, 26, 0, varno, -2); /* add it to base_relation_list_ */ result = get_base_rel(root, varno); add_tl_element(result, var); diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index 1c59f64a4c8..10e67b76cd2 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.17 1998/01/20 22:11:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.18 1998/02/10 04:01:12 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -464,6 +464,7 @@ make_groupPlan(List **tlist, else te->expr = (Node *) makeVar(1, resdom->resno, resdom->restype, + resdom->restypmod, 0, -1, resdom->resno); } diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index 284ac836f63..16fd96aae1b 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.16 1998/01/20 22:11:32 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.17 1998/02/10 04:01:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -440,6 +440,7 @@ replace_joinvar_refs(Var *var, List *outer_tlist, List *inner_tlist) return (makeVar(OUTER, outer_resdom->resno, var->vartype, + var->vartypmod, 0, var->varnoold, var->varoattno)); @@ -454,6 +455,7 @@ replace_joinvar_refs(Var *var, List *outer_tlist, List *inner_tlist) return (makeVar(INNER, inner_resdom->resno, var->vartype, + var->vartypmod, 0, var->varnoold, var->varoattno)); @@ -499,6 +501,7 @@ tlist_temp_references(Oid tempid, (Node *) makeVar(tempid, xtl->resdom->resno, xtl->resdom->restype, + xtl->resdom->restypmod, 0, tempid, oattno)); diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index ad2c697db5a..43ba76ff54a 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.8 1998/01/20 22:11:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.9 1998/02/10 04:01:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -108,13 +108,13 @@ preprocess_targetlist(List *tlist, resdom = makeResdom(length(t_list) + 1, 27, - 6, + -1, "ctid", 0, 0, 1); - var = makeVar(result_relation, -1, 27, 0, result_relation, -1); + var = makeVar(result_relation, -1, 27, -1, 0, result_relation, -1); ctid = makeNode(TargetEntry); ctid->resdom = resdom; @@ -260,23 +260,20 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type) AttrNumber attno; List *t_list = NIL; char *attname; + int typlen; Oid atttype = 0; - int16 typlen = 0; bool attisset = false; -/* Oid type_id; */ -/* type_id = RelationIdGetTypeId(relid); */ - for (attno = 1; attno <= get_relnatts(relid); attno++) { - attname = get_attname( /* type_id, */ relid, attno); - atttype = get_atttype( /* type_id, */ relid, attno); + attname = get_attname(relid, attno); + atttype = get_atttype(relid, attno); /* * Since this is an append or replace, the size of any set * attribute is the size of the OID used to represent it. */ - attisset = get_attisset( /* type_id, */ relid, attname); + attisset = get_attisset(relid, attname); if (attisset) typlen = typeLen(typeidType(OIDOID)); else @@ -300,14 +297,14 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type) temp, (Datum) typedefault, (typedefault == (struct varlena *) NULL), - /* XXX this is bullshit */ + /* XXX ? */ false, false, /* not a set */ false); temp3 = MakeTLE(makeResdom(attno, atttype, - typlen, + -1, attname, 0, (Oid) 0, @@ -322,11 +319,13 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type) TargetEntry *temp_list = NULL; temp_var = - makeVar(rt_index, attno, atttype, 0, rt_index, attno); + makeVar(rt_index, attno, atttype, + get_atttypmod(relid, attno), + 0, rt_index, attno); temp_list = MakeTLE(makeResdom(attno, atttype, - typlen, + get_atttypmod(relid, attno), attname, 0, (Oid) 0, diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c index edac3e8bf4b..805ac38b902 100644 --- a/src/backend/optimizer/util/tlist.c +++ b/src/backend/optimizer/util/tlist.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.9 1998/01/20 22:11:41 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.10 1998/02/10 04:01:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -108,6 +108,7 @@ add_tl_element(Rel *rel, Var *var) Var *newvar = makeVar(var->varno, var->varattno, var->vartype, + var->vartypmod, var->varlevelsup, var->varno, var->varoattno); @@ -137,7 +138,7 @@ create_tl_element(Var *var, int resdomno) tlelement->resdom = makeResdom(resdomno, var->vartype, - get_typlen(var->vartype), + var->vartypmod, NULL, (Index) 0, (Oid) 0, @@ -398,7 +399,7 @@ flatten_tlist(List *tlist) r = makeResdom(last_resdomno, var->vartype, - get_typlen(var->vartype), + var->vartypmod, NULL, (Index) 0, (Oid) 0, @@ -591,7 +592,7 @@ AddGroupAttrToTlist(List *tlist, List *grpCl) r = makeResdom(last_resdomno, var->vartype, - get_typlen(var->vartype), + var->vartypmod, NULL, (Index) 0, (Oid) 0, diff --git a/src/backend/optimizer/util/var.c b/src/backend/optimizer/util/var.c index e3ed305ed88..41624a17107 100644 --- a/src/backend/optimizer/util/var.c +++ b/src/backend/optimizer/util/var.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.8 1998/01/20 22:11:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.9 1998/02/10 04:01:27 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -209,6 +209,7 @@ var_equal(Var *var1, Var *var2) if (IsA(var1, Var) &&IsA(var2, Var) && (((Var *) var1)->varno == ((Var *) var2)->varno) && (((Var *) var1)->vartype == ((Var *) var2)->vartype) && + (((Var *) var1)->vartypmod == ((Var *) var2)->vartypmod) && (((Var *) var1)->varlevelsup == ((Var *) var2)->varlevelsup) && (((Var *) var1)->varattno == ((Var *) var2)->varattno)) { diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 64069bfa2b7..fc5ce5736e5 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.69 1998/02/06 16:46:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.70 1998/02/10 04:01:38 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -307,7 +307,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt) te = makeNode(TargetEntry); te->resdom = makeResdom(defval[ndef].adnum, att[defval[ndef].adnum - 1]->atttypid, - att[defval[ndef].adnum - 1]->attlen, + att[defval[ndef].adnum - 1]->atttypmod, pstrdup(nameout(&(att[defval[ndef].adnum - 1]->attname))), 0, 0, 0); te->fjoin = NULL; diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 0100081a4a1..fdf0a4419a5 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.104 1998/02/04 06:11:46 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.105 1998/02/10 04:01:44 momjian Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -1314,6 +1314,7 @@ def_arg: ColId { $$ = (Node *)makeString($1); } n->name = $2; n->setof = TRUE; n->arrayBounds = NULL; + n->typmod = -1; $$ = (Node *)n; } | DOUBLE { $$ = (Node *)makeString("double"); } @@ -2218,6 +2219,7 @@ LockStmt: LOCK_P relation_name c->val.val.str = "f"; c->typename = makeNode(TypeName); c->typename->name = xlateSqlType("bool"); + c->typename->typmod = -1; n->relname = $2; n->whereClause = (Node *)c; @@ -2656,6 +2658,7 @@ Generic: generic { $$ = makeNode(TypeName); $$->name = xlateSqlType($1); + $$->typmod = -1; } ; @@ -2674,16 +2677,19 @@ Numeric: FLOAT opt_float { $$ = makeNode(TypeName); $$->name = xlateSqlType($2); + $$->typmod = -1; } | DECIMAL opt_decimal { $$ = makeNode(TypeName); $$->name = xlateSqlType("integer"); + $$->typmod = -1; } | NUMERIC opt_numeric { $$ = makeNode(TypeName); $$->name = xlateSqlType("integer"); + $$->typmod = -1; } ; @@ -2779,6 +2785,7 @@ Character: character '(' Iconst ')' { $$ = makeNode(TypeName); $$->name = xlateSqlType($1); + $$->typmod = -1; } ; @@ -2824,22 +2831,26 @@ Datetime: datetime { $$ = makeNode(TypeName); $$->name = xlateSqlType($1); + $$->typmod = -1; } | TIMESTAMP opt_timezone { $$ = makeNode(TypeName); $$->name = xlateSqlType("timestamp"); $$->timezone = $2; + $$->typmod = -1; } | TIME { $$ = makeNode(TypeName); $$->name = xlateSqlType("time"); + $$->typmod = -1; } | INTERVAL opt_interval { $$ = makeNode(TypeName); $$->name = xlateSqlType("interval"); + $$->typmod = -1; } ; @@ -3327,7 +3338,8 @@ a_expr: attr opt_indirection t->name = xlateSqlType("date"); t->setof = FALSE; - + t->typmod = -1; + $$ = (Node *)n; } | CURRENT_TIME @@ -3341,6 +3353,7 @@ a_expr: attr opt_indirection t->name = xlateSqlType("time"); t->setof = FALSE; + t->typmod = -1; $$ = (Node *)n; } @@ -3359,6 +3372,7 @@ a_expr: attr opt_indirection t->name = xlateSqlType("time"); t->setof = FALSE; + t->typmod = -1; if ($3 != 0) elog(NOTICE,"CURRENT_TIME(%d) precision not implemented; zero used instead",$3); @@ -3376,6 +3390,7 @@ a_expr: attr opt_indirection t->name = xlateSqlType("timestamp"); t->setof = FALSE; + t->typmod = -1; $$ = (Node *)n; } @@ -3394,6 +3409,7 @@ a_expr: attr opt_indirection t->name = xlateSqlType("timestamp"); t->setof = FALSE; + t->typmod = -1; if ($3 != 0) elog(NOTICE,"CURRENT_TIMESTAMP(%d) precision not implemented; zero used instead",$3); @@ -3487,6 +3503,7 @@ a_expr: attr opt_indirection n->val.val.str = "t"; n->typename = makeNode(TypeName); n->typename->name = xlateSqlType("bool"); + n->typename->typmod = -1; $$ = makeA_Expr(OP, "=", $1,(Node *)n); } | a_expr IS NOT FALSE_P @@ -3496,6 +3513,7 @@ a_expr: attr opt_indirection n->val.val.str = "t"; n->typename = makeNode(TypeName); n->typename->name = xlateSqlType("bool"); + n->typename->typmod = -1; $$ = makeA_Expr(OP, "=", $1,(Node *)n); } | a_expr IS FALSE_P @@ -3505,6 +3523,7 @@ a_expr: attr opt_indirection n->val.val.str = "f"; n->typename = makeNode(TypeName); n->typename->name = xlateSqlType("bool"); + n->typename->typmod = -1; $$ = makeA_Expr(OP, "=", $1,(Node *)n); } | a_expr IS NOT TRUE_P @@ -3514,6 +3533,7 @@ a_expr: attr opt_indirection n->val.val.str = "f"; n->typename = makeNode(TypeName); n->typename->name = xlateSqlType("bool"); + n->typename->typmod = -1; $$ = makeA_Expr(OP, "=", $1,(Node *)n); } | a_expr BETWEEN b_expr AND b_expr @@ -3906,6 +3926,7 @@ b_expr: attr opt_indirection t->name = xlateSqlType("date"); t->setof = FALSE; + t->typmod = -1; $$ = (Node *)n; } @@ -3920,6 +3941,7 @@ b_expr: attr opt_indirection t->name = xlateSqlType("time"); t->setof = FALSE; + t->typmod = -1; $$ = (Node *)n; } @@ -3938,6 +3960,7 @@ b_expr: attr opt_indirection t->name = xlateSqlType("time"); t->setof = FALSE; + t->typmod = -1; if ($3 != 0) elog(NOTICE,"CURRENT_TIME(%d) precision not implemented; zero used instead",$3); @@ -3955,6 +3978,7 @@ b_expr: attr opt_indirection t->name = xlateSqlType("timestamp"); t->setof = FALSE; + t->typmod = -1; $$ = (Node *)n; } @@ -3973,6 +3997,7 @@ b_expr: attr opt_indirection t->name = xlateSqlType("timestamp"); t->setof = FALSE; + t->typmod = -1; if ($3 != 0) elog(NOTICE,"CURRENT_TIMESTAMP(%d) precision not implemented; zero used instead",$3); @@ -4478,6 +4503,7 @@ AexprConst: Iconst n->val.val.str = "t"; n->typename = makeNode(TypeName); n->typename->name = xlateSqlType("bool"); + n->typename->typmod = -1; $$ = (Node *)n; } | FALSE_P @@ -4487,6 +4513,7 @@ AexprConst: Iconst n->val.val.str = "f"; n->typename = makeNode(TypeName); n->typename->name = xlateSqlType("bool"); + n->typename->typmod = -1; $$ = (Node *)n; } ; diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c index 2325251ade3..79a97826409 100644 --- a/src/backend/parser/parse_func.c +++ b/src/backend/parser/parse_func.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.12 1998/02/05 04:08:42 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.13 1998/02/10 04:01:52 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -192,13 +192,10 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs, */ if (get_attnum(relid, funcname) != InvalidAttrNumber) { - Oid dummyTypeId; - - return ((Node *) make_var(pstate, + return (Node *) make_var(pstate, relid, refname, - funcname, - &dummyTypeId)); + funcname); } else { @@ -311,7 +308,7 @@ ParseFuncOrColumn(ParseState *pstate, char *funcname, List *fargs, toid = typeTypeId(typenameType(relname)); /* replace it in the arg list */ lfirst(fargs) = - makeVar(vnum, 0, toid, 0, vnum, 0); + makeVar(vnum, 0, toid, -1, 0, vnum, 0); } else if (!attisset) { /* set functions don't have parameters */ @@ -1059,6 +1056,7 @@ setup_tlist(char *attname, Oid relid) Resdom *resnode; Var *varnode; Oid typeid; + int type_mod; int attno; attno = get_attnum(relid, attname); @@ -1066,14 +1064,16 @@ setup_tlist(char *attname, Oid relid) elog(ERROR, "cannot reference attribute '%s' of tuple params/return values for functions", attname); typeid = get_atttype(relid, attno); + type_mod = get_atttypmod(relid, attno); + resnode = makeResdom(1, typeid, - typeLen(typeidType(typeid)), + type_mod, get_attname(relid, attno), 0, (Oid) 0, 0); - varnode = makeVar(-1, attno, typeid, 0, -1, attno); + varnode = makeVar(-1, attno, typeid, type_mod, 0, -1, attno); tle = makeNode(TargetEntry); tle->resdom = resnode; @@ -1095,12 +1095,12 @@ setup_base_tlist(Oid typeid) resnode = makeResdom(1, typeid, - typeLen(typeidType(typeid)), + -1, "<noname>", 0, (Oid) 0, 0); - varnode = makeVar(-1, 1, typeid, 0, -1, 1); + varnode = makeVar(-1, 1, typeid, -1, 0, -1, 1); tle = makeNode(TargetEntry); tle->resdom = resnode; tle->expr = (Node *) varnode; diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c index 02e51087526..3b46ae212aa 100644 --- a/src/backend/parser/parse_node.c +++ b/src/backend/parser/parse_node.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.10 1998/01/20 22:11:57 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.11 1998/02/10 04:01:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -240,12 +240,13 @@ make_op(char *opname, Node *ltree, Node *rtree) Var * make_var(ParseState *pstate, Oid relid, char *refname, - char *attrname, Oid *type_id) + char *attrname) { Var *varnode; int vnum, attid; Oid vartypeid; + int type_mod; int sublevels_up; vnum = refnameRangeTablePosn(pstate, refname, &sublevels_up); @@ -255,9 +256,10 @@ make_var(ParseState *pstate, Oid relid, char *refname, elog(ERROR, "Relation %s does not have attribute %s", refname, attrname); vartypeid = get_atttype(relid, attid); + type_mod = get_atttypmod(relid, attid); - varnode = makeVar(vnum, attid, vartypeid, sublevels_up, vnum, attid); - *type_id = vartypeid; + varnode = makeVar(vnum, attid, vartypeid, type_mod, + sublevels_up, vnum, attid); return varnode; } diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 9a70613f4a7..e5a774dc894 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.9 1998/02/05 22:48:44 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.10 1998/02/10 04:01:56 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -234,8 +234,6 @@ expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno) Var *varnode; int varattno, maxattrs; - Oid type_id; - int type_len; RangeTblEntry *rte; rte = refnameRangeTableEntry(pstate, refname); @@ -257,9 +255,7 @@ expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno) TargetEntry *te = makeNode(TargetEntry); attrname = pstrdup((rdesc->rd_att->attrs[varattno]->attname).data); - varnode = (Var *) make_var(pstate, rte->relid, refname, - attrname, &type_id); - type_len = (int) typeLen(typeidType(type_id)); + varnode = (Var *) make_var(pstate, rte->relid, refname, attrname); handleTargetColname(pstate, &resname, refname, attrname); if (resname != NULL) @@ -271,8 +267,8 @@ expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno) */ te->resdom = makeResdom((AttrNumber) (*this_resno)++, - type_id, - (Size) type_len, + varnode->vartype, + varnode->vartypmod, attrname, (Index) 0, (Oid) 0, diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 4aa961ed456..271645573e0 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.7 1998/01/20 05:04:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.8 1998/02/10 04:01:57 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -25,6 +25,7 @@ #include "parser/parse_relation.h" #include "parser/parse_target.h" #include "utils/builtins.h" +#include "utils/lsyscache.h" static List *expandAllTables(ParseState *pstate); static char *figureColname(Node *expr, Node *resval); @@ -54,7 +55,7 @@ transformTargetList(ParseState *pstate, List *targetlist) { Node *expr; Oid type_id; - int type_len; + int type_mod; char *identname; char *resname; @@ -67,11 +68,14 @@ transformTargetList(ParseState *pstate, List *targetlist) */ expr = transformIdent(pstate, (Node *) res->val, EXPR_COLUMN_FIRST); type_id = exprType(expr); - type_len = typeLen(typeidType(type_id)); + if (nodeTag(expr) == T_Var) + type_mod = ((Var *)expr)->vartypmod; + else + type_mod = -1; resname = (res->name) ? res->name : identname; tent->resdom = makeResdom((AttrNumber) pstate->p_last_resno++, (Oid) type_id, - (Size) type_len, + type_mod, resname, (Index) 0, (Oid) 0, @@ -190,7 +194,7 @@ transformTargetList(ParseState *pstate, List *targetlist) case T_Attr: { Oid type_id; - int type_len; + int type_mod; Attr *att = (Attr *) res->val; Node *result; char *attrname; @@ -253,8 +257,7 @@ transformTargetList(ParseState *pstate, List *targetlist) /* - * Target item is fully specified: ie. - * relation.attribute + * Target item is fully specified: ie. relation.attribute */ result = ParseNestedFuncOrColumn(pstate, att, &pstate->p_last_resno,EXPR_COLUMN_FIRST); handleTargetColname(pstate, &res->name, att->relname, attrname); @@ -273,14 +276,17 @@ transformTargetList(ParseState *pstate, List *targetlist) result = (Node *) make_array_ref(result, att->indirection); } type_id = exprType(result); - type_len = typeLen(typeidType(type_id)); + if (nodeTag(result) == T_Var) + type_mod = ((Var *)result)->vartypmod; + else + type_mod = -1; /* move to last entry */ while (lnext(attrs) != NIL) attrs = lnext(attrs); resname = (res->name) ? res->name : strVal(lfirst(attrs)); resnode = makeResdom((AttrNumber) pstate->p_last_resno++, (Oid) type_id, - (Size) type_len, + type_mod, resname, (Index) 0, (Oid) 0, @@ -326,8 +332,7 @@ make_targetlist_expr(ParseState *pstate, { Oid type_id, attrtype; - int type_len, - attrlen, + int type_mod, attrtypmod; int resdomno; Relation rd; @@ -339,12 +344,10 @@ make_targetlist_expr(ParseState *pstate, elog(ERROR, "make_targetlist_expr: invalid use of NULL expression"); type_id = exprType(expr); - if (type_id == InvalidOid) - { - type_len = 0; - } + if (nodeTag(expr) == T_Var) + type_mod = ((Var *)expr)->vartypmod; else - type_len = typeLen(typeidType(type_id)); + type_mod = -1; /* Processes target columns that will be receiving results */ if (pstate->p_is_insert || pstate->p_is_update) @@ -361,7 +364,6 @@ make_targetlist_expr(ParseState *pstate, attrtype = attnumTypeId(rd, resdomno); if ((arrayRef != NIL) && (lfirst(arrayRef) == NIL)) attrtype = GetArrayElementType(attrtype); - attrlen = typeLen(typeidType(attrtype)); attrtypmod = rd->rd_att->attrs[resdomno - 1]->atttypmod; #if 0 if (Input_is_string && Typecast_ok) @@ -438,7 +440,7 @@ make_targetlist_expr(ParseState *pstate, else expr = (Node *) parser_typecast2(expr, type_id, - typeidType(attrtype), + typeidType(attrtype), attrtypmod); } else @@ -486,20 +488,20 @@ make_targetlist_expr(ParseState *pstate, lowerIndexpr, (Expr *) expr); attrtype = attnumTypeId(rd, resdomno); - attrlen = typeLen(typeidType(attrtype)); + attrtypmod = get_atttypmod(rd->rd_id, resdomno); } } else { resdomno = pstate->p_last_resno++; attrtype = type_id; - attrlen = type_len; + attrtypmod = type_mod; } tent = makeNode(TargetEntry); resnode = makeResdom((AttrNumber) resdomno, (Oid) attrtype, - (Size) attrlen, + attrtypmod, colname, (Index) 0, (Oid) 0, diff --git a/src/backend/rewrite/rewriteManip.c b/src/backend/rewrite/rewriteManip.c index 493e0c4c4ae..be8fa5d075d 100644 --- a/src/backend/rewrite/rewriteManip.c +++ b/src/backend/rewrite/rewriteManip.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.11 1998/01/21 04:24:39 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.12 1998/02/10 04:02:02 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -206,7 +206,7 @@ FixResdomTypes(List *tlist) Var *var = (Var *) tle->expr; tle->resdom->restype = var->vartype; - tle->resdom->reslen = get_typlen(var->vartype); + tle->resdom->restypmod = var->vartypmod; } } } diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c index 93f581807d6..04d7d8b35d6 100644 --- a/src/backend/storage/large_object/inv_api.c +++ b/src/backend/storage/large_object/inv_api.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.27 1998/01/31 04:38:42 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.28 1998/02/10 04:02:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,6 +32,7 @@ #include "catalog/index.h" /* for index_create() */ #include "catalog/catalog.h" /* for newoid() */ #include "catalog/pg_am.h" /* for BTREE_AM_OID */ +#include "catalog/pg_type.h" /* for INT4OID */ #include "catalog/pg_opclass.h" /* for INT4_OPS_OID */ #include "catalog/pg_proc.h" /* for INT4GE_PROC_OID */ #include "storage/itemptr.h" @@ -127,12 +128,12 @@ inv_create(int flags) tupdesc = CreateTemplateTupleDesc(2); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "olastbye", - "int4", - 0, false); + INT4OID, + -1, 0, false); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "odata", - "bytea", - 0, false); + BYTEAOID, + -1, 0, false); /* * First create the table to hold the inversion large object. It will diff --git a/src/include/access/tupdesc.h b/src/include/access/tupdesc.h index 812fee562ca..4871745be04 100644 --- a/src/include/access/tupdesc.h +++ b/src/include/access/tupdesc.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: tupdesc.h,v 1.13 1998/01/24 22:48:12 momjian Exp $ + * $Id: tupdesc.h,v 1.14 1998/02/10 04:02:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -68,7 +68,8 @@ extern void FreeTupleDesc(TupleDesc tupdesc); extern bool TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, char *attributeName, - char *typeName, + Oid typeid, + int typmod, int attdim, bool attisset); diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_attribute.h index 98ecb807b5f..a4a9dc3884e 100644 --- a/src/include/catalog/pg_attribute.h +++ b/src/include/catalog/pg_attribute.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_attribute.h,v 1.25 1998/02/07 06:11:56 momjian Exp $ + * $Id: pg_attribute.h,v 1.26 1998/02/10 04:02:16 momjian Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -95,8 +95,6 @@ CATALOG(pg_attribute) BOOTSTRAP * typed constant associated with a variable. We also have a hack in * execMain.c/execUtils.c that uses atttypmod to properly create tables * for SELECT * INTO TABLE test2 FROM test; - * One day, we may add this to Resdom, and pass it through all areas. - * 1998/1/18 bjm */ bool attbyval; diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h index 76e4f52bda0..56065752a86 100644 --- a/src/include/catalog/pg_type.h +++ b/src/include/catalog/pg_type.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_type.h,v 1.31 1998/02/04 21:32:12 momjian Exp $ + * $Id: pg_type.h,v 1.32 1998/02/10 04:02:17 momjian Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -156,6 +156,8 @@ DESCR("boolean 'true'/'false'"); DATA(insert OID = 17 ( bytea PGUID -1 -1 f b t \054 0 18 byteain byteaout byteain byteaout i _null_ )); DESCR("variable length array of bytes"); +#define BYTEAOID 17 + DATA(insert OID = 18 ( char PGUID 1 1 t b t \054 0 0 charin charout charin charout c _null_ )); DESCR("single character"); #define CHAROID 18 diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index 5837b7bf5fe..e5251886bc5 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: executor.h,v 1.18 1998/01/19 02:37:51 momjian Exp $ + * $Id: executor.h,v 1.19 1998/02/10 04:02:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -18,11 +18,6 @@ #include <stdio.h> #include <executor/execdesc.h> -/* ---------------------------------------------------------------- - * ---------------------------------------------------------------- - */ - - /* * prototypes from functions in execAmi.c */ @@ -120,8 +115,6 @@ extern TupleDesc ExecTypeFromTL(List *targetList); extern void ResetTupleCount(void); extern void ExecAssignNodeBaseInfo(EState *estate, CommonState *basenode, Plan *parent); -extern void setAtttypmodForCreateTable(TupleDesc tupType, List *targetList, - List *rangeTable); extern void ExecAssignExprContext(EState *estate, CommonState *commonstate); extern void ExecAssignResultType(CommonState *commonstate, TupleDesc tupDesc); @@ -143,14 +136,5 @@ extern void ExecOpenIndices(Oid resultRelationOid, extern void ExecCloseIndices(RelationInfo *resultRelationInfo); extern void ExecInsertIndexTuples(TupleTableSlot *slot, ItemPointer tupleid, EState *estate, bool is_update); -extern void resetVarAttrLenForCreateTable(TupleDesc tupType); -extern void setVarAttrLenForCreateTable(TupleDesc tupType, - List *targetList, List *rangeTable); - - -/* ---------------------------------------------------------------- - * the end - * ---------------------------------------------------------------- - */ #endif /* EXECUTOR_H */ diff --git a/src/include/nodes/makefuncs.h b/src/include/nodes/makefuncs.h index f792438701b..8b7cb299e03 100644 --- a/src/include/nodes/makefuncs.h +++ b/src/include/nodes/makefuncs.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: makefuncs.h,v 1.7 1998/01/24 22:49:25 momjian Exp $ + * $Id: makefuncs.h,v 1.8 1998/02/10 04:02:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -25,13 +25,14 @@ extern Oper * makeOper(Oid opno, extern Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, + int vartypmod, Index varlevelsup, Index varnoold, AttrNumber varoattno); extern Resdom * makeResdom(AttrNumber resno, Oid restype, - int reslen, + int restypmod, char *resname, Index reskey, Oid reskeyop, diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index af370b893c7..3907e457c3a 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: primnodes.h,v 1.16 1998/01/20 22:12:14 momjian Exp $ + * $Id: primnodes.h,v 1.17 1998/02/10 04:02:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -26,7 +26,7 @@ * Resdom (Result Domain) * resno - attribute number * restype - type of the resdom - * reslen - length (in bytes) of the result + * restypmod - type-specific modifier of the result * resname - name of the resdom (could be NULL) * reskey - order of key in a sort (for those > 0) * reskeyop - sort operator Oid @@ -41,7 +41,7 @@ typedef struct Resdom NodeTag type; AttrNumber resno; Oid restype; - int reslen; + int restypmod; char *resname; Index reskey; Oid reskeyop; @@ -104,6 +104,7 @@ typedef struct Expr * (could be INNER or OUTER) * varattno - attribute number of this var, or zero for all * vartype - pg_type tuple oid for the type of this var + * vartypmod - pg_attribute typmod value * varlevelsup - for subquery variables referencing outer relations * varnoold - keep varno around in case it got changed to INNER/ * OUTER (see match_varid) @@ -123,6 +124,7 @@ typedef struct Var Index varno; AttrNumber varattno; Oid vartype; + int vartypmod; Index varlevelsup; /* erased by upper optimizer */ Index varnoold; /* only used by optimizer */ AttrNumber varoattno; /* only used by optimizer */ diff --git a/src/include/parser/parse_node.h b/src/include/parser/parse_node.h index c92c2861816..5300db1e86b 100644 --- a/src/include/parser/parse_node.h +++ b/src/include/parser/parse_node.h @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: parse_node.h,v 1.8 1998/01/31 04:39:26 momjian Exp $ + * $Id: parse_node.h,v 1.9 1998/02/10 04:02:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -45,7 +45,7 @@ typedef struct ParseState extern ParseState *make_parsestate(ParseState *parentParseState); extern Expr *make_op(char *opname, Node *ltree, Node *rtree); extern Var *make_var(ParseState *pstate, Oid relid, char *refname, - char *attrname, Oid *type_id); + char *attrname); extern ArrayRef *make_array_ref(Node *expr, List *indirection); extern ArrayRef *make_array_set(Expr *target_expr, diff --git a/src/man/explain.l b/src/man/explain.l index 8a70071d12e..a50912eed10 100644 --- a/src/man/explain.l +++ b/src/man/explain.l @@ -1,6 +1,6 @@ .\" This is -*-nroff-*- .\" XXX standard disclaimer belongs here.... -.\" $Header: /cvsroot/pgsql/src/man/Attic/explain.l,v 1.8 1998/01/11 22:17:35 momjian Exp $ +.\" $Header: /cvsroot/pgsql/src/man/Attic/explain.l,v 1.9 1998/02/10 04:02:59 momjian Exp $ .TH EXPLAIN SQL 06/12/97 PostgreSQL PostgreSQL .SH NAME explain - explains statement execution details @@ -30,12 +30,12 @@ tgl=> explain verbose select sum(a) from test; NOTICE:QUERY PLAN: {AGG :cost 0 :size 0 :width 0 :state <> :qptargetlist - ({TLE :resdom {RESDOM :resno 1 :restype 700 :reslen 4 :resname "sum" + ({TLE :resdom {RESDOM :resno 1 :restype 700 :restypmod 4 :resname "sum" :reskey 0 :reskeyop 0 :resjunk 0} :expr {AGGREG :aggname "sum" :basetype 700 :aggtype 700 :aggno 0 :target {VAR :varno 1 :varattno 1 :vartype 700 :varnoold 1 :varoattno 1}}}) :qpqual <> :lefttree {SEQSCAN :cost 0 :size 0 :width 4 :state <> - :qptargetlist ({TLE :resdom {RESDOM :resno 1 :restype 700 :reslen 4 + :qptargetlist ({TLE :resdom {RESDOM :resno 1 :restype 700 :restypmod 4 :resname "null" :reskey 0 :reskeyop 0 :resjunk 0} :expr {VAR :varno 1 :varattno 1 :vartype 700 :varnoold 1 :varoattno 1}}) :qpqual <> :lefttree <> :righttree <> :scanrelid 1} :righttree <> :numagg 1 } -- GitLab