Bitmap index explained

A bitmap index is a special kind of database index that uses bitmaps.

Bitmap indexes have traditionally been considered to work well for low-cardinality columns, which have a modest number of distinct values, either absolutely, or relative to the number of records that contain the data. The extreme case of low cardinality is Boolean data (e.g., does a resident in a city have internet access?), which has two values, True and False. Bitmap indexes use bit arrays (commonly called bitmaps) and answer queries by performing bitwise logical operations on these bitmaps. Bitmap indexes have a significant space and performance advantage over other structures for query of such data. Their drawback is they are less efficient than the traditional B-tree indexes for columns whose data is frequently updated: consequently, they are more often employed in read-only systems that are specialized for fast query - e.g., data warehouses, and generally unsuitable for online transaction processing applications.

Some researchers argue that bitmap indexes are also useful for moderate or even high-cardinality data (e.g., unique-valued data) which is accessed in a read-only manner, and queries access multiple bitmap-indexed columns using the AND, OR or XOR operators extensively.[1]

Bitmap indexes are also useful in data warehousing applications for joining a large fact table to smaller dimension tables such as those arranged in a star schema.

Example

Continuing the internet access example, a bitmap index may be logically viewed as follows:

IdentifierHasInternetBitmaps
Y N
1 Yes 10
2 No 0 1
3 No 0 1
4 Unspecified 0 0
5 Yes 1 0

On the left, Identifier refers to the unique number assigned to each resident, HasInternet is the data to be indexed, the content of the bitmap index is shown as two columns under the heading bitmaps. Each column in the left illustration under the Bitmaps header is a bitmap in the bitmap index. In this case, there are two such bitmaps, one for "has internet" Yes and one for "has internet" No. It is easy to see that each bit in bitmap Y shows whether a particular row refers to a person who has internet access. This is the simplest form of bitmap index. Most columns will have more distinct values. For example, the sales amount is likely to have a much larger number of distinct values. Variations on the bitmap index can effectively index this data as well. We briefly review three such variations.

Note: Many of the references cited here are reviewed at (John Wu (2007)).[2] For those who might be interested in experimenting with some of the ideas mentioned here, many of them are implemented in open source software such as FastBit,[3] the Lemur Bitmap Index C++ Library,[4] the Roaring Bitmap Java library[5] and the Apache Hive Data Warehouse system.

Compression

For historical reasons, bitmap compression and inverted list compression were developed as separate lines of research, and only later were recognized as solving essentially the same problem.[6]

Software can compress each bitmap in a bitmap index to save space. There has been considerable amount of work on this subject.[7] [8] Though there are exceptions such as Roaring bitmaps,[9] Bitmap compression algorithms typically employ run-length encoding, such as the Byte-aligned Bitmap Code, the Word-Aligned Hybrid code, the Partitioned Word-Aligned Hybrid (PWAH) compression,[10] the Position List Word Aligned Hybrid,[11] the Compressed Adaptive Index (COMPAX),[12] Enhanced Word-Aligned Hybrid (EWAH) [13] and the COmpressed 'N' Composable Integer SEt (CONCISE).[14] These compression methods require very little effort to compress and decompress. More importantly, bitmaps compressed with BBC, WAH, COMPAX, PLWAH, EWAH and CONCISE can directly participate in bitwise operations without decompression. This gives them considerable advantages over generic compression techniques such as LZ77. BBC compression and its derivatives are used in a commercial database management system. BBC is effective in both reducing index sizes and maintaining query performance. BBC encodes the bitmaps in bytes, while WAH encodes in words, better matching current CPUs. "On both synthetic data and real application data, the new word aligned schemes use only 50% more space, but perform logical operations on compressed data 12 times faster than BBC."[15] PLWAH bitmaps were reported to take 50% of the storage space consumed by WAH bitmaps and offer up to 20% faster performance on logical operations. Similar considerations can be done for CONCISE [16] and Enhanced Word-Aligned Hybrid.[13]

