在Oracle中优化TO_TIMESTAMP()查询

时间:2018-07-09 19:33:31

标签: oracle to-timestamp

每次执行此查询时,都需要2分钟才能执行:

select * from CPOB_Monitoring_Dashboard
where  VOYAGE_STRT_DT >= TO_TIMESTAMP('2014-07-03 00:00:00.000','YYYY-MM-DD HH24:MI:SS.FF') 
and    VOYAGE_STRT_DT <= TO_TIMESTAMP('2018-07-03 00:00:00.000','YYYY-MM-DD HH24:MI:SS.FF')

但是,如果我将其更改为使用TO_DATE而不是TO_TIMESTAMP,那确实非常快。 Linq正在使用TOTIMESTAMP生成查询,但我还没有找到一种更改方法来使用TO_DATE,有什么方法可以优化TOTIMESTAMP查询?? 这是使用TOTIMESTAMP的查询的执行计划:

PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 246273147

---------------------------------------------------------------------------------------------------------------------
| Id  | Operation                       | Name                      | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |                           | 21842 |  4820K|       |  1336   (1)| 00:00:17 |
|   1 |  VIEW                           |  CPOB_Monitoring_Dashboard| 21842 |  4820K|       |  1336   (1)| 00:00:17 |
|   2 |   HASH UNIQUE                   |                           | 21842 |  3988K|  4384K|  1336   (1)| 00:00:17 |
|   3 |    NESTED LOOPS                 |                           | 21842 |  3988K|       |   442   (1)| 00:00:06 |
|   4 |     NESTED LOOPS                |                           |    47 |  7661 |       |   160   (1)| 00:00:02 |
|*  5 |      TABLE ACCESS FULL          |      VOYAGE_INFO          |    46 |  1012 |       |    68   (0)| 00:00:01 |
|   6 |      TABLE ACCESS BY INDEX ROWID|      PROCESS_CTRL         |     1 |   141 |       |     2   (0)| 00:00:01 |
|*  7 |       INDEX RANGE SCAN          |      VOYAGE_ID_IDX        |     1 |       |       |     1   (0)| 00:00:01 |
|*  8 |     INDEX RANGE SCAN            |      PLY_IDX2             |   467 | 11208 |       |     6   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   5 - filter(INTERNAL_FUNCTION("CPVI"."VOYAGE_STRT_DT")>=TIMESTAMP' 2014-07-03 00:00:00.000000000' AND 
              INTERNAL_FUNCTION("CPVI"."VOYAGE_STRT_DT")<=TIMESTAMP' 2018-07-03 00:00:00.000000000')
   7 - access("CPC"."VOYAGE_ID"="CPVI"."VOYAGE_ID")
   8 - access("CPC"."BRAND_NAME"="CPOB"."BRAND_ID" AND "CPC"."SHIP_NAME"=""SHIP_NAME")
       filter("CPC"."SHIP_NAME"="CPOB"."SHIP_NAME")

24 rows selected. 

0 个答案:

没有答案