If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Performance question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-05-11, 16:59
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
Performance question

Hi...
I try run this query in db2 for iSeries 5.4

This query run in 4 seconds ~

Code:
select 	*
from 	pd812dta.f4211
where 	sdIVD 	= 	111217
but this, run in 2 minutes ~
Code:
select 	*
from 	pd812dta.f4211
where 	sdIVD 	= 	((year( '2011-08-05' )-1900)*1000) + ( dayofyear( '2011-08-05'))
any idea? the field sdIVD store a julian date...
TIA
Abel.
Reply With Quote
  #2 (permalink)  
Old 08-08-11, 01:56
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
probably because of the operation on the index. try explain and see
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 08-08-11, 08:03
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
thanks for your replay.
Reply With Quote
  #4 (permalink)  
Old 08-09-11, 08:08
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
The visual explain said:

The first qry ( sdIVD = 111217 ) make a index seek, the second a table scan...:X Any idea???
Reply With Quote
  #5 (permalink)  
Old 08-09-11, 08:18
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
DB2 may not use an index if a function is applied to the predicate.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 08-09-11, 09:13
stiruvee stiruvee is offline
Registered User
 
Join Date: May 2010
Location: India
Posts: 34
Same question was asked by you two months ago and answered.


Question about Performance in a Qry
Reply With Quote
  #7 (permalink)  
Old 08-09-11, 09:32
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
Thanks, but NOT is a problem of casting a field... read all post.
Reply With Quote
  #8 (permalink)  
Old 08-09-11, 09:50
stiruvee stiruvee is offline
Registered User
 
Join Date: May 2010
Location: India
Posts: 34
What is the data type for the field sdIVD? Any change in query performance when you force type cast right side in expression to data type of the field sdIVD?
Reply With Quote
  #9 (permalink)  
Old 08-09-11, 10:00
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
nop.. same results, the field sdIVD is numeric(8,0) and ever the query optimizer make a table scan when use a fx in the right side. Thanks for your replay.
Reply With Quote
  #10 (permalink)  
Old 08-09-11, 10:02
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Marcus_A wrote
Quote:
DB2 may not use an index if a function is applied to the predicate.
I found the description on manual "IBM i Database Performance and Query Optimization 7.1"
---> Creating an index strategy ---> Coding for effective indexes
Quote:
Avoid arithmetic expressions
Do not use an arithmetic expression as an operand to compare to a column in a row selection predicate.
The optimizer does not use an index on a column compared to an arithmetic expression. While this
technique might not cause the column index to become unusable, it prevents any estimates and possibly
the use of index scan-key positioning. The primary thing that is lost is the ability to use and extract any
statistics that might be useful in the optimization of the query.
Reply With Quote
  #11 (permalink)  
Old 08-09-11, 10:09
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
How about add an extra condition, like...
" AND sdIVD > 0"

or

" AND sdIVD BETWEEN 1 AND 200366"
Reply With Quote
  #12 (permalink)  
Old 08-09-11, 10:20
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
Quote:
Originally Posted by tonkuma View Post
How about add an extra condition, like...
" AND sdIVD > 0"

or

" AND sdIVD BETWEEN 1 AND 200366"
In both cases make a table scan... thanks.
Reply With Quote
  #13 (permalink)  
Old 08-09-11, 16:11
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
My solution was.

Code:
SET PATH='TEMPORAL';
SET SCHEMA='TEMPORAL';

 CREATE FUNCTION GRE2JUL ( FECHA date )
     RETURNS TABLE ( sdDOCO NUMERIC(8,0) )
     LANGUAGE SQL    
     DISALLOW PARALLEL
BEGIN
      declare FECHA_JUL numeric(6,0);
	set FECHA_JUL = ((year( FECHA  ) - 1900)*1000) + ( dayofyear(FECHA));
   	RETURN
	 	select sdDOCO
		from pd812dta.f4211 
		where sdIVD = FECHA_JUL;
  END;
and....

Code:
select 	*  from 	table( TEMPORAL.GRE2JUL ( CAST('2011-08-09' AS DATE) ) ) as x;


Thanks to all...
Reply With Quote
  #14 (permalink)  
Old 08-09-11, 17:13
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
If the table function showed good performance,
how about to put the expression in another subquery?

For example:
Code:
SELECT *
 FROM  (SELECT (YEAR(fecha) - 1900) * 1000 + DAYOFYEAR(fecha)
         FROM  (SELECT CAST('2011-08-09' AS DATE)
                 FROM  sysibm.sysdummy1
               ) p(fecha)
       ) gre2jul(fecha_jul)
     , pd812dta.f4211
 WHERE sdIVD = fecha_jul
;
Reply With Quote
  #15 (permalink)  
Old 08-09-11, 17:38
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
Hi Tonkuma. Thanks for your replay.
My first option was this, but, with a subquery not change nothing and make a tablescan...
The performance of table fx is very good, respond in 0-1~ seconds.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On