CMU 15-445 Lecture #13: Query Processing I
目录
CMU 15-445 Database Systems
Lecture #13: Query Processing I
Query Plan
- 就是前面提到的执行树
- 同一个SQL可以有很多执行计划
Processing Models
- Approach #1: Iterator Model
- Approach #2: Materialization Model
- Approach #3: Vectorized / Batch Model
-
Iterator Model
-
每一个算子需要提供一个Next()的方法,父算子调用一次就吐出来一些数据,如果返回null说明数据都吐出来了(很像Python的yield),我也可以调用我的子算子的Next()方法
-
也叫“Volcano/Pipeline Model”
-
Volcano Model计算的模型 -
这个模型几乎在所有DBMS中都有使用
-
这个模型会有Block的现象,比如Join的时候左边在hash,这个时候上层会被Block
-
部分操作不适合这个模型,比如Sort,只能Block之后全吐出来
-
优点:便于操作,比如LIMIT 100的话我Next() 100次就OK
-
缺点:过多的函数调用(一次返回一个,要调用好多次)会影响性能
-
- Vectorized / Batch Model
- 函数调用的方向可以根到叶子,也可以叶子到根
Access Methods
- Sequential Scan
- Index Scan
- 考虑的条件后面会讲
- 用什么索引要靠优化器分析
Modification Queries
-
更改的操作,逻辑会不一样
-
expression tree
CONCLUSION
- The same query plan can be executed in multiple different ways.
- (Most) DBMSs will want to use index scans as much as possible.
- Expression trees are flexible but slow.JIT compilation can (sometimes) speed them up.