Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 17th, 2005, 05:21 AM
tvc3mye's Avatar
tvc3mye tvc3mye is offline
Daniel Schildsky
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: KL, Malaysia.
Posts: 677 tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 6 Days 19 h 27 m 51 sec
Reputation Power: 201
Send a message via ICQ to tvc3mye Send a message via MSN to tvc3mye Send a message via Yahoo to tvc3mye
No improvement after adding indices to the tables

Hi all,

Recently I have received complaints from my users that the queries involving a schema containing several tables are very slow. After inspecting the tables in the schema, I found out that there were no column being indexed except primary keys.

However, after indexing several columns in those tables, I have analysed the statistics using tkprof utility. The results were disappointing and varied from one run to another.

One of the queries I used is as follows:

Code:
CREATE OR REPLACE PROCEDURE "USP_CLD_ENG_CHK_BFD"
(
	cd_in		    IN 	tbl_cld_evt_lvl.cd%TYPE,
	dt_in           IN  tbl_cld_evt.dt_effective_from%TYPE,
	highest_lvl     IN  tbl_cld_lvl_mt.cd%TYPE,
	lowest_lvl		IN  tbl_cld_lvl_mt.cd%TYPE
--    result_cursor   OUT TYPES.cursor_type
)
AS
  	trunc_dt_in_		DATE		   := NULL;
	trunc_dt_in2_       DATE           := NULL;
	all_upp_lvl_code_	NVARCHAR2(500) := NULL;
	tmp_date_			DATE		   := NULL;
	is_bfd_             NVARCHAR2(1)   := 'N';

BEGIN
	BEGIN
		all_upp_lvl_code_ := USF_CLD_ENG_RET_UPP_LVL_CD(cd_in, highest_lvl, lowest_lvl);

		trunc_dt_in_  := TRUNC(dt_in) - 1;   --Get yesterday
		trunc_dt_in2_ := TRUNC(dt_in);

		BEGIN
	  	   SELECT trunc_dt_in_ INTO tmp_date_
		   FROM DUAL
		   WHERE EXISTS
		   (
			   SELECT DISTINCT evtResult.dt_effective_from
		  	   		   			, evtResult.dt_effective_to
				FROM tbl_cld_evt evtResult, tbl_cld_evt_lvl evtLvlResult
				WHERE evtResult.id = evtLvlResult.evt_id
					  AND (TRUNC(evtResult.dt_effective_from) <= trunc_dt_in_
					  	  AND TRUNC(evtResult.dt_effective_to) >= trunc_dt_in_)
				      AND evtLvlResult.is_associated = 'Y'
					  AND evtResult.id NOT IN (SELECT DISTINCT evtExpResult.id
					  	  			   	   	   FROM tbl_cld_evt evtExpResult, tbl_cld_evt_lvl evtExpLvlResult
											   WHERE evtExpResult.id = evtExpLvlResult.evt_id
														 AND (TRUNC(evtExpResult.dt_effective_from) <= trunc_dt_in_
														  	 AND TRUNC(evtExpResult.dt_effective_to) >= trunc_dt_in_)
														 AND evtExpLvlResult.is_associated = 'N'
														 AND (USF_CLD_ENG_INSTR(all_upp_lvl_code_, evtExpLvlResult.cd) = 1)
														 AND evtExpResult.evt_typ_cd = 'CLD_EVT_TYP_HOL'
											  )
					  AND (USF_CLD_ENG_INSTR(all_upp_lvl_code_, evtLvlResult.cd) = 1)
					  AND evtResult.evt_typ_cd = 'CLD_EVT_TYP_HOL'
			);
			EXCEPTION
				WHEN NO_DATA_FOUND THEN
					tmp_date_ := NULL;

		END;

		IF(tmp_date_ IS NOT NULL) THEN
		BEGIN
			SELECT 'Y' INTO is_bfd_
			FROM DUAL
			WHERE NOT EXISTS(
							SELECT DISTINCT evtWorkingDayResult.dt_effective_from
											, evtWorkingDayResult.dt_effective_to
											, evtWorkingDayResult.wk_no
											, evtWorkingDayResult.dy_no

							FROM (SELECT DISTINCT evtResult.dt_effective_from
												, evtResult.dt_effective_to
												, evtReptResult.wk_no
												, evtReptResult.dy_no
 								  FROM  tbl_cld_evt evtResult, tbl_cld_evt_rept evtReptResult, tbl_cld_evt_lvl evtLvlResult
 								  WHERE evtResult.evt_typ_cd = 'CLD_EVT_TYP_WD'
							   		    AND evtResult.id = evtLvlResult.evt_id
										AND evtResult.id = evtReptResult.evt_id
 										AND (TRUNC(evtResult.dt_effective_from) <= trunc_dt_in_
											AND TRUNC(evtResult.dt_effective_to) >= trunc_dt_in_)
 									    AND evtLvlResult.is_associated = 'Y'
									    AND evtResult.id NOT IN (SELECT DISTINCT evtExpResult.id
									  	  			   	   	     FROM tbl_cld_evt evtExpResult, tbl_cld_evt_rept evtExpReptResult, tbl_cld_evt_lvl evtExpLvlResult
															     WHERE evtExpResult.id = evtExpLvlResult.evt_id
															   		   AND evtExpResult.id = evtExpReptResult.evt_id
																	   AND (TRUNC(evtExpResult.dt_effective_from) <= trunc_dt_in2_
																	   	   AND TRUNC(evtExpResult.dt_effective_to) >= trunc_dt_in2_)
																	   AND evtExpResult.evt_typ_cd = 'CLD_EVT_TYP_WD'
																	   AND evtExpLvlResult.is_associated = 'N'
																	   AND (USF_CLD_ENG_INSTR(all_upp_lvl_code_, evtExpLvlResult.cd) = 1)
															    )
 									    AND (USF_CLD_ENG_INSTR(all_upp_lvl_code_, evtLvlResult.cd) = 1)
 								  ) evtWorkingDayResult

							WHERE USF_CLD_ENG_INSTR(USF_CLD_ENG_RET_REPT_DAY
														(evtWorkingDayResult.wk_no, evtWorkingDayResult.dy_no,
														 evtWorkingDayResult.dt_effective_from, evtWorkingDayResult.dt_effective_to
														),
													TO_CHAR(tmp_date_, 'DD-MM-YYYY')
												   ) = 1
			);

			EXCEPTION
				WHEN NO_DATA_FOUND THEN
					is_bfd_ := 'N';
		END;
		END IF;
