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 > Create Index using function Syntax Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-27-07, 10:21
Quigley007 Quigley007 is offline
Registered User
 
Join Date: Dec 2004
Location: MN, USA
Posts: 4
Angry Create Index using function Syntax Help

Hi,

I am trying to create an index with a function and am getting stuck on the syntax. I am on V9 on AIX. I checked the online manuals, but I am still doing something wrong.

Here is my command:
CREATE INDEX INDEX_NAME ON TABLE_NAME
(
LOWER(column1) ASC
) PCTFREE 20 MINPCTUSED 10 COLLECT STATISTICS;


and the error:

CREATE INDEX INDEXNAME TABLENAME( LOWER(column1) ASC ) PCTFREE 20 MINPCTUSED 10 COLLECT STATISTICS
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "(column1)" was found following "TABLENAME (
LOWER". Expected tokens may include: "<space>". SQLSTATE=42601


Thanks for your comments.
Reply With Quote
  #2 (permalink)  
Old 08-27-07, 10:47
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
indexes can be created on real data
add the lower when executing the select
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8
Reply With Quote
  #3 (permalink)  
Old 08-27-07, 11:27
Quigley007 Quigley007 is offline
Registered User
 
Join Date: Dec 2004
Location: MN, USA
Posts: 4
This link seems to suggest that functions are available for creating indexes:

http://publib.boulder.ibm.com/infoce...c/r0052232.htm
Reply With Quote
  #4 (permalink)  
Old 08-27-07, 11:40
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
This is a command specific for the Net Search Extender and must be executed in the "db2text" command - not the regular "db2" CLP.
Quote:
function-schema.function-name
The schema and the name of a user-defined function used to access text documents that are in a column of an unsupported type. The function performs a column type conversion, using as input parameter an arbitrary column type. It returns the value as one of the Net Search Extender supported types.
The regular CREATE INDEX statement is described here: http://publib.boulder.ibm.com/infoce...c/r0000919.htm
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 08-27-07, 11:50
Quigley007 Quigley007 is offline
Registered User
 
Join Date: Dec 2004
Location: MN, USA
Posts: 4
Thanks for the replies.

- I did a little more research and discovered the meaning of the 'net search extender'. I will get back to my developer and let him know a lcase index in not available.
Reply With Quote
  #6 (permalink)  
Old 08-27-07, 12:06
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You can create such an index with the help of generated columns:
Code:
ALTER TABLE ... ADD COLUMN column1_lcase VARCHAR(...) GENERATED ALWAYS AS ( LCASE(column1) );
CREATE INDEX ... ON ... ( column1_lcase );
DB2 will automatically reroute to COLUMN1_LCASE if the query contains a predicate like "LCASE(column1) = '...'". Then you may see that the index is exploited. All that depends on the usual optimizer decisions regarding the best execution plan.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 08-27-07, 20:18
nagbuchi nagbuchi is offline
Registered User
 
Join Date: Feb 2005
Location: Bangalore,India
Posts: 39
Just wanted to pointed out..

Index on the generated column LCASE(..) will not be useful if a predicate uses LOWER(though LCASE and LOWER do the same functionality).

Need to use the correct subfunction(LCASE or LOWER) in the SQL statements based on the table design.

--Naga
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