Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

B-Tree vs Bitmap database indexes

Can someone explain the different between the bitmap and b tree indexes. in what situations will you use both of these? What are the advantages/disadvantages of each.

like image 849
Luke101 Avatar asked Mar 02 '12 22:03

Luke101


People also ask

What is the difference between index and bitmap index?

An index provides pointers to the rows in a table that contain a given key value. A regular index stores a list of rowids for each key corresponding to the rows with that key value. In a bitmap index, a bitmap for each key value replaces a list of rowids.

Under what circumstances should a bitmap index be considered instead of a B-tree index?

If the number of distinct key values is small, bitmap indexes compress better and the space saving benefit compared to a B-tree index becomes even better. Bitmap indexes are most effective for queries that contain multiple conditions in the WHERE clause.

Is B-tree used for indexing?

B-tree provides an efficient way to insert and read data. In actual Database implementation, the database uses both B-tree and B+tree together to store data. B-tree used for indexing and B+tree used to store the actual records.

When would you use a bitmap index?

In reality, a bitmap index is always advisable for systems in which data is not frequently updated by many concurrent systems. In fact, as I'll demonstrate here, a bitmap index on a culumn with 100-percent unique values (a culumn candidate for primary key) is as efficient as a B-tree index.


1 Answers

From wikipedia: B-Trees and bitmap indexes. The use cases:

  • B-Trees are the typical index type used when you do CREATE INDEX ... in a database:

    1. They are very fast when you are selecting just a small very subset of the index data (5%-10% max typically)
  • They work better when you have a lot of distinct indexed values.
  • Combining several B-Tree indexes can be done, but simpler approaches are often more efficient.
  • They are not useful when there are few distinct values for the indexed data, or when you want to get a large (>10% typically) subset of the data.
  • Each B-Tree index impose a small penalty when inserting/updating values on the indexed table. This can be a problem if you have a lot of indexes in a very busy table.

  • This characteristics make B-Tree indexes very useful for speeding searches in OLTP applications, when you are working with very small data sets at a time, most queries filter by ID, and you want good concurrent performance.

  • Bitmap indexes are a more specialized index variant:

    1. They encode indexed values as bitmaps and so are very space efficient.
    2. They tend to work better when there are few distinct indexed values
    3. DB optimizers can combine several bitmap indexed very easily, this allows for efficient execution of complex filters in queries.
    4. They are very inefficient when inserting/updating values.


    Bitmap indexes are mostly used in data warehouse applications, where the database is read only except for the ETL processes, and you usually need to execute complex queries against a star schema, where bitmap indexes can speed up filtering based on conditions in your dimension tables, which do not usually have too many distinct values.

As a very short summary: use B-Tree indexes (the "default" index in most databases) unless you are a data warehouse developer and know you will benefit for a bitmap index.

like image 94
gpeche Avatar answered Oct 18 '22 23:10

gpeche