Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the processing logic of query_planner function in PostgreSQL

Shulou Source: shulou.com Published: 2022-05-31 14:39:00 09月25日 Update

< root->

Simple_rel_array_size; rti++) / / calculate the total pages {RelOptInfo * brel = root- > simple_rel_ array [RTI]; if (brel = = NULL) continue; Assert (brel- > relid = = rti); / * sanity check on array * / if (IS_SIMPLE_REL (brel)) total_pages + = (double) brel- > pages;} root- > total_table_pages = total_pages / / assign / * * Ready to do the primary planning. * / final_rel = make_one_rel (root, joinlist); / / execute the main planning process / * Check that we got at least one usable path * / if (! final_rel | |! final_rel- > cheapest_total_path | | final_rel- > cheapest_total_path- > param_info! = NULL) elog (ERROR, "failed to construct the join relation"); / / check the result returned by return final_rel;//}

Setup_simple_rel_arrays

Initialize setup_simple_rel_arrays (Note: [0] useless) and setup_simple_rel_arrays

/ * * setup_simple_rel_arrays * Prepare the arrays we use for quickly accessing base relations. * / void setup_simple_rel_arrays (PlannerInfo * root) {Index rti; ListCell * lc; / * Arrays are accessed using RT indexes (1.. N) * / root- > simple_rel_array_size = list_length (root- > parse- > rtable) + 1; / * simple_rel_array is initialized to all NULLs * / root- > simple_rel_array = (RelOptInfo * *) palloc0 (root- > simple_rel_array_size * sizeof (RelOptInfo *)) / * simple_rte_array is an array equivalent of the rtable list * / root- > simple_rte_array = (RangeTblEntry * *) palloc0 (root- > simple_rel_array_size * sizeof (RangeTblEntry *)); rti = 1; foreach (lc, root- > parse- > rtable) {RangeTblEntry * rte = (RangeTblEntry *) lfirst (lc); root- > simple_rte_ array [RTI + +] = rte;}}

Setup_append_rel_array

The source code is relatively simple. Read the information in append_rel_list to initialize append_rel_array.

/ * * setup_append_rel_array * Populate the append_rel_array to allow direct lookups of * AppendRelInfos by child relid. * * The array remains unallocated if there are no AppendRelInfos. * / void setup_append_rel_array (PlannerInfo * root) {ListCell * lc; int size = list_length (root- > parse- > rtable) + 1; if (root- > append_rel_list = = NIL) {root- > append_rel_array = NULL; return;} root- > append_rel_array = (AppendRelInfo *) palloc0 (size * sizeof (AppendRelInfo *)) Foreach (lc, root- > append_rel_list) {AppendRelInfo * appinfo = lfirst_node (AppendRelInfo, lc); int child_relid = appinfo- > child_relid; / * Sanity check * / Assert (child_relid

< size); if (root->

Append_rel_ array [child _ relid]) elog (ERROR, "child relation already exists"); root- > append_rel_ array [child _ relid] = appinfo }} Thank you for your reading, the above is the content of "what is the query_planner function processing logic in PostgreSQL". After the study of this article, I believe you have a deeper understanding of how the query_planner function processing logic in PostgreSQL is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Processing function information query logic array path condition statement highest highest level identity equivalence result expression storage learning projection generation selection Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info NVidia Shulou Information MySQL