Documentation / Extension Hooks / Statistics and estimation
get_relation_stats_hook
get_relation_stats_hook
Hooks for plugins to get control when we ask for stats
Reading PostgreSQL 18.
Description
Hooks for plugins to get control when we ask for stats
- Interface type
- get_relation_stats_hook_type
- Header
- src/include/utils/selfuncs.h
- Subsystem
- Statistics and estimation
- Initial value
- NULL (no hook installed)
C interface
typedef bool (*get_relation_stats_hook_type) (PlannerInfo *root, RangeTblEntry *rte, AttrNumber attnum, VariableStatData *vardata);
extern PGDLLIMPORT get_relation_stats_hook_type get_relation_stats_hook;Call sites
src/backend/utils/adt/selfuncs.c:5717
src/backend/utils/adt/selfuncs.c:6198
src/backend/utils/adt/selfuncs.c:8752
Core call context: src/backend/utils/adt/selfuncs.c:5711–5725
{
RangeTblEntry *rte = root->simple_rte_array[var->varno];
Assert(IsA(rte, RangeTblEntry));
if (get_relation_stats_hook &&
(*get_relation_stats_hook) (root, rte, var->varattno, vardata))
{
/*
* The hook took control of acquiring a stats tuple. If it did supply
* a tuple, it'd better have supplied a freefunc.
*/
if (HeapTupleIsValid(vardata->statsTuple) &&
!vardata->freefunc)
elog(ERROR, "no function provided to release variable stats with");Core call context: src/backend/utils/adt/selfuncs.c:6192–6206
relid = rte->relid;
Assert(relid != InvalidOid);
colnum = index->indexkeys[indexcol];
vardata->rel = index->rel;
if (get_relation_stats_hook &&
(*get_relation_stats_hook) (root, rte, colnum, vardata))
{
/*
* The hook took control of acquiring a stats tuple. If it did
* supply a tuple, it'd better have supplied a freefunc.
*/
if (HeapTupleIsValid(vardata->statsTuple) &&
!vardata->freefunc)
elog(ERROR, "no function provided to release variable stats with");Core call context: src/backend/utils/adt/selfuncs.c:8746–8760
/* attempt to lookup stats in relation for this index column */
if (attnum != 0)
{
/* Simple variable -- look to stats for the underlying table */
if (get_relation_stats_hook &&
(*get_relation_stats_hook) (root, rte, attnum, &vardata))
{
/*
* The hook took control of acquiring a stats tuple. If it
* did supply a tuple, it'd better have supplied a freefunc.
*/
if (HeapTupleIsValid(vardata.statsTuple) && !vardata.freefunc)
elog(ERROR,
"no function provided to release variable stats with");Related entries
Documentation and source
Source build
- Version
- 18
- Build
- REL_18_STABLE
- Source fingerprint
753057e340da8f22e57c9a409ea7a235fd6a46bd
Related entries
get_attavgwidth_hookget_attavgwidth_hookget_index_stats_hookget_index_stats_hook
Back to Extension Hooks · Recorded in PostgreSQL 10 through 20; the first sample is not necessarily its introduction.