【发布时间】:2018-01-27 22:08:28
【问题描述】:
我有一个这样的查询。
我使用 Jpa 并且只检索前 50 个结果,但在我的表上有 200 万条记录需要很长时间。
如何提高性能?
SELECT * FROM TRANSACTION
WHERE
(trunc(REQUEST_TIME,'MI') between to_date('1390/01/01 01:01','YYYY/MM/DD HH24:MI','nls_calendar=persian')
and to_date('1396/11/01 01:01','YYYY/MM/DD HH24:MI','nls_calendar=persian'))
and CUSTOMER like '%123%'
and (case when (ERROR_CODE is not null and ERROR_CODE <> 200) then -1
when (ERROR_CODE is not null and ERROR_CODE =200) then 200
else 0 end =0)
and (URL = 'url1')
and ( SOURCE like '%123%')
and ( ERROR_CODE=200)
and ( REQUEST_ID like '%1234%')
【问题讨论】:
-
您在
ERROR_CODE上的条件是矛盾的。尤其是CASE表达式,除非ERROR_CODE是NULL,否则永远不会有匹配项。但这会被后面的条件过滤掉。 -
你的桌子上有什么索引?
标签: sql oracle performance spring-data large-data