oracle實驗記錄 (FTS的cost與基數計算)
SQL> ed~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~FTS
Wrote file afiedt.buf
1 explain plan for select
2 small_vc
3 from
4 t1
5 where
6 n1 = 2
7* and n2 = 3
SQL> /
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1931397137
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 20 | 340 | 113 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 20 | 340 | 113 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
1 - filter("N1"=2 AND "N2"=3)
13 rows selected.
SQL> select column_name ,num_distinct from user_tab_col_statistics where table_
name='T1';
COLUMN_NAME NUM_DISTINCT
------------------------------ ------------
N1 25
IND_PAD 1
N2 20
SMALL_VC 10000
PADDING 1
SQL> select num_rows from user_tab_statistics where table_name='T1';
NUM_ROWS
----------
10000
CARD=10000 *(1/25*1/20)~~雙謂詞=20
SQL> show parameter db_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_multiblock_read_count integer 16
db_file_name_convert string
db_files integer 200
SQL>
SQL> show parameter db_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_multiblock_read_count integer 16
db_file_name_convert string
db_files integer 200
SQL>
SQL> select pname ,pval1 from aux_stats$ where sname='SYSSTATS_MAIN';
PNAME PVAL1
------------------------------ ----------
CPUSPEEDNW 1212.002
IOSEEKTIM 10
IOTFRSPEED 4096
SREADTIM 8.621
MREADTIM 18.125
CPUSPEED 1498
MBRC 7
MAXTHR
SLAVETHR
SQL> select blocks from user_segments where segment_name='T1';
BLOCKS
----------
384
SQL>
SQL> select (384/7)*(18.125/8.621) from dual;
(384/7)*(18.125/8.621)
----------------------
115.332991
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~關於card
SQL> create table t2 (a int,b int ,c int);
Table created.
1 declare
2 begin
3 for i in 1..10000 loop
4 insert into t2 values(i,i+1,i+2);
5 end loop;
6 commit;
7* end;
SQL> /
SQL> exec dbms_stats.gather_table_stats('sys','t2');
PL/SQL procedure successfully completed.
SQL> /
SQL> explain plan for select count(*) from t2 where a=2 and b=3 and c=4;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
----------------------------------------------------
Plan hash value: 720591907
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 10 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 11 | | |
|* 2 | TABLE ACCESS FULL| T2 | 1 | 11 | 10 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
----------------------------------------------------
---------------------------------------------------
2 - filter("A"=2 AND "B"=3 AND "C"=4)
14 rows selected.
SQL> select pname ,pval1 from aux_stats$ where sname='SYSSTATS_MAIN';
PNAME PVAL1
------------------------------ ----------
CPUSPEEDNW 1212.002
IOSEEKTIM 10
IOTFRSPEED 4096
SREADTIM 8.621
MREADTIM 18.125
CPUSPEED 1498
MBRC 7
MAXTHR
SLAVETHR
9 rows selected.
SQL> select column_name ,num_distinct,density from user_tab_col_statistics wher
e table_name='T2';
COLUMN_NAME NUM_DISTINCT DENSITY
------------------------------ ------------ ----------
A 10000 .0001
B 10000 .0001
C 10000 .0001
SQL>
card=10000*(1/10000)*1/10000*1/10000)~太小了只能等於1最小 也得 1吧,不然搜尋啥呢
SQL> select blocks from user_segments where segment_name='T2';
BLOCKS
----------
32
cost (IO)=(32/7)*( 18.125/8.621)
SQL> select (32/7)*( 18.125/8.621) from dual;
(32/7)*(18.125/8.621)
---------------------
9.61108257
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12020513/viewspace-611427/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle實驗記錄(並行操作與FTS COST)Oracle並行
- oracle實驗記錄 (計算hash join cost)Oracle
- oracle實驗記錄 (全表掃描COST計算方法)Oracle
- oracle實驗記錄 (oracle b*tree index訪問Cost計算(1))OracleIndex
- oracle實驗記錄 (oracle單表選擇率與基數計算(1))Oracle
- oracle實驗記錄 (oracle單表選擇率與基數計算(2))Oracle
- oracle實驗記錄 (oracle單表選擇率與基數計算(3))Oracle
- oracle實驗記錄 (分割槽表,掃描基數的計算)Oracle
- oracle實驗記錄(分割槽全表掃描(全區掃描) FTS 時候的成本計算)Oracle
- oracle實驗記錄 (predicate對cpu cost的影響)Oracle
- oracle實驗記錄 (oracle consistent gets 計算)Oracle
- oracle計算表的記錄數Oracle
- oracle實驗記錄 (基礎,truncate與delete區別實驗)Oracledelete
- oracle實驗記錄(INDEX fast full scan 的成本計算)OracleIndexAST
- oracle cost計算方式Oracle
- oracle實驗記錄 (logfile基礎操作)Oracle
- 計算記錄個數
- oracle實驗記錄 (子游標與解析)Oracle
- oracle實驗記錄 (flashback)Oracle
- oracle實驗記錄 (OMF)Oracle
- oracle實驗記錄 (NET)Oracle
- oracle實驗記錄 (audit)Oracle
- oracle實驗記錄(logfile基礎操作2)Oracle
- oracle實驗記錄 (storage儲存引數(1))Oracle
- oracle實驗記錄 (storage儲存引數(2))Oracle
- oracle實驗記錄 (oracle reset parameter)Oracle
- oracle實驗記錄 (PGA manual or auto 與hash join)Oracle
- oracle cost計算(轉自itpub網友)Oracle
- Oracle Data Redaction實驗記錄Oracle
- oracle實驗記錄 (block cleanout)OracleBloC
- oracle實驗記錄 (dump undo)Oracle
- oracle實驗記錄 (inlist card)Oracle
- oracle實驗記錄 (oracle 關於instance引數設定)Oracle
- oracle實驗記錄 (oracle 10G dataguard(2)引數部分)Oracle
- oracle實驗記錄 (CKPT的觸發)Oracle
- oracle實驗記錄 (listener.ora與 tnsnames.ora)Oracle
- oracle實驗記錄 (oracle 資料字典)Oracle
- oracle實驗記錄 (oracle 10G dataguard(10)flashback 與dg)Oracle