The performance of schemes such as BBC, WAH, PLWAH, EWAH, COMPAX and CONCISE is dependent on the order of the rows. A simple lexicographical sort can divide the index size by 9 and make indexes several times faster.[17] The larger the table, the more important it is to sort the rows. Reshuffling techniques have also been proposed to achieve the same results of sorting when indexing streaming data.[12]

Encoding

Basic bitmap indexes use one bitmap for each distinct value. It is possible to reduce the number of bitmaps used by using a different encoding method.[18] [19] For example, it is possible to encode C distinct values using log(C) bitmaps with binary encoding.[20]

This reduces the number of bitmaps, further saving space, but to answer any query, most of the bitmaps have to be accessed. This makes it potentially not as effective as scanning a vertical projection of the base data, also known as a materialized view or projection index. Finding the optimal encoding method that balances (arbitrary) query performance, index size and index maintenance remains a challenge.

Without considering compression, Chan and Ioannidis analyzed a class of multi-component encoding methods and came to the conclusion that two-component encoding sits at the kink of the performance vs. index size curve and therefore represents the best trade-off between index size and query performance.[18]

Binning

For high-cardinality columns, it is useful to bin the values, where each bin covers multiple values and build the bitmaps to represent the values in each bin. This approach reduces the number of bitmaps used regardless of encoding method.[21] However, binned indexes can only answer some queries without examining the base data. For example, if a bin covers the range from 0.1 to 0.2, then when the user asks for all values less than 0.15, all rows that fall in the bin are possible hits and have to be checked to verify whether they are actually less than 0.15. The process of checking the base data is known as the candidate check. In most cases, the time used by the candidate check is significantly longer than the time needed to work with the bitmap index. Therefore, binned indexes exhibit irregular performance. They can be very fast for some queries, but much slower if the query does not exactly match a bin.

History

The concept of bitmap index was first introduced by Professor Israel Spiegler and Rafi Maayan in their research "Storage and Retrieval Considerations of Binary Data Bases", published in 1985.[22] The first commercial database product to implement a bitmap index was Computer Corporation of America's Model 204. Patrick O'Neil published a paper about this implementation in 1987.[23] This implementation is a hybrid between the basic bitmap index (without compression) and the list of Row Identifiers (RID-list). Overall, the index is organized as a B+tree. When the column cardinality is low, each leaf node of the B-tree would contain long list of RIDs. In this case, it requires less space to represent the RID-lists as bitmaps. Since each bitmap represents one distinct value, this is the basic bitmap index. As the column cardinality increases, each bitmap becomes sparse and it may take more disk space to store the bitmaps than to store the same content as RID-lists. In this case, it switches to use the RID-lists, which makes it a B+tree index.[24] [25]

In-memory bitmaps

