PostgreSQL code Analysis, query Optimization section, Pull_ands () and Pull_ors ()

Source: Internet
Author: User

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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.