|
|
正常情况下,拥有足够的信息,Oracle应该可以识别这个差异的。
以下是构造的一个测试例子:
[php]
SQL> create table test (a varchar2(30),b number,c number);
Table created.
SQL> insert into test select object_name,rownum,rownum+10 from dba_objects;
6307 rows created.
SQL> commit;
Commit complete.
SQL> insert into test select * from test;
6307 rows created.
SQL> /
12614 rows created.
SQL> /
25228 rows created.
SQL> /
50456 rows created.
SQL> commit;
Commit complete.
SQL> insert into test select * from test;
100912 rows created.
SQL> commit;
Commit complete.
SQL> insert into test select * from test;
201824 rows created.
SQL> SQL>
SQL> commit;
Commit complete.
SQL> select count(*) from test;
COUNT(*)
----------
403648
SQL>
SQL> insert into test select * from test;
403648 rows created.
SQL> commit;
Commit complete.
--'构造80w测试记录'
SQL> update test set b=1 where rownum <10000;
9999 rows updated.
SQL> commit;
--'b=1记录为1w-1条'
Commit complete.
SQL> update test set a = 'eygle' where rownum <30000;
29999 rows updated.
--'eygle记录为3w-1条'
SQL> commit;
Commit complete.
SQL> update test set a='eygle.com' where a<>'eygle';
777297 rows updated.
--'eygle.com记录为777297 条'
SQL> commit;
Commit complete.
SQL> create index i_a on test (a);
Index created.
SQL> create index i_bc on test(b,c);
Index created.
SQL> analyze table test compute statistics for table for all indexes for all indexed columns;
Table analyzed.
--'收集统计信息,包括柱状图'
SQL> set autotrace traceoly
Usage: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
SQL> set autotrace traceonly
SQL> set timing on
SQL> select count(*) from test where a='eygle' and b=1;
Elapsed: 00:00:00.55
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=212 Card=1 Bytes=12)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TEST' (Cost=212 Card=9 Bytes=108)
3 2 INDEX (RANGE SCAN) OF 'I_A' (NON-UNIQUE) (Cost=90 Card=29999)
--'注意此时选择i_a索引,这是差别不大的'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
942 consistent gets
194 physical reads
0 redo size
381 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select count(*) from test where a='eygle.com' and b=1;
Elapsed: 00:00:00.35
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=255 Card=1 Bytes=12)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TEST' (Cost=255 Card=242 Bytes=2904)
3 2 INDEX (RANGE SCAN) OF 'I_BC' (NON-UNIQUE) (Cost=3 Card=252)
--'此时Oracle优选了索引i_bc'
--'注意我构造的数据,柱状图差异明显,如过差别不大,执行计划可能不同'
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
7803 consistent gets
63 physical reads
0 redo size
380 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
[/php] |
|