Solved

Huge tables, multiple commands, deathly slow query via Crystal

Posted on 2007-04-03
7
1,936 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:jakyll
7 Comments
 
LVL 26

Accepted Solution

by:
Kurt Reinhardt earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 26

Expert Comment

by:Kurt Reinhardt
Comment Utility
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:jakyll
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now