Why rownum is not used in the query [message #654415] |
Tue, 02 August 2016 08:18 |
|
samiran_cts
Messages: 52 Registered: January 2012
|
Member |
|
|
Hello Sir,
I have one query which was doing good for the last 1 year but suddenly the query is degrading and in the AWR report the rownum is not being used. The query is like this:
select PXCOVERINSKEY,"PXCOVEREDCOUNT","PXOBJCLASS","PXUPDATEDATETIME","PYRESOLVEDTIMESTAMP","PYSTATUSWORK","PZINSKEY",
"EXTENDEDARCHIVE","UNARCHDATETIME" FROM TEST_WORK
WHERE PYRESOLVEDTIMESTAMP < TRUNC(SYSDATE) - 90
And nvl(unarchdatetime, sysdate - 7) < sysdate -1
AND PXOBJCLASS = 'JPMC-CIB-GSM-Work-Suspect-Txn%'
AND "PYSTATUSWORK" like 'Resolved%'
AND ( EXTENDEDARCHIVE is null or EXTENDEDARCHIVE = 'NO')
AND rownum < 90
But in the AWR report the query is becoming and ignoring the rownum.
SELECT /*+ OPAQUE_TRANSFORM */ "PXCOVERINSKEY", "PXCOVEREDCOUNT", "PXOBJCLASS", "PXUPDATEDATETIME", "PYRESOLVEDTIMESTAMP", "PYSTATUSWORK", "PZINSKEY", "EXTENDEDARCHIVE", "UNARCHDATETIME" FROM "TEST_WORK" WHERE "PXOBJCLASS" LIKE :1 AND "PYSTATUSWORK" LIKE :2 AND ("EXTENDEDARCHIVE" IS NULL OR "EXTENDEDARCHIVE"=:3) AND "PYRESOLVEDTIMESTAMP"<TRUNC(:4)-:"SYS_B_0" AND NVL("UNARCHDATETIME", :5-:"SYS_B_1")<:6-:"SYS_B_2"
So what could be the reason for ignoring the rownum in the query ? There are indexes present in the where condition still performance is degrading. If rownum is replaced with analytical function row_number() can its performance will improve.
Regards,
Samiran
|
|
|
Re: Why rownum is not used in the query [message #654416 is a reply to message #654415] |
Tue, 02 August 2016 08:22 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
SELECT pxcoverinskey,
"pxcoveredcount",
"pxobjclass",
"pxupdatedatetime",
"pyresolvedtimestamp",
"pystatuswork",
"pzinskey",
"extendedarchive",
"unarchdatetime"
FROM test_work
WHERE pyresolvedtimestamp < Trunc(SYSDATE) - 90
AND Nvl(unarchdatetime, SYSDATE - 7) < SYSDATE - 1
AND pxobjclass = 'JPMC-CIB-GSM-Work-Suspect-Txn%'
AND "pystatuswork" LIKE 'Resolved%'
AND ( extendedarchive IS NULL
OR extendedarchive = 'NO' )
AND ROWNUM < 90
http://www.dpriver.com/pp/sqlformat.htm?ref=g_wangz
post EXPLAIN PLAN
post CREATE TABLE & CREATE INDEX for all involved
|
|
|
|
Re: Why rownum is not used in the query [message #654451 is a reply to message #654417] |
Wed, 03 August 2016 03:38 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Rownum isn't the only difference, the order of the where clause is different, plus this:
AND PXOBJCLASS = 'JPMC-CIB-GSM-Work-Suspect-Txn%'
WHERE "PXOBJCLASS" LIKE :1
As Michel says - the query AWR is reporting isn't the one you posted at the top.
|
|
|
|
|
|
|
|
|
Re: Why rownum is not used in the query [message #654463 is a reply to message #654461] |
Wed, 03 August 2016 04:45 |
|
samiran_cts
Messages: 52 Registered: January 2012
|
Member |
|
|
The query is something like this SqlQuery:= SqlQuery || ' select pxcoverinskey,nvl(pxcoveredcount,0) pxcoveredcount ,pzInskey,pyresolvedtimestamp, pxupdatedatetime,sysdate, nvl(EXTENDEDARCHIVE,' || '''No'''|| ') extendedarchive, pxobjclass from '||SCHEMA_NAME ||'.'||workTableName' where PYRESOLVEDTIMESTAMP < trunc(SYSDATE) - '||cutoffDays ;
SqlQuery:= SqlQuery || ' and nvl(unarchdatetime, sysdate - 7) < sysdate -1 ';
end if;
if( workClass is not null ) then
SqlQuery := SqlQuery || ' and PXOBJCLASS like '|| ':1';
end if;
if (jobName='ARCHIVE') then
SqlQuery:= SqlQuery || ' and pystatuswork like ' || ':2';
if extendedarchive= 'Yes' then
SqlQuery:= SqlQuery || ' and EXTENDEDARCHIVE = :3';
end if;
if (extendedarchive= 'No' and workclass = 'JPMC-CIB-GSM-Work-Suspect-Client') then
SqlQuery:= SqlQuery || ' and ( EXTENDEDARCHIVE is null or EXTENDEDARCHIVE = :3)';
end if;
if rowlimit > 0 then
SqlQuery:= SqlQuery || ' and rownum < '|| rowlimit;
end if;
I hope I have explained the problem statement.
|
|
|
|
|
|