*** src/backend/commands/analyze.c --- src/backend/commands/analyze.c 2008-05-15 20:08:27.000000000 +0200 *************** *** 1319,1350 **** { ArrayType *arry; ! /* ! * XXX horrible hack - we're creating a pg_statistic tuple for ! * a tsvector, but need to store an array of cstrings. ! * ! * Temporary measures... ! */ ! if (stats->stakind[0] == STATISTIC_KIND_MCL) ! { ! elog(NOTICE, "severly breaking stuff by brute force hackage"); ! arry = construct_array(stats->stavalues[k], ! stats->numvalues[k], ! CSTRINGOID, ! -2, /* typlen, -2 for cstring, per ! * comment from pg_type.h */ ! false, ! 'c'); ! } ! else ! { ! 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 --- 1319,1330 ---- { ArrayType *arry; ! arry = construct_array(stats->stavalues[k], ! stats->numvalues[k], ! stats->statypid[k], ! stats->statyplen[k], ! stats->statypbyval[k], ! stats->statypalign[k]); values[i++] = PointerGetDatum(arry); /* stavaluesN */ } else *************** *** 1874,1879 **** --- 1854,1867 ---- stats->numnumbers[0] = num_mcv; stats->stavalues[0] = mcv_values; stats->numvalues[0] = num_mcv; + /* + * MCV entries have the same element type as the analyzed + * attribute. + */ + stats->statypid[0] = stats->attr->atttypid; + stats->statyplen[0] = stats->attrtype->typlen; + stats->statypbyval[0] = stats->attrtype->typbyval; + stats->statypalign[0] = stats->attrtype->typalign; } } else if (null_cnt > 0) *************** *** 2217,2222 **** --- 2205,2218 ---- stats->numnumbers[slot_idx] = num_mcv; stats->stavalues[slot_idx] = mcv_values; stats->numvalues[slot_idx] = num_mcv; + /* + * MCV entries have the same element type as the analyzed + * attribute. + */ + stats->statypid[slot_idx] = stats->attr->atttypid; + stats->statyplen[slot_idx] = stats->attrtype->typlen; + stats->statypbyval[slot_idx] = stats->attrtype->typbyval; + stats->statypalign[slot_idx] = stats->attrtype->typalign; slot_idx++; } *************** *** 2301,2306 **** --- 2297,2310 ---- stats->staop[slot_idx] = mystats->ltopr; stats->stavalues[slot_idx] = hist_values; stats->numvalues[slot_idx] = num_hist; + /* + * Histogram entries have the same element type as the analyzed + * attribute. + */ + stats->statypid[slot_idx] = stats->attr->atttypid; + stats->statyplen[slot_idx] = stats->attrtype->typlen; + stats->statypbyval[slot_idx] = stats->attrtype->typbyval; + stats->statypalign[slot_idx] = stats->attrtype->typalign; slot_idx++; } *** src/include/commands/vacuum.h --- src/include/commands/vacuum.h 2008-05-16 00:11:20.000000000 +0200 *************** *** 94,99 **** --- 94,119 ---- Datum *stavalues[STATISTIC_NUM_SLOTS]; /* + * These fields describe the stavalues[n] element types. They will + * typically be the same as the column's that's underlying the slot, but + * sometimes a custom typanalyze function might want to store an array of + * something other that the analyzed column's elements. This must be filled + * in by the compute_stats routine. + * + * XXX or maybe fall back on attrtype-> stuff when these are NULL? That way + * we won't break other people's custom typanalyze functions. Not sure if + * any exist, though. + * + * Another concern is that typlen, typbyval and typalign are reduntant + * given the OID. But the caller is in better position to cache this so + * maybe we shouldn't worry about it? + */ + Oid statypid[STATISTIC_NUM_SLOTS]; + int2 statyplen[STATISTIC_NUM_SLOTS]; + bool statypbyval[STATISTIC_NUM_SLOTS]; + char statypalign[STATISTIC_NUM_SLOTS]; + + /* * These fields are private to the main ANALYZE code and should not be * looked at by type-specific functions. */