實(shí)驗(yàn)環(huán)境:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),武鄉(xiāng)企業(yè)網(wǎng)站建設(shè),武鄉(xiāng)品牌網(wǎng)站建設(shè),網(wǎng)站定制,武鄉(xiāng)網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷(xiāo),網(wǎng)絡(luò)優(yōu)化,武鄉(xiāng)網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專(zhuān)業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶(hù)成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
1、創(chuàng)建表插入數(shù)據(jù)
SQL> create table txtx(id int,name char(2),tx char(3),id1 int,primary key(id,name,tx)); 表已創(chuàng)建。 SQL> insert into txtx values(1,'tx','tx',1); 已創(chuàng)建 1 行。 SQL> insert into txtx values(2,'tx','tx',2); 已創(chuàng)建 1 行。 SQL> insert into txtx values(3,'tx','tx',3); 已創(chuàng)建 1 行。 SQL> commit;
SQL> select * from txtx; ID NA TX ID1 ---------- -- --- ---------- 1 tx tx 1 2 tx tx 2 3 tx tx 3
2、執(zhí)行計(jì)劃
SQL> explain plan for select * from txtx where id=1 and id1 =1 and tx='tx'; 已解釋。 SQL> set linesize 200 SQL> select * from table(DBMS_XPLAN.DISPLAY); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Plan hash value: 4191381592 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 35 | 3 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| TXTX | 1 | 35 | 3 (0)| 00:00:01 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 - filter("ID"=1 AND "ID1"=1 AND "TX"='tx') Note ----- - dynamic sampling used for this statement (level=2) 已選擇17行。
通過(guò)以上執(zhí)行計(jì)劃,可以看出,不含前導(dǎo)列,進(jìn)行了全表掃描,以下使用了前導(dǎo)列,查詢(xún)速度就上來(lái)了
SQL> explain plan for select * from txtx where id=1 and name ='tx' and tx='tx'; 已解釋。 SQL> select * from table(DBMS_XPLAN.DISPLAY); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Plan hash value: 913771524 -------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 35 | 1 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| TXTX | 1 | 35 | 1 (0)| 00:00:01 | |* 2 | INDEX UNIQUE SCAN | SYS_C0024000 | 1 | | 1 (0)| 00:00:01 | -------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------- 2 - access("ID"=1 AND "NAME"='tx' AND "TX"='tx') 已選擇14行。