472,354 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 6375
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.com 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
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...
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:...
108
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...
59
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
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
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...
4
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...
0
by: NEW2DB2 | last post by:
Does the optimizer create a temporay table for the index that allows reverse scans ?
1
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.