Cues-Postgres-Bit Map Index

We all know that we can create a B-tree index on column in a table for Postgres ..
But any one ever thought how to create a Bit map index on table column ..

Few points on Postgres Indexing....

We can create multiple column indexes in postgres.Here is the example

CREATE INDEX indexname ON tablename(column1,column2);

Only B-tree and GiST index types support multicolumn indexes.Let's not worry about Gist Indexes they are beyond the present discussion.

Multicolumn indexes can be used with any query conditions that involve any subset of the index's columns,but the index will be more and more effective when the query includes the constriants on the left most columns i.e, for example in the above index the left most column is column2.

As i know ,directly we can not create a Bitmap index in Postgres 8.2.

PostgreSQL can combine multiple indexes and use a bitmap scan during query execution.

This can explained with a example .

CREATE TABLE tablename(
column1 charactervarying(10),column2 charactervarying(10)
);

now assume that we have two indexes one on column1,another on column2 with names index1 and index2.

This our query:

select * from tablename where column1='aa' and column2='bb';

Now postgres will combine both the indexes .To combine multiple indexes i.e. both the indexes , the system scans each needed index and prepares a bitmap in memory giving the locations of table rows which satisfies the index conditions.

The two bitmaps are then added and returned as requested by the query.

Now these rows are scanned and returned .Here the rows are visited in the physcial order because that is how the bitmap is laid out and index will take some additional extra time.

So the postgres query plan executer may not choose this option and it may use another query plan and the return the query output.

No comments:

Post a Comment

My Space

Hang over--Wrath of Grapes