Hi,
I am trying to improve the performance of a SQL Pass-Through query that supposed to retrieve two sets of data:
1) Newly added documents
2) Newly added change documents
The query below executes under 5 minutes for small number of records that are being compared. But it runs for half an hour, if the number of records are being queried is over 10,000.
There is an index on the table being searched. The indexed columns are the load_date and reportgroup.
Instead of UNION, I tried "OR"-in the two NOT EXISTS clause but the performance for did not improve.
Is there another way I can re-write this query ? Any suggestions would be appreciate.
Here's the query:
SELECT PREFIX, REVISION, DOC_TYPE, ISSUED_DATE, CHANGE_DOCUMENT,
CHANGE_REVISION, LOAD_DATE, 'Added Documents' AS Delta_Type
from wtp_techdelta_view new
where REPORTGROUP='ABCDE'
and load_date = to_date('14-JAN-2004','DD-MON-YYYY')
and not exists ( SELECT 'X' FROM wtp_techdelta_view old
WHERE old.load_date = to_date('13-JAN-2004','DD-MON-YYYY') AND REPORTGROUP='ABCDE'
AND old.prefix = new.prefix and old.revision = new.revision
and nvl(old.doc_type,'X') = nvl(new.doc_type,'X')
and nvl(old.issued_date,'X') = nvl(new.issued_date,'X') )
UNION
SELECT new.PREFIX, new.REVISION, new.DOC_TYPE, new.ISSUED_DATE, new.CHANGE_DOCUMENT,
new.CHANGE_REVISION, new.LOAD_DATE,'Added Change Docs' as Delta_Type
from wtp_techdelta_view new
WHERE REPORTGROUP='ABCDE'
and load_date = to_date('14-JAN-2004','DD-MON-YYYY')
and new.change_document is not null
AND NOT EXISTS ( SELECT 'X' FROM wtp_techdelta_view old
WHERE old.load_date = to_date('13-JAN-2004','DD-MON-YYYY') AND REPORTGROUP='ABCDE'
and old.prefix = new.prefix and old.revision = new.revision
and nvl(old.doc_type,'X') = nvl(new.doc_type,'X')
and nvl(old.issued_date,'X') = nvl(new.issued_date,'X')
and nvl(new.change_document,'X') = nvl(old.change_document,'X')
and nvl(new.change_revision,'X') = nvl(old.change_revision,'X') )
I am trying to improve the performance of a SQL Pass-Through query that supposed to retrieve two sets of data:
1) Newly added documents
2) Newly added change documents
The query below executes under 5 minutes for small number of records that are being compared. But it runs for half an hour, if the number of records are being queried is over 10,000.
There is an index on the table being searched. The indexed columns are the load_date and reportgroup.
Instead of UNION, I tried "OR"-in the two NOT EXISTS clause but the performance for did not improve.
Is there another way I can re-write this query ? Any suggestions would be appreciate.
Here's the query:
SELECT PREFIX, REVISION, DOC_TYPE, ISSUED_DATE, CHANGE_DOCUMENT,
CHANGE_REVISION, LOAD_DATE, 'Added Documents' AS Delta_Type
from wtp_techdelta_view new
where REPORTGROUP='ABCDE'
and load_date = to_date('14-JAN-2004','DD-MON-YYYY')
and not exists ( SELECT 'X' FROM wtp_techdelta_view old
WHERE old.load_date = to_date('13-JAN-2004','DD-MON-YYYY') AND REPORTGROUP='ABCDE'
AND old.prefix = new.prefix and old.revision = new.revision
and nvl(old.doc_type,'X') = nvl(new.doc_type,'X')
and nvl(old.issued_date,'X') = nvl(new.issued_date,'X') )
UNION
SELECT new.PREFIX, new.REVISION, new.DOC_TYPE, new.ISSUED_DATE, new.CHANGE_DOCUMENT,
new.CHANGE_REVISION, new.LOAD_DATE,'Added Change Docs' as Delta_Type
from wtp_techdelta_view new
WHERE REPORTGROUP='ABCDE'
and load_date = to_date('14-JAN-2004','DD-MON-YYYY')
and new.change_document is not null
AND NOT EXISTS ( SELECT 'X' FROM wtp_techdelta_view old
WHERE old.load_date = to_date('13-JAN-2004','DD-MON-YYYY') AND REPORTGROUP='ABCDE'
and old.prefix = new.prefix and old.revision = new.revision
and nvl(old.doc_type,'X') = nvl(new.doc_type,'X')
and nvl(old.issued_date,'X') = nvl(new.issued_date,'X')
and nvl(new.change_document,'X') = nvl(old.change_document,'X')
and nvl(new.change_revision,'X') = nvl(old.change_revision,'X') )