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. saltstack(五) saltstack的state状态管理

    一,YAML语法 首先先了解一下YAML,默认的SLS文件的renderer是YAML renderer.YAML是一个有很多强大特性的标记性语言.Salt使用了一个YAML的小型子集,映射非常常用的 ...

  2. MySQL 分库、分表

    Mysql Sharding 前言 1)Sharding是按照一定规则重新分布数据的方式 2)解决单机写入压力过大和容量问题 3)  解决单机查询慢的问题 4)本文主要根据用户登录场景分析 Shard ...

  3. springboot 生产环境不能访问swagger

    @Profile({"local", "dev", "test"}) local,dev, test 分支都可以访问swagger

  4. 设置mysql5.7远程连接-----------https://blog.csdn.net/qiyueqinglian/article/details/52778230

    https://blog.csdn.net/qiyueqinglian/article/details/52778230 设置mysql5.7远程连接

  5. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 Scores

    #1236 : Scores 时间限制:4000ms 单点时限:4000ms 内存限制:256MB 描述 Kyle is a student of Programming Monkey Element ...

  6. 转载 - C - 枚举类型详解

    出处:http://www.cnblogs.com/JCSU/articles/1299051.html 注:以下全部代码的执行环境为VC++ 6.0 在程序中,可能需要为某些整数定义一个别名,我们可 ...

  7. 【BZOJ4514】数字配对(费用流)

    题意: 有 n 种数字,第 i 种数字是 ai.有 bi 个,权值是 ci. 若两个数字 ai.aj 满足,ai 是 aj 的倍数,且 ai/aj 是一个质数, 那么这两个数字可以配对,并获得 ci× ...

  8. C/C++ Threads): Creating worker threads that will be listening to jobs and executing them concurrently when wanted

    Suppose we have two workers. Each worker has an id of 0 and 1. Also suppose that we have jobs arrivi ...

  9. zoj 1610 Count the Colors 【区间覆盖 求染色段】

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  10. EditText 光标的颜色

    EditText有一个属性:android:textCursorDrawable,这个属性是用来控制光标颜色的   android:textCursorDrawable="@null&quo ...