Solved

Huge tables, multiple commands, deathly slow query via Crystal

Posted on 2007-04-03
7
1,944 Views
Last Modified: 2013-12-19
Hi, this is both an Oracle 9i and Crystal XI R2 question.

I have three large tables, and I'm trying to crunch them to create a report - however the resulting dataset is so slow to appear the report is useless.  It's ran for over a day before..... below is my Query.  Any suggestions on how to speed this up - even to 2 hours would be great :-)

Three Crystal Commands:
QRY_DESTINATION_WHS:
SELECT COMPANY_CODE, DOCUMENT_NUMBER, MOVEMENT_DATE, WAREHOUSE, PART_CODE, IC_LOT_NUMBER, USERNAME,IC_MOVE_QUANTITY, IC_STATUS_CODE ,  DOCUMENT_LINE, DOCUMENT_SEQUENCE, UNIT_OF_MEASURE
FROM fin_prod.IC_MOVEMENTS
WHERE MOVEMENT_CODE = 'WHTO' and SOURCE_MODULE = 'IC' AND IC_STATUS_CODE <> 'CONFINQ'

QRY_SORUCE_WHS:
SELECT COMPANY_CODE, DOCUMENT_NUMBER, MOVEMENT_DATE, WAREHOUSE, PART_CODE, IC_LOT_NUMBER, USERNAME,IC_MOVE_QUANTITY, IC_STATUS_CODE,
 DOCUMENT_LINE, DOCUMENT_SEQUENCE, UNIT_OF_MEASURE
FROM fin_prod.IC_MOVEMENTS
WHERE MOVEMENT_CODE = 'WHFR' AND SOURCE_MODULE = 'IC' AND IC_STATUS_CODE <> 'CONFIN'
QRY_LPN:
SELECT COMPANY_CODE, DC_LICENSE_PLATE_ID,WAREHOUSE, BIN_LOCATION, WH_XFER_DOC_REFERENCE, DC_LICENSE_PLATE_LINE,
              PART_CODE, DOC_REFERENCE, CAST(DOC_LINE AS VARCHAR(8)) AS DOC_LINE_NUMBER
FROM  FIN_PROD.DC_LICENSE_PLATE_HISTORY
WHERE DC_LICENSE_PLATE_STATUS='ACTIVE'
GROUP BY COMPANY_CODE, DC_LICENSE_PLATE_ID, WAREHOUSE, BIN_LOCATION, WH_XFER_DOC_REFERENCE, DC_LICENSE_PLATE_LINE,
               PART_CODE, DOC_REFERENCE, CAST(DOC_LINE AS VARCHAR(8))
------------------
the query:
oracle1
SELECT COMPANY_CODE, DOCUMENT_NUMBER, MOVEMENT_DATE, WAREHOUSE, PART_CODE, IC_LOT_NUMBER, USERNAME,IC_MOVE_QUANTITY, IC_STATUS_CODE,
 DOCUMENT_LINE, DOCUMENT_SEQUENCE, UNIT_OF_MEASURE
FROM fin_prod.IC_MOVEMENTS
WHERE MOVEMENT_CODE = 'WHFR' AND SOURCE_MODULE = 'IC' AND IC_STATUS_CODE <> 'CONFIN'
 EXTERNAL JOIN QRY_SORUCE_WHS.COMPANY_CODE={?oracle1: QRY_DESTINATION_WHS.COMPANY_CODE} AND QRY_SORUCE_WHS.DOCUMENT_NUMBER={?oracle1: QRY_DESTINATION_WHS.DOCUMENT_NUMBER} AND QRY_SORUCE_WHS.PART_CODE={?oracle1: QRY_DESTINATION_WHS.PART_CODE} AND QRY_SORUCE_WHS.DOCUMENT_LINE={?oracle1: QRY_DESTINATION_WHS.DOCUMENT_LINE} AND QRY_SORUCE_WHS.DOCUMENT_SEQUENCE={?oracle1: QRY_DESTINATION_WHS.DOCUMENT_SEQUENCE} AND QRY_SORUCE_WHS.UNIT_OF_MEASURE={?oracle1: QRY_DESTINATION_WHS.UNIT_OF_MEASURE}


