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

溫馨提示×

溫馨提示×

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

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

索引系列八--索引特性之有序難優化union

發布時間:2020-07-25 20:47:03 來源:網絡 閱讀:573 作者:1415699306 欄目:關系型數據庫

----UNION 是需要排序的

drop table t1 purge;

create table t1 as select * from dba_objects where object_id is not null;

alter table t1 modify OBJECT_ID not null;

drop table t2 purge;

create table t2 as select * from dba_objects where object_id is not null;

alter table t2 modify OBJECT_ID not null;

set linesize 1000

set autotrace traceonly


select object_id from t1

union

select object_id from t2;

執行計劃

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

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

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

|   0 | SELECT STATEMENT    |      |   136K|  1732K|       |  1241  (55)| 00:00:15 |

|   1 |  SORT UNIQUE        |      |   136K|  1732K|  2705K|  1241  (55)| 00:00:15 |

|   2 |   UNION-ALL         |      |       |       |       |            |          |

|   3 |    TABLE ACCESS FULL| T1   | 57994 |   736K|       |   292   (1)| 00:00:04 |

|   4 |    TABLE ACCESS FULL| T2   | 78456 |   996K|       |   292   (1)| 00:00:04 |

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

統計信息

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

          0  recursive calls

          0  db block gets

       2094  consistent gets

          0  physical reads

          0  redo size

    1062305  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)

      73120  rows processed

      

      

      

--發現索引無法消除UNION 排序(INDEX FAST FULL SCAN)

create index idx_t1_object_id on t1(object_id);

create index idx_t2_object_id on t2(object_id);

set autotrace traceonly

set linesize 1000


select  object_id from t1

union

select  object_id from t2;

執行計劃

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

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

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

|   0 | SELECT STATEMENT       |                  |   136K|  1732K|       |   755  (57)| 00:00:10 |

|   1 |  SORT UNIQUE           |                  |   136K|  1732K|  2705K|   755  (57)| 00:00:10 |

|   2 |   UNION-ALL            |                  |       |       |       |            |          |

|   3 |    INDEX FAST FULL SCAN| IDX_T1_OBJECT_ID | 57994 |   736K|       |    49   (0)| 00:00:01 |

|   4 |    INDEX FAST FULL SCAN| IDX_T2_OBJECT_ID | 78456 |   996K|       |    49   (0)| 00:00:01 |

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

統計信息

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

          0  recursive calls

          0  db block gets

        340  consistent gets

          0  physical reads

          0  redo size

    1062305  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)

      73120  rows processed

      

--INDEX FULL SCAN的索引依然無法消除UNION排序

select /*+index(t1)*/ object_id from t1

union

select /*+index(t2)*/  object_id from t2; 

執行計劃

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

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

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

|   0 | SELECT STATEMENT  |                  |   136K|  1732K|       |  1010  (56)| 00:00:13 |

|   1 |  SORT UNIQUE      |                  |   136K|  1732K|  2705K|  1010  (56)| 00:00:13 |

|   2 |   UNION-ALL       |                  |       |       |       |            |          |

|   3 |    INDEX FULL SCAN| IDX_T1_OBJECT_ID | 57994 |   736K|       |   177   (1)| 00:00:03 |

|   4 |    INDEX FULL SCAN| IDX_T2_OBJECT_ID | 78456 |   996K|       |   177   (1)| 00:00:03 |

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

統計信息

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

          0  recursive calls

          0  db block gets

        326  consistent gets

          0  physical reads

          0  redo size

    1062305  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)

      73120  rows processed

      


--結論:索引無法消除UNION 排序,一般來說在使用UNION時要確定必要性,在數據不會重復時只需UNION ALL即可。      


向AI問一下細節

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

AI

葫芦岛市| 隆子县| 通渭县| 江源县| 廊坊市| 荔波县| 闽侯县| 昌吉市| 宜城市| 勐海县| 莲花县| 资中县| 博客| 新昌县| 牟定县| 宁夏| 枝江市| 安陆市| 镇安县| 中宁县| 隆林| 留坝县| 屏山县| 织金县| 隆昌县| 荔波县| 安丘市| 红原县| 珠海市| 铜山县| 民乐县| 商城县| 平原县| 柯坪县| 永城市| 健康| 乐业县| 乌审旗| 武陟县| 海原县| 化德县|