hint--all_rows和fist_rows
来源:互联网 发布:mac如何更改账户 编辑:程序博客网 时间:2024/05/17 02:08
在日常工作中经常被是该用all_rows还是fist_rows所迷惑,今天静下心来研究了一下,大致上明白了他们的区别。
all_rows的功能是指示优化器在优化语句时,以消耗最少资源的最佳吞吐量为优化目标。
fist_rows指示优化器在优化语句时,以最高效地返回前面指定数量的记录为目标。
SQL> SET AUTOTRACE ON
SQL> select /*+ all_rows */* from t where rownum<=10;
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 508354683
-----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 280 | 56 (2)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 50375 | 1377K| 56 (2)| 00:00:01 | 可以看出all_rows是一次性获取所有结果集
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<=10)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
5 consistent gets
0 physical reads
0 redo size
804 bytes sent via SQL*Net to client
469 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10 rows processed
SQL> select * from t where rownum<=10;
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 508354683
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 280 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 10 | 280 | 2 (0)| 00:00:01 | ---只获得想要的结果
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<=10)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
5 consistent gets
0 physical reads
0 redo size
804 bytes sent via SQL*Net to client
469 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10 rows processed
最终的结论是,在OLAP环境下需要一次返回所有记录时用all_rows较好,返回部分记录时用first_rows较好
- hint--all_rows和fist_rows
- 如何选择first_rows和all_rows
- 【优化】ALL_ROWS模式和FIRST_ROWS模式的适用场景
- oracle hint 和 并行
- hint: merge 和 push_pred
- Oracle执行计划——all_rows和first_rows(n) 优化器模式
- Hint
- hint
- Hint
- hint
- hint
- hint
- hint
- HINT
- HINT
- Index hint 和 Index 的区别
- ORDERED 和 USE_NL() hint (zt)的用法
- ORDERED 和 USE_NL() hint (zt)的用法
- Deep Learning(深度学习)学习笔记整理系列之(五)
- matlab视频保存为图片
- 触摸屏G+G,G+P,G+F这些是什么意思?
- 28个Unix/Linux的命令行神器
- Hibernate多对一级联
- hint--all_rows和fist_rows
- google Map API实现地址解析
- Deep Learning(深度学习)学习笔记整理系列之(六)
- lua的一些api文档总结吧
- 原型模式
- Deep Learning(深度学习)学习笔记整理系列之(七)
- socket 网络编程(2)UDP部分
- IOS多线程编程之Grand Central Dispatch(GCD)介绍和使用
- Android系统MK文件分析