Microsoft SQL Server 2012 Internals 把 SQL 语句的处理分为四个阶段,分别是 解析、绑定、优化、执行,如图所示:

 
 
解析(Parse)主要是语法分析,比较简单。绑定(Bind),书中的解释比较简略:
 
For queries with valid SQL syntax, the next stage performs a series of validation steps on the query, generally called binding, where the columns and tables in the tree are compared to database metadata to ensure that those columns and tables exist and are visible to the current user. This stage also performs semantic checks on the query to ensure that it's valid, such as making sure that the columns bound to a GROUP BY operation are valid.
 
(要是查询的语法正确,那么下一步则是针对该查询做一系列的验证,统称为绑定(binding),树中的列和表要与数据库元数据比对,确保这些列和表在数据库中是存在的,且对当前用户可见。这个阶段也要做一些语义检查,以确保查询在语义上的合法性,譬如,检查 GROUP BY 列的合法性。)
 
两句话,说明了这个阶段的两项主要工作:绑定(可以认为是变量合法性检查)和语义检查。解析主要做语法检查,这个阶段加入了语义检查。语法与语义检查的区别可以用一个例子说明:
 
USE AdventureWorks2012
GO
 
SELECT MakeFlag, SUM(ListPrice)
FROM Production.Product
GROUP BY ProductNumber
 
按 Ctrl + F5 做语法检查,显示 命令已成功完成,表示该查询再语法上没有错误。按 F5 执行,则显示如下错误信息:
 
消息 8120,级别 16,状态 1,第 1 行
选择列表中的列 'Production.Product.MakeFlag' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
 
说明此查询在语义上有错误。
 
这个阶段虽然被称为绑定(Bind),但并不是正式名称,其正式名称在 SQL Server 2000 以前称为 Normalizer,而在 SQL Server 2005 以后改为 Algebrizer。由于技术保密,这本 Internals 书没有透露更多信息,甚至都没有 Algebrizer 这个名字,只笼统以 Bind 名之。
 
SQL Server 2014 Development Essentials 一书关于 Algebrizer 给出了更多信息:
 
If the query syntax is valid, the command parser generates a parse tree and proceeds to the algebrizer. The algebrizer's primary function is to perform binding, that is, to validate whether the tables and columns used in the query exist; load the metadata information for the tables and columns; identify all of the data types used for the query; add information about the required implicit data conversions (typecasting) to the algebrizer tree; replace views with definitions; verify whether the GROUP BY and aggregate functions are used in the right place; and perform simple, syntax-based optimizations.
 
(如果查询的语法正确,则命令解析器为该查询生成语法树并将其传递给 algebrizer。Algebrizer 的主要作用:绑定,也就是说,验证查询中用到的表与列是否存在;加载这些表和列的元数据;识别查询中所有的数据类型;为 algebrizer 树中所需要的隐式数据转换(类型转换)添加必要的信息;对查询中所有的视图,用其定义替换;核实 GROUP BY 以及聚集函数的使用是否得当;并执行一些简单的基于语法的优化。)
 
这段对 algebrizer 的描述更为具体。从这段描述中,我们是否可以合理地猜测 algebrizer = algebra + optimizer?如果此猜测成立,则 algebrizer 可以译为 代数优化器。
 
Microsoft SQL Server 的工程师 HarshDeep Singh 写了一篇文章 An in-depth look at SQL Server Memory ,其中有关于 Algebrizer Trees 的内容:
 
The query optimizer does not directly act on raw query text; it needes a more structured input. The Algebrizer's job is to produce an algebrizer tree, which represents the logical structure of a query. As part of this process, the Algebrizer performs tasks like resolving table, column, and variable names to particular objects in the database. It also determines the data types of any expressions in the query. Since we have the compiled plans, we do not need to cache Algebrizer trees.
 
(查询优化器并不直接在查询的原始文本上工作,它需要一个更加结构化的输入。Algebrizer 的任务就是产生 algebrizer tree,这棵树表示了查询的逻辑结构。作为其工作的一部分,Algebrizer 还要做一些诸如将表、列、及变量名解析到数据库中特定对象的工作。确定查询表达式的数据类型也是 Algebrizer 的事。因为我们有编译后的执行计划,所以不需要缓存 Algebrizer 树。)
 
 
 
 

