91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

索引系列十--索引特性之有序優化order by

發布時間:2020-08-09 21:07:05 來源:網絡 閱讀:1523 作者:1415699306 欄目:關系型數據庫

--索引與排序 

  

drop table t purge;

create table t as select * from dba_objects ;

set autotrace traceonly

--oracle還算智能,不會傻到這里都去排序,做了查詢轉換,忽略了這個排序

select count(*) from t order by object_id;




 ---以下語句說明排序

set autotrace traceonly

set linesize 1000

drop table t purge;

create table t as select * from dba_objects;


--以下語句沒有索引又有order by ,必然產生排序

select * from t where object_id>2 order by object_id;

執行計劃

-----------------------------------------------------------------------------------

| Id  | Operation          | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |      | 92407 |    18M|       |  4454   (1)| 00:00:54 |

|   1 |  SORT ORDER BY     |      | 92407 |    18M|    21M|  4454   (1)| 00:00:54 |

|*  2 |   TABLE ACCESS FULL| T    | 92407 |    18M|       |   294   (2)| 00:00:04 |

-----------------------------------------------------------------------------------

統計信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

       1047  consistent gets

          0  physical reads

          0  redo size

    3513923  bytes sent via SQL*Net to client

      54029  bytes received via SQL*Net from client

       4876  SQL*Net roundtrips to/from client

          1  sorts (memory)

          0  sorts (disk)

      73117  rows processed



---新增索引后,Oracle就有可能利用索引本身就有序的特點,利用索引來避免排序,如下:

create index idx_t_object_id on t(object_id);

set autotrace traceonly


select * from t where object_id>2 order by object_id;

執行計劃

-----------------------------------------------------------------------------------------------

| Id  | Operation                   | Name            | Rows  | Bytes | Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                 | 92407 |    18M|  1302   (1)| 00:00:16 |

|   1 |  TABLE ACCESS BY INDEX ROWID| T               | 92407 |    18M|  1302   (1)| 00:00:16 |

|*  2 |   INDEX RANGE SCAN          | IDX_T_OBJECT_ID | 92407 |       |   177   (1)| 00:00:03 |

-----------------------------------------------------------------------------------------------

統計信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

      10952  consistent gets

          0  physical reads

          0  redo size

    8115221  bytes sent via SQL*Net to client

      54029  bytes received via SQL*Net from client

       4876  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

      73117  rows processed


--如下情況Oracle肯定毫不猶豫的選擇用索引,因為回表取消了 !      

select  object_id from t where object_id>2 order by object_id;

執行計劃

------------------------------------------------------------------------------------

| Id  | Operation        | Name            | Rows  | Bytes | Cost (%CPU)| Time     |

------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT |                 | 92407 |  1173K|   177   (1)| 00:00:03 |

|*  1 |  INDEX RANGE SCAN| IDX_T_OBJECT_ID | 92407 |  1173K|   177   (1)| 00:00:03 |

------------------------------------------------------------------------------------

統計信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

       5027  consistent gets

          0  physical reads

          0  redo size

    1062289  bytes sent via SQL*Net to client

      54029  bytes received via SQL*Net from client

       4876  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

      73117  rows processed

      

--另外,如果是如下語句,Oracle打死也不用索引了。  

select  object_id from t where object_id>2;    


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

伊川县| 太湖县| 鄯善县| 吉木乃县| 达州市| 三台县| 漳浦县| 鹤庆县| 丰都县| 酒泉市| 南漳县| 连州市| 靖宇县| 界首市| 镇雄县| 东台市| 施甸县| 玛沁县| 衢州市| 德阳市| 荔波县| 伊金霍洛旗| 昌都县| 股票| 文水县| 江山市| 汝南县| 开江县| 咸丰县| 庐江县| 吉水县| 太湖县| 铁岭县| 黔南| 宁强县| 恭城| 中方县| 雷山县| 修文县| 淮滨县| 正镶白旗|