对于一个两列的复合索引,where条件中都是用 “=” 号 和 and,
选取索引时,为什么选择 索引名 ascii码小的??
在天师 老托拉呱 的指点下, 不用动态采样+cbo, 还是一样的结果 。
用rbo的话,会一直有同一个。但是 不晓得 cbo的原因 。
最终在 天师的指示下看到Handling
of equally ranked (RBO) or costed (CBO) indexes (Doc ID
73167.1)
create table t11 as select * from dba_objects;
create index idx_1 on t11(object_id,object_name);
create index idx_2 on t11(object_name,object_id);
Alter session set events '10053 trace name context forever,
level 1';
select * from t11 where object_name='ICOL$' and
object_id=20;
Alter session set events '10053 trace name context off';
Access Path: TableScan
Cost:
139.65 Resp: 139.65
Degree: 0
Cost_io: 139.00 Cost_cpu: 20044626
Resp_io: 139.00 Resp_cpu: 20044626
Access Path: index (AllEqRange)
Index: IDX_1
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.6000e-05
ix_sel_with_filters: 1.6000e-05
Cost: 2.00
Resp: 2.00 Degree: 1
Access Path: index (AllEqRange)
Index: IDX_2
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.6000e-05
ix_sel_with_filters: 1.6000e-05
Cost: 2.00
Resp: 2.00 Degree: 1
****** trying bitmap/domain indexes
******
****** finished trying bitmap/domain
indexes ******
Best:: AccessPath: IndexRange
Index: IDX_1
Cost: 2.00
Degree: 1 Resp: 2.00
Card: 5.75
Bytes:
***************************************
OPTIMIZER STATISTICS AND COMPUTATIONS
***************************************
GENERAL PLANS
***************************************
Considering cardinality-based initial join order.
Permutations for Starting Table :0
***********************
Join order[1]: T11[T11]#0
***********************
Best so far: Table#: 0 cost: 2.0005
card: 5.7533 bytes: 1062
(newjo-stop-1) k:0, spcnt:0, perm:1, maxperm:80000
*********************************
Number of join permutations tried: 1
*********************************
Final - All Rows Plan: Best join order:
1
Cost: 2.0005 Degree: 1
Card: 6.0000 Bytes: 1062
Resc: 2.0005 Resc_io:
2.0000 Resc_cpu: 15683
Resp: 2.0005 Resp_io:
2.0000 Resc_cpu: 15683
kkoipt: Query block SEL$1 (#0)
******* UNPARSED QUERY IS *******
SELECT "T11"."OWNER" "OWNER","T11"."OBJECT_NAME"
"OBJECT_NAME","T11"."SUBOBJECT_NAME"
"SUBOBJECT_NAME","T11"."OBJECT_ID"
"OBJECT_ID","T11"."DATA_OBJECT_ID"
"DATA_OBJECT_ID","T11"."OBJECT_TYPE" "OBJECT_TYPE","T11"."CREATED"
"CREATED","T11"."LAST_DDL_TIME" "LAST_DDL_TIME","T11"."TIMESTAMP"
"TIMESTAMP","T11"."STATUS" "STATUS","T11"."TEMPORARY"
"TEMPORARY","T11"."GENERATED" "GENERATED","T11"."SECONDARY"
"SECONDARY" FROM "SONG"."T11" "T11" WHERE
"T11"."OBJECT_NAME"='ICOL$' AND "T11"."OBJECT_ID"=20
kkoqbc-subheap (delete addr=0x2b271cfabe38, in-use=17008,
alloc=18400)
kkoqbc-end
: call(in-use=37416,
alloc=65448), compile(in-use=48936, alloc=50504)
apadrv-end: call(in-use=37416, alloc=65448),
compile(in-use=49808, alloc=50504)
sql_id=7a6qgwc26kkq4.
Current SQL statement for this session:
select * from t11 where object_name='ICOL$' and
object_id=20
============
Plan Table
============
-----------------------------------------------+-----------------------------------+
| Id | Operation | Name
| Rows |
Bytes | Cost | Time |
-----------------------------------------------+-----------------------------------+
| 0 | SELECT STATEMENT | |
|
|
2 | |
| 1 | TABLE ACCESS BY
INDEX ROWID | T11 |
6 | 1062 |
2 |
00:00:01 |
| 2 | INDEX RANGE SCAN
| IDX_1 |
1 | | 1 | 00:00:01 |
-----------------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - access("OBJECT_ID"=20 AND "OBJECT_NAME"='ICOL$')
Content of other_xml column
===========================
db_version : 10.2.0.4
parse_schema :
SONG
dynamic_sampling: yes
plan_hash : 1193947757
Outline Data:
select * from dba_objects;
alter system flush buffer_cache;
alter system flush shared_pool;
drop index idx_1;
create index idx_3 on t11(object_id,object_name);
Alter session set events '10053 trace name context forever,
level 1';
select * from t11 where object_name='ICOL$' and
object_id=20;
Alter session set events '10053 trace name context off';
Access Path: TableScan
Cost:
139.65 Resp: 139.65
Degree: 0
Cost_io: 139.00 Cost_cpu: 20044626
Resp_io: 139.00 Resp_cpu: 20044626
Access Path: index (AllEqRange)
Index: IDX_2
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.6000e-05
ix_sel_with_filters: 1.6000e-05
Cost: 2.00
Resp: 2.00 Degree: 1
Access Path: index (AllEqRange)
Index: IDX_3
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.6000e-05
ix_sel_with_filters: 1.6000e-05
Cost: 2.00
Resp: 2.00 Degree: 1
****** trying bitmap/domain indexes
******
****** finished trying bitmap/domain
indexes ******
Best:: AccessPath: IndexRange
Index: IDX_2
Cost: 2.00
Degree: 1 Resp: 2.00
Card: 5.75 Bytes: 0
***************************************
OPTIMIZER STATISTICS AND COMPUTATIONS
***************************************
GENERAL PLANS
***************************************
Considering cardinality-based initial join order.
Permutations for Starting Table :0
***********************
Join order[1]: T11[T11]#0
***********************
Best so far: Table#: 0 cost: 2.0005
card: 5.7533 bytes: 1062
(newjo-stop-1) k:0, spcnt:0, perm:1, maxperm:80000
*********************************
Number of join permutations tried: 1
*********************************
Final - All Rows Plan: Best join order:
1
Cost: 2.0005 Degree: 1
Card: 6.0000 Bytes: 1062
Resc: 2.0005 Resc_io:
2.0000 Resc_cpu: 15683
Resp: 2.0005 Resp_io:
2.0000 Resc_cpu: 15683
kkoipt: Query block SEL$1 (#0)
******* UNPARSED QUERY IS *******
SELECT "T11"."OWNER" "OWNER","T11"."OBJECT_NAME"
"OBJECT_NAME","T11"."SUBOBJECT_NAME"
"SUBOBJECT_NAME","T11"."OBJECT_ID"
"OBJECT_ID","T11"."DATA_OBJECT_ID"
"DATA_OBJECT_ID","T11"."OBJECT_TYPE" "OBJECT_TYPE","T11"."CREATED"
"CREATED","T11"."LAST_DDL_TIME" "LAST_DDL_TIME","T11"."TIMESTAMP"
"TIMESTAMP","T11"."STATUS" "STATUS","T11"."TEMPORARY"
"TEMPORARY","T11"."GENERATED" "GENERATED","T11"."SECONDARY"
"SECONDARY" FROM "SONG"."T11" "T11" WHERE "T11"."OBJECT_ID"=20 AND
"T11"."OBJECT_NAME"='ICOL$'
kkoqbc-subheap (delete addr=0x2aca370cbe38, in-use=17008,
alloc=18400)
kkoqbc-end
: call(in-use=37416,
alloc=65448), compile(in-use=48936, alloc=50504)
apadrv-end: call(in-use=37416, alloc=65448),
compile(in-use=49808, alloc=50504)
sql_id=7a6qgwc26kkq4.
Current SQL statement for this session:
select * from t11 where object_name='ICOL$' and
object_id=20
============
Plan Table
============
-----------------------------------------------+-----------------------------------+
| Id | Operation | Name
| Rows |
Bytes | Cost | Time |
-----------------------------------------------+-----------------------------------+
| 0 | SELECT STATEMENT | |
|
|
2 | |
| 1 | TABLE ACCESS BY
INDEX ROWID | T11 |
6 | 1062 |
2 |
00:00:01 |
| 2 | INDEX RANGE SCAN
| IDX_2 |
1 | | 1 | 00:00:01 |
-----------------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - access("OBJECT_NAME"='ICOL$' AND "OBJECT_ID"=20)
Content of other_xml column
===========================
db_version : 10.2.0.4
parse_schema :
SONG
dynamic_sampling: yes
plan_hash : 4084186866
Outline Data:
alter system flush buffer_cache;
alter system flush shared_pool;
drop index idx_3;
create index idx on t11(object_id,object_name);
Alter session set events '10053 trace name context forever,
level 1';
select * from t11 where object_name='ICOL$' and
object_id=20;
Alter session set events '10053 trace name context off';
Access Path: TableScan
Cost:
139.65 Resp: 139.65
Degree: 0
Cost_io: 139.00 Cost_cpu: 20044626
Resp_io: 139.00 Resp_cpu: 20044626
Access Path: index (AllEqRange)
Index: IDX
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.6000e-05
ix_sel_with_filters: 1.6000e-05
Cost: 2.00
Resp: 2.00 Degree: 1
Access Path: index (AllEqRange)
Index: IDX_2
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.6000e-05
ix_sel_with_filters: 1.6000e-05
Cost: 2.00
Resp: 2.00 Degree: 1
****** trying bitmap/domain indexes
******
****** finished trying bitmap/domain
indexes ******
Best:: AccessPath: IndexRange
Index: IDX
Cost: 2.00
Degree: 1 Resp: 2.00
Card: 5.75 Bytes: 0
***************************************
OPTIMIZER STATISTICS AND COMPUTATIONS
***************************************
GENERAL PLANS
***************************************
Considering cardinality-based initial join order.
Permutations for Starting Table :0
***********************
Join order[1]: T11[T11]#0
***********************
Best so far: Table#: 0 cost: 2.0005
card: 5.7533 bytes: 1062
(newjo-stop-1) k:0, spcnt:0, perm:1, maxperm:80000
*********************************
Number of join permutations tried: 1
*********************************
Final - All Rows Plan: Best join order:
1
Cost: 2.0005 Degree: 1
Card: 6.0000 Bytes: 1062
Resc: 2.0005 Resc_io:
2.0000 Resc_cpu: 15683
Resp: 2.0005 Resp_io:
2.0000 Resc_cpu: 15683
kkoipt: Query block SEL$1 (#0)
******* UNPARSED QUERY IS *******
SELECT "T11"."OWNER" "OWNER","T11"."OBJECT_NAME"
"OBJECT_NAME","T11"."SUBOBJECT_NAME"
"SUBOBJECT_NAME","T11"."OBJECT_ID"
"OBJECT_ID","T11"."DATA_OBJECT_ID"
"DATA_OBJECT_ID","T11"."OBJECT_TYPE" "OBJECT_TYPE","T11"."CREATED"
"CREATED","T11"."LAST_DDL_TIME" "LAST_DDL_TIME","T11"."TIMESTAMP"
"TIMESTAMP","T11"."STATUS" "STATUS","T11"."TEMPORARY"
"TEMPORARY","T11"."GENERATED" "GENERATED","T11"."SECONDARY"
"SECONDARY" FROM "SONG"."T11" "T11" WHERE
"T11"."OBJECT_NAME"='ICOL$' AND "T11"."OBJECT_ID"=20
kkoqbc-subheap (delete addr=0x2b431ecbbe38, in-use=17008,
alloc=18400)
kkoqbc-end
: call(in-use=37416,
alloc=65448), compile(in-use=48936, alloc=50504)
apadrv-end: call(in-use=37416, alloc=65448),
compile(in-use=49808, alloc=50504)
sql_id=7a6qgwc26kkq4.
Current SQL statement for this session:
select * from t11 where object_name='ICOL$' and
object_id=20
============
Plan Table
============
-----------------------------------------------+-----------------------------------+
| Id | Operation | Name
| Rows |
Bytes | Cost | Time |
-----------------------------------------------+-----------------------------------+
| 0 | SELECT STATEMENT | |
|
|
2 | |
| 1 | TABLE ACCESS BY
INDEX ROWID | T11 |
6 | 1062 |
2 |
00:00:01 |
| 2 | INDEX RANGE SCAN
| IDX | 1 |
|
1 |
00:00:01 |
-----------------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - access("OBJECT_ID"=20 AND "OBJECT_NAME"='ICOL$')
Content of other_xml column
===========================
db_version : 10.2.0.4
parse_schema :
SONG
dynamic_sampling: yes
plan_hash : 1540313942
Outline Data:
SINGLE TABLE ACCESS PATH
-----------------------------------------
BEGIN Single Table Cardinality
Estimation
-----------------------------------------
*** 2014-05-21 23:57:46.850
** Performing dynamic sampling initial checks. **
** Not using dynamic sampling since sampling disabled or level
equals 0.
Column (#2): OBJECT_NAME(VARCHAR2)
NO STATISTICS (using defaults)
AvgLen: 66.00 NDV: 1812
Nulls: 0 Density: 5.5179e-04
Column (#4): OBJECT_ID(NUMBER)
NO STATISTICS (using defaults)
AvgLen: 13.00 NDV: 1812
Nulls: 0 Density: 5.5179e-04
Table: T11 Alias: T11
Card: Original: 57993
Rounded: 6 Computed: 5.80
Non Adjusted: 5.80
-----------------------------------------
END Single Table
Cardinality Estimation
-----------------------------------------
Access Path: TableScan
Cost:
139.66 Resp: 139.66
Degree: 0
Cost_io: 139.00 Cost_cpu: 20164479
Resp_io: 139.00 Resp_cpu: 20164479
Access Path: index (AllEqRange)
Index: IDX
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.9926e-05
ix_sel_with_filters: 1.9926e-05
Cost: 2.00
Resp: 2.00 Degree: 1
Access Path: index (AllEqRange)
Index: IDX_2
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.9926e-05
ix_sel_with_filters: 1.9926e-05
Cost: 2.00
Resp: 2.00 Degree: 1
****** trying bitmap/domain indexes
******
****** finished trying bitmap/domain
indexes ******
Best:: AccessPath: IndexRange
Index: IDX
Cost: 2.00
Degree: 1 Resp: 2.00
Card: 5.80 Bytes: 0
***************************************
OPTIMIZER STATISTICS AND COMPUTATIONS
***************************************
GENERAL PLANS
***************************************
Considering cardinality-based initial join order.
Permutations for Starting Table :0
***********************
Join order[1]: T11[T11]#0
***********************
Best so far: Table#: 0 cost: 2.0005
card: 5.7993 bytes: 1062
(newjo-stop-1) k:0, spcnt:0, perm:1, maxperm:80000
*********************************
Number of join permutations tried: 1
*********************************
Final - All Rows Plan: Best join order:
1
Cost: 2.0005 Degree: 1
Card: 6.0000 Bytes: 1062
Resc: 2.0005 Resc_io:
2.0000 Resc_cpu: 15683
Resp: 2.0005 Resp_io:
2.0000 Resc_cpu: 15683
kkoipt: Query block SEL$1 (#0)
******* UNPARSED QUERY IS *******
SELECT "T11"."OWNER" "OWNER","T11"."OBJECT_NAME"
"OBJECT_NAME","T11"."SUBOBJECT_NAME"
"SUBOBJECT_NAME","T11"."OBJECT_ID"
"OBJECT_ID","T11"."DATA_OBJECT_ID"
"DATA_OBJECT_ID","T11"."OBJECT_TYPE" "OBJECT_TYPE","T11"."CREATED"
"CREATED","T11"."LAST_DDL_TIME" "LAST_DDL_TIME","T11"."TIMESTAMP"
"TIMESTAMP","T11"."STATUS" "STATUS","T11"."TEMPORARY"
"TEMPORARY","T11"."GENERATED" "GENERATED","T11"."SECONDARY"
"SECONDARY" FROM "SONG"."T11" "T11" WHERE
"T11"."OBJECT_NAME"='ICOL$' AND "T11"."OBJECT_ID"=20
kkoqbc-subheap (delete addr=0x2b1185b7be38, in-use=16056,
alloc=18400)
kkoqbc-end
: call(in-use=29840,
alloc=65448), compile(in-use=48624, alloc=50504)
apadrv-end: call(in-use=29840, alloc=65448),
compile(in-use=49408, alloc=50504)
sql_id=22bwf2zav4aha.
Current SQL statement for this session:
select * from t11 where object_name='ICOL$' and
object_id=20
============
Plan Table
============
-----------------------------------------------+-----------------------------------+
| Id | Operation | Name
| Rows |
Bytes | Cost | Time |
-----------------------------------------------+-----------------------------------+
| 0 | SELECT STATEMENT | |
|
|
2 | |
| 1 | TABLE ACCESS BY
INDEX ROWID | T11 |
6 | 1062 |
2 |
00:00:01 |
| 2 | INDEX RANGE SCAN
| IDX | 1 |
|
1 |
00:00:01 |
-----------------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - access("OBJECT_ID"=20 AND "OBJECT_NAME"='ICOL$')
Content of other_xml column
===========================
db_version : 10.2.0.4
parse_schema :
SONG
plan_hash : 1540313942
Outline Data:
drop index idx;
create index idx_3 on
t11(object_id,object_name);
****************
QUERY BLOCK TEXT
****************
select * from t11 where object_name='ICOL$' and
object_id=20
*********************
QUERY BLOCK SIGNATURE
*********************
qb name was generated
signature (optimizer): qb_name=SEL$1 nbfros=1 flg=0
fro(0): flg=0 objn=57349
hint_alias="T11"@"SEL$1"
*****************************
SYSTEM STATISTICS INFORMATION
*****************************
Using NOWORKLOAD Stats
CPUSPEED: 2563 millions
instruction/sec
IOTFRSPEED: 4096 bytes per millisecond
(default is 4096)
IOSEEKTIM: 10 milliseconds (default is
10)
***************************************
BASE STATISTICAL INFORMATION
***********************
Table Stats::
Table: T11 Alias: T11
(NOT ANALYZED)
#Rows: 57993
#Blks: 710
AvgRowLen: 100.00
Index Stats::
Index: IDX_2 Col#: 2
4
LVLS: 1
#LB: 281 #DK: 50186
LB/K: 1.00 DB/K: 1.00
CLUF: 25485.00
Index: IDX_3 Col#: 4
2
LVLS: 1
#LB: 281 #DK: 50186
LB/K: 1.00 DB/K: 1.00
CLUF: 749.00
***************************************
SINGLE TABLE ACCESS PATH
-----------------------------------------
BEGIN Single Table Cardinality
Estimation
-----------------------------------------
*** 2014-05-22 00:00:45.072
** Performing dynamic sampling initial checks. **
** Not using dynamic sampling since sampling disabled or level
equals 0.
Column (#2): OBJECT_NAME(VARCHAR2)
NO STATISTICS (using defaults)
AvgLen: 66.00 NDV: 1812
Nulls: 0 Density: 5.5179e-04
Column (#4): OBJECT_ID(NUMBER)
NO STATISTICS (using defaults)
AvgLen: 13.00 NDV: 1812
Nulls: 0 Density: 5.5179e-04
Table: T11 Alias: T11
Card: Original: 57993
Rounded: 6 Computed: 5.80
Non Adjusted: 5.80
-----------------------------------------
END Single Table
Cardinality Estimation
-----------------------------------------
Access Path: TableScan
Cost:
139.66 Resp: 139.66
Degree: 0
Cost_io: 139.00 Cost_cpu: 20164479
Resp_io: 139.00 Resp_cpu: 20164479
Access Path: index (AllEqRange)
Index: IDX_2
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.9926e-05
ix_sel_with_filters: 1.9926e-05
Cost: 2.00
Resp: 2.00 Degree: 1
Access Path: index (AllEqRange)
Index: IDX_3
resc_io: 2.00
resc_cpu: 15683
ix_sel: 1.9926e-05
ix_sel_with_filters: 1.9926e-05
Cost: 2.00
Resp: 2.00 Degree: 1
****** trying bitmap/domain indexes
******
****** finished trying bitmap/domain
indexes ******
Best:: AccessPath: IndexRange
Index: IDX_2
Cost: 2.00
Degree: 1 Resp: 2.00
Card: 5.80 Bytes: 0
***************************************
OPTIMIZER STATISTICS AND COMPUTATIONS
***************************************
GENERAL PLANS
***************************************
Considering cardinality-based initial join order.
Permutations for Starting Table :0
***********************
Join order[1]: T11[T11]#0
***********************
Best so far: Table#: 0 cost: 2.0005
card: 5.7993 bytes: 1062
(newjo-stop-1) k:0, spcnt:0, perm:1, maxperm:80000
*********************************
Number of join permutations tried: 1
*********************************
Final - All Rows Plan: Best join order:
1
Cost: 2.0005 Degree: 1
Card: 6.0000 Bytes: 1062
Resc: 2.0005 Resc_io:
2.0000 Resc_cpu: 15683
Resp: 2.0005 Resp_io:
2.0000 Resc_cpu: 15683
kkoipt: Query block SEL$1 (#0)
******* UNPARSED QUERY IS *******
SELECT "T11"."OWNER" "OWNER","T11"."OBJECT_NAME"
"OBJECT_NAME","T11"."SUBOBJECT_NAME"
"SUBOBJECT_NAME","T11"."OBJECT_ID"
"OBJECT_ID","T11"."DATA_OBJECT_ID"
"DATA_OBJECT_ID","T11"."OBJECT_TYPE" "OBJECT_TYPE","T11"."CREATED"
"CREATED","T11"."LAST_DDL_TIME" "LAST_DDL_TIME","T11"."TIMESTAMP"
"TIMESTAMP","T11"."STATUS" "STATUS","T11"."TEMPORARY"
"TEMPORARY","T11"."GENERATED" "GENERATED","T11"."SECONDARY"
"SECONDARY" FROM "SONG"."T11" "T11" WHERE "T11"."OBJECT_ID"=20 AND
"T11"."OBJECT_NAME"='ICOL$'
kkoqbc-subheap (delete addr=0x2b479b4abe38, in-use=16056,
alloc=18400)
kkoqbc-end
: call(in-use=29840,
alloc=65448), compile(in-use=48624, alloc=50504)
apadrv-end: call(in-use=29840, alloc=65448),
compile(in-use=49408, alloc=50504)
sql_id=22bwf2zav4aha.
Current SQL statement for this session:
select * from t11 where object_name='ICOL$' and
object_id=20
============
Plan Table
============
-----------------------------------------------+-----------------------------------+
| Id | Operation | Name
| Rows |
Bytes | Cost | Time |
-----------------------------------------------+-----------------------------------+
| 0 | SELECT STATEMENT | |
|
|
2 | |
| 1 | TABLE ACCESS BY
INDEX ROWID | T11 |
6 | 1062 |
2 |
00:00:01 |
| 2 | INDEX RANGE SCAN
| IDX_2 |
1 | | 1 | 00:00:01 |
-----------------------------------------------+-----------------------------------+
Predicate Information:
----------------------
2 - access("OBJECT_NAME"='ICOL$' AND "OBJECT_ID"=20)
Content of other_xml column
===========================
db_version : 10.2.0.4
parse_schema :
SONG
plan_hash : 4084186866
Outline Data: