Reputation:
I am using 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.
Upvotes: 0
Views: 51
Reputation: 142713
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. If INVDATE
is a DATE
datatype column, you're forcing Oracle to perform implicit conversion between VARCHAR2
and DATE
. Use a date literal instead, e.g. and invdate > date '2018-02-01'
. The same goes for TRANDATE
.LIKE
is slow. You use it twice. See if you can rewrite it to invno = :passingmn.dept
. By the way, what is :passingmn.dept
? Looks like a variable, but - what is that dot doing here? The same goes for VDESCRIPT
.DISTINCT
requires you to select all rows, and then remove duplicates. It seems that you don't really care about it, so - remove DISTINCT
.INVNO
has to look like some parameter value, then it isn't NULL
so you can probably remove invno is not null
condition.ORDER BY
also affects performance. Moreover, it selects a substring. Do you need it? If not, remove itWHERE
clause indexed? If not, do soFinally, explain plan would help. Without it, people are partially blind.
Upvotes: 1