我正在 oracle 10 中运行查询select A from B where C = D
B 有数百万条记录,C 上没有索引
第一次运行大约需要 30 秒,第二次运行查询大约需要 1 秒。
显然它正在缓存一些东西,我希望它停止它,每次我运行查询时我希望它花费 30 秒 - 就像它第一次运行一样。
Thanks
清除缓存来测量性能是可能的,但非常不方便。
跟踪调优工作所取得的性能的一个非常好的衡量标准是计算查询执行期间读取块的数量。最简单的方法之一是使用 sqlplus 和 autotrace,如下所示:
set autotrace traceonly
<your query>
outputs
...
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1 consistent gets
0 physical reads
0 redo size
363 bytes sent via SQL*Net to client
364 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
无论是从缓存还是从磁盘读取的块数为consistent gets
.
另一种方法是使用增加的统计信息运行查询,即使用提示gather_plan_statistics
然后从游标缓存中查看查询计划:
auto autotrace off
set serveroutput off
<your query with hint gather_plan_statistics>
select * from table(dbms_xplan.display_cursor(null,null,'typical allstats'));
读取的块数在列中输出buffers
.
---------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | | 1 (100)| | 3 |00:00:00.01 | 3 |
| 1 | SORT AGGREGATE | | 3 | 1 | | | 3 |00:00:00.01 | 3 |
| 2 | INDEX FULL SCAN| ABCDEF | 3 | 176 | 1 (0)| 00:00:01 | 528 |00:00:00.01 | 3 |
---------------------------------------------------------------------------------------------------------------------
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)