/*
		OPEN result_cursor FOR

		SELECT is_bfd_ AS is_bfd
		FROM DUAL;*/
	END;
END;
/


My questions are :
1. Why was the performance remain the same after I added the indices to several tables? I thought adding indices would speed up the queries..(if there is nothing there which causes the index to be suppressed).

2. The readings from tkprof report shows that the elapsed time is getting slower and slower each time when I execute the stored procedure. Anyone has any idea about this?
__________________
When the programming world turns decent, the real world will turn upside down.

Reply With Quote
  #2  
Old October 17th, 2005, 09:46 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,073 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 4 Weeks 4 h 9 m 58 sec
Reputation Power: 281
Did you collect fresh stats?

Reply With Quote
  #3  
Old October 18th, 2005, 10:56 AM
tvc3mye's Avatar
tvc3mye tvc3mye is offline
Daniel Schildsky
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: KL, Malaysia.
Posts: 677 tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 6 Days 19 h 27 m 51 sec
Reputation Power: 201
Send a message via ICQ to tvc3mye Send a message via MSN to tvc3mye Send a message via Yahoo to tvc3mye
I did collect fresh stats

Yes I did. After adding the indices to the tables, I have executed the dbms_stats.gather_schema_stats to collect the new statistics from the database.

I then rerun the test by executing the sample stored procedure 10 times. Afterwards, I used tkprof to generate a new set of report.

Reply With Quote
  #4  
Old October 18th, 2005, 11:07 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,073 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 4 Weeks 4 h 9 m 58 sec
Reputation Power: 281
Did you run an explain of the query contained in your proc with sample values for parameters?
oracle8 Code:
Original - oracle8 Code
  1. SELECT DISTINCT evtResult.dt_effective_from, evtResult.dt_effective_to
  2. FROM tbl_cld_evt evtResult, tbl_cld_evt_lvl evtLvlResult
  3. WHERE evtResult.id = evtLvlResult.evt_id
  4. AND (TRUNC(evtResult.dt_effective_from) <= trunc_dt_in_
  5. AND TRUNC(evtResult.dt_effective_to) >= trunc_dt_in_)
  6. AND evtLvlResult.is_associated = 'Y'
  7. AND evtResult.id NOT IN (SELECT DISTINCT evtExpResult.id
  8.                 FROM tbl_cld_evt evtExpResult, tbl_cld_evt_lvl evtExpLvlResult
  9.                WHERE evtExpResult.id = evtExpLvlResult.evt_id
  10.                AND (TRUNC(evtExpResult.dt_effective_from) <= trunc_dt_in_
  11.                AND TRUNC(evtExpResult.dt_effective_to) >= trunc_dt_in_)
  12.                AND evtExpLvlResult.is_associated = 'N'
  13.                AND (USF_CLD_ENG_INSTR(all_upp_lvl_code_, evtExpLvlResult.cd) = 1)
  14.                AND evtExpResult.evt_typ_cd = 'CLD_EVT_TYP_HOL'
  15.               )
  16. AND (USF_CLD_ENG_INSTR(all_upp_lvl_code_, evtLvlResult.cd) = 1)
  17. AND evtResult.evt_typ_cd = 'CLD_EVT_TYP_HOL'

Also, which indexes did you add? Are you aware of function based indexes? Can you rewrite the ... NOT IN (SELECT DISTINCT evtExpResult.id ... part as an outer join with ... where .. is null clause?

Reply With Quote
  #5  
Old October 26th, 2005, 03:24 AM
time_out time_out is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 4 time_out User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 42 m 59 sec
Reputation Power: 0
maybe oracle doesn't know which index to use. You can use hint but the result is still uncertain

Reply With Quote
  #6  
Old October 30th, 2005, 12:28 AM
imchi imchi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 135 imchi User rank is Sergeant (500 - 2000 Reputation Level)imchi User rank is Sergeant (500 - 2000 Reputation Level)imchi User rank is Sergeant (500 - 2000 Reputation Level)imchi User rank is Sergeant (500 - 2000 Reputation Level)imchi User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 21 h 45 m 37 sec
Reputation Power: 21
In my experience, Oracle is pretty slow with IN, NOT IN, EXISTS, and NOT EXISTS. I would rewrite the query using an outer join.

Reply With Quote
  #7  
Old November 1st, 2005, 12:13 PM
tvc3mye's Avatar
tvc3mye tvc3mye is offline
Daniel Schildsky
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: KL, Malaysia.
Posts: 677 tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level)tvc3mye User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 6 Days 19 h 27 m 51 sec
Reputation Power: 201
Send a message via ICQ to tvc3mye Send a message via MSN to tvc3mye Send a message via Yahoo to tvc3mye
Thanks

Well, thanks for the reply from all. After a few more fine tuning in some other related stored functions, the stored procedures involved were quite fast in execution now. Thanks again to all!

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsDatabasesOracle Development > No improvement after adding indices to the tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...