PostgreSQL在何处处理 sql查询之二十四
接前面,回到 get_relation_info(plancat.c)函数 上:
relation 是由 heap_open 函数调用后获得的。
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel) { Index varno = rel->relid; Relation relation; bool hasindex; List *indexinfos = NIL; /* * We need not lock the relation since it was already locked, either by * the rewriter or when expand_inherited_rtentry() added it to the query's * rangetable. */ relation = heap_open(relationObjectId, NoLock); ... /* * Estimate relation size --- unless it's an inheritance parent, in which * case the size will be computed later in set_append_rel_pathlist, and we * must leave it zero for now to avoid bollixing the total_table_pages * calculation. */ if (!inhparent) estimate_rel_size(relation, rel->attr_widths - rel->min_attr, &rel->pages, &rel->tuples, &rel->allvisfrac); ... }
经过验证,heap_open后,就把relation的一些信息准备好了。
其中包括 relation->rd_rel->reltuples。
仍然回到 此get_relation_info函数中,当我访问表 tst01时(其对应文件为 16384),
我可以看到入口参数的 oid正好是 16384。