> New version of Postgres patch, v5. Implements suggested changes.
> Ready for review and apply.
Applied with some revisions. The method for passing back freefunc
didn't work, so I made it pass the whole VariableStatsData struct
instead; this might allow some additional flexibility by changing other
fields besides the intended statsTuple and freefunc. Also, I was still
unhappy about adding a hook in the midst of code that clearly needs
improvement, without making it possible for the hook to override the
adjacent broken code paths; so I refactored the API a bit for that too.
The plugin function would now be something like this:
HeapTuple statstup = NULL;
/* For now, we only cover the simple-relation case */
if (rte->rtekind != RTE_RELATION || rte->inh)
if (!get_tom_stats_tupletable(rte->relid, attnum))
* Get stats if present. We asked for only one row, so no need for loops.
if (SPI_processed > 0)
statstup = SPI_copytuple(SPI_tuptable->vals);
return false; /* should this happen? */
vardata->statsTuple = statstup;
/* define function to use when time to free the tuple */
vardata->freefunc = heap_freetuple;
and if you want to insert stats for expression indexes then there's a
separate get_index_stats_hook for that.
regards, tom lane