文档performance tuning 第299页有段话先记录下来;
2014-05-29 16:01
281 查看
--查询优化器如何选择执行计划中的连接方式?
The Query Optimizer 11-23
How the Query Optimizer Chooses Execution Plans for Joins
The query optimizer considers the following when choosing an execution plan:
--大意是说对于含有unique,primary key的列,在做表连接时会先将此类表放在表连接顺序的第一位然后再做剩余表的连接;
■The optimizer first determines whether joining two or more tables definitely results in a row source containing at most one row. The optimizer recognizes such situations based on UNIQUE and PRIMARY KEY constraints on the tables. If such a situation exists,
then the optimizer places these tables first in the join order. The optimizer then optimizes the join of the remaining set of tables.
--但对于这段就不能很好理解!
■For join statements with outer join conditions, the table with the outer join operator must come after the other table in the condition in the join order. The optimizer does not consider join orders that violate this rule. Similarly, when a subquery has
been converted into an antijoin or semijoin, the tables from the subquery must come after those tables in the outer query block to which they were connected or correlated. However, hash antijoins and semijoins are able to override this ordering condition in
certain circumstances.
The Query Optimizer 11-23
How the Query Optimizer Chooses Execution Plans for Joins
The query optimizer considers the following when choosing an execution plan:
--大意是说对于含有unique,primary key的列,在做表连接时会先将此类表放在表连接顺序的第一位然后再做剩余表的连接;
■The optimizer first determines whether joining two or more tables definitely results in a row source containing at most one row. The optimizer recognizes such situations based on UNIQUE and PRIMARY KEY constraints on the tables. If such a situation exists,
then the optimizer places these tables first in the join order. The optimizer then optimizes the join of the remaining set of tables.
--但对于这段就不能很好理解!
■For join statements with outer join conditions, the table with the outer join operator must come after the other table in the condition in the join order. The optimizer does not consider join orders that violate this rule. Similarly, when a subquery has
been converted into an antijoin or semijoin, the tables from the subquery must come after those tables in the outer query block to which they were connected or correlated. However, hash antijoins and semijoins are able to override this ordering condition in
certain circumstances.
SQL> select count(1) from t1; COUNT(1) ---------- 72620 SQL> select count(1) from t3; COUNT(1) ---------- 2 SQL> select t1.status,t3.status 2 from t1,t3 3 where t1.object_id(+)=t3.object_id 4 / Execution Plan ---------------------------------------------------------- Plan hash value: 2157823540 ------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 2 | 72 | 7 (0)| 00:00:01 | | 1 | NESTED LOOPS OUTER | | 2 | 72 | 7 (0)| 00:00:01 | | 2 | TABLE ACCESS FULL | T3 | 2 | 36 | 3 (0)| 00:00:01 | | 3 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 18 | 2 (0)| 00:00:01 | |* 4 | INDEX RANGE SCAN | IDX_T1_ID | 1 | | 1 (0)| 00:00:01 | ------------------------------------------------------------------------------------------ SQL> select t1.status,t3.status 2 from t1,t3 3 where t1.object_id=t3.object_id(+) 4 / 72620 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 3402958174 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 79534 | 2796K| 294 (1)| 00:00:04 | |* 1 | HASH JOIN RIGHT OUTER| | 79534 | 2796K| 294 (1)| 00:00:04 | | 2 | TABLE ACCESS FULL | T3 | 2 | 36 | 3 (0)| 00:00:01 | | 3 | TABLE ACCESS FULL | T1 | 79534 | 1398K| 291 (1)| 00:00:04 | ------------------------------------------------------------------------------ --无论hash还是nl,都是T1跟在T3后面; --换成子查询格式看看,文档意思是说子查询块要跟在外查询块,可结果确是先执行了T3再执行外查询块的T1,跟文档相反感觉; SQL> select t1.status 2 from t1 3 where exists (select 1 from t3 where t1.object_id=t3.object_id); Execution Plan ---------------------------------------------------------- Plan hash value: 2149433430 ------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 2 | 62 | 6 (17)| 00:00:01 | | 1 | NESTED LOOPS | | | | | | | 2 | NESTED LOOPS | | 2 | 62 | 6 (17)| 00:00:01 | | 3 | SORT UNIQUE | | 2 | 26 | 3 (0)| 00:00:01 | | 4 | TABLE ACCESS FULL | T3 | 2 | 26 | 3 (0)| 00:00:01 | |* 5 | INDEX RANGE SCAN | IDX_T1_ID | 1 | | 1 (0)| 00:00:01 | | 6 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 18 | 2 (0)| 00:00:01 | ------------------------------------------------------------------------------------------
相关文章推荐
- 偶尔记录下来
- 基于Beautiful Soup 4.2.0文档的学习记录(1)——find()、find_all()、findAll()
- BGinfo设置记录文档
- 输入网址不被IE记录下来
- 使用cgitb来简化异常调试(记录下来,感觉很有用)
- Druid数据源监控及慢sql记录使用文档
- WEB文件配置,记录下来以后用
- Beautiful Soup 4.4.0文档学习记录
- 记录Android dnk 文档
- 清除windows系统打开文档历史记录
- 基于PyMongo3.4.0文档的学习记录(1)——Tutorial
- 记不住就存下来---- HTML 5 新增常用属性 之 文档结构元素
- 真没想到刚刚会把这个记录下来。嘿嘿。
- 上传自己写的cacti文档,由于都是图片,自己博客保存一份记录
- Leslie 趁还没忘掉,赶快记录下来 jsp:useBean
- Win7系统盘瘦身:删除索引记录文档减少系统空间占用
- 编译错误记录文档
- android 官方文档阅读记录-多屏幕适配
- 将一些想法记录下来以供以后回忆的地方
- 关于人事,户口等问题,我需要记录下来