One of the strongest reasons for using bitmap indexes is that the intermediate results produced from them are also bitmaps and can be efficiently reused in further operations to answer more complex queries. Many programming languages support this as a bit array data structure. For example, Java has the [http://download.oracle.com/javase/6/docs/api/java/util/BitSet.html BitSet] class.

Some database systems that do not offer persistent bitmap indexes use bitmaps internally to speed up query processing. For example, PostgreSQL versions 8.1 and later implement a "bitmap index scan" optimization to speed up arbitrarily complex logical operations between available indexes on a single table.

For tables with many columns, the total number of distinct indexes to satisfy all possible queries (with equality filtering conditions on either of the fields) grows very fast, being defined by this formula:

\left
C
n

[

n
2

\right]\equiv

n!
\left(n-\left[
n
2
\right]\right)!\left[
n
2
\right]!
.[26] [27]

A bitmap index scan combines expressions on different indexes, thus requiring only one index per column to support all possible queries on a table.

Applying this access strategy to B-tree indexes can also combine range queries on multiple columns. In this approach, a temporary in-memory bitmap is created with one bit for each row in the table (1 MB can thus store over 8 million entries). Next, the results from each index are combined into the bitmap using bitwise operations. After all conditions are evaluated, the bitmap contains a "1" for rows that matched the expression. Finally, the bitmap is traversed and matching rows are retrieved. In addition to efficiently combining indexes, this also improves locality of reference of table accesses, because all rows are fetched sequentially from the main table.[28] The internal bitmap is discarded after the query. If there are too many rows in the table to use 1 bit per row, a "lossy" bitmap is created instead, with a single bit per disk page. In this case, the bitmap is just used to determine which pages to fetch; the filter criteria are then applied to all rows in matching pages.

References

Notes
Bibliography

Notes and References

  1. http://www.oracle.com/technetwork/articles/sharma-indexes-093638.html Bitmap Index vs. B-tree Index: Which and When?
  2. Web site: JohnWu2007 . John Wu . 2007 . Annotated References on Bitmap Index . https://archive.today/20120630230927/http://www.cs.umn.edu/~kewu/annotated.html . dead . 2012-06-30 .
  3. http://codeforge.lbl.gov/projects/fastbit/ FastBit
  4. https://code.google.com/p/lemurbitmapindex/ Lemur Bitmap Index C++ Library
  5. http://roaringbitmap.org/ Roaring bitmaps
  6. Jianguo Wang; Chunbin Lin; Yannis Papakonstantinou; Steven Swanson."An Experimental Study of Bitmap Compression vs. Inverted List Compression" .2017.doi: 10.1145/3035918.3064007
  7. Book: T. Johnson . Malcolm P. Atkinson . Maria E. Orlowska . Maria Orłowska . Patrick Valduriez . Stanley B. Zdonik . Michael L. Brodie . VLDB'99, Proceedings of 25th International Conference on Very Large Data Bases, September 7–10, 1999, Edinburgh, Scotland, UK . Morgan Kaufmann . 1999 . 978-1-55860-615-9 . Performance Measurements of Compressed Bitmap Indices . 278–89 . http://www.vldb.org/conf/1999/P29.pdf .
  8. Web site: Wu K, Otoo E, Shoshani A . On the performance of bitmap indices for high cardinality attributes . March 5, 2004 .
  9. Chambi . S. . Lemire . D. . Kaser . O. . Godin . R. . Better bitmap performance with Roaring bitmaps . 10.1002/spe.2325 . Software: Practice and Experience . 46 . 5 . 709–719 . 2016 . 1402.6407 . 1139669 .
  10. A memory efficient reachability data structure through bit vector compression . van Schaik . Sebastiaan . de Moor . Oege . 2011 . ACM . Proceedings of the 2011 international conference on Management of data . 913–924 . Athens, Greece . 10.1145/1989323.1989419 . SIGMOD '11 . 978-1-4503-0661-4 .
  11. Book: Position list word aligned hybrid: optimizing space and performance for compressed bitmaps . Deliège F, Pedersen TB . Ioana Manolescu . Stefano Spaccapietra . Jens Teubner . Masaru Kitsuregawa . Alain Leger . Felix Naumann . Anastasia Ailamaki . Fatma Ozcan . EDBT '10, Proceedings of the 13th International Conference on Extending Database Technology . ACM . New York, NY, USA . 2010 . 228–39 . 978-1-60558-945-9 . 10.1145/1739041.1739071 . 12234453 . http://alpha.uhasselt.be/icdt/edbticdt2010proc/edbt/papers/p0228-Deliege.pdf .
  12. F. Fusco . M. Stoecklin . M. Vlachos . NET-FLi: on-the-fly compression, archiving and indexing of streaming network traffic . September 2010 . 3 . 1–2 . 1382–93 . Proc. VLDB Endow. . 10.14778/1920841.1921011 . 787443 .
  13. Lemire . D. . Kaser . O. . Aouiche . K. . Sorting improves word-aligned bitmap indexes . 10.1016/j.datak.2009.08.006 . Data & Knowledge Engineering . 69 . 3–28 . 2010 . 0901.3751 . 6297890 .
  14. http://ricerca.mat.uniroma3.it/users/colanton/concise.html Concise: Compressed 'n' Composable Integer Set
  15. Book: Wu K, Otoo EJ, Shoshani A . Henrique Paques . Ling Liu. Ling Liu (computer scientist) . David Grossman . A Performance comparison of bitmap indexes . 2001 . CIKM '01 Proceedings of the tenth international conference on Information and knowledge management . ACM . New York, NY, USA . 559–61 . 978-1-58113-436-0 . 10.1145/502585.502689 . 10974671 . http://crd.lbl.gov/~kewu/ps/LBNL-48975.pdf .
  16. Colantonio A, Di Pietro R . Concise: Compressed 'n' Composable Integer Set . Information Processing Letters . 110 . 16 . 31 July 2010 . 10.1016/j.ipl.2010.05.018 . 644–50 . 1004.0403 . 8092695 . 2 February 2011 . https://web.archive.org/web/20110722064102/http://ricerca.mat.uniroma3.it/users/colanton/docs/concise.pdf . 22 July 2011 . dead .
  17. D. Lemire . O. Kaser . K. Aouiche . Sorting improves word-aligned bitmap indexes . Data & Knowledge Engineering . 69 . 1 . January 2010 . 0901.3751 . 10.1016/j.datak.2009.08.006. 3–28 . 6297890 .
  18. Bitmap index design and evaluation . C.-Y. Chan . Y. E. Ioannidis . 1998 . Proceedings of the 1998 ACM SIGMOD international conference on Management of data (SIGMOD '98) . Ashutosh Tiwary . Michael Franklin . ACM . New York, NY, USA . 355–6 . 10.1145/276304.276336 . 0897919955 .
  19. An efficient bitmap encoding scheme for selection queries . C.-Y. Chan . Y. E. Ioannidis . 1999 . Proceedings of the 1999 ACM SIGMOD international conference on Management of data (SIGMOD '99) . ACM . New York, NY, USA . 215–26 . 10.1145/304182.304201 . 1581130848 .
  20. P. E. O'Neil . D. Quass . Improved Query Performance with Variant Indexes . Proceedings of the 1997 ACM SIGMOD international conference on Management of data (SIGMOD '97) . 1997 . Joan M. Peckman . Sudha Ram . Michael Franklin . ACM . New York, NY, USA . 38–49. 10.1145/253260.253268 . 0897919114 .
  21. Book: Space efficient bitmap indexing. Proceedings of the ninth international conference on Information and knowledge management (CIKM '00) . 2000 . N. Koudas . ACM . New York, NY, USA . 194–201 . 10.1145/354756.354819 . 978-1581133202 . 7504216 .
  22. Storage and retrieval considerations of binary data bases . Spiegler I . Maayan R . Information Processing and Management. 21 . 3 . 1985 . 10.1016/0306-4573(85)90108-6 . 233–54 .
  23. O'Neil . Patrick . Model 204 Architecture and Performance . Proceedings of the 2nd International Workshop on High Performance Transaction Systems . 40–59 . Springer-Verlag . 1987 . London, UK . Dieter Gawlick . Mark N. Haynie . Andreas Reuter.
  24. Bit-sliced index arithmetic . Proceedings of the 2001 ACM SIGMOD international conference on Management of data (SIGMOD '01) . 2001 . D. Rinfret . P. O'Neil . E. O'Neil . Timos Sellis . ACM . New York, NY, USA . 47–57 . 10.1145/375663.375669 . 1581133324 .
  25. E. O'Neil . P. O'Neil . K. Wu . Bitmap Index Design Choices and Their Performance Implications . 11th International Database Engineering and Applications Symposium (IDEAS 2007) . 2007 . 72–84 . 978-0-7695-2947-9 . 10.1109/IDEAS.2007.19 .
  26. Web site: Alex Bolenok. 2009-05-09. Creating indexes.
  27. Web site: Egor Timoshenko. On minimal collections of indexes.
  28. Web site: Tom Lane . 2005-12-26 . Re: Bitmap indexes etc. . PostgreSQL mailing lists . 2007-04-06 .