473,480 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to do index scan

hi, we are using db2 udb v8.1 on windows, if i have a query use where
clause where key > value, the explain sql gives me access path is
table scan, but if i do key = value, it uses index scan, so how can i
force db2 to use index scan when key > value to makes the query run
faster?
Nov 12 '05 #1
4 6260
Ian
xixi wrote:
hi, we are using db2 udb v8.1 on windows, if i have a query use where
clause where key > value, the explain sql gives me access path is
table scan, but if i do key = value, it uses index scan, so how can i
force db2 to use index scan when key > value to makes the query run
faster?


Unless your stats are wrong (or if you haven't collected distribution
stats), the DB2 Optimizer is usually pretty smart about what is better.

If your predicate key > value matches 90% of the table, it's not likely
that DB2 will perform an index scan AND then scan the table, unless you
are looking only for columns that exist in the index.

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 12 '05 #2
"xixi" <da****@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
hi, we are using db2 udb v8.1 on windows, if i have a query use where
clause where key > value, the explain sql gives me access path is
table scan, but if i do key = value, it uses index scan, so how can i
force db2 to use index scan when key > value to makes the query run
faster?


Make sure you have run runstats with distribution on key columns and index
all.

DB2 will use an index "IF" it can avoid reading some 4K data pages (or what
ever the page size is) in the table. But if there is at least 1 qualifying
row on each data page, it usually will not be any fast to use an index
because DB2 does I/O one page at a time. If the row size is 100 bytes, there
are 40 rows on each data page.

If you cluster the table on the index in question, that will likely cause
the index to be used for a > predicate. Or you can just reorg on that index
and then do runstats.
Nov 12 '05 #3
AK
da****@yahoo.com (xixi) wrote in message news:<c0**************************@posting.google. com>...
hi, we are using db2 udb v8.1 on windows, if i have a query use where
clause where key > value, the explain sql gives me access path is
table scan, but if i do key = value, it uses index scan, so how can i
force db2 to use index scan when key > value to makes the query run
faster?


if you really wish to _force_, try OPTIMIZE FOR FIRST clause, or use SELECTIVITY
Use db2batch to see if the query runs faster. Please post the results
Nov 12 '05 #4
Xixi, once you´ve checked the other possibilities, and all is ok
including your index (your key is the first column within the index,
isn´t it?), you may set the table to volatile.
This forces the optimizer to use an index rather than doing a table scan.
Stefan

xixi schrieb:
hi, we are using db2 udb v8.1 on windows, if i have a query use where
clause where key > value, the explain sql gives me access path is
table scan, but if i do key = value, it uses index scan, so how can i
force db2 to use index scan when key > value to makes the query run
faster?

Nov 12 '05 #5

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

Similar topics

3
5677
by: Carlos Moreno | last post by:
I can't find a reasonable explanation for this. I have a table game, with primary key gameid (an int). If I use a where involving gameid and <, or >, or <=, or >=, then I get a sequential...
5
503
by: Gerard M. Operana | last post by:
unsubscribe
14
5383
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
1
6714
by: Gorilla | last post by:
I bound my package with EXPLAIN(YES), and it's got the following static SQL in it: EXEC SQL SELECT CARDF, RECLENGTH INTO :CARDF,:RECLENGTH FROM SYSIBM.SYSTABLES WHERE NAME = :TBNAME AND...
2
1878
by: Pavel Stehule | last post by:
Hello, Pg make query 1. and 2. very fast (use index), but for query 3. dont use index. I can solve its using select union, but I readed so pg 7.5 don't problem with OR operator. I use cvs pg. I...
8
9224
by: Mike Wertheim | last post by:
Hi, I'm using PostgreSQL 8. I have two tables that I am doing a join on, and the join executes very slowly. The table called Notification has a text field called NotificationID, which is...
2
5091
by: bobby_b_ | last post by:
I have a table where fields 1 and 2 make up the primary key. Because of this, I have a unique composite index on fields 1 and 2 (as required by DB2). Now my question is: Fields 1 and 2 are also...
2
2478
by: BD | last post by:
Hi, all. My background is more Oracle than db2. My skills at SQL tuning are quite limited. I'm running 8.2 on Windows. I'm tasked with some SQL optimization, and am doing some explain plans...
1
3184
by: Steffen Stellwag | last post by:
Truely is often better to scan a table in full passing by an index , but if you can force the optimizer to use an index via a hint for testing and comparing the results. But the index in the...
6
3918
by: Henry J. | last post by:
I have a composite index on two columns in a table. However, the index is not used in a query that restricts the 2nd column to a constant. If both columns are linked with columns in other join...
0
7055
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
6920
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
7060
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,...
0
7106
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...
1
6760
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...
0
7022
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...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
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...

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.