X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fbackend%2Fcommands%2Fanalyze.c;h=68ebccd30d4e09a3cb49ccccfce833c7715beadc;hb=9743783d5a036ba837d1879b575756ad05cda935;hp=67b46180b718ca13dca49bfc759992389e127981;hpb=39a67533975c8cbadf3d755216cea3ec2c3ce64c;p=pg-rex%2Fsyncrep.git diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 67b46180b7..68ebccd30d 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -695,6 +695,12 @@ compute_index_stats(Relation onerel, double totalrows, { HeapTuple heapTuple = rows[rowno]; + /* + * Reset the per-tuple context each time, to reclaim any cruft + * left behind by evaluating the predicate or index expressions. + */ + ResetExprContext(econtext); + /* Set up for predicate or expression evaluation */ ExecStoreTuple(heapTuple, slot, InvalidBuffer, false); @@ -719,15 +725,26 @@ compute_index_stats(Relation onerel, double totalrows, isnull); /* - * Save just the columns we care about. + * Save just the columns we care about. We copy the values + * into ind_context from the estate's per-tuple context. */ for (i = 0; i < attr_cnt; i++) { VacAttrStats *stats = thisdata->vacattrstats[i]; int attnum = stats->attr->attnum; - exprvals[tcnt] = values[attnum - 1]; - exprnulls[tcnt] = isnull[attnum - 1]; + if (isnull[attnum - 1]) + { + exprvals[tcnt] = (Datum) 0; + exprnulls[tcnt] = true; + } + else + { + exprvals[tcnt] = datumCopy(values[attnum - 1], + stats->attrtype->typbyval, + stats->attrtype->typlen); + exprnulls[tcnt] = false; + } tcnt++; } }