案例2
确认可以使用union all取代union,从而可以避免排序操作。
案例3
-
DROP TABLE t;
-
CREATE TABLE t AS SELECT * FROM dba_objects;
-
CREATE INDEX idx_t ON t(owner, object_id);
-
-
SET AUTOTRACE TRACEONLY EXPLAIN
-
ALTER TABLE t MODIFY owner NOT NULL;
-
-
--执行语句
-
SELECT /*+ index(a, idx_t) */ * FROM t a ORDER BY owner DESC, object_type ASC;
-
-
Elapsed: 00:00:00.01
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 332749522

-
--重新定义索引
-
DROP INDEX idx_t;
-
CREATE INDEX idx_t ON t(owner DESC, object_type ASC);
-
-
--再次执行语句,排序操作消失
-
SELECT /*+ index(a, idx_t) */ * FROM t a ORDER BY owner DESC, object_type ASC;
-
-
Elapsed: 00:00:00.02
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 112249094

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/17013648/viewspace-1072154/
,如需转载,请注明出处,否则将追究法律责任。