Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
oracle sql在大数据集中的性能_Sql_Oracle_Performance_Spring Data_Large Data - Fatal编程技术网

oracle sql在大数据集中的性能

oracle sql在大数据集中的性能,sql,oracle,performance,spring-data,large-data,Sql,Oracle,Performance,Spring Data,Large Data,我有一个这样的疑问 我使用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/1

我有一个这样的疑问

我使用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%')
从事务中选择*
哪里
(trunc(请求时间,'MI')介于日期('1390/01/01 01:01','YYYY/MM/DD HH24:MI','nls_日历=波斯语')
截至日期('1396/11/01 01:01','YYYY/MM/DD HH24:MI','nls_calendar=persian'))
和客户,如“%123%”
和(当(错误代码不为null且错误代码为200)时,则为-1
当(错误代码不为空且错误代码=200)时,则为200
否则0结束=0)
和(URL='url1')
和(源,如“%123%”)
和(错误代码=200)
和(请求ID,如“%1234%”)

从此处删除
TRUNC
功能,无需此功能,但可防止RDBMS在
请求时间
列上使用索引(如果有):


从此处删除
ERROR\u code不为空
条件,如果
ERROR\u code 200
ERROR\u code=200
,则它必须始终不为空:

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)
但是,由于您的查询中有另一个条件
和(ERROR\u code=200)
,因此第一个条件排除了另一个条件
和(ERROR\u code=200)
,因此我认为您没有在问题中向我们展示真正的查询。我只想删除这个条件,因为它很可能是一个逻辑错误


经过上述简化后,您将得到:

case when ERROR_CODE <> 200 then -1 
     when ERROR_CODE =200 then 200 
     else 0 
end =0
SELECT * FROM TRANSACTION 
WHERE
  REQUEST_TIME 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 (URL = 'url1')
  and ( SOURCE like '%123%')
  and ( ERROR_CODE=200) and( REQUEST_ID like '%1234%')

现在确保有一个在
请求时间
上创建的索引,如果没有,则创建它并验证查询的性能。

从这里删除
TRUNC
函数,它是无需的,但可以防止RDBMS在
请求时间
列上使用索引(如果有):


从此处删除
ERROR\u code不为空
条件,如果
ERROR\u code 200
ERROR\u code=200
,则它必须始终不为空:

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)
但是,由于您的查询中有另一个条件
和(ERROR\u code=200)
,因此第一个条件排除了另一个条件
和(ERROR\u code=200)
,因此我认为您没有在问题中向我们展示真正的查询。我只想删除这个条件,因为它很可能是一个逻辑错误


经过上述简化后,您将得到:

case when ERROR_CODE <> 200 then -1 
     when ERROR_CODE =200 then 200 
     else 0 
end =0
SELECT * FROM TRANSACTION 
WHERE
  REQUEST_TIME 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 (URL = 'url1')
  and ( SOURCE like '%123%')
  and ( ERROR_CODE=200) and( REQUEST_ID like '%1234%')

现在,请确保在
请求时间
上创建了索引,如果没有,则创建索引并验证查询的性能。

前提是这不是临时(很少使用)类型的查询。

trunc(请求时间,'MI')
上的功能索引定义为列。

前提是这不是一个临时(很少使用)类型的查询。

trunc(请求时间,'MI')
上的功能索引定义为列。

您在
ERROR\u code
上的条件相互矛盾。尤其是
大小写
表达式,除非
ERROR\u code
NULL
,否则不应该有匹配项。但是这会被后面的条件过滤掉。表上有什么索引?您在
ERROR\u code
上的条件是矛盾的。尤其是
大小写
表达式,除非
ERROR\u code
NULL
,否则不应该有匹配项。但是这会被后面的条件过滤掉。表上有什么索引?