Lou*_*ong 12 sql oracle indexing
我在oracle中运行查询10 select A from B where C = D
B有数百万条记录,C上没有索引
我第一次运行它需要大约30秒,第二次运行查询需要大约1秒钟.
显然它正在缓存一些东西,我希望它能阻止它,每次我运行查询时我都希望它需要30秒 - 就像它第一次运行一样.
谢谢
Pet*_* G. 10
清除缓存以测量性能是可能的,但非常笨拙.
用于跟踪调优工作的性能的非常好的措施是计算查询执行期间的读取块的数量.最简单的方法之一是使用带有autotrace的sqlplus,如下所示:
set autotrace traceonly
<your query>
Run Code Online (Sandbox Code Playgroud)
输出
...
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
Run Code Online (Sandbox Code Playgroud)
从缓存或磁盘读取的块数是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'));
Run Code Online (Sandbox Code Playgroud)
读取的块数按列输出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 |
---------------------------------------------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)