473,779 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB2/UDB B-Tree Indexing, Reverse Scans

I'm relatively new to DB2 and was reasonably amused to see the REVERSE
SCAN availability for Indexes.

My assumptions are as follows:

DB2/UDB uses B-Tree for indexing by default and is likely the main
offering for Indexing within the DB.

Reverse Scans could possibly only happen on the the leaf node of
the index

Now if these assumptions are indeed true:

I wonder how does the algorithm for a Reverse Scan work. I thought
at the level of the Leaf Node a scan of every entry is made.

And if that is so, how will a Reverse Scan Help is one question.

The other is, what predicates the optimizer, query plan to do a
reverse scan, what sets this bias?

It does not make sense to me to have a reverse scan.

Thanks,

Zridhar

Nov 12 '05 #1
6 6464
AK
ALLOW REVERSE SCANS is not an algorythm, it's an option to choose when
builing indexes.
if an index is built without REVERSE SCAN option, it can be scanned in
one direction only. The simplest example is
SELECT MIN(X) FROM SOME_TABLE
returns right away, reading from the root to the first leaf page

SELECT MAX(X) FROM SOME_TABLE
returns in a while, reading from the root to the first leaf page, then
scanning all the leaf pages

Nov 12 '05 #2
I don't think can be a reverse scan at the root or non-leaf node pages
of an index.

And I think I'm right when I say that its an Algorithm that is behind a
Reverse Scan, I do know its an option when Building an index.

The question is what it gives the user.

I'm not sure how MIN and MAX can be helped by this at all.

As I said, I do not understand, given the organization of a B-Tree, how
there can be a Reverse Scan or for that matter a predicated Bias to the
Scan of an B-Tree Index.

Nov 12 '05 #3
In DB2, allowing reverse scans will speed up some queries with and
order by decending sequence, where DB2 can use the index instead of
actually performed a sort of the rows.

Allow reverse scan also speeds up the MAX funciton, if the column in
the MAX is an indexed column.

Nov 12 '05 #4
m0****@yahoo.co m wrote:
In DB2, allowing reverse scans will speed up some queries with and
order by decending sequence, where DB2 can use the index instead of
actually performed a sort of the rows.

Allow reverse scan also speeds up the MAX funciton, if the column in
the MAX is an indexed column.

Or encourage a merge-join if the other join partner is already sorted
that way.

To get back to the algorithm:
If you create an index i1 on T(c1 asc, c2 desc)
The leaf pages are pointered so DB2 can easily travers from one to teh
next without having to walk back you the index tree.
When allowing reverse scans there simply is a reverse pointer for each
forward pointer, so the index will be slightly bigger.

When the optimizer "asks" for a an order (c1 desc, c2 asc) the answer
will be that i1 provides this order. There really isn't much in the
sense of magic....

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #5
Zri Man wrote:
I don't think can be a reverse scan at the root or non-leaf node pages
of an index.

And I think I'm right when I say that its an Algorithm that is behind a
Reverse Scan, I do know its an option when Building an index.

The question is what it gives the user.

I'm not sure how MIN and MAX can be helped by this at all.

As I said, I do not understand, given the organization of a B-Tree, how
there can be a Reverse Scan or for that matter a predicated Bias to the
Scan of an B-Tree Index.


First, I don't know exactly if DB2 works that way...

A B-Tree - as it was invented by Rudolf Bayer in the early 70s - has only
pointers/references from a parent node to its sons (and maybe even the
backwards direction). In particular, there is no pointer/reference from
one leaf node to the next/previous one.

I'd say that DB2 implements per default a "next" pointer on the leaf nodes.
Those pointers allow a sequential scan of the leaf nodes in the sort order
of the index. Also, the pointers can be maintained during a split
operation without any additional I/O.

But note that you cannot do a reverse scan on the leaf nodes because you
don't know the predecessor of any given leaf - there are no "prev"
pointers. That is what ALLOW REVERSE SCAN adds. You do have now a
doubled-linked list at the leaf level, and you can perform index scans in
ascending and descending order. Besides the few bytes overhead for the
pointer (which is negligible), you will have to maintain the linked list
all the time, and that means you have 1 additional I/O operation because
the "prev" pointer of the successor page of the page being split has to be
corrected.

I don't know right now if there are other considerations when choosing
reverse scans. Have a look at the manual.

--
Knut Stolze
Information Integration Development
IBM Germany / University of Jena
Nov 12 '05 #6
Stolze,

Thanks for your detailed message, as also to the other contributors.

I guess its safe to assume that the elements of the sorted linked
list at the leaf node level will be scanned only when a query requires
sorted data, that is MIN or MAX and I guess the Reverse Scan is
svailable at the level to point either way.

Zridhar

Nov 12 '05 #7

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

Similar topics

59
4345
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The HTML version is much more readable than the ReST version. See: http://www.python.org/peps/pep-0322.html
9
3979
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
108
6461
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would describe if applied to a sequence of length items. It returns a tuple of three integers; respectively these are the /start/ and /stop/ indices and the /step/ or stride length of the slice. Missing or out-of-bounds indices are handled in a manner...
59
6878
by: AK | last post by:
I tried to google "skip scan DB2" but came up with nothing. Does DB2 have the feature under a different name?
14
14815
by: ford_desperado | last post by:
Why isn't ALLOW REVERSE SCANS the default? Why do we have to - drop PK - create an index - recreate PK What are the advantages of indexes that do not allow reverse scans?
7
1820
by: Ryan | last post by:
I have a bit of a problem with regards an indexing strategy. Well, basically there is no indexing strategy on a set of data I have at work. Now, I didn't create the design as I would have allowed for this. OK, so there is primary key (clustered) indexes (mainly composite keys), but no other indexes on the tables. As you would expect, the performance leaves a lot to be desired. A hell of a lot. We have several million rows in a lot of the...
4
2059
by: Amar | last post by:
Hi All, I need to select data from a database table containing huge amount of data. Now I am storing data using one primary key and I am just using simple select statement, and this process gives me the output but it is taking long to execute the query. As much I had heared I want to use some indexing or cluster indexing which might help me but I am not so familiar with these things. So if any one having some solutions to execute the...
0
1059
by: NEW2DB2 | last post by:
Does the optimizer create a temporay table for the index that allows reverse scans ?
1
2505
by: BD | last post by:
Hey, all. Subject line says it all. But for background: I'm developing on UDB for Windows. The production application is on z/ OS. I'm using some Quest tools (SQL Optimizer) to review some queries, and
0
9633
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
10305
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
10137
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...
0
9928
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...
1
7483
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
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...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.