Unix Technical Forum

Re: Implementing Bitmap Indexes

This is a discussion on Re: Implementing Bitmap Indexes within the pgsql Hackers forums, part of the PostgreSQL category; --> * Pawe� Niewiadomski <new@foo-baz.com> [29.01.2005 17:45]: > > I'd like to implement bitmap indexes and want your comments. Here ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 03:31 AM
Victor Y. Yegorov
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

* Pawe� Niewiadomski <new@foo-baz.com> [29.01.2005 17:45]:
> > I'd like to implement bitmap indexes and want your comments. Here is
> > an essence of what I've found regarding bitmaps for the last month.

>
> Do you think it would be possible to work on it as a team?


Yes, why not.

But everything depends on the community, may bitmaps will be realized as a
contrib or pgfoundry module. The only thing --- I don't know, if that is
possible for indexes.


--

Victor Y. Yegorov

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 03:31 AM
Mike Rylander
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

On Sat, 29 Jan 2005 19:41:20 +0200, Victor Y. Yegorov <viy@mits.lv> wrote:
> * Pawe� Niewiadomski <new@foo-baz.com> [29.01.2005 17:45]:
> > > I'd like to implement bitmap indexes and want your comments. Here is
> > > an essence of what I've found regarding bitmaps for the last month.

> >
> > Do you think it would be possible to work on it as a team?

>
> Yes, why not.
>
> But everything depends on the community, may bitmaps will be realized as a
> contrib or pgfoundry module. The only thing --- I don't know, if that is
> possible for indexes.


For on-disk bitmap indexes, yes. I don't see any reason this couldn't
be done with GiST, perhaps even as a generalization of the index stuff
in the int_array contrib module. But the bitmaps that Tom as been
advocating, the ones used to join two index scans, will require a new
planner Op.

As a side note, wouldn't the in-memory bitmaps pretty much kill the
need for multicolumn indexes? It seems that they would be able to
join index scans on the same table, and then there would be no need
for industrial strength cross-column correlation stats. The planner
would be able to choose a multi index scan based on multiple single
column stat entries and completely sidestep the need for precalculated
cross-column correlations. Am I getting that right?

--
Mike Rylander
mrylander@gmail.com
GPLS -- PINES Development
Database Developer
http://open-ils.org

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 03:32 AM
Dawid Kuroczko
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

On Sat, 29 Jan 2005 18:46:44 +0000, Mike Rylander <mrylander@gmail.com> wrote:
> As a side note, wouldn't the in-memory bitmaps pretty much kill the
> need for multicolumn indexes? It seems that they would be able to
> join index scans on the same table, and then there would be no need
> for industrial strength cross-column correlation stats. The planner
> would be able to choose a multi index scan based on multiple single
> column stat entries and completely sidestep the need for precalculated
> cross-column correlations. Am I getting that right?


I'm not too sure of that. Lets imagine big table with two columns,
a and b. If we use multicolumn index (a,b), the search must go through
a tree, find a value, and from there find b value.

With in-memory bitmap, the search would start with index a, all
matching rows would form the bitmap; then the second search
would go through b index, forming another bitmap. Which then
would be ANDed with previous bitmap.
If I am correct, in case of in-memory bitmap PostgreSQL would
have to read more index tuples (the less unique values, the
more tuples to read) which in majority of cases would mean
more work than multicolumn index.

However in-memory bitmap would speed up many other
cases (think: OR), but multicolumn indexes are there to stay.

Regards,
Dawid

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 03:32 AM
Victor Yegorov
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

* Dawid Kuroczko <qnex42@gmail.com> [29.01.2005 21:25]:

> With in-memory bitmap, the search would start with index a, all
> matching rows would form the bitmap; then the second search
> would go through b index, forming another bitmap. Which then
> would be ANDed with previous bitmap.


Not only matching rows will form a bitmap, all rows should.

And the physical order of rows in the table is important to form bitmap.


--

Victor Y. Yegorov

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 03:32 AM
Tom Lane
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

Mike Rylander <mrylander@gmail.com> writes:
> As a side note, wouldn't the in-memory bitmaps pretty much kill the
> need for multicolumn indexes? It seems that they would be able to
> join index scans on the same table, and then there would be no need
> for industrial strength cross-column correlation stats.


