1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

Fix a passel of problems with incorrect calls to typinput and typoutput

functions, which would lead to trouble with datatypes that paid attention
to the typelem or typmod parameters to these functions.  In particular,
incorrect code in pg_aggregate.c explains the platform-specific failures
that have been reported in NUMERIC avg().
This commit is contained in:
Tom Lane
2000-01-15 22:43:25 +00:00
parent 0f4a586821
commit 584e646ad8
11 changed files with 89 additions and 50 deletions

View File

@@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.77 2000/01/15 02:59:27 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.78 2000/01/15 22:43:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -680,11 +680,10 @@ InsertOneValue(Oid objectid, char *value, int i)
values[i] = fmgr(ap->am_typ.typinput,
value,
ap->am_typ.typelem,
-1); /* shouldn't have char() or varchar()
* types during boostrapping but just to
* be safe */
-1);
prt = fmgr(ap->am_typ.typoutput, values[i],
ap->am_typ.typelem);
ap->am_typ.typelem,
-1);
if (!Quiet)
printf("%s ", prt);
pfree(prt);

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.27 2000/01/10 17:14:31 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.28 2000/01/15 22:43:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -262,7 +262,9 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
HeapTuple tup;
Relation aggRel;
int initValAttno;
Oid transtype;
Oid transtype,
typinput,
typelem;
text *textInitVal;
char *strInitVal,
*initVal;
@@ -320,7 +322,11 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
pfree(strInitVal);
elog(ERROR, "AggNameGetInitVal: cache lookup failed on aggregate transition function return type");
}
initVal = fmgr(((Form_pg_type) GETSTRUCT(tup))->typinput, strInitVal, -1);
typinput = ((Form_pg_type) GETSTRUCT(tup))->typinput;
typelem = ((Form_pg_type) GETSTRUCT(tup))->typelem;
initVal = fmgr(typinput, strInitVal, typelem, -1);
pfree(strInitVal);
return initVal;
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.134 2000/01/10 04:09:50 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.135 2000/01/15 22:43:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -516,9 +516,15 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
ObjectIdGetDatum(stats->attr->atttypid),
0, 0, 0);
if (HeapTupleIsValid(typetuple))
{
stats->outfunc = ((Form_pg_type) GETSTRUCT(typetuple))->typoutput;
stats->typelem = ((Form_pg_type) GETSTRUCT(typetuple))->typelem;
}
else
{
stats->outfunc = InvalidOid;
stats->typelem = InvalidOid;
}
}
vacrelstats->va_natts = attr_cnt;
/* delete existing pg_statistic rows for relation */
@@ -2488,13 +2494,13 @@ vc_updstats(Oid relid, int num_pages, int num_tuples, bool hasindex,
/* hack: this code knows float4 is pass-by-ref */
values[i++] = PointerGetDatum(&nullratio); /* stanullfrac */
values[i++] = PointerGetDatum(&bestratio); /* stacommonfrac */
out_string = (*fmgr_faddr(&out_function)) (stats->best, stats->attr->atttypid, stats->attr->atttypmod);
out_string = (*fmgr_faddr(&out_function)) (stats->best, stats->typelem, stats->attr->atttypmod);
values[i++] = PointerGetDatum(textin(out_string)); /* stacommonval */
pfree(out_string);
out_string = (*fmgr_faddr(&out_function)) (stats->min, stats->attr->atttypid, stats->attr->atttypmod);
out_string = (*fmgr_faddr(&out_function)) (stats->min, stats->typelem, stats->attr->atttypmod);
values[i++] = PointerGetDatum(textin(out_string)); /* staloval */
pfree(out_string);
out_string = (char *) (*fmgr_faddr(&out_function)) (stats->max, stats->attr->atttypid, stats->attr->atttypmod);
out_string = (char *) (*fmgr_faddr(&out_function)) (stats->max, stats->typelem, stats->attr->atttypmod);
values[i++] = PointerGetDatum(textin(out_string)); /* stahival */
pfree(out_string);

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.50 1999/12/09 15:56:16 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.51 2000/01/15 22:43:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -669,21 +669,21 @@ array_out(ArrayType *v, Oid element_type)
switch (typlen)
{
case 1:
values[i] = (*fmgr_faddr(&outputproc)) (*p, typelem);
values[i] = (*fmgr_faddr(&outputproc)) (*p, typelem, -1);
break;
case 2:
values[i] = (*fmgr_faddr(&outputproc)) (*(int16 *) p, typelem);
values[i] = (*fmgr_faddr(&outputproc)) (*(int16 *) p, typelem, -1);
break;
case 3:
case 4:
values[i] = (*fmgr_faddr(&outputproc)) (*(int32 *) p, typelem);
values[i] = (*fmgr_faddr(&outputproc)) (*(int32 *) p, typelem, -1);
break;
}
p += typlen;
}
else
{
values[i] = (*fmgr_faddr(&outputproc)) (p, typelem);
values[i] = (*fmgr_faddr(&outputproc)) (p, typelem, -1);
if (typlen > 0)
p += typlen;
else

View File

@@ -3,7 +3,7 @@
* out of its tuple
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.38 2000/01/15 02:59:38 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.39 2000/01/15 22:43:24 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -1604,7 +1604,6 @@ get_const_expr(Const *constval, deparse_context *context)
FmgrInfo finfo_output;
char *extval;
char *valptr;
bool isnull = FALSE;
typetup = SearchSysCacheTuple(TYPEOID,
ObjectIdGetDatum(constval->consttype),
@@ -1629,7 +1628,8 @@ get_const_expr(Const *constval, deparse_context *context)
fmgr_info(typeStruct->typoutput, &finfo_output);
extval = (char *) (*fmgr_faddr(&finfo_output)) (constval->constvalue,
&isnull, -1);
typeStruct->typelem,
-1);
switch (constval->consttype)
{

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.47 2000/01/15 02:59:38 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.48 2000/01/15 22:43:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -600,6 +600,7 @@ getattstatistics(Oid relid, AttrNumber attnum, Oid opid, Oid typid,
HeapTuple tuple;
HeapTuple typeTuple;
FmgrInfo inputproc;
Oid typelem;
rel = heap_openr(StatisticRelationName, AccessShareLock);
@@ -630,6 +631,7 @@ getattstatistics(Oid relid, AttrNumber attnum, Oid opid, Oid typid,
elog(ERROR, "getattstatistics: Cache lookup failed for type %u",
typid);
fmgr_info(((Form_pg_type) GETSTRUCT(typeTuple))->typinput, &inputproc);
typelem = ((Form_pg_type) GETSTRUCT(typeTuple))->typelem;
/* Values are variable-length fields, so cannot access as struct fields.
* Must do it the hard way with heap_getattr.
@@ -649,7 +651,7 @@ getattstatistics(Oid relid, AttrNumber attnum, Oid opid, Oid typid,
{
char *strval = textout(val);
*commonval = (Datum)
(*fmgr_faddr(&inputproc)) (strval, typid, typmod);
(*fmgr_faddr(&inputproc)) (strval, typelem, typmod);
pfree(strval);
}
}
@@ -669,7 +671,7 @@ getattstatistics(Oid relid, AttrNumber attnum, Oid opid, Oid typid,
{
char *strval = textout(val);
*loval = (Datum)
(*fmgr_faddr(&inputproc)) (strval, typid, typmod);
(*fmgr_faddr(&inputproc)) (strval, typelem, typmod);
pfree(strval);
}
}
@@ -689,7 +691,7 @@ getattstatistics(Oid relid, AttrNumber attnum, Oid opid, Oid typid,
{
char *strval = textout(val);
*hival = (Datum)
(*fmgr_faddr(&inputproc)) (strval, typid, typmod);
(*fmgr_faddr(&inputproc)) (strval, typelem, typmod);
pfree(strval);
}
}