oracle1
SELECT COMPANY_CODE, DOCUMENT_NUMBER, MOVEMENT_DATE, WAREHOUSE, PART_CODE, IC_LOT_NUMBER, USERNAME,IC_MOVE_QUANTITY, IC_STATUS_CODE ,  DOCUMENT_LINE, DOCUMENT_SEQUENCE, UNIT_OF_MEASURE
FROM fin_prod.IC_MOVEMENTS
WHERE MOVEMENT_CODE = 'WHTO' and SOURCE_MODULE = 'IC' AND IC_STATUS_CODE <> 'CONFINQ'
 EXTERNAL JOIN QRY_DESTINATION_WHS.COMPANY_CODE={?oracle1: QRY_SORUCE_WHS.COMPANY_CODE} AND QRY_DESTINATION_WHS.DOCUMENT_NUMBER={?oracle1: QRY_SORUCE_WHS.DOCUMENT_NUMBER} AND QRY_DESTINATION_WHS.PART_CODE={?oracle1: QRY_SORUCE_WHS.PART_CODE} AND QRY_DESTINATION_WHS.DOCUMENT_LINE={?oracle1: QRY_SORUCE_WHS.DOCUMENT_LINE} AND QRY_DESTINATION_WHS.DOCUMENT_SEQUENCE={?oracle1: QRY_SORUCE_WHS.DOCUMENT_SEQUENCE} AND QRY_DESTINATION_WHS.UNIT_OF_MEASURE={?oracle1: QRY_SORUCE_WHS.UNIT_OF_MEASURE} AND QRY_DESTINATION_WHS.COMPANY_CODE={?oracle1: QRY_LPN.COMPANY_CODE} AND QRY_DESTINATION_WHS.DOCUMENT_NUMBER={?oracle1: QRY_LPN.DOC_REFERENCE} AND QRY_DESTINATION_WHS.DOCUMENT_LINE={?oracle1: QRY_LPN.DOC_LINE_NUMBER}


oracle1
SELECT COMPANY_CODE, DC_LICENSE_PLATE_ID,WAREHOUSE, BIN_LOCATION, WH_XFER_DOC_REFERENCE, DC_LICENSE_PLATE_LINE,
              PART_CODE, DOC_REFERENCE, CAST(DOC_LINE AS VARCHAR(8)) AS DOC_LINE_NUMBER
FROM  FIN_PROD.DC_LICENSE_PLATE_HISTORY
WHERE DC_LICENSE_PLATE_STATUS='ACTIVE'
GROUP BY COMPANY_CODE, DC_LICENSE_PLATE_ID, WAREHOUSE, BIN_LOCATION, WH_XFER_DOC_REFERENCE, DC_LICENSE_PLATE_LINE,
               PART_CODE, DOC_REFERENCE, CAST(DOC_LINE AS VARCHAR(8))
 EXTERNAL JOIN QRY_LPN.COMPANY_CODE={?oracle1: QRY_DESTINATION_WHS.COMPANY_CODE} AND QRY_LPN.DOC_REFERENCE={?oracle1: QRY_DESTINATION_WHS.DOCUMENT_NUMBER} AND QRY_LPN.DOC_LINE_NUMBER={?oracle1: QRY_DESTINATION_WHS.DOCUMENT_LINE}
0
Comment
Question by:Dan Flood
7 Comments
 
LVL 26

Accepted Solution

by:
Kurt Reinhardt earned 500 total points
ID: 18843645
The very first thing you can do to speed up the report is to consolidate all commands into either a single Command or a Stored Procedure, which is conceptually the same as a SQL Command Object (it's just stored on the DB, not in Crystal).  Commands and Procedures are executed fully before any of the joins or additional filters in Crystal Reports are applied.  This means that you're executing three commands, bringing back all possible records from the database across the network to the client before you even apply the joins....  That's bad.
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 18843909
from the database side, it is good to have an index for those columns used in the where clause as long
as we are not using <>, not in , not like, is null because index won't be used even if index is there.

WHERE MOVEMENT_CODE = 'WHTO' and SOURCE_MODULE = 'IC' AND IC_STATUS_CODE <> 'CONFINQ'

so any other way to modify the <> in the where clause will speed up the query.

Thanks
0
 
LVL 16

Expert Comment

by:MohanKNair
ID: 18845827
The best practice to tune SQL in reports is by making use of SQLTRACE and TKPROF reports. Enable SQLTRACE for the crystal reports sessionand run the reports. This will generate a trace file in the server. Gererate TKPROF report with EXPLAIN PLAN. This report will show all the SQL's used by the report and the execution plan used and cost of each query.

If any query is executed many times then the network traffic may be high. Try to buffer some data in the front-end.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 18845907
I don't disagree with the comments from either nav_kum_v or MohanKNair, but neither of those suggestions pertain to actual Crystal Reports functionality and neither will solve your immediate problem.  Both are, however, good suggestions to consider after you've removed the multiple commands.

~Kurt
0
 

Author Comment

by:Dan Flood
ID: 18846114
Thanks I have tried to reduce it to one command, but it's been running for several hours now.  I am not sure how to enable sqltrace for this....  I'm a MSSQL guy just getting my feet wet with Oracle :)
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 18846180
1)  Can you please post the current Command?

2)  Do you have any subreport, shared variables, additional parameters or selection criteria outside of the command?

3)  If you run the command in Toad, SQL+ or some other analyser tool, how long does the query take?

~Kurt
0
 
LVL 16

Expert Comment

by:MohanKNair
ID: 18846402
The first SQL statement in crystal reports shoud be to enable the SQLTRACE and the last SQL is for disabling the sqltrace

Start of reports

ALTER SESSION SET SQL_TRACE=TRUE;

end of the reports

ALTER SESSION SET SQL_TRACE=FALSE;;
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
'G_F01' is not a procedure or is undefined 3 24
MULTIPLE DATE QUERY 15 77
Deleting Rows from an Oracle Database - Performance 19 46
Oracle dataguard 5 30
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question