您好,登錄后才能下訂單哦!
實驗環境:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
1、創建表插入數據
SQL> create table txtx(id int,name char(2),tx char(3),id1 int,primary key(id,name,tx)); 表已創建。 SQL> insert into txtx values(1,'tx','tx',1); 已創建 1 行。 SQL> insert into txtx values(2,'tx','tx',2); 已創建 1 行。 SQL> insert into txtx values(3,'tx','tx',3); 已創建 1 行。 SQL> commit;
SQL> select * from txtx; ID NA TX ID1 ---------- -- --- ---------- 1 tx tx 1 2 tx tx 2 3 tx tx 3
2、執行計劃
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行。
通過以上執行計劃,可以看出,不含前導列,進行了全表掃描,以下使用了前導列,查詢速度就上來了
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行。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。