![]() |
Tuning an SQL query
IntroductionI had a complex SQL query that was used to extract data from my system and send it across via web request to an external system. The query was taking unduly longer time to run. I made few changes to the query structure and reduced it run time to 7 mins. A part of the main query that was actually causing the delay has been pasted in the sections below. Problem DescriptionOne of my external systems reported that one of the queries that run at my end have failed with the error below: ORA-20001: Error - WebService Request Failed. ORA-29276: transfer timeout. When I tried running the SELECT query in question at my end (on Toad), the query kept running after I aborted it after almost 90 minutes. The central part of the original query is as below. This part was causing the entire query to slow down. The tables TEAM, TIMESHEET, TIMEENTRY and ASSIGNMENT are considerably huge tables with billions of records. The explain plan showed a full table access on ASSIGNMENT and TIMESHEET tables. The codeProblem Code: SQL
I changed the query structure as below. This query took 7 mins to run, a considerable improvement from the old query: Code:
More readable code by Nimesh Code: sql
|
Re: Tuning an SQL query
7 Mins is a huge time.
|
Re: Tuning an SQL query
thanks dear admin
|
Re: Tuning an SQL query
Nice work
A kind request to format the codes in a more readable format, from next time. :) -Nimesh |
Re: Tuning an SQL query
Yes and if you plan to do it for the current one email me the content in text file. You know my email which is shabbir @ this domain
|
Re: Tuning an SQL query
how to make it more readable?
|
Re: Tuning an SQL query
Quote:
|
Re: Tuning an SQL query
Indentation?
|
Re: Tuning an SQL query
I follow this kind of Indentation, which is little different from what other use ;)
And when writing the codes, use fixed with font so the indentation will appear properly. Code: sql
Did you use the same query exactly, as I found lot of syntactical errors? :crazy: |
Re: Tuning an SQL query
You can make some more changes (which I don't prefer :))
like this, Code: sql
|
| All times are GMT +5.5. The time now is 09:12. |