PostgreSQL code analysis, query optimization, pull_ands (), pull_ors (), pull_andspull_ors

Source: Internet
Author: User

PostgreSQL code analysis, query optimization, pull_ands (), pull_ors (), pull_andspull_ors

PostgreSQL code analysis and query optimization.


Here, we have finished sorting out the part of the regular expression. The reading order is as follows:

I. PostgreSQL code analysis, query optimization, canonicalize_qual

Ii. PostgreSQL code analysis, query optimization, pull_ands () and pull_ors ()

Iii. PostgreSQL code analysis and query optimization, process_duplicate_ors


**************************************** **************************************** **************************************** *************************************


The Code of pull_ands () AND pull_ors () is easier to understand. It is to flatten the AND operation of the tree structure. It is an example of pull_ands. The logic of pull_ors 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 subexpression's arglist * because we know the recursive invocation of pull_ands will have * built a new arglist not shared with 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 subexpression's arglist * because we know the recursive invocation of pull_ors will have * built a new arglist not shared with 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;}

Big understand blog: http://blog.csdn.net/shujiezhang



Source code analysis of PostgreSQL Query Processing

When updating the first data

1 + 1 = 2

The column 2 already exists, so an error occurs during update.

Multiple records of Columns with unique restrictions during one update cannot be used in this way.

PostgreSQL: How to query parameters set based on the user (role)

The following example shows Method 1: Query through pg_user View -- 1.1 set the log_statement parameter S = # alter role francs set log_statement = "all "; alter role -- 1.2 verify ipvs = # select * From pg_user where usename = 'francs '; -[RECORD 1] Using usename | francsusesysid | 24920 usecreatedb | fusesuper | fusecatupd | fuserepl | fpasswd | ******* valuntil | useconfig | {log_statement = all} -- 1.3 set the user's maintenance_work_mem parameter postg Res = # alter role francs set maintenance_work_mem = "1 GB"; alter role--1.4 verify postgres again = # select * From pg_user where usename = 'francs '; -[RECORD 1] Using usename | francsusesysid | 24920 usecreatedb | fusesuper | fusecatupd | fuserepl | fpasswd | ******* valuntil | useconfig | {log_statement = all, maintenance_work_mem = 1 GB} Remarks: The above is queried through pg_user.useconfig. Method 2: query using the pg_db_role_setting catalog base Table -- 2.1 pg_db_role_setting Table structure Table "tables" Column | Type | Modifiers ------------- + -------- + ----------- setdatabase | oid | not null setrole | oid | not null setconfig | text [] | Indexes: "pg_db_role_setting_databaseid_rol_index" UNIQUE, btree (setdatabase, setrole), tablespace "pg_global" Remarks: we can see that pg_db_role_setting records the database and user level. -- 2.2 verify ipvs = # select oid, rolname from pg_authid where rolname = 'francs '; oid | rolname ------- + --------- 24920 | francs (1 row) S = # select * From pg_db_role_setting where setrole = 24920; setdatabase | setrole | setconfig -----------...... remaining full text>

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.