Skip to content

Instantly share code, notes, and snippets.

@xtender
Created May 24, 2022 23:17
Show Gist options
  • Save xtender/3c2d608f0d8de6b63b78f814903c70ea to your computer and use it in GitHub Desktop.
Save xtender/3c2d608f0d8de6b63b78f814903c70ea to your computer and use it in GitHub Desktop.
Controlling “direct path reads” decision with "table_stats" hint
SQL> select name,block_size,buffers from v$buffer_pool;
NAME BLOCK_SIZE BUFFERS
-------------------- ---------- ----------
DEFAULT 8192 41118
SQL> col vlot new_value vlot;
SQL> select buffers*5+1 as vlot from v$buffer_pool;
VLOT
----------
205591
SQL> create table t_direct as select 1 x from dual;
Table created.
SQL> select name,value from v$statname n,v$sesstat s where s.sid=userenv('sid') and s.statistic#=n.statistic# and name='physical reads direct';
NAME VALUE
---------------------------------------------------------------- ----------
physical reads direct 0
SQL> select count(*) from t_direct;
COUNT(*)
----------
1
SQL> select name,value from v$statname n,v$sesstat s where s.sid=userenv('sid') and s.statistic#=n.statistic# and name='physical reads direct';
NAME VALUE
---------------------------------------------------------------- ----------
physical reads direct 0
SQL> select/*+ table_stats(t_direct set rows=1000000 blocks=&vlot) */ count(*) from t_direct;
COUNT(*)
----------
1
SQL> select name,value from v$statname n,v$sesstat s where s.sid=userenv('sid') and s.statistic#=n.statistic# and name='physical reads direct';
NAME VALUE
---------------------------------------------------------------- ----------
physical reads direct 1
@vparam_ _very_large_object_threshold
select name,block_size,buffers from v$buffer_pool;
col vlot new_value vlot;
select buffers*5+1 as vlot from v$buffer_pool;
create table t_direct as select 1 x from dual;
select name,value from v$statname n,v$sesstat s where s.sid=userenv('sid') and s.statistic#=n.statistic# and name='physical reads direct';
select count(*) from t_direct;
select name,value from v$statname n,v$sesstat s where s.sid=userenv('sid') and s.statistic#=n.statistic# and name='physical reads direct';
select/*+ table_stats(t_direct set rows=1000000 blocks=&vlot) */ count(*) from t_direct;
select name,value from v$statname n,v$sesstat s where s.sid=userenv('sid') and s.statistic#=n.statistic# and name='physical reads direct';
@xtender
Copy link
Author

xtender commented May 24, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment