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 tuning of query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-02-09, 05:47
shalini11 shalini11 is offline
Registered User
 
Join Date: Sep 2009
Posts: 1
Performance tuning of query

Hi All,

I have a requirement of creating a view which is having joins on 9 tables. This view is used by Cognos team to fetch data for reporting.

For reporting purpose, they need mostly counts based on some where clauses.For one of those where clauses the query on view is taking too long. This where clause contains a derived column. Even if I create index on the base column, the query dosen't speeds up.

The query which they are firing on view is:

select count(*) from test_view where col2='Approved';

This col2 is derived as follows:

Coalesce((CASE col1 When 'Y' Then 'Approved' When 'N' Then 'Rejected' Else NULL End),'Pending') col2

Please guide as to how can i increase the query efficiency.

Thanks in adv
Reply With Quote
  #2 (permalink)  
Old 09-02-09, 06:40
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
shalini11, First, this has nothing to do with your performance issue but I would remove the COALESCE and replace NULL with 'Pending':

CASE col1 WHEN 'Y' THEN 'Approved' WHEN 'N' THEN 'Rejected' ELSE 'Pending' END AS col2

There is just extra work by having the CASE set a NULL and then using a COALESCE to replace the NULL with a value when the CASE could set the value in the first place.

Second, as you found out, creating an Index on the base column but using a derived (or converted) value from that column does not use the index (because the derived value is not indexed).

I don't know if this will help or not but you can return both the base value (col1) and the derived value (col2) in the View and then change the query on the View to use the base value (col1) in the WHERE clause and the derived value (col2) in the SELECT clause. This should allow the Index to be use by the WHERE clause but still display the user friendly text string for the report. (But if all that is being done is COUNT(*) you don't really need the derived/converted value although it may be needed by other queries.)
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