加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle在组合索引上,只使用部分列进行查询(查询时必须包含前导

发布时间:2020-12-12 15:05:19 所属栏目:百科 来源:网络整理
导读:实验环境:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 1、创建表插入数据 SQLcreatetabletxtx(idint,namechar(2),txchar(3),id1int,primarykey(id,name,tx));表已创建。SQLinsertintotxtxvalues(1,'tx',1);已创建1行。S

实验环境:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

1、创建表插入数据

SQL>createtabletxtx(idint,namechar(2),txchar(3),id1int,primarykey(id,name,tx));
表已创建。
SQL>insertintotxtxvalues(1,'tx',1);
已创建1行。
SQL>insertintotxtxvalues(2,2);
已创建1行。
SQL>insertintotxtxvalues(3,3);
已创建1行。
SQL>commit;
SQL>select*fromtxtx;
IDNATXID1
-------------------------
1txtx1
2txtx2
3txtx3

2、执行计划

SQL>explainplanforselect*fromtxtxwhereid=1andid1=1andtx='tx';
已解释。
SQL>setlinesize200
SQL>select*fromtable(DBMS_XPLAN.DISPLAY);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Planhashvalue:4191381592
--------------------------------------------------------------------------
|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|
--------------------------------------------------------------------------
|0|SELECTSTATEMENT||1|35|3(0)|00:00:01|
|*1|TABLEACCESSFULL|TXTX|1|35|3(0)|00:00:01|
--------------------------------------------------------------------------
PredicateInformation(identifiedbyoperationid):
---------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1-filter("ID"=1AND"ID1"=1AND"TX"='tx')
Note
-----
-dynamicsamplingusedforthisstatement(level=2)
已选择17行。

通过以上执行计划,可以看出,不含前导列,进行了全表扫描,以下使用了前导列,查询速度就上来了

SQL>explainplanforselect*fromtxtxwhereid=1andname='tx'andtx='tx';
已解释。
SQL>select*fromtable(DBMS_XPLAN.DISPLAY);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Planhashvalue:913771524
--------------------------------------------------------------------------------------------
|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|
--------------------------------------------------------------------------------------------
|0|SELECTSTATEMENT||1|35|1(0)|00:00:01|
|1|TABLEACCESSBYINDEXROWID|TXTX|1|35|1(0)|00:00:01|
|*2|INDEXUNIQUESCAN|SYS_C0024000|1||1(0)|00:00:01|
--------------------------------------------------------------------------------------------
PredicateInformation(identifiedbyoperationid):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------
2-access("ID"=1AND"NAME"='tx'AND"TX"='tx')
已选择14行。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读