SELECT * from mtl_material_transactions where transaction_id >30000000
这句执行 返回结果 在一秒内 select max(transaction_id)-100000 from mtl_material_transactions
这句一样在1秒内SELECT * from mtl_material_transactions a where a.transaction_id > (select max(transaction_id)-100000 from mtl_material_transactions )这句的执行就很长时间 mtl_material_transactions 这个表的数据量非常大 大概了4千万
这句执行 返回结果 在一秒内 select max(transaction_id)-100000 from mtl_material_transactions
这句一样在1秒内SELECT * from mtl_material_transactions a where a.transaction_id > (select max(transaction_id)-100000 from mtl_material_transactions )这句的执行就很长时间 mtl_material_transactions 这个表的数据量非常大 大概了4千万
1.explain plan for SELECT * from mtl_material_transactions a where a.transaction_id > (select max(transaction_id)-100000 from mtl_material_transactions )2.select * from table(DBMS_XPLAN.Display);
第一步 执行的是 (select max(transaction_id)-100000 from mtl_material_transactions )
如 写个 date > sysdate 或者date > TO_DATE('2010-10-1','YYYY-mm-DD')就比较快 但是 写个 date > sysdate -10 就非常慢
按理说应该不会太慢啊.
SQL> EXPLAIN PLAN FOR
2 SELECT * FROM test;已解释。SQL> SET LINESIZE 130
SQL> SET PAGESIZE 0
SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY);
Plan hash value: 1357081020--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 16 | 48 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| TEST | 16 | 48 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------已选择8行。
示例2:
SELECT * from mtl_material_transactions a where a.transaction_id > (select max(transaction_id)-100000 from mtl_material_transactions )
----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 537K| 142M| 16264 |
| 1 | TABLE ACCESS BY INDEX ROWID | MTL_MATERIAL_TRANSACTIONS | 537K| 142M| 16264 |
|* 2 | INDEX RANGE SCAN | MTL_MATERIAL_TRANSACTIONS_U1 | 96713 | | 383 |
| 3 | SORT AGGREGATE | | 1 | 6 | |
| 4 | INDEX FULL SCAN (MIN/MAX)| MTL_MATERIAL_TRANSACTIONS_U1 | 10M| 61M| 3 |
----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("A"."TRANSACTION_ID"> (SELECT /*+ */ MAX("B"."TRANSACTION_ID")-100000 FROM
"APPS"."MTL_MATERIAL_TRANSACTIONS" "B"))
Note: cpu costing is off
select max(transaction_id)-100000 from mtl_material_transactions )索引列上有运算,
执行计划是index full scan。
改成这样
SELECT * from mtl_material_transactions a where a.transaction_id > (select max(transaction_id) from mtl_material_transactions )- 100000,
然后再看下执行计划
服务器重启后 现在能正常搜出来了
不过还是想知道,查询条件中 使用了函数 index 失效的 问题有没什么方法能避免
transaction_id是不是唯一不重复的?
WITH TMP AS (SELECT max(transaction_id)-100000 AS transaction_id from mtl_material_transactions)
SELECT * from mtl_material_transactions a,TMP where a.transaction_id > TMP.transaction_id
这样会不一样么