Algebrizer的更多相关文章

  1. SQL Server 内存中OLTP内部机制概述(四)

    ----------------------------我是分割线------------------------------- 本文翻译自微软白皮书<SQL Server In-Memory ...

  2. java之IO

    IO流主要用于硬板.内存.键盘等处理设备上得数据操作 一.IO流分类 java.io包中定义了多个流类型(类或抽象类)来实现输入/输出功能,可以从不同角度对其分类: 1.按数据流的方向不同分为:输入流 ...

  3. SQL 查询的执行过程

    所述内容均来自互联网,文章仅作为学习笔记,备忘使用. 有时候我在想我们总是在谈优化,FA 优化结构.优化框架.优化程序…,可是我真的了解将要进行的操作[优化]吗?以最近我的工作-优化SQL为例,我真的 ...

  4. select查询原理

    原文:select查询原理 我并非专业DBA,但做为B/S架构的开发人员,总是离不开数据库,一般开发员只会应用SQL的四条经典语句:select ,insert,delete,update.但是我从来 ...

  5. SQL Server查询优化器的工作原理

    SQL Server的查询优化器是一个基于成本的优化器.它为一个给定的查询分析出很多的候选的查询计划,并且估算每个候选计划的成本,从而选择一个成本最低的计划进行执行.实际上,因为查询优化器不可能对每一 ...

  6. ms_sql_server_architecture

    We have classified the architecture of SQL Server into the following parts for easy understanding − ...

  7. SQLServer组成:

    SQL Server DB Engine (Relational Engine),SQL语言用于向Engine描述问题. Algebrizer:代数器,检查语法,并将查询转换成内部表达式 Query ...

  8. Microsoft SQL Server 2005技术内幕:T-SQL查询笔记

    logical operation:基于微软查询处理概念模型的逻辑操作.例如,联接运算符的physical operation属性表示联接算法(nested loops,merge ,hash)物理运 ...

随机推荐

  1. 转载 - Struts2 拦截器详细配置过程

    出处:http://www.blogjava.net/zzzlyr/archive/2009/10/12/297998.html Struts2 拦截器详细配置过程 1:所有拦截器的超级接口Inter ...

  2. Calculate S(n)

    Problem Description Calculate S(n). S(n)=13+23 +33 +......+n3 .   Input Each line will contain one i ...

  3. 欧拉回路输出(DFS,不用回溯!)Watchcow POJ 2230

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8109   Accepted: 3551   Special Judge D ...

  4. ECMAScript 6 入门学习笔记(一)——let和const

    一.let ①声明变量 let a = 1: ②只在所在代码块内有效,不影响块以外 ③不存在变量提升(不能先用后声明) ④暂时性死区 let声明的变量“绑定”这个区域,不受外部影响. let声明之前, ...

  5. mybatis mapper文件sql语句传入hashmap参数

    1.怎样在mybatis mapper文件sql语句传入hashmap参数? 答:直接这样写map就可以 <select id="selectTeacher" paramet ...

  6. PHP array_pad()

    定义和用法 array_pad() 函数向一个数组插入带有指定值的指定数量的元素. 语法 array_pad(array,size,value) 参数 描述 array 必需.规定数组. size 必 ...

  7. Alcatel OmniSwitch 重置密码

    OmniSwitch 6250重置密码 Press s to STOP AT MINIBOOT... [Miniboot]->cd "network" value = 0 = ...

  8. _stdcall与_cdecl

    _cdecl(C Declaration的缩写)是C/C++和MFC程序默认使用的调用约定,因此可以省略,也可以在函数声明时加上_cdecl关键字来手工指定.采用_cdecl约定时,函数参数按照从右到 ...

  9. ios2--UIView的常见属性

    // // ViewController.m // 06-UIView的常见属性 // #import "ViewController.h" @interface ViewCont ...

  10. 转 linux/unix学习经典书籍

    都是一些链接. 1. Linux网络编程经典书籍推荐 http://blog.csdn.net/zhangpeng_linux/article/details/7001970 2. C语言经典著作导读 ...