473,836 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10661
"crazy_jutt " <ud******@gmail .comwrote in message
news:11******** *************@t 46g2000cwa.goog legroups.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,articl es 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
6543
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 some servers and not others......... Most of the servers I run it on just ignore the problem and result in the variable being assigned empty.
1
4644
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 'kr.ac.dke.protein.compression.SequenceCompressor.decode(java.lang.String) return java.lang.String';
9
3980
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: table email_address (id int, email varchar) with the following entries
0
2826
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
4841
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 but my queries do not use the index I created for that column. Is there any way I can force the usage of the index or to ommit a value on the index creation, like 0 (zeroes) or spaces? Thanks in advance, André Queiroz
2
5522
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
3894
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 directly the parameter value -2 but it is dynamically calculated (e.g.: WHERE SUBSTR(afield, anotherfield * 2) = '01'
2
2136
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 memory size of 134217728 bytes exhausted (tried to allocate 11 bytes) in /location_of_script/database.php on line 75" Now I know basically what's causing this problem I'm just not sure exactly how I should go about fixing it... See after I got...
4
6349
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 Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92 Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
0
9813
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10834
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10584
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10248
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5817
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.