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 > LIKE prevent use of index?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-28-10, 18:18
BigBob77 BigBob77 is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
Talking LIKE prevent use of index?

I have the following SQL statement and explain results. This query is taking an excessive amount of time.

A couple questions:

1) does the use of LIKE still allow the optimizer to use an index?

2) the index it is using has policy_num, batch_date, batch_seq and seq_num. Sould I create a new index with just policy_num so this query will utilize it and perform faster?

Thanks!
Bob

SELECT ITEM.BATCH_DATE, ITEM.BATCH_SEQ, ITEM.SEQ_NUM, ITEM.POLICY_NUM,
ITEM.INSURED_NAME, ITEM.ITEM_TYPE_CODE, ITEM.EFFECTIVE_DATE,
ITEM.TRAN_EFFECT_DATE, ITEM.ITEM_PREMIUM, ITEM.ITEM_RETURNED, ITEM.ENTRY_SOURCE,
ITEM.NOTES_EXIST, ITEM.TAGS_EXIST, ITEM.REASONS_EXIST FROM ITEM ITEM WHERE
POLICY_NUM LIKE ? ESCAPE '+' ORDER BY ITEM.POLICY_NUM,ITEM.INSURED_NAME ASC
SQL4021 Access plan last saved on 09/22/09 at 15:20:19.
SQL4020 Estimated query run time is 27 seconds.
SQL4017 Host variables implemented as reusable ODP.
SQL4002 Reusable ODP sort used.
SQL4006 All indexes considered for table 1.
SQL4008 Index I1A30310 used for table 1.
SQL4011 Index scan-key row positioning used on table 1.
Reply With Quote
  #2 (permalink)  
Old 01-29-10, 02:43
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
use dynamic sql and supply the value at prep time
do not use '%xxxx' because in that case it can not use the index either
__________________
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 01-29-10, 09:26
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
If policy_num is already in the first position in the current index, there is no need to create a stand alone index on policy_num.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #4 (permalink)  
Old 02-04-10, 18:11
BigBob77 BigBob77 is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
thank you both!
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