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 > DB2 SQL perforamance

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-07-10, 11:52
donjahnas donjahnas is offline
Registered User
 
Join Date: Jul 2010
Posts: 13
DB2 SQL perforamance

I have a DB2 table with over 22 million records. The table is BY FISCAL DATE
from 1999 to now. There's about 1 million rows per YEAR(FISCAL DATE).

The current selection is:

if YEAR(FISC_DATE) = 2010
AND ADATE <= '2010-07-07'


the proposed coding is plus ADATE is made index:
write new sql to retrieve the earliest ADATE for YEAR(FISC_DATE) = 2010
and pass it in @ED to next sql

if YEAR(FISC_DATE) = 2010
AND ADATE between '@ED and 2010-07-07'

WILL THIS PROPOSED CHANGE HELP PERFORMANCE?

Thanks, Don






where AC is acceptance_date
Reply With Quote
  #2 (permalink)  
Old 07-07-10, 11:57
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What columns do you have indexes on?

Andy
Reply With Quote
  #3 (permalink)  
Old 07-07-10, 12:00
donjahnas donjahnas is offline
Registered User
 
Join Date: Jul 2010
Posts: 13
DB@# sql

fisc_date and acceptance_date
Reply With Quote
  #4 (permalink)  
Old 07-07-10, 12:08
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Exclamation Using indexes or functions

Instead of
Code:
IF YEAR(FISC_DATE) = 2010
use
Code:
IF FISC_DATE between '2010-01-01' and '2010-12-31'
Lenny
Reply With Quote
  #5 (permalink)  
Old 07-07-10, 12:36
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
I think when you use a function index is not used. So Lenny is right.
But fiscal year is not necessaraly from Jan 1 to Dec 31 so the statement
IF FISC_DATE between '2010-01-01' and '2010-12-31' might not work.

Or if fiscal year end Jan 1 - Dec 31 you do not need to use FISC_DATE in your query so can do it this way:

Code:
if ADATE between '2010-01-01' and '2010-07-07'
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS

Last edited by MarkhamDBA; 07-07-10 at 12:43.
Reply With Quote
  #6 (permalink)  
Old 07-07-10, 12:39
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quote:
Originally Posted by MarkhamDBA View Post
did you mean instead of:
Code:
if YEAR(FISC_DATE) = 2010
AND ADATE <= '2010-07-07'
use:
Code:
if FISC_DATE between '2010-01-01' and '2010-07-07'
?
No he meant that you replace it with this:
Code:
if FISC_DATE between '2010-01-01' and '2010-07-07
AND ADATE <= '2010-07-07'
Andy
Reply With Quote
  #7 (permalink)  
Old 07-07-10, 12:59
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
Quote:
Originally Posted by ARWinner View Post
No he meant that you replace it with this:
Code:
if FISC_DATE between '2010-01-01' and '2010-07-07
AND ADATE <= '2010-07-07'
Andy
you mean:
Code:
if FISC_DATE between '2010-01-01' and '2010-12-31'
AND ADATE <= '2010-07-07'
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #8 (permalink)  
Old 07-07-10, 13:01
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Yes, that is what I meant.

Andy
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