PostgreSQL程式碼分析,查詢最佳化部分,pull_ands()和pull_ors(),pull_andspull_ors

來源:互聯網
上載者:User

PostgreSQL程式碼分析,查詢最佳化部分,pull_ands()和pull_ors(),pull_andspull_ors

PostgreSQL程式碼分析,查詢最佳化部分。


這裡把正式指令動詞運算式的部分就整理完了,閱讀的順序如下:

一、PostgreSQL程式碼分析,查詢最佳化部分,canonicalize_qual

二、PostgreSQL程式碼分析,查詢最佳化部分,pull_ands()和pull_ors()

三、PostgreSQL程式碼分析,查詢最佳化部分,process_duplicate_ors


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


pull_ands()和pull_ors()的代碼比較便於理解,就是把樹狀結構的AND操作拉平,是pull_ands的例子,pull_ors邏輯相同:




/* * 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;}

張大明白的blog:http://blog.csdn.net/shujiezhang



PostgreSQL的查詢處理部分原始碼分析

更新第一條資料的時候

1+1 = 2

該列上 2 已經存在,所以 update 會出錯。

一次 update 有唯一性限制的列的多條記錄,可不能這樣幹。
 
PostgreSQL:怎查詢基於使用者(role)設定的參數

下面示範下:一 方法一:通過 pg_user 視圖查詢--1.1 設定使用者的 log_statement 參數 postgres=# alter role francs set log_statement="all";ALTER ROLE --1.2 驗證 postgres=# select * From pg_user where usename='francs';-[ RECORD 1 ]--------------------usename | francsusesysid | 24920usecreatedb | fusesuper | fusecatupd | fuserepl | fpasswd | ********valuntil | useconfig | {log_statement=all}--1.3 設定使用者的 maintenance_work_mem 參數 postgres=# alter role francs set maintenance_work_mem="1GB";ALTER ROLE--1.4 再次驗證 postgres=# select * From pg_user where usename='francs';-[ RECORD 1 ]---------------------------------------------usename | francsusesysid | 24920usecreatedb | fusesuper | fusecatupd | fuserepl | fpasswd | ********valuntil | useconfig | {log_statement=all,maintenance_work_mem=1GB} 備忘:上面是通過 pg_user.useconfig 查詢。二 方法二: 通過 pg_db_role_setting catalog 基表查詢--2.1 pg_db_role_setting 表結構 Table "pg_catalog.pg_db_role_setting" 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"備忘:可見 pg_db_role_setting 會針對資料庫,使用者層級進行記錄。--2.2 驗證 postgres=# select oid,rolname from pg_authid where rolname='francs'; oid | rolname -------+--------- 24920 | francs(1 row)postgres=# select * From pg_db_role_setting where setrole=24920; setdatabase | setrole | setconfig -----------......餘下全文>>
 

相關文章

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.