我有兩個表都有開始日期和結束日期。這兩個表都與名爲cust_id的列相關聯。我加入這些表來獲取特定的列並按日期範圍限制它應用於一個表上。不管日期範圍是4天還是1小時,我都會看到查詢需要50-55秒。當我提供更小的日期範圍時,我假定Oracle需要解析的行數較少。這是預期的行爲,還是我應該查找一些東西?Oracle - 調整具有日期範圍的查詢
select to_char(t.start_ts,'YYYY-MM-DD HH24:MI'),
COUNT(CASE WHEN f.fault = 'N' THEN 1 END) success,
COUNT(CASE WHEN f.fault = 'Y' THEN 1 END) failure
from customer t,profile f where 1=1
and t.cust_id = f.cust_id
and to_char(t.start_ts,'YYYY-MM-DD HH24:MI:SS') between '2017-03-01 00:00:00'
and '2017-05-01 23:59:59'
group by to_char(t.start_ts,'YYYY-MM-DD HH24:MI')
order by to_char(t.start_ts,'YYYY-MM-DD HH24:MI');
然在不同的Env對類似表的查詢我在那裏觀察相同的行爲:
Plan hash value: 2851258613
---------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
---------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 362 | 11651 (1)| 00:00:01 | | |
| 1 | SORT GROUP BY | | 2 | 362 | 11651 (1)| 00:00:01 | | |
| 2 | NESTED LOOPS | | 2 | 362 | 11650 (1)| 00:00:01 | | |
| 3 | NESTED LOOPS | | 2 | 362 | 11650 (1)| 00:00:01 | | |
| 4 | PARTITION RANGE ALL | | 2 | 284 | 11644 (1)| 00:00:01 | 1 | 41 |
|* 5 | TABLE ACCESS BY LOCAL INDEX ROWID| TXNS | 2 | 284 | 11644 (1)| 00:00:01 | 1 | 41 |
|* 6 | INDEX SKIP SCAN | XIE1TXNS | 4 | | 11641 (1)| 00:00:01 | 1 | 41 |
|* 7 | INDEX RANGE SCAN | XAK1FRONTEND_DTLS | 1 | | 2 (0)| 00:00:01 | | |
| 8 | TABLE ACCESS BY GLOBAL INDEX ROWID | FRONTEND_DTLS | 1 | 39 | 3 (0)| 00:00:01 | ROWID | ROWID |
---------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter("T"."SRVC_NAME"='ControllerSvc' AND "T"."SRVC_VERSION"='10.00' AND
"T"."SRC_SERV_ID"<>'test' AND "T"."SRC_SERV_ID"<>'endtoendtesting' AND "T"."SRVR_NODE_NAME" NOT LIKE
'%test.net' AND "T"."SRC_SERV_ID"<>'test' AND "T"."SRC_SERV_ID"<>'SYN')
6 - access("T"."SRVC_OP_NAME"='getTestInfo')
filter("T"."SRVC_OP_NAME"='getTestInfo' AND TO_CHAR(INTERNAL_FUNCTION("T"."START_TS"),'YYYY-MM-DD
HH24:MI:SS')>='2017-03-01 00:00:00' AND TO_CHAR(INTERNAL_FUNCTION("T"."START_TS"),'YYYY-MM-DD
HH24:MI:SS')<='2017-05-01 23:59:59')
7 - access("T"."TXN_ID"="F"."TXN_ID")
PS: 我無法查找解釋計劃,因爲我沒有足夠的訪問。
沒有獲得基本的診斷工具,如解釋計劃或能力SQL監視器,你所有的答案將是猜測。我鼓勵你訪問這些工具,以便我們更好地幫助你。 – BobC
Hi @BobC。我從一個不同的env開始瞭解釋計劃,我在那裏看到類似的行爲。 –