Oracle 参数之_small_table_threshold

SQL> select * from v$version;

BANNER
-----------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production SQL> show sga Total System Global Area 3423965184 bytes
Fixed Size 2180544 bytes
Variable Size 1929382464 bytes
Database Buffers 1476395008 bytes
Redo Buffers 16007168 bytes SQL> set linesize 120
SQL> col name for a30
SQL> col value for a20
SQL> col pdesc for a50
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.KSPPDESC PDESC
2 FROM SYS.x$ksppi x, SYS.x$ksppcv y
3 WHERE x.indx = y.indx AND x.ksppinm LIKE '%small_table_threshold%'; NAME VALUE PDESC
------------------------------ -------------------- --------------------------------------------------
_small_table_threshold 3467 threshold level of table size for direct reads SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.KSPPDESC PDESC
2 FROM SYS.x$ksppi x, SYS.x$ksppcv y
3 WHERE x.indx = y.indx AND x.ksppinm LIKE '%_serial_direct_read%'; NAME VALUE PDESC
------------------------------ ------------------------------ --------------------------------------------------
_serial_direct_read FALSE enable direct read in serial SQL> alter session set "_serial_direct_read"=true; SQL> alter session set events '10949 trace name context off'; SQL> create table dt as select * from dba_objects; SQL> insert into dt select * from dt; SQL> insert into dt select * from dt; SQL> select count(*) from dt; COUNT(*)
----------
290364 SQL> select blockS from user_segments where segment_name='DT'; BLOCKS
----------
4224 SQL> alter session set events '10046 trace name context forever,level 8'; 会话已更改。 SQL> alter system flush buffer_cache; 系统已更改。 SQL> select count(*) from dt; COUNT(*)
----------
290364 WAIT #3: nam='reliable message' ela= 160 channel context=8795194841928 channel handle=8795194796064 broadcast message=8795145225720 obj#=74914 tim=19703281481
WAIT #3: nam='enq: KO - fast object checkpoint' ela= 1109 name|mode=1263468550 2=65555 0=1 obj#=74914 tim=19703282668
WAIT #3: nam='direct path read' ela= 4401 file number=4 first dba=57635 block cnt=13 obj#=74914 tim=19703287486
WAIT #3: nam='direct path read' ela= 1424 file number=4 first dba=57649 block cnt=15 obj#=74914 tim=19703289236
WAIT #3: nam='direct path read' ela= 1183 file number=4 first dba=57665 block cnt=15 obj#=74914 tim=19703290787
WAIT #3: nam='direct path read' ela= 1403 file number=4 first dba=57681 block cnt=15 obj#=74914 tim=19703292472
WAIT #3: nam='direct path read' ela= 1181 file number=4 first dba=57697 block cnt=15 obj#=74914 tim=19703293980
WAIT #3: nam='direct path read' ela= 1261 file number=4 first dba=57713 block cnt=15 obj#=74914 tim=19703295567
WAIT #3: nam='direct path read' ela= 1232 file number=4 first dba=61825 block cnt=15 obj#=74914 tim=19703297126
WAIT #3: nam='direct path read' ela= 548 file number=4 first dba=61841 block cnt=15 obj#=74914 tim=19703298609
WAIT #3: nam='direct path read' ela= 8324 file number=4 first dba=61954 block cnt=126 obj#=74914 tim=19703307811
WAIT #3: nam='direct path read' ela= 7573 file number=4 first dba=62082 block cnt=126 obj#=74914 tim=19703317154 SQL> delete from dt where rownum<140000; 已删除139999行。 SQL> alter table dt enable row movement; 表已更改。 SQL> alter table dt move tablespace users; 表已更改。 SQL> select blocks from user_segments where segment_name='DT'; BLOCKS
----------
2304 SQL> alter system flush buffer_cache; 系统已更改。 SQL> select count(*) from dt; COUNT(*)
----------
290364

PARSING IN CURSOR #7 len=23 dep=0 uid=91 oct=3 lid=91 tim=20802442129 hv=4123149654 ad='7ffc8c72548' sqlid='4paafg3uw4jaq'
select count(*) from dt
END OF STMT
PARSE #7:c=0,e=124,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=341227488,tim=20802442128
EXEC #7:c=0,e=43,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=341227488,tim=20802442340
WAIT #7: nam='SQL*Net message to client' ela= 4 driver id=1111838976 #bytes=1 p3=0 obj#=0 tim=20802442426
WAIT #7: nam='db file sequential read' ela= 8896 file#=4 block#=57634 blocks=1 obj#=74914 tim=20802451409
WAIT #7: nam='direct path read' ela= 805 file number=4 first dba=57635 block cnt=13 obj#=74914 tim=20802452734
WAIT #7: nam='direct path read' ela= 1085 file number=4 first dba=57649 block cnt=15 obj#=74914 tim=20802454106
WAIT #7: nam='direct path read' ela= 422 file number=4 first dba=57665 block cnt=15 obj#=74914 tim=20802454836
WAIT #7: nam='direct path read' ela= 544 file number=4 first dba=57681 block cnt=15 obj#=74914 tim=20802455670
WAIT #7: nam='direct path read' ela= 564 file number=4 first dba=57697 block cnt=15 obj#=74914 tim=20802456506
WAIT #7: nam='direct path read' ela= 492 file number=4 first dba=57713 block cnt=15 obj#=74914 tim=20802457278
WAIT #7: nam='direct path read' ela= 1183 file number=4 first dba=61825 block cnt=15 obj#=74914 tim=20802458751
WAIT #7: nam='direct path read' ela= 661 file number=4 first dba=61841 block cnt=15 obj#=74914 tim=20802460256

 

缺省情况下Oracle认为在2%的cache buffer以下的表格认为是小表,在FTS操作中被放到MRU end。 
在_small_table_threshold以上的表格标记为大表,FTS操作结果被放置到LRU end。也就是说Oracle仅仅缓冲一次操作的结果。

The default is not 5 blocks; it is 2% of db_block_buffers with a minimum of 4 blocks. The effect is exactly as you describe. Small tables are cached at the MRU end of the cache by default. The statistic is incremented for all logical small table scans, even against fully cached tables. It is also incremented for scans of small tables for which the NOCACHE keyword has been specified. It is not however incremented for large tables for which the CACHE keyword has been specified.

This parameter is session modifiable and system modifiable with deferred semantics. If changed dynamically, the parameter name needs to be enclosed in quotes to protect the leading underscore, as follows.

alter session set "_small_table_theshold" = 100;

需要指出的是该参数可以动态调整,其默认值不是业界所认为的5 blocks,而是小于等于db_cache_size*2%或者是4*blocksize(当db_cache_size小于200个blocks时),假设2G的Cache buffer,那么2G*2%=40m,这样在40m以下的表格都可能被认为小表。假设表格平均行长为200字节,8k块,具有5120个块。平均可用空间8000,这样40m的表格有204800行。这个数字还是颇为可观的

上一篇:【Jenkins】linux下Jenkins集成ant进行编译并发送结果


下一篇:阿里巴巴2016研发project师笔试题