1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-06 13:46:51 +03:00

Instead of storing pg_statistic stavalues entries as text strings, store

them as arrays of the internal datatype.  This requires treating the
stavalues columns as 'anyarray' rather than 'text[]', which is not 100%
kosher but seems to work fine for the purposes we need for pg_statistic.
Perhaps in the future 'anyarray' will be allowed more generally.
This commit is contained in:
Tom Lane
2003-03-23 05:14:37 +00:00
parent efeffae245
commit 8d9e025e7f
8 changed files with 67 additions and 88 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.240 2003/03/20 03:34:55 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.241 2003/03/23 05:14:36 tgl Exp $
*
*
* INTERFACE ROUTINES
@@ -421,8 +421,12 @@ CheckAttributeType(const char *attname, Oid atttypid)
"\n\tProceeding with relation creation anyway",
attname);
else if (att_typtype == 'p')
elog(ERROR, "Attribute \"%s\" has pseudo-type %s",
attname, format_type_be(atttypid));
{
/* Special hack for pg_statistic: allow ANYARRAY during initdb */
if (atttypid != ANYARRAYOID || IsUnderPostmaster)
elog(ERROR, "Attribute \"%s\" has pseudo-type %s",
attname, format_type_be(atttypid));
}
else if (att_typtype == 'c')
{
Oid typrelid = get_typ_typrelid(atttypid);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.51 2002/11/29 21:39:10 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.52 2003/03/23 05:14:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1694,7 +1694,6 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
for (attno = 0; attno < natts; attno++)
{
VacAttrStats *stats = vacattrstats[attno];
FmgrInfo out_function;
HeapTuple stup,
oldtup;
int i,
@@ -1708,8 +1707,6 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
if (!stats->stats_valid)
continue;
fmgr_info(stats->attrtype->typoutput, &out_function);
/*
* Construct a new pg_statistic tuple
*/
@@ -1758,33 +1755,16 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
}
for (k = 0; k < STATISTIC_NUM_SLOTS; k++)
{
int ntxt = stats->numvalues[k];
if (ntxt > 0)
if (stats->numvalues[k] > 0)
{
Datum *txtdatums = (Datum *) palloc(ntxt * sizeof(Datum));
ArrayType *arry;
for (n = 0; n < ntxt; n++)
{
/*
* Convert data values to a text string to be inserted
* into the text array.
*/
Datum stringdatum;
stringdatum =
FunctionCall3(&out_function,
stats->stavalues[k][n],
ObjectIdGetDatum(stats->attrtype->typelem),
Int32GetDatum(stats->attr->atttypmod));
txtdatums[n] = DirectFunctionCall1(textin, stringdatum);
pfree(DatumGetPointer(stringdatum));
}
/* XXX knows more than it should about type text: */
arry = construct_array(txtdatums, ntxt,
TEXTOID,
-1, false, 'i');
arry = construct_array(stats->stavalues[k],
stats->numvalues[k],
stats->attr->atttypid,
stats->attrtype->typlen,
stats->attrtype->typbyval,
stats->attrtype->typalign);
values[i++] = PointerGetDatum(arry); /* stavaluesN */
}
else

View File

@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.133 2003/03/23 01:49:02 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.134 2003/03/23 05:14:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1826,16 +1826,11 @@ mergejoinscansel(Query *root, Node *clause,
/*
* Now skip any binary-compatible relabeling; there can only be one level
* since constant-expression folder eliminates adjacent RelabelTypes.
*
* XXX can't enable this quite yet, it exposes regproc uncertainty problems
* in regression tests. FIXME soon.
*/
#if 0
if (IsA(left, RelabelType))
left = (Var *) ((RelabelType *) left)->arg;
if (IsA(right, RelabelType))
right = (Var *) ((RelabelType *) right)->arg;
#endif
/* Can't do anything if inputs are not Vars */
if (!IsA(left, Var) ||

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.90 2003/02/03 21:15:44 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.91 2003/03/23 05:14:36 tgl Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
@@ -28,6 +28,7 @@
#include "nodes/makefuncs.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
@@ -1387,8 +1388,7 @@ get_attstatsslot(HeapTuple statstuple,
ArrayType *statarray;
int narrayelem;
HeapTuple typeTuple;
FmgrInfo inputproc;
Oid typelem;
Form_pg_type typeForm;
for (i = 0; i < STATISTIC_NUM_SLOTS; i++)
{
@@ -1408,48 +1408,40 @@ get_attstatsslot(HeapTuple statstuple,
elog(ERROR, "get_attstatsslot: stavalues is null");
statarray = DatumGetArrayTypeP(val);
/*
* Do initial examination of the array. This produces a list of
* text Datums --- ie, pointers into the text array value.
*/
deconstruct_array(statarray,
TEXTOID, -1, false, 'i',
values, nvalues);
narrayelem = *nvalues;
/*
* We now need to replace each text Datum by its internal
* equivalent.
*
* Get the type input proc and typelem for the column datatype.
*/
/* Need to get info about the array element type */
typeTuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(atttype),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "get_attstatsslot: Cache lookup failed for type %u",
atttype);
fmgr_info(((Form_pg_type) GETSTRUCT(typeTuple))->typinput, &inputproc);
typelem = ((Form_pg_type) GETSTRUCT(typeTuple))->typelem;
ReleaseSysCache(typeTuple);
typeForm = (Form_pg_type) GETSTRUCT(typeTuple);
/* Deconstruct array into Datum elements */
deconstruct_array(statarray,
atttype,
typeForm->typlen,
typeForm->typbyval,
typeForm->typalign,
values, nvalues);
/*
* Do the conversions. The palloc'd array of Datums is reused in
* place.
* If the element type is pass-by-reference, we now have a bunch
* of Datums that are pointers into the syscache value. Copy them
* to avoid problems if syscache decides to drop the entry.
*/
for (j = 0; j < narrayelem; j++)
if (!typeForm->typbyval)
{
char *strval;
strval = DatumGetCString(DirectFunctionCall1(textout,
(*values)[j]));
(*values)[j] = FunctionCall3(&inputproc,
CStringGetDatum(strval),
ObjectIdGetDatum(typelem),
Int32GetDatum(atttypmod));
pfree(strval);
for (j = 0; j < *nvalues; j++)
{
(*values)[j] = datumCopy((*values)[j],
typeForm->typbyval,
typeForm->typlen);
}
}
ReleaseSysCache(typeTuple);
/*
* Free statarray if it's a detoasted copy.
*/