最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

ROWID走索引之判决

来源:动视网 责编:小采 时间:2020-11-09 11:27:48
文档

ROWID走索引之判决

ROWID走索引之判决:ROWID走索引之判决,在NOT NULL 且数据位0的情况下 index的 block 为0,table的至少为1 那么index的cost就是0,CBO当然会选择cost ROWID走索引之判决: SQL> select rowid from a;ROWID------------------AAAQ/LAAC
推荐度:
导读ROWID走索引之判决:ROWID走索引之判决,在NOT NULL 且数据位0的情况下 index的 block 为0,table的至少为1 那么index的cost就是0,CBO当然会选择cost ROWID走索引之判决: SQL> select rowid from a;ROWID------------------AAAQ/LAAC


ROWID走索引之判决,在NOT NULL 且数据位0的情况下 index的 block 为0,table的至少为1 那么index的cost就是0,CBO当然会选择cost

ROWID走索引之判决:

SQL> select rowid from a;
ROWID
------------------
AAAQ/LAACAAABacAAA
AAAQ/LAACAAABacAAB
SQL> desc a;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(5)
NAME VARCHAR2(35)
CREATE_TIME DATE
SQL> select index_name from user_indexes where table_name='A';
INDEX_NAME
--------------------------------------------------------------------------------
IDX_A_ID
SQL> delete from a;
2 rows deleted.
SQL> commit;
Commit complete.
SQL> exec dbms_stats.gather_table_stats(ownname=>'TEST',tabname=>'A',cascade=>true);
PL/SQL procedure successfully completed.
SQL> set autotrace traceonly;
SQL> delete from a where rowid='AAAQ/LAACAAABacAAA';
0 rows deleted.

Execution Plan
----------------------------------------------------------
Plan hash value: 2233874139
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | DELETE STATEMENT | | 1 | 25 | 0 (0)| 00:00:01 |
| 1 | DELETE | A | | | | |
|* 2 | INDEX FULL SCAN| IDX_A_ID | 1 | 25 | 0 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(ROWID='AAAQ/LAACAAABacAAA')

Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
1 consistent gets
0 physical reads
0 redo size
824 bytes sent via SQL*Net to client
739 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> set autotrace off;
SQL> desc a;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(5)
NAME VARCHAR2(35)
CREATE_TIME DATE
SQL> alter table a modify id null;
Table altered.
SQL> desc a;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(5)
NAME VARCHAR2(35)
CREATE_TIME DATE
SQL> set autotrace traceonly;
SQL> delete from a where rowid='AAAQ/LAACAAABacAAB';
0 rows deleted.

Execution Plan
----------------------------------------------------------
Plan hash value: 18483634
--------------------------------------------------------------------------------
----
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
----
| 0 | DELETE STATEMENT | | 1 | 25 | 1 (0)| 00:00:
01 |
| 1 | DELETE | A | | | |
|
| 2 | TABLE ACCESS BY USER ROWID| A | 1 | 25 | 1 (0)| 00:00:
01 |
--------------------------------------------------------------------------------
----

Statistics
----------------------------------------------------------
34 recursive calls
0 db block gets
5 consistent gets
0 physical reads
0 redo size
826 bytes sent via SQL*Net to client
739 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
0 rows processed

作了个10053,以下是trace 文件部分内容 走索引
***********************
Table Stats::
Table: T Alias: T
#Rows: 0 #Blks: 1 AvgRowLen: 0.00
Index Stats::
Index: I_T Col#: 1
LVLS: 0 #LB: 0 #DK: 0 LB/K: 0.00 DB/K: 0.00 CLUF: 0.00
***************************************
1-ROW TABLES: T[T]#0
***************************************
SINGLE TABLE ACCESS PATH
Column (#1001): ROWID(ROWID) NO STATISTICS (using defaults)
AvgLen: 10.00 NDV: 0 Nulls: 0 Density: 0.0000e+000
Table: T Alias: T
Card: Original: 0 Rounded: 1 Computed: 0.00 Non Adjusted: 0.00
Access Path: TableScan
Cost: 2.00 Resp: 2.00 Degree: 0
Cost_io: 2.00 Cost_cpu: 7121
Resp_io: 2.00 Resp_cpu: 7121
Access Path: Rowid
Cost: 1.00 Resp: 1.00 Degree: 0
Cost_io: 1.00 Cost_cpu: 7271
Resp_io: 1.00 Resp_cpu: 7271
kkofmx: index filter:"T".ROWID='AAAQ9uAACAAABacAAB'
Access Path: index (FullScan)
Index: I_T
resc_io: 0.00 resc_cpu: 200
ix_sel: 1 ix_sel_with_filters: 1
Cost: 0.00 Resp: 0.00 Degree: 1
Best:: AccessPath: IndexRange Index: I_T
Cost: 0.00 Degree: 1 Resp: 0.00 Card: 1.00 Bytes: 0

走表

INGLE TABLE ACCESS PATH
Column (#1001): ROWID(ROWID) NO STATISTICS (using defaults)
AvgLen: 10.00 NDV: 3 Nulls: 0 Density: 0.33333
Table: A Alias: A
Card: Original: 3 Rounded: 1 Computed: 0.03 Non Adjusted: 0.03
Access Path: TableScan
Cost: 3.00 Resp: 3.00 Degree: 0
Cost_io: 3.00 Cost_cpu: 36167
Resp_io: 3.00 Resp_cpu: 36167
Access Path: Rowid
Cost: 1.00 Resp: 1.00 Degree: 0
Cost_io: 1.00 Cost_cpu: 7271
Resp_io: 1.00 Resp_cpu: 7271
kkofmx: index filter:"A".ROWID='AAAQ/LAACAAABacAAD'
Access Path: index (FullScan)
Index: IDX_A_ID
resc_io: 1.00 resc_cpu: 7721
ix_sel: 1 ix_sel_with_filters: 1
Cost: 1.00 Resp: 1.00 Degree: 1
One row Card: 1.00
Best:: AccessPath: RowId
Cost: 1.00 Degree: 1 Resp: 1.00 Card: 1.00 Bytes: 0

在 NULL 约束下并且PK的约束的话~是必须要table access full的 因为首先要保证的是结果的准确

在NOT NULL 且数据位0的情况下 index的 block 为0,,table的至少为1 那么index的cost就是0,CBO当然会选择cost低的来执行了
NOT NULL约束保证了结果准确性 才选择成本低的INDEX

说明一点要做好表信息分析收集工作

更多Oracle相关信息见Oracle 专题页面 ?tid=12

文档

ROWID走索引之判决

ROWID走索引之判决:ROWID走索引之判决,在NOT NULL 且数据位0的情况下 index的 block 为0,table的至少为1 那么index的cost就是0,CBO当然会选择cost ROWID走索引之判决: SQL> select rowid from a;ROWID------------------AAAQ/LAAC
推荐度:
标签: 数据库 ora 索引
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top