PostgreSQL代码分析,查询优化部分,canonicalize_qual
这里把规范谓词表达式的部分就整理完了。阅读的顺序例如以下:
一、PostgreSQL代码分析,查询优化部分,canonicalize_qual
二、PostgreSQL代码分析,查询优化部分,pull_ands()和pull_ors()
三、 PostgreSQL代码分析。查询优化部分。process_duplicate_ors
/*
* canonicalize_qual
* Convert a qualification expression to the most useful form.
*
* The name of this routine is a holdover from a time when it would try to
* force the expression into canonical AND-of-ORs or OR-of-ANDs form.
* Eventually, we recognized that that had more theoretical purity than
* actual usefulness, and so now the transformation doesn't involve any
* notion of reaching a canonical form.
*
* NOTE: we assume the input has already been through eval_const_expressions
* and therefore possesses AND/OR flatness. Formerly this function included
* its own flattening logic, but that requires a useless extra pass over the
* tree.
*
* Returns the modified qualification.
*/
/*
* 对WHERE语句或ON语句中的条件进行规范化,从集合的角度对AND和OR两个操作做合并分解。 */
Expr *
canonicalize_qual(Expr *qual)
{
Expr *newqual; /* Quick exit for empty qual */
if (qual == NULL)
return NULL; /*
* Pull up redundant subclauses in OR-of-AND trees. We do this only
* within the top-level AND/OR structure; there's no point in looking
* deeper.
*/
/*
* 查找反复的OR操作。即化简条件语句。 * 假设WHERE条件为:
* (A=1 AND B=1) OR (A=1 AND C=1)
* 能够化简为:
* A=1 AND (B=1 OR C=1)
*
* 另外,这个函数中做了将树状的AND或OR语句平面化(flatten。或拉平)的工作,
* 这两个工作主要体如今pull_ands()和pull_ors()两个函数中。
*/
newqual = find_duplicate_ors(qual); return newqual;
} /*
* find_duplicate_ors
* Given a qualification tree with the NOTs pushed down, search for
* OR clauses to which the inverse OR distributive law might apply.
* Only the top-level AND/OR structure is searched.
*
* Returns the modified qualification. AND/OR flatness is preserved.
*/
static Expr *
find_duplicate_ors(Expr *qual)
{
/*
* “分支一:or_clause”
*
* 假设WHERE表达式中的主操作是OR,比如是例如以下形式:
* A=1 OR B=1 OR (C=1 AND D=1)
* 那么參数qual指针实际指向一个BoolExpr结构体。
typedef struct BoolExpr
{
Expr xpr; = 略
BoolExprType boolop; = OR_EXPR。即对以下的3个进行OR操作
List *args; = 3个,各自是A=1和 B=1和(C=1 AND D=1)
} BoolExpr;
*
* 这里的args是一个list。当中的3个元素的类型分别例如以下:
* 第一个是比較操作,类型是OpExpr
* 第二个是比較操作。类型是OpExpr
* 第三个是AND操作,是一个AND_EXPR类型的BoolExpr,递归调用时会处理
*
* 张大明确的blog:http://blog.csdn.net/shujiezhang
*/
if (or_clause((Node *) qual))
{
List *orlist = NIL;
ListCell *temp; /* Recurse */
/*
* 对BoolExpr中的三个条件分别进行递归处理。 * 在这里须要重点关注上例中的AND_EXPR类型的BoolExpr。由于在递归调用中,他将
* 触发下一个分支(分支二)。
*/
foreach(temp, ((BoolExpr *) qual)->args)
orlist = lappend(orlist, find_duplicate_ors(lfirst(temp))); /*
* Don't need pull_ors() since this routine will never introduce an OR
* where there wasn't one before.***这个原因没理解。***
*/
/* 详情见《PostgreSQL代码分析,查询优化部分,process_duplicate_ors》博文*/
return process_duplicate_ors(orlist);
}
/*
* “分支二:and_clause”
*
* 这里主要做了两个操作:
* 1) 假设子语句中有OR类型的子语句,则递归调用find_duplicate_ors。由于 子OR语句中
* 也许也能提取公共项。
* 2) 对AND操作进行拉平。 */
else if (and_clause((Node *) qual))
{
List *andlist = NIL;
ListCell *temp; /* Recurse */
/*
* 子语句中存在一系列OR的情况。
* 比如对于:
* A=1 AND ((B=1 AND C=1) OR (B=1 AND D=1))
* 这里的qual指针指向一个AND_EXPR类型的BoolExpr结构体,则
*
typedef struct BoolExpr
{
Expr xpr; = 略
BoolExprType boolop; = AND_EXPR,即对以下的2个进行AND操作
List *args; = 2个,各自是“A=1”和 “((B=1 AND C=1) OR (B=1 AND D=1))”
} BoolExpr;
*
* 对于当中的“((B=1 AND C=1) OR (B=1 AND D=1))”。在递归调用中,
* 会进入“分支一:or_clause”,进而转换为:
* B=1 AND (C=1 OR D=1)
*
* 张大明确的blog:http://blog.csdn.net/shujiezhang
*/
foreach(temp, ((BoolExpr *) qual)->args)
andlist = lappend(andlist, find_duplicate_ors(lfirst(temp))); /* Flatten any ANDs introduced just below here */
/*
* 拉平。
*
* 由于主语句是AND类型。子语句也是AND类型。所以能够直接把子语句拉到父节点。 *
*/
andlist = pull_ands(andlist);
/* The AND list can't get shorter, so result is always an AND */
return make_andclause(andlist);
}
else
return qual;
}
PostgreSQL代码分析,查询优化部分。
PostgreSQL代码分析,查询优化部分,canonicalize_qual的更多相关文章
- PostgreSQL代码分析,查询优化部分,pull_ands()和pull_ors()
PostgreSQL代码分析,查询优化部分. 这里把规范谓词表达式的部分就整理完了,阅读的顺序例如以下: 一.PostgreSQL代码分析,查询优化部分,canonicalize_qual 二.Pos ...
- SonarQube-5.6.3 代码分析平台搭建使用
python代码分析 官网主页: http://docs.sonarqube.org/display/PLUG/Python+Plugin Windows下安装使用: 快速使用: 1.下载jdk ht ...
- 静态代码分析工具sonarqube+sonar-runner的安装配置及使用
配置成功后的代码分析页面: 可以看到对复杂度.语法使用.重复度等等都做了分析,具体到了每一个方法和每一句代码. 四种使用方式: sonarqube + sonar-runner sonarqube + ...
- PostgreSQL内核分析——BTree索引
文中附图参考至<PostgreSQL数据库内核分析> (一)概念描述 B+树是一种索引数据结构,其一个特征在于非叶子节点用于描述索引,而叶子节点指向具体的数据存储位置.在PostgreSQ ...
- 2017.4.18 静态代码分析工具sonarqube+sonar-runner的安装配置及使用
配置成功后的代码分析页面: 可以看到对复杂度.语法使用.重复度等等都做了分析,具体到了每一个方法和每一句代码. 四种使用方式: sonarqube + sonar-runner sonarqube + ...
- Android代码分析工具lint学习
1 lint简介 1.1 概述 lint是随Android SDK自带的一个静态代码分析工具.它用来对Android工程的源文件进行检查,找出在正确性.安全.性能.可使用性.可访问性及国际化等方面可能 ...
- pmd静态代码分析
在正式进入测试之前,进行一定的静态代码分析及code review对代码质量及系统提高是有帮助的,以上为数据证明 Pmd 它是一个基于静态规则集的Java源码分析器,它可以识别出潜在的如下问题:– 可 ...
- [Asp.net 5] DependencyInjection项目代码分析-目录
微软DI文章系列如下所示: [Asp.net 5] DependencyInjection项目代码分析 [Asp.net 5] DependencyInjection项目代码分析2-Autofac [ ...
- [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(5)(IEnumerable<>补充)
Asp.net 5的依赖注入注入系列可以参考链接: [Asp.net 5] DependencyInjection项目代码分析-目录 我们在之前讲微软的实现时,对于OpenIEnumerableSer ...
随机推荐
- camera驱动框架分析(上)
前言 camera驱动框架涉及到的知识点比较多,特别是camera本身的接口就有很多,有些是直接连接到soc的camif口上的,有些是通过usb接口导出的,如usb camera.我这里主要讨论前者, ...
- iptables-25个常用用法【转】
本文介绍25个常用的iptables用法.如果你对iptables还不甚了解,可以参考上一篇iptables详细教程:基础.架构.清空规则.追加规则.应用实例,看完这篇文章,你就能明白iptables ...
- PHP中冒号、endif、endwhile、endfor使用介绍
我们经常在wordpress一类博客程序的模板里面看到很多奇怪的PHP语法,比如: 复制代码代码如下: <?php if(empty($GET_['a'])): ?> <font c ...
- MVC控制器使用总结
一.新手入门 1.特性 [AuthorizeFilter] 用于权限过滤 [HttpGet] [HttpPost] 2.参数 GET获取 [HttpGet] ) { return Json(&quo ...
- 001_软件waf
一.优秀的软件waf开源软件 <1>openwaf介绍 http://www.oschina.net/p/openwaf http://git.oschina.net/miracleqi ...
- Java环境的搭建及用记事本来揭露下JDK到底做了些什么
和我一样的新手想学Java就从自己搭建环境开始,请看完这边文章,我搜集资料的整合. Java的标准版本是Java SE,所说的JDK(Java Development Kits)就是Java SE的开 ...
- WCF服务安全控制之netTcpBinding的用户名密码验证【转】
选择netTcpBinding WCF的绑定方式比较多,常用的大体有四种: wsHttpBinding basicHttpBinding netTcpBinding wsDualHttpBinding ...
- 通过anaconda进行python多版本控制
---恢复内容开始--- linux与windows通用. 1. 假设电脑上已经转好anaconda3. (anaconda 默认装好了python3.jupyter.spyter) 2. 现在需求是 ...
- springmvc上下文与springcontext上下文的关系
内容摘自:springmvc与spring上下文的关系 原理区别 一直不清楚springmvc-servlet.xml配置与spring.xml两个配置文件出现的上下文关系.今天找到一上面的文章,倒是 ...
- ERP渠道文档详细和修改(二十五)
前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChannelD ...