[英]Query takes too much time for execution
I am using Oracle 10g. 我正在使用Oracle 10g。 The following query takes too much time: 以下查询花费太多时间:
SELECT invno, invdate, ccode
FROM acct
WHERE invno IS NOT NULL
AND invdate > '01-Feb-2018'
AND invno LIKE '%' || :ppassingmn.dept || '%'
AND invno NOT IN (SELECT DISTINCT (vdescript)
FROM genldgr
WHERE vchrno LIKE 'IV%'
AND trandate > '01-Feb-2018'
AND vdescript LIKE
'%' || :ppassingmn.dept || '%')
ORDER BY SUBSTR (invno, 12, 15);
Please optimize it. 请对其进行优化。
You didn't provide much info. 您没有提供太多信息。 Query itself is pretty much useless (as if you called the mechanic and said "my blue car is slow. Why?"). 查询本身几乎没有用(就好像您叫机械师说“我的蓝车很慢。为什么?”)。
Anyway, a few hints; 无论如何,有一些提示; maybe they'll help. 也许他们会帮忙。
'01-Feb-2018'
is a string. '01-Feb-2018'
是一个字符串。 If INVDATE
is a DATE
datatype column, you're forcing Oracle to perform implicit conversion between VARCHAR2
and DATE
. 如果INVDATE
是DATE
数据类型列, INVDATE
强制Oracle在VARCHAR2
和DATE
之间执行隐式转换。 Use a date literal instead, eg and invdate > date '2018-02-01'
. 请改用日期文字,例如and invdate > date '2018-02-01'
。 The same goes for TRANDATE
. TRANDATE
。 LIKE
is slow. LIKE
慢。 You use it twice. 您使用两次。 See if you can rewrite it to invno = :passingmn.dept
. 看看是否可以将其重写为invno = :passingmn.dept
。 By the way, what is :passingmn.dept
? 顺便说一句, :passingmn.dept
什么? Looks like a variable, but - what is that dot doing here? 看起来像一个变量,但是-这个点在做什么? The same goes for VDESCRIPT
. VDESCRIPT
。 DISTINCT
requires you to select all rows, and then remove duplicates. DISTINCT
要求您选择所有行,然后删除重复项。 It seems that you don't really care about it, so - remove DISTINCT
. 似乎您并不是很在乎,因此-删除DISTINCT
。 INVNO
has to look like some parameter value, then it isn't NULL
so you can probably remove invno is not null
condition. 由于INVNO
必须看起来像某个参数值,所以它不是NULL
因此您可以删除invno is not null
条件。 ORDER BY
also affects performance. ORDER BY
也影响性能。 Moreover, it selects a substring . 而且,它选择一个substring 。 Do you need it? 你需要它吗? If not, remove it 如果没有,请将其删除 WHERE
clause indexed? WHERE
子句中涉及的列是否已建立索引? If not, do so 如果没有,请这样做 Finally, explain plan would help. 最后,说明计划会有所帮助。 Without it, people are partially blind. 没有它,人们就会部分失明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.