No, because the ability to do it is not the same as the ability to
predict in advance how many rows will result.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 03:32 AM
Mike Rylander
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

On Sun, 30 Jan 2005 11:07:59 +1100, Neil Conway <neilc@samurai.com> wrote:
> Mike Rylander wrote:
> > For on-disk bitmap indexes, yes. I don't see any reason this couldn't
> > be done with GiST

>
> It might be possible to do it with GiST, but GiST is designed for
> implementing tree-structured indexes; I don't think it's the right tool
> for the job.


For the initial example where the index is implemented as a set of
unique keys from the table and a bitmap for each key this would look a
unique index, but with an extra datum at at each index node to hold
the bitmap for that key. If implemented that way an augmented B-Tree
structure would work fine. At least that's how I would imagine an
on-disk bitmap index would work. I suppose that would make the index
much more efficient for high-cardinality values, no?

--
Mike Rylander
mrylander@gmail.com
GPLS -- PINES Development
Database Developer
http://open-ils.org

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-11-2008, 03:32 AM
Neil Conway
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

Mike Rylander wrote:
> For on-disk bitmap indexes, yes. I don't see any reason this couldn't
> be done with GiST


It might be possible to do it with GiST, but GiST is designed for
implementing tree-structured indexes; I don't think it's the right tool
for the job.

-Neil

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-11-2008, 03:32 AM
Mike Rylander
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

On Sun, 30 Jan 2005 12:15:20 +1100, Neil Conway <neilc@samurai.com> wrote:
> It might _work_, I just don't see the point. Given an attribute of a
> heap relation that has N distinct values and T tuples, you need to store
>
> - N bitmaps, each of T bits (before compression)
> - T ctids
> - a way to map from a bit in one of the bitmaps to a heap tuple
> - a way to decide which bitmap(s) to use for a given index scan
>
> I don't see why it's a win to organize this data in a tree. Why not
> store the ctids in a simple array? You then know that bit K of any
> bitmap refers to entry K of the ctid array. You'd also need some meta
> data to figure out which bitmap to use for a given scankey, but it
> should be pretty easy to do that efficiently.


OK, I think it just clicked. I was seeing a tree for the initial
lookup to find the right bitmaps to scan. Does that seem like to much
overhead for the first step?

So, pick the bitmap(s) based on the key, scan the bitmaps and combine
them based on the WHERE condition combination type, and as you find
matching bits you toss the ctids into a "matching" array. Then it's a
fast ctid scan. That it? I'm very interested in this after reading a
bit (heh he) about bitmap indexes. Here's how I'm visualizing it now:

For a query like "SELECT * FROM table WHERE a IN (1,3)" ...

Index on "table.a" looks like:

bitmaps
1 | 001001001001000
2 | 100000010100001
3 | 010110100010110

ctids
1 | {2,5,8,11}
2 | {0,7,9,14}
3 | {1,3,4,6,10,12,13}


The index scan would do bitwise a OR on bitmaps 1 and 3, find the
possition of the "1"s, jump to those possitions in the ctid array, and
bounce to the heap for the value.


--
Mike Rylander
mrylander@gmail.com
GPLS -- PINES Development
Database Developer
http://open-ils.org

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-11-2008, 03:32 AM
Neil Conway
 
Posts: n/a
Default Re: Implementing Bitmap Indexes

Mike Rylander wrote:
> For the initial example where the index is implemented as a set of
> unique keys from the table and a bitmap for each key this would look a
> unique index, but with an extra datum at at each index node to hold
> the bitmap for that key. If implemented that way an augmented B-Tree
> structure would work fine. At least that's how I would imagine an
> on-disk bitmap index would work.


It might _work_, I just don't see the point. Given an attribute of a
heap relation that has N distinct values and T tuples, you need to store

- N bitmaps, each of T bits (before compression)
- T ctids
- a way to map from a bit in one of the bitmaps to a heap tuple
- a way to decide which bitmap(s) to use for a given index scan

I don't see why it's a win to organize this data in a tree. Why not
store the ctids in a simple array? You then know that bit K of any
bitmap refers to entry K of the ctid array. You'd also need some meta
data to figure out which bitmap to use for a given scankey, but it
should be pretty easy to do that efficiently.

-Neil

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:25 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com