{"Entry":{"collection":"hook","key":"get_relation_stats_hook","name":"get_relation_stats_hook","aliases":[],"metadata":{"aliases":[],"category":"Statistics and estimation","content_hash":"ac1568d690af48273e0bf228c6febb6054261afb5f9e0ddae42db5701d43d577","derived_content_hash":"5acdd350b2f9f0f78487c0add78c592e320b0743b90de85c59d93d0bfb88aabf","imported_at":"2026-09-27T17:57:58.898538+08:00","name":"get_relation_stats_hook","name_zh":"get_relation_stats_hook","repair_provenance":{"original_source_revision":"","receipt_sha256":"15f7c6e0030110d3f1d1a3c47168e5eea0499e92427ea39de2ac4abf4fc9555f","repair":"wiki-repair-20261023"},"slug":"get_relation_stats_hook","source_rev":"wiki-repair-20261023:5d0fae9c2c698be12509767e8f7d768f21cd9e5f2fd151fcf0a1f633509d51c2","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"],"description_zh":"供插件在请求统计信息时接管处理的钩子。","description_zh_html":"\u003cp\u003e供插件在请求统计信息时接管处理的钩子。\u003c/p\u003e\u003cp\u003e以下中文为本站依据所列 PostgreSQL 源码注释编译的说明。\u003c/p\u003e\u003ch3\u003e接口声明\u003c/h3\u003e\u003cpre\u003etypedef 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;\u003c/pre\u003e\u003ch3\u003e调用位置\u003c/h3\u003e\u003cul\u003e\u003cli\u003e\u003ccode\u003esrc/backend/utils/adt/selfuncs.c:5717\u003c/code\u003e\u003c/li\u003e\u003cli\u003e\u003ccode\u003esrc/backend/utils/adt/selfuncs.c:6198\u003c/code\u003e\u003c/li\u003e\u003cli\u003e\u003ccode\u003esrc/backend/utils/adt/selfuncs.c:8752\u003c/code\u003e\u003c/li\u003e\u003c/ul\u003e\u003ch3\u003e核心调用上下文：src/backend/utils/adt/selfuncs.c:5711–5725\u003c/h3\u003e\u003cpre\u003e{\n\tRangeTblEntry *rte = root-\u0026gt;simple_rte_array[var-\u0026gt;varno];\n\n\tAssert(IsA(rte, RangeTblEntry));\n\n\tif (get_relation_stats_hook \u0026amp;\u0026amp;\n\t\t(*get_relation_stats_hook) (root, rte, var-\u0026gt;varattno, 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\u0026#x27;d better have supplied a freefunc.\n\t\t */\n\t\tif (HeapTupleIsValid(vardata-\u0026gt;statsTuple) \u0026amp;\u0026amp;\n\t\t\t!vardata-\u0026gt;freefunc)\n\t\t\telog(ERROR, \u0026quot;no function provided to release variable stats with\u0026quot;);\u003c/pre\u003e\u003ch3\u003e核心调用上下文：src/backend/utils/adt/selfuncs.c:6192–6206\u003c/h3\u003e\u003cpre\u003e\t\trelid = rte-\u0026gt;relid;\n\t\tAssert(relid != InvalidOid);\n\t\tcolnum = index-\u0026gt;indexkeys[indexcol];\n\t\tvardata-\u0026gt;rel = index-\u0026gt;rel;\n\n\t\tif (get_relation_stats_hook \u0026amp;\u0026amp;\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\u0026#x27;d better have supplied a freefunc.\n\t\t\t */\n\t\t\tif (HeapTupleIsValid(vardata-\u0026gt;statsTuple) \u0026amp;\u0026amp;\n\t\t\t\t!vardata-\u0026gt;freefunc)\n\t\t\t\telog(ERROR, \u0026quot;no function provided to release variable stats with\u0026quot;);\u003c/pre\u003e\u003ch3\u003e核心调用上下文：src/backend/utils/adt/selfuncs.c:8746–8760\u003c/h3\u003e\u003cpre\u003e\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 \u0026amp;\u0026amp;\n\t\t\t\t(*get_relation_stats_hook) (root, rte, attnum, \u0026amp;vardata))\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\u0026#x27;d better have supplied a freefunc.\n\t\t\t\t */\n\t\t\t\tif (HeapTupleIsValid(vardata.statsTuple) \u0026amp;\u0026amp; !vardata.freefunc)\n\t\t\t\t\telog(ERROR,\n\t\t\t\t\t\t \u0026quot;no function provided to release variable stats with\u0026quot;);\u003c/pre\u003e","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"}],"translation_provenance":{"inputs":[{"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"}],"kind":"authored-source-translation","locale":"zh-Hans","source_revision":"753057e340da8f22e57c9a409ea7a235fd6a46bd","translated_source_sha256":"aec1dc23ef114202b3f8b319a841d53ec826927bce6357e146889c056866b358","version":"18"},"zh_from":"authored-source-translation"},"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":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
