B-Tree vs Bitmap database indexes

后端 未结 2 1440
失恋的感觉
失恋的感觉 2021-02-12 14:44

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.

相关标签:
2条回答
  • 2021-02-12 15:22

    When using normal BTree indexes, rows where all the column values are null are excluded from the index. This means that queries with "column is null" conditions won't benefit from a normal index.

    By creating an index on (column_name, 1) (or some other constant) null valued columns are now included in it, allowing the optimizer to use the query when executing "is null" queries.

    A bitmap index, unlike a B*Tree index, automatically includes null values. This means bitmap indexes may be used by the optimizer in the evaluation of "is null" predicates.

    Bitmap indexes may lead to concurrency issues however, possibly blocking other DML on the same table. Therefore these should be avoided in an OLTP applications. Bitmap indexes also require Enterprise Edition, so there may be licensing implications to using these.

    0 讨论(0)
  • 2021-02-12 15:34

    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)
      2. They work better when you have a lot of distinct indexed values.
      3. Combining several B-Tree indexes can be done, but simpler approaches are often more efficient.
      4. 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.
      5. 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.

    0 讨论(0)
提交回复
热议问题