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 > HOW to create function index

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-05, 09:09
chenlangyun chenlangyun is offline
Registered User
 
Join Date: Dec 2005
Posts: 8
HOW to create function index

Hi,
everyone
I create a function as follows :


drop function convid!
create function convid(id varchar(25))
returns char(15)
begin atomic
return
case
when length(ltrim(rtrim(id)))=18 then substr(id,1,6)||substr(id,9,9)
when length(ltrim(rtrim(id)))=15 then id
else null
end;

end!

The function convid will be used in many place ,for example
update bd_psndoc set ts=? where (psnclscope=0 or psnclscope=1) and pk_psndoc in (select pk_psndoc from bd_accpsndoc where convid(id)=?)

I found the perfomance is not well,so I want to create function index for convid via index extender,can i achiveve?
Any one help me
Reply With Quote
  #2 (permalink)  
Old 12-05-05, 09:54
gardenman gardenman is offline
Registered User
 
Join Date: Apr 2004
Posts: 54
DB2 does not support function based indexes.
You have to create field "GENERATED ALWAYS AS " and then create an index based on the one.
Reply With Quote
  #3 (permalink)  
Old 12-05-05, 21:00
chenlangyun chenlangyun is offline
Registered User
 
Join Date: Dec 2005
Posts: 8
Can you give me more details?
Reply With Quote
  #4 (permalink)  
Old 12-06-05, 03:45
gardenman gardenman is offline
Registered User
 
Join Date: Apr 2004
Posts: 54
> Can you give me more details?

create table ex (
id int not null,
name char(30),
dt date,
-- here is a generated field
yearquarter char(6) generated always as (
substr(char(dt),1,4)||
case
when (month(dt)<4) then '.1'
when (month(dt)<7) then '.2'
when (month(dt)<10) then '.3'
else '.4'
end
),
constraint pk primary key(id)
)@

create unique index iquarter on ex (yearquarter,id) allow reverse scans@
rollback@
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