473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

index usage when using SUBSTR

hi all,

i heard that db2 ignores indexes when using any column function on the
column which has index on it. but i have seen db2 using indexes even
when using column function.

what is the criteria of db2 about picking index or not picking index
when there is a column function ?

i am using function on one column like below

SUBSTR(abc,1,1) IN ('SS',V'V',OO',PP',EE') and db2 is doing table scan
and Filter Factor : 0.0798775

what is the best way to deal with this kind of criteria in where clause
?
should there be extra column added to table with only SUBSTR data from
original column and make index on that column and then use that column
in where instead

Dec 15 '06 #1
4 10530
"crazy_jutt" <ud******@gmail.comwrote in message
news:11*********************@t46g2000cwa.googlegro ups.com...
hi all,

i heard that db2 ignores indexes when using any column function on the
column which has index on it. but i have seen db2 using indexes even
when using column function.

what is the criteria of db2 about picking index or not picking index
when there is a column function ?

i am using function on one column like below

SUBSTR(abc,1,1) IN ('SS',V'V',OO',PP',EE') and db2 is doing table scan
and Filter Factor : 0.0798775

what is the best way to deal with this kind of criteria in where clause
?
should there be extra column added to table with only SUBSTR data from
original column and make index on that column and then use that column
in where instead
I believe that you meant WHERE SUBSTR(abc,1,2) IN ('SS',VV','OO',PP',EE')
since the literals have 2 bytes.

In this particular case, you might try:
WHERE abc like 'SS%'
or abc like 'VV%',
or abc like 'OO%',
or abc like 'PP%',
or abc like 'EE%'

Note that there are 2 main types of index access. One is the b-tree (which
is the fastest and what most people think of as index access), and there is
also a index space scan where it reads all the leaf pages of the index
without the b-tree (non-leaf pages). The later is slower, but faster than a
table scan.

A statement with "WHERE abc like 'SS%' " will normally use the b-tree of the
index since the leftmost characters are being searched (there is no leading
%). I am not quite sure about what will happen with all the OR's.
Dec 15 '06 #2
I tested by using Sample table data as following.
The last query used the Index.
Has your index include only column abc?
Or, do you have many AND conditions and is another index more
effective?
If your FixPack of DB2 is low, it may be better to upgrade latest FP.

------------------------------ Commands Entered
------------------------------
CREATE TABLE Employee_I LIKE Employee;
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
INSERT INTO Employee_I SELECT * FROM Employee;
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
CREATE INDEX EmpI_fnm ON Employee_I
(firstnme);
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
SELECT empno, lastname || ', ' || firstnme AS "FullName"
FROM Employee_I
WHERE SUBSTR(firstnme,1,2) IN ('SA','MA','IA','VI','WI');
------------------------------------------------------------------------------

EMPNO FullName
------ -----------------------------
000270 PEREZ, MARIA
000180 SCOUTTEN, MARILYN
000170 YOSHIMURA, MASATOSHI
000310 SETRIGHT, MAUDE
000030 KWAN, SALLY
000240 MARINO, SALVATORE
000110 LUCCHESSI, VINCENZO
000210 JONES, WILLIAM
000330 LEE, WING

9 record(s) selected.

Dec 16 '06 #3

Tonkuma wrote:
I tested by using Sample table data as following.
The last query used the Index.
Has your index include only column abc?
Or, do you have many AND conditions and is another index more
effective?
I'm sorry. I made mistake. You wrote DB2 do tablespace scan.

Dec 16 '06 #4
hi,

first, thanks to all trying to help
using LIKE clause with OR made explain plain go crazy with 10 to power
38 timerons from 798000 timerons withSUBSTR (abc,1,1) IN
('SS',V'V',OO',PP',EE')
so, i stayed with SUBSTR(abc,1,1) IN ('SS',V'V',OO',PP',EE')
there were three more columns along with abc used in the same where
clause from this table say XYZ
i created compund index with all four columns and ordered column in
index with decreasing cardinality and allow reverse scans
now, it used index for SUBSTR(abc,1,1) IN ('SS',V'V',OO',PP',EE')
i do not understand this behaviour. previously, i had indexes on
individual columns and db2 did use indexes for all columns from table
XYZ but abc column
not when i create compound index, db2 uses index for all.
please someone explain

also, give me some good web,book,articles references to understand
behaviour of indexes in db2


On Dec 15, 10:51 pm, "Tonkuma" <tonk...@jp.ibm.comwrote:
Tonkuma wrote:
I tested by using Sample table data as following.
The last query used the Index.
Has your index include only column abc?
Or, do you have many AND conditions and is another index more
effective?I'm sorry. I made mistake. You wrote DB2 do tablespace scan.
Dec 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Neil Strong | last post by:
I'm getting an error message "Unidentified Index" when reading posted variables from a form $x = $_POST I know I can use 'isset()' to check them first, but I'm curious as to why this works on...
1
by: Min-Koo Seo | last post by:
Hi. I have a java stored procedure whose spec is as follows: CREATE OR REPLACE FUNCTION DECODE_SEQUENCE(SEQUENCE VARCHAR2) RETURN VARCHAR2 DETERMINISTIC AS LANGUAGE JAVA NAME...
9
by: Robert Brown | last post by:
If I use _reverse_ wildcard search will it always result in a table scan? Is it possible to get the DB (Oracle or SQL server) to use indexes when doing reverse wildcard match? let's say I have:...
0
by: Guy Deprez | last post by:
Hi, i'm having a problem to create indexes. STEP 1 ----------- Connection is OK (you can find the string at the end of the message) Table ("Couleurs") creation is OK STEP 2. Index Creation
8
by: Andr? Queiroz | last post by:
Hi, I have a table with 10M records and col A has a index created on it. The data on that table has the same value for col A on all 10M records. After that I insert diferent values for that column...
2
by: FBergemann | last post by:
if i compile following sample: #include <iostream> #include <string> int main(int argc, char **argv) { std::string test = "hallo9811111z"; std::string::size_type ret;
3
by: kocek | last post by:
Hi! If I create an index using function Substr (e.g.: create index on SUBSTR(afield, -2) ) then if I use the substr on the given field, with the given parameter in a select, but I do not type...
2
jlm699
by: jlm699 | last post by:
Greetings all, I'm using a PHP-based web page to access an SQL database containing logs which has grown quite large over time. A few weeks ago I recieved the following error: "Fatal error: Allowed...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.