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 > Date conditions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-27-09, 15:36
citi citi is offline
Registered User
 
Join Date: Aug 2007
Posts: 45
Date conditions

Shown below is a portion of a query that I've written. Would using date conditions cause DB2 to skip an index that is comprised of the
W02_POS_BEG_xx date fields? The table is fairly large. Despite a number of indexes, DB2 chooses to perform a tablescan instead of using the indexes.



(DATE(DIGITS(CAST(W02_POS_BEG_YY AS DECIMAL(4, 0))) || '-' || DIGITS(CAST(W02_POS_BEG_mm AS DECIMAL(2, 0))) ||'-'|| DIGITS(CAST(W02_POS_BEG_dd AS DECIMAL(2, 0)))))as W02POSDT,
(DIGITS(W02_POS_BEG_MM)||'/'||DIGITS(W02_POS_BEG_DD)||'/'||DIGITS(W02_POS_BEG_YY))AS POSBEG,
('6'||'/'||'30'||'/'||DIGITS(W02_POS_END_YY))AS POSEND,

Thank you
Reply With Quote
  #2 (permalink)  
Old 07-27-09, 15:57
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by citi
Shown below is a portion of a query that I've written. Would using date conditions cause DB2 to skip an index that is comprised of the
W02_POS_BEG_xx date fields? The table is fairly large. Despite a number of indexes, DB2 chooses to perform a tablescan instead of using the indexes.
I guess this would have been better stated as:
Quote:
Our data model is seriously flawed. We store dates as numeric fields for year, month, and day values, while many queries have values of the DATE datatype in their selection criteria. Performance is unacceptable. How can we improve it?
You have three options:
- change the way you store dates;
- create (and keep updated) a computed DATE column, calculated from your year, month, and day values; build an index on that column;
- parse the search criteria into the year, month, and day values and make your queries search by those values.
Reply With Quote
  #3 (permalink)  
Old 07-27-09, 15:58
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What DB2 version and OS?

What determines the access plan more than anything is the WHERE clause. Returning calculations on the columns will not have much of an impact.

Andy
Reply With Quote
  #4 (permalink)  
Old 07-27-09, 16:19
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Maybe it is a question for Lenny77 as he also works at citi
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #5 (permalink)  
Old 07-27-09, 16:35
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by Cougar8000
Maybe it is a question for Lenny77 as he also works at citi
He's busy calculating prime numbers. Digits of pi will be next.
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