{"Entry":{"collection":"hook","key":"get_relation_stats_hook","name":"get_relation_stats_hook","aliases":[],"metadata":{"aliases":[],"category":"Statistics and estimation","content_hash":"ac1568d690af48273e0bf228c6febb6054261afb5f9e0ddae42db5701d43d577","imported_at":"2026-09-27T17:57:58.898538+08:00","name":"get_relation_stats_hook","name_zh":"get_relation_stats_hook","slug":"get_relation_stats_hook","summary":"Hooks for plugins to get control when we ask for stats"}},"Definition":{"Collection":"hook","Key":"get_relation_stats_hook","SourceDatabase":"center","Version":"18","SourceTable":"hook","SourceKey":"get_relation_stats_hook","SourceRevision":"753057e340da8f22e57c9a409ea7a235fd6a46bd","Facts":{"description":["Hooks for plugins to get control when we ask for stats"],"facts":[{"label":"Interface type","value":"get_relation_stats_hook_type"},{"label":"Header","value":"src/include/utils/selfuncs.h"},{"label":"Subsystem","value":"Statistics and estimation"},{"label":"Initial value","value":"NULL (no hook installed)"}],"related":[{"label":"The Planner/Optimizer","url":"/docs/18/planner-optimizer.html"}],"release":{"channel":"stable","label":"18","major":"18","ref":"REL_18_STABLE","revision":"753057e340da8f22e57c9a409ea7a235fd6a46bd"},"sections":[{"paragraphs":["src/backend/utils/adt/selfuncs.c:5717","src/backend/utils/adt/selfuncs.c:6198","src/backend/utils/adt/selfuncs.c:8752"],"title":"Call sites"},{"code":"{\n\tRangeTblEntry *rte = root-\u003esimple_rte_array[var-\u003evarno];\n\n\tAssert(IsA(rte, RangeTblEntry));\n\n\tif (get_relation_stats_hook \u0026\u0026\n\t\t(*get_relation_stats_hook) (root, rte, var-\u003evarattno, vardata))\n\t{\n\t\t/*\n\t\t * The hook took control of acquiring a stats tuple.  If it did supply\n\t\t * a tuple, it'd better have supplied a freefunc.\n\t\t */\n\t\tif (HeapTupleIsValid(vardata-\u003estatsTuple) \u0026\u0026\n\t\t\t!vardata-\u003efreefunc)\n\t\t\telog(ERROR, \"no function provided to release variable stats with\");","paragraphs":[],"title":"Core call context: src/backend/utils/adt/selfuncs.c:5711–5725"},{"code":"\t\trelid = rte-\u003erelid;\n\t\tAssert(relid != InvalidOid);\n\t\tcolnum = index-\u003eindexkeys[indexcol];\n\t\tvardata-\u003erel = index-\u003erel;\n\n\t\tif (get_relation_stats_hook \u0026\u0026\n\t\t\t(*get_relation_stats_hook) (root, rte, colnum, vardata))\n\t\t{\n\t\t\t/*\n\t\t\t * The hook took control of acquiring a stats tuple.  If it did\n\t\t\t * supply a tuple, it'd better have supplied a freefunc.\n\t\t\t */\n\t\t\tif (HeapTupleIsValid(vardata-\u003estatsTuple) \u0026\u0026\n\t\t\t\t!vardata-\u003efreefunc)\n\t\t\t\telog(ERROR, \"no function provided to release variable stats with\");","paragraphs":[],"title":"Core call context: src/backend/utils/adt/selfuncs.c:6192–6206"},{"code":"\n\t\t/* attempt to lookup stats in relation for this index column */\n\t\tif (attnum != 0)\n\t\t{\n\t\t\t/* Simple variable -- look to stats for the underlying table */\n\t\t\tif (get_relation_stats_hook \u0026\u0026\n\t\t\t\t(*get_relation_stats_hook) (root, rte, attnum, \u0026vardata))\n\t\t\t{\n\t\t\t\t/*\n\t\t\t\t * The hook took control of acquiring a stats tuple.  If it\n\t\t\t\t * did supply a tuple, it'd better have supplied a freefunc.\n\t\t\t\t */\n\t\t\t\tif (HeapTupleIsValid(vardata.statsTuple) \u0026\u0026 !vardata.freefunc)\n\t\t\t\t\telog(ERROR,\n\t\t\t\t\t\t \"no function provided to release variable stats with\");","paragraphs":[],"title":"Core call context: src/backend/utils/adt/selfuncs.c:8746–8760"}],"signature":"typedef bool (*get_relation_stats_hook_type) (PlannerInfo *root, RangeTblEntry *rte, AttrNumber attnum, VariableStatData *vardata);\nextern PGDLLIMPORT get_relation_stats_hook_type get_relation_stats_hook;","sources":[{"label":"Interface declaration","path":"src/include/utils/selfuncs.h","sha256":"a3b64e2dd2d41eab2c162a2571bfbe98fac83ae9fab514b73d637220157a501a","url":"https://github.com/postgres/postgres/blob/753057e340da8f22e57c9a409ea7a235fd6a46bd/src/include/utils/selfuncs.h#L142"},{"label":"Core definition","path":"src/backend/utils/adt/selfuncs.c","sha256":"c51b0d3f9c9015e98278241c8efc28c39739a56337ffec1163427b3876170f19","url":"https://github.com/postgres/postgres/blob/753057e340da8f22e57c9a409ea7a235fd6a46bd/src/backend/utils/adt/selfuncs.c#L148"},{"label":"Call sites","path":"src/backend/utils/adt/selfuncs.c","sha256":"c51b0d3f9c9015e98278241c8efc28c39739a56337ffec1163427b3876170f19","url":"https://github.com/postgres/postgres/blob/753057e340da8f22e57c9a409ea7a235fd6a46bd/src/backend/utils/adt/selfuncs.c#L5717"}]},"ManualEvidence":{"release":{"channel":"stable","label":"18","major":"18","ref":"REL_18_STABLE","revision":"753057e340da8f22e57c9a409ea7a235fd6a46bd"},"sources":[{"label":"Interface declaration","path":"src/include/utils/selfuncs.h","sha256":"a3b64e2dd2d41eab2c162a2571bfbe98fac83ae9fab514b73d637220157a501a","url":"https://github.com/postgres/postgres/blob/753057e340da8f22e57c9a409ea7a235fd6a46bd/src/include/utils/selfuncs.h#L142"},{"label":"Core definition","path":"src/backend/utils/adt/selfuncs.c","sha256":"c51b0d3f9c9015e98278241c8efc28c39739a56337ffec1163427b3876170f19","url":"https://github.com/postgres/postgres/blob/753057e340da8f22e57c9a409ea7a235fd6a46bd/src/backend/utils/adt/selfuncs.c#L148"},{"label":"Call sites","path":"src/backend/utils/adt/selfuncs.c","sha256":"c51b0d3f9c9015e98278241c8efc28c39739a56337ffec1163427b3876170f19","url":"https://github.com/postgres/postgres/blob/753057e340da8f22e57c9a409ea7a235fd6a46bd/src/backend/utils/adt/selfuncs.c#L5717"}]},"MeasuredEvidence":{}},"Text":{"Collection":"hook","Key":"get_relation_stats_hook","SourceDatabase":"center","Version":"18","Locale":"en","Title":"get_relation_stats_hook","Summary":"Hooks for plugins to get control when we ask for stats","BodyHTML":"\u003cp\u003eHooks for plugins to get control when we ask for stats\u003c/p\u003e","SourceRevision":"753057e340da8f22e57c9a409ea7a235fd6a46bd","ContentHash":"462662bcdb7c173d8324f40f9e12628a1268a15d470ba60a93309eb48d5750a5","Payload":{"description":["Hooks for plugins to get control when we ask for stats"],"related":[{"label":"The Planner/Optimizer","url":"/docs/18/planner-optimizer.html"}],"sections":[{"paragraphs":["src/backend/utils/adt/selfuncs.c:5717","src/backend/utils/adt/selfuncs.c:6198","src/backend/utils/adt/selfuncs.c:8752"],"title":"Call sites"},{"code":"{\n\tRangeTblEntry *rte = root-\u003esimple_rte_array[var-\u003evarno];\n\n\tAssert(IsA(rte, RangeTblEntry));\n\n\tif (get_relation_stats_hook \u0026\u0026\n\t\t(*get_relation_stats_hook) (root, rte, var-\u003evarattno, vardata))\n\t{\n\t\t/*\n\t\t * The hook took control of acquiring a stats tuple.  If it did supply\n\t\t * a tuple, it'd better have supplied a freefunc.\n\t\t */\n\t\tif (HeapTupleIsValid(vardata-\u003estatsTuple) \u0026\u0026\n\t\t\t!vardata-\u003efreefunc)\n\t\t\telog(ERROR, \"no function provided to release variable stats with\");","paragraphs":[],"title":"Core call context: src/backend/utils/adt/selfuncs.c:5711–5725"},{"code":"\t\trelid = rte-\u003erelid;\n\t\tAssert(relid != InvalidOid);\n\t\tcolnum = index-\u003eindexkeys[indexcol];\n\t\tvardata-\u003erel = index-\u003erel;\n\n\t\tif (get_relation_stats_hook \u0026\u0026\n\t\t\t(*get_relation_stats_hook) (root, rte, colnum, vardata))\n\t\t{\n\t\t\t/*\n\t\t\t * The hook took control of acquiring a stats tuple.  If it did\n\t\t\t * supply a tuple, it'd better have supplied a freefunc.\n\t\t\t */\n\t\t\tif (HeapTupleIsValid(vardata-\u003estatsTuple) \u0026\u0026\n\t\t\t\t!vardata-\u003efreefunc)\n\t\t\t\telog(ERROR, \"no function provided to release variable stats with\");","paragraphs":[],"title":"Core call context: src/backend/utils/adt/selfuncs.c:6192–6206"},{"code":"\n\t\t/* attempt to lookup stats in relation for this index column */\n\t\tif (attnum != 0)\n\t\t{\n\t\t\t/* Simple variable -- look to stats for the underlying table */\n\t\t\tif (get_relation_stats_hook \u0026\u0026\n\t\t\t\t(*get_relation_stats_hook) (root, rte, attnum, \u0026vardata))\n\t\t\t{\n\t\t\t\t/*\n\t\t\t\t * The hook took control of acquiring a stats tuple.  If it\n\t\t\t\t * did supply a tuple, it'd better have supplied a freefunc.\n\t\t\t\t */\n\t\t\t\tif (HeapTupleIsValid(vardata.statsTuple) \u0026\u0026 !vardata.freefunc)\n\t\t\t\t\telog(ERROR,\n\t\t\t\t\t\t \"no function provided to release variable stats with\");","paragraphs":[],"title":"Core call context: src/backend/utils/adt/selfuncs.c:8746–8760"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
