PostgreSQL code Analysis, query optimization section.
Here the parts of the canonical predicate expression are sorted out, and the order of reading is as follows:
One, PostgreSQL code Analysis, query optimization section, canonicalize_qual
Two, PostgreSQL code Analysis, query Optimization section, Pull_ands () and Pull_ors ()
Third, PostgreSQL Code Analysis, query optimization section, Process_duplicate_ors
*************************************************************************************************************** **********************************************
The code for Pull_ands () and pull_ors () is easier to understand, which is to flatten the and operations of the tree structure, which is the pull_ands example, and the pull_ors logic is the same:
/* * Pull_ands * recursively flatten nested and clauses into a single and-clause list. * * Input is the arglist of an AND clause. * Returns the rebuilt arglist (note original list structure is not touched). */static list *pull_ands (list *andlist) {list *out_list = NIL; Listcell *arg;foreach (ARG, andlist) {node *subexpr = (node *) Lfirst (ARG);/* * Note:we can destructively concat the SU Bexpression ' s arglist * because we know the recursive invocation of Pull_ands would has * built a new arglist not shared W ith any other expr. Otherwise we ' d * need a list_copy here. */if (And_clause (subexpr)) Out_list = List_concat (Out_list, Pull_ands (((boolexpr) subexpr)->args); elseout_list = Lappend (Out_list, subexpr);} return out_list;} /* * pull_ors * recursively flatten nested OR clauses into a single or-clause list. * * Input is the arglist of an OR clause. * Returns the rebuilt arglist (note original list structure is not touched). */static list *pull_ors (list *orlist) {List *out_list = NIL; Listcell *arg;foreach (ARG, orlist) {node *subexpr = (node *) Lfirst (ARG);/* * Note:we can destructively concat the sub Expression ' s arglist * because we know the recursive invocation of Pull_ors would has * built a new arglist not shared wit H any other expr. Otherwise we ' d * need a list_copy here. */if (Or_clause (subexpr)) Out_list = List_concat (Out_list, Pull_ors (((boolexpr) subexpr)->args); elseout_list = Lappend (Out_list, subexpr);} return out_list;}
A clear Blog:http://blog.csdn.net/shujiezhang
PostgreSQL code Analysis, query Optimization section, Pull_ands () and Pull_ors ()