Solved

Huge tables, multiple commands, deathly slow query via Crystal

Posted on 2007-04-03
7
1,950 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
set item in form 7 22
sql server store procedure contains temp tables need to convert oracle? 3 59
Oracle Date 6 42
Shared Service Environment 2 55
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

710 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