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));
else
out_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));
else
out_list = lappend(out_list, subexpr);
}
return out_list;
}张大明白的blog:http://blog.csdn.net/shujiezhang
更新第一条数据的时候
1+1 = 2
该列上 2 已经存在,所以 update 会出错。
一次 update 有唯一性限制的列的多条记录,可不能这样干。
下面演示下:一 方法一:通过 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 -----------......余下全文>>