15-721 DATABASE SYSTEMS [Source] Lecture #08 Indexing (OLAP) - - PowerPoint PPT Presentation

15 721
SMART_READER_LITE
LIVE PREVIEW

15-721 DATABASE SYSTEMS [Source] Lecture #08 Indexing (OLAP) - - PowerPoint PPT Presentation

15-721 DATABASE SYSTEMS [Source] Lecture #08 Indexing (OLAP) Andy Pavlo / / Carnegie Mellon University / / Spring 2016 2 TODAYS AGENDA Background Projection/Columnar Indexes (MSSQL) Bitmap Indexes Project #2 CMU 15-721 (Spring


slide-1
SLIDE 1

Andy Pavlo / / Carnegie Mellon University / / Spring 2016

Lecture #08 – Indexing (OLAP)

DATABASE SYSTEMS

15-721

[Source]
slide-2
SLIDE 2

CMU 15-721 (Spring 2016)

TODAY’S AGENDA

Background Projection/Columnar Indexes (MSSQL) Bitmap Indexes Project #2

2

slide-3
SLIDE 3

CMU 15-721 (Spring 2016)

DECISION SUPPORT SYSTEMS

Applications that serve the management,

  • perations, and planning levels of an
  • rganization to help people make decisions

about future issues and problems by analyzing historical data. Star Schema vs. Snowflake Schema

3

slide-4
SLIDE 4

CMU 15-721 (Spring 2016)

STAR SCHEMA

4

CATEGORY_NAME CATEGORY_DESC PRODUCT_CODE PRODUCT_NAME PRODUCT_DESC

PRODUCT_DIM

COUNTRY STATE_CODE STATE_NAME ZIP_CODE CITY

LOCATION_DIM

ID FIRST_NAME LAST_NAME EMAIL ZIPCODE

CUSTOMER_DIM

YEAR DAY_OF_YEAR MONTH_NUM MONTH_NAME DAY_OF_MONTH

TIME_DIM

SALES_FACT

PRODUCT_FK TIME_FK LOCATION_FK CUSTOMER_FK PRICE QUANTITY

slide-5
SLIDE 5

CMU 15-721 (Spring 2016)

STAR SCHEMA

4

CATEGORY_NAME CATEGORY_DESC PRODUCT_CODE PRODUCT_NAME PRODUCT_DESC

PRODUCT_DIM

COUNTRY STATE_CODE STATE_NAME ZIP_CODE CITY

LOCATION_DIM

ID FIRST_NAME LAST_NAME EMAIL ZIPCODE

CUSTOMER_DIM

YEAR DAY_OF_YEAR MONTH_NUM MONTH_NAME DAY_OF_MONTH

TIME_DIM

SALES_FACT

PRODUCT_FK TIME_FK LOCATION_FK CUSTOMER_FK PRICE QUANTITY

slide-6
SLIDE 6

CMU 15-721 (Spring 2016)

STAR SCHEMA

4

CATEGORY_NAME CATEGORY_DESC PRODUCT_CODE PRODUCT_NAME PRODUCT_DESC

PRODUCT_DIM

COUNTRY STATE_CODE STATE_NAME ZIP_CODE CITY

LOCATION_DIM

ID FIRST_NAME LAST_NAME EMAIL ZIPCODE

CUSTOMER_DIM

YEAR DAY_OF_YEAR MONTH_NUM MONTH_NAME DAY_OF_MONTH

TIME_DIM

SALES_FACT

PRODUCT_FK TIME_FK LOCATION_FK CUSTOMER_FK PRICE QUANTITY

slide-7
SLIDE 7

CMU 15-721 (Spring 2016)

SNOWFLAKE SCHEMA

5 CATEGORY_FK PRODUCT_CODE PRODUCT_NAME PRODUCT_DESC

PRODUCT_DIM

COUNTRY STATE_FK ZIP_CODE CITY

LOCATION_DIM

ID FIRST_NAME LAST_NAME EMAIL ZIPCODE

CUSTOMER_DIM

YEAR DAY_OF_YEAR MONTH_FK DAY_OF_MONTH

TIME_DIM

SALES_FACT

PRODUCT_FK TIME_FK LOCATION_FK CUSTOMER_FK PRICE QUANTITY

CATEGORY_ID CATEGORY_NAME CATEGORY_DESC

CAT_LOOKUP

STATE_ID STATE_CODE STATE_NAME

STATE_LOOKUP

MONTH_NUM MONTH_NAME MONTH_SEASON

MONTH_LOOKUP

slide-8
SLIDE 8

CMU 15-721 (Spring 2016)

SNOWFLAKE SCHEMA

5 CATEGORY_FK PRODUCT_CODE PRODUCT_NAME PRODUCT_DESC

PRODUCT_DIM

COUNTRY STATE_FK ZIP_CODE CITY

LOCATION_DIM

ID FIRST_NAME LAST_NAME EMAIL ZIPCODE

CUSTOMER_DIM

YEAR DAY_OF_YEAR MONTH_FK DAY_OF_MONTH

TIME_DIM

SALES_FACT

PRODUCT_FK TIME_FK LOCATION_FK CUSTOMER_FK PRICE QUANTITY

CATEGORY_ID CATEGORY_NAME CATEGORY_DESC

CAT_LOOKUP

STATE_ID STATE_CODE STATE_NAME

STATE_LOOKUP

MONTH_NUM MONTH_NAME MONTH_SEASON

MONTH_LOOKUP

slide-9
SLIDE 9

CMU 15-721 (Spring 2016)

OBSERVATION

Using a B+tree index on a large table results in a lot of wasted storage if the values are repetitive and the cardinality is low.

6

slide-10
SLIDE 10

CMU 15-721 (Spring 2016)

OBSERVATION

Using a B+tree index on a large table results in a lot of wasted storage if the values are repetitive and the cardinality is low.

6

SELECT COUNT(*) FROM sales_fact AS S JOIN customer_dim AS C ON S.customer_fk = C.id WHERE C.zipcode = 15217

CREATE TABLE customer_dim ( id INT PRIMARY KEY, ⋮ zipcode INT ); CREATE TABLE sales_fact ( id INT PRIMARY KEY, ⋮ customer_fk INT REFERENCES customer_dim (id) );

slide-11
SLIDE 11

CMU 15-721 (Spring 2016)

MSSQL: COLUMNAR INDEXES

Decompose rows into compressed column segments for single attributes.

→ Original data still remains in row store. → No way to map an entry in the column index back to its corresponding entry in row store.

Use as many existing components in MSSQL. Original implementation in 2012 would force a table to become read-only.

7

SQL SERVER COLUMN STORE INDEXES SIGMOD 2010

slide-12
SLIDE 12

CMU 15-721 (Spring 2016)

MSSQL: COLUMNAR INDEXES

8

Data Table

A B C D

slide-13
SLIDE 13

CMU 15-721 (Spring 2016)

MSSQL: COLUMNAR INDEXES

8

Data Table

A B C D

Row Group 1 Row Group 2 Row Group 3

slide-14
SLIDE 14

CMU 15-721 (Spring 2016)

MSSQL: COLUMNAR INDEXES

8

Data Table

A B C D

Row Group 1 Row Group 2 Row Group 3

slide-15
SLIDE 15

CMU 15-721 (Spring 2016)

MSSQL: COLUMNAR INDEXES

8

Encode + Compress

Data Table

A B C D

Row Group 1 Row Group 2 Row Group 3

slide-16
SLIDE 16

CMU 15-721 (Spring 2016)

MSSQL: COLUMNAR INDEXES

8

Encode + Compress

Data Table

A B C D

Row Group 1 Row Group 2 Row Group 3

Blob Storage Segment Directory

DICTIONARY DICTIONARY DICTIONARY

slide-17
SLIDE 17

CMU 15-721 (Spring 2016)

MSSQL: INTERNAL CATALOG

Segment Directory: Keeps track of statistics for each column segments per row group.

→ Size → # of Rows → Min and Max key values → Encoding Meta-data

Data Dictionary: Maps dictionary ids to their

  • riginal values.

9

slide-18
SLIDE 18

CMU 15-721 (Spring 2016)

MSSQL: DICTIONARY ENCODING

Construct a separate table of the unique values for an attribute sorted by frequency. For each tuple, store the 32-bit position of its value in the dictionary instead of the real value.

10

slide-19
SLIDE 19

CMU 15-721 (Spring 2016)

MSSQL: DICTIONARY ENCODING

11

Original Data

id 2 1 city Chicago New York 4 3 New York New York 7 6 Chicago Pittsburgh 9 8 New York New York

slide-20
SLIDE 20

CMU 15-721 (Spring 2016)

MSSQL: DICTIONARY ENCODING

11

Original Data

id 2 1 city Chicago New York 4 3 New York New York 7 6 Chicago Pittsburgh 9 8 New York New York

slide-21
SLIDE 21

CMU 15-721 (Spring 2016)

MSSQL: DICTIONARY ENCODING

11

Original Data

id 2 1 city Chicago New York 4 3 New York New York 7 6 Chicago Pittsburgh 9 8 New York New York

Compressed Data

id 2 1 4 3 7 6 9 8 city 1 1 2 DICTIONARY

0→(New York,5) 1→(Chicago,2) 2→(Pittsburgh,1)

slide-22
SLIDE 22

CMU 15-721 (Spring 2016)

MSSQL: DICTIONARY ENCODING

11

Original Data

id 2 1 city Chicago New York 4 3 New York New York 7 6 Chicago Pittsburgh 9 8 New York New York

Compressed Data

id 2 1 4 3 7 6 9 8 city 1 1 2 DICTIONARY

0→(New York,5) 1→(Chicago,2) 2→(Pittsburgh,1)

slide-23
SLIDE 23

CMU 15-721 (Spring 2016)

MSSQL: VALUE ENCODING

Transform the domain of a numeric column segment into a set of distinct values in a smaller domain of integers. Allows the DBMS to use smaller data types to store larger values. Also sometimes called delta encoding.

12

slide-24
SLIDE 24

CMU 15-721 (Spring 2016)

VALUE ENCODING: DECIMALS

Values: 0.5, 10.77, 1.33

13

slide-25
SLIDE 25

CMU 15-721 (Spring 2016)

VALUE ENCODING: DECIMALS

Values: 0.5, 10.77, 1.33 Exponent: 3 (i.e., 103)

13

slide-26
SLIDE 26

CMU 15-721 (Spring 2016)

VALUE ENCODING: DECIMALS

Values: 0.5, 10.77, 1.33 Exponent: 3 (i.e., 103) Initial Encoding: 0.5 103→500 10.77 103→10770 1.33 103→1333

13

slide-27
SLIDE 27

CMU 15-721 (Spring 2016)

VALUE ENCODING: DECIMALS

Values: 0.5, 10.77, 1.33 Exponent: 3 (i.e., 103) Initial Encoding: 0.5 103→500 10.77 103→10770 1.33 103→1333 Base: 500

13

slide-28
SLIDE 28

CMU 15-721 (Spring 2016)

VALUE ENCODING: DECIMALS

Values: 0.5, 10.77, 1.33 Exponent: 3 (i.e., 103) Initial Encoding: 0.5 103→500 10.77 103→10770 1.33 103→1333 Base: 500

13

slide-29
SLIDE 29

CMU 15-721 (Spring 2016)

VALUE ENCODING: DECIMALS

Values: 0.5, 10.77, 1.33 Exponent: 3 (i.e., 103) Initial Encoding: 0.5 103→500 10.77 103→10770 1.33 103→1333 Base: 500 Final Encoding: (0.5 103)-500→0 (10.77 103)-500→10270 (1.33 103)–500→833

13

slide-30
SLIDE 30

CMU 15-721 (Spring 2016)

VALUE ENCODING: INTEGERS

Values: 500, 1700, 1333000

14

slide-31
SLIDE 31

CMU 15-721 (Spring 2016)

VALUE ENCODING: INTEGERS

Values: 500, 1700, 1333000 Exponent: -2 (i.e., 10-2)

14

slide-32
SLIDE 32

CMU 15-721 (Spring 2016)

VALUE ENCODING: INTEGERS

Values: 500, 1700, 1333000 Exponent: -2 (i.e., 10-2) Initial Encoding: 500 10-2→5 1700 10-2→17 1333000 10-2→13330

14

slide-33
SLIDE 33

CMU 15-721 (Spring 2016)

VALUE ENCODING: INTEGERS

Values: 500, 1700, 1333000 Exponent: -2 (i.e., 10-2) Initial Encoding: 500 10-2→5 1700 10-2→17 1333000 10-2→13330 Base: 5

14

slide-34
SLIDE 34

CMU 15-721 (Spring 2016)

VALUE ENCODING: INTEGERS

Values: 500, 1700, 1333000 Exponent: -2 (i.e., 10-2) Initial Encoding: 500 10-2→5 1700 10-2→17 1333000 10-2→13330 Base: 5 Final Encoding: (500 10-2)-5→0 (1700 10-2)-5→12 (1333000 10-2)–5→13325

14

slide-35
SLIDE 35

CMU 15-721 (Spring 2016)

MSSQL: RUN-LENGTH ENCODING

Compress runs of the same value in a single column into triplets:

→ The value of the attribute. → The start position in the column segment. → The # of elements in the run.

Requires the columns to be sorted intelligently to maximize compression opportunities.

15

slide-36
SLIDE 36

CMU 15-721 (Spring 2016)

MSSQL: RUN-LENGTH ENCODING

16

Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M

slide-37
SLIDE 37

CMU 15-721 (Spring 2016)

MSSQL: RUN-LENGTH ENCODING

16

Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M

slide-38
SLIDE 38

CMU 15-721 (Spring 2016)

MSSQL: RUN-LENGTH ENCODING

16

Compressed Data

id 2 1 4 3 7 6 9 8 sex (F,3,1) (M,0,3) (F,5,1) (M,4,1) (M,6,2)

Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M

slide-39
SLIDE 39

CMU 15-721 (Spring 2016)

MSSQL: RUN-LENGTH ENCODING

16

Compressed Data

id 2 1 4 3 7 6 9 8 sex (F,3,1) (M,0,3) (F,5,1) (M,4,1) (M,6,2)

Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M

RLE Triplet

  • Value
  • Offset
  • Length
slide-40
SLIDE 40

CMU 15-721 (Spring 2016)

MSSQL: RUN-LENGTH ENCODING

16

Compressed Data

id 2 1 4 3 7 6 9 8 sex (F,3,1) (M,0,3) (F,5,1) (M,4,1) (M,6,2)

Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M

RLE Triplet

  • Value
  • Offset
  • Length
slide-41
SLIDE 41

CMU 15-721 (Spring 2016)

MSSQL: RUN-LENGTH ENCODING

16

Compressed Data Sorted Data

id 2 1 6 3 9 8 7 4 sex M M M M M M F F

RLE Triplet

  • Value
  • Offset
  • Length
slide-42
SLIDE 42

CMU 15-721 (Spring 2016)

MSSQL: RUN-LENGTH ENCODING

16

Compressed Data Sorted Data

id 2 1 6 3 9 8 7 4 sex M M M M M M F F id 2 1 6 3 9 7 7 4 sex (F,7,2) (M,0,6)

RLE Triplet

  • Value
  • Offset
  • Length
slide-43
SLIDE 43

CMU 15-721 (Spring 2016)

MSSQL: QUERY PROCESSING

Modify the query planner and optimizer to be aware of the columnar indexes. Add new vector-at-a-time operators that can

  • perate directly on columnar indexes.

Compute joins using Bitmaps built on-the-fly.

17

slide-44
SLIDE 44

CMU 15-721 (Spring 2016)

MSSQL: UPDATES SINCE 2012

Clustered column indexes. More data types. Support for INSERT, UPDATE, and DELETE:

→ Use a delta store for modifications and updates. The DBMS seamlessly combines results from both the columnar indexes and the delta store. → Deleted tuples are marked in a bitmap.

18

ENHANCEMENTS TO SQL SERVER COLUMN STORES SIGMOD 2013

slide-45
SLIDE 45

CMU 15-721 (Spring 2016)

BITMAP INDEXES

Store a separate Bitmap for each unique value for a particular attribute where an offset in the vector corresponds to a tuple.

→ The ith position in the Bitmap corresponds to the ith tuple in the table.

Typically segmented into chunks to avoid allocating large blocks of contiguous memory.

19

MODEL 204 ARCHITECTURE AND PERFORMANCE High Performance Transaction Systems 1987

slide-46
SLIDE 46

CMU 15-721 (Spring 2016)

BITMAP INDEXES

20

Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M

slide-47
SLIDE 47

CMU 15-721 (Spring 2016)

BITMAP INDEXES

20

Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M

slide-48
SLIDE 48

CMU 15-721 (Spring 2016)

BITMAP INDEXES

20

Compressed Data Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M id 2 1 4 3 7 6 9 8 M 1 1 1 1 1 1 F 1 1 sex

slide-49
SLIDE 49

CMU 15-721 (Spring 2016)

BITMAP INDEXES

20

Compressed Data Original Data

id 2 1 4 3 7 6 9 8 sex M M F M F M M M id 2 1 4 3 7 6 9 8 M 1 1 1 1 1 1 F 1 1 sex

slide-50
SLIDE 50

CMU 15-721 (Spring 2016)

BITMAP INDEXES: EXAMPLE

21

CREATE TABLE customer_dim ( id INT PRIMARY KEY, name VARCHAR(32), email VARCHAR(64), address VARCHAR(64), zipcode INT );

slide-51
SLIDE 51

CMU 15-721 (Spring 2016)

BITMAP INDEXES: EXAMPLE

21

CREATE TABLE customer_dim ( id INT PRIMARY KEY, name VARCHAR(32), email VARCHAR(64), address VARCHAR(64), zipcode INT );

slide-52
SLIDE 52

CMU 15-721 (Spring 2016)

BITMAP INDEXES: EXAMPLE

Assume we have 10 million tuples. 43,000 zip codes in the US.

→ 10000000 43000 = 53.75 GB

21

CREATE TABLE customer_dim ( id INT PRIMARY KEY, name VARCHAR(32), email VARCHAR(64), address VARCHAR(64), zipcode INT );

slide-53
SLIDE 53

CMU 15-721 (Spring 2016)

BITMAP INDEXES: EXAMPLE

Assume we have 10 million tuples. 43,000 zip codes in the US.

→ 10000000 43000 = 53.75 GB

Every time a txn inserts a new tuple, we have to extend 43,000 different bitmaps.

21

CREATE TABLE customer_dim ( id INT PRIMARY KEY, name VARCHAR(32), email VARCHAR(64), address VARCHAR(64), zipcode INT );

slide-54
SLIDE 54

CMU 15-721 (Spring 2016)

BITMAP INDEX: DESIGN CHOICES

Encoding Scheme Compression

22

slide-55
SLIDE 55

CMU 15-721 (Spring 2016)

BITMAP INDEX: ENCODING

Choice #1: Equality Encoding

→ Basic scheme with one Bitmap per unique value.

Choice #2: Range Encoding

→ Use one Bitmap per interval instead of one per value.

Choice #3: Bit-sliced Encoding

→ Use a Bitmap per bit location across all values.

23

slide-56
SLIDE 56

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623

Source: Jignesh Patel

slide-57
SLIDE 57

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623

Source: Jignesh Patel

slide-58
SLIDE 58

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623

bin(21042)→ 00101001000110010

Source: Jignesh Patel

slide-59
SLIDE 59

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N?

bin(21042)→ 00101001000110010

Source: Jignesh Patel

slide-60
SLIDE 60

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N?

bin(21042)→ 00101001000110010

Source: Jignesh Patel

slide-61
SLIDE 61

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N?

bin(21042)→ 00101001000110010

Source: Jignesh Patel

slide-62
SLIDE 62

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N? 0 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0

bin(21042)→ 00101001000110010

Source: Jignesh Patel

slide-63
SLIDE 63

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N? 0 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0

Source: Jignesh Patel

slide-64
SLIDE 64

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N? 0 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0

Source: Jignesh Patel

slide-65
SLIDE 65

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N? 0 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0

SELECT * FROM customer_dim WHERE zipcode < 15217

Source: Jignesh Patel

slide-66
SLIDE 66

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N? 0 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0

SELECT * FROM customer_dim WHERE zipcode < 15217

Walk each slice and construct a result bitmap.

Source: Jignesh Patel

slide-67
SLIDE 67

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N? 0 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0

SELECT * FROM customer_dim WHERE zipcode < 15217

Walk each slice and construct a result bitmap.

Source: Jignesh Patel

slide-68
SLIDE 68

CMU 15-721 (Spring 2016)

Bit-Slices

BIT-SLICED ENCODING

24

Original Data

id 2 1 4 3 7 6 zipcode 15217 21042 90220 02903 53703 14623 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 N? 0 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0

SELECT * FROM customer_dim WHERE zipcode < 15217

Walk each slice and construct a result bitmap. Skip entries that have 1 in first 3 slices (16, 15, 14)

Source: Jignesh Patel

slide-69
SLIDE 69

CMU 15-721 (Spring 2016)

BIT-SLICED ENCODING

Bit-slices can also be used for efficient aggregate computations. Example: SUM(attr)

→ First, count the number of 1s in slice17 and multiply the count by 217 → Then, count the number of 1s in slice16 and multiply the count by 216 → Repeat for the rest of slices…

25

slide-70
SLIDE 70

CMU 15-721 (Spring 2016)

BITMAP INDEX: COMPRESSION

Choice #1: General Purpose Compression

→ Use standard compression algorithms (e.g., LZ4, Snappy). → Have to decompress before you can use it to process a

  • query. Not useful for in-memory DBMSs.

Choice #2: Byte-aligned Bitmap Codes (BBC)

→ Structured run-length encoding compression.

Choice #3: Roaring Bitmaps

→ Modern hybrid of run-length encoding and value lists.

26

slide-71
SLIDE 71

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

Divide Bitmap into chunks that contain different categories of bytes:

→ Gap Byte: All the bits are 0s. → Tail Byte: Some bits are 1s.

Encode each chunk that consists of some Gap Bytes followed by some Tail Bytes.

→ Gap Bytes are compressed with RLE. → Tail Bytes are stored uncompressed unless it consists

  • f only 1 byte or has only 1 non-zero bit.

27

BYTE-ALIGNED BITMAP COMPRESSION Data Compression Conference 1995

slide-72
SLIDE 72

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

slide-73
SLIDE 73

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

slide-74
SLIDE 74

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

#1

slide-75
SLIDE 75

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Gap Bytes Tail Bytes #1

slide-76
SLIDE 76

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Gap Bytes Tail Bytes #1 #2

slide-77
SLIDE 77

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Chunk #1 (Bytes 1-3) Header Byte:

→ Number of Gap Bytes (Bits 1-3) → Is the tail special? (Bit 4) → Number of verbatim bytes (if Bit 4=0) → Index of 1 bit in tail byte (if Bit 4=1)

No gap length bytes since gap length < 7 No verbatim bytes since tail is special

slide-78
SLIDE 78

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Chunk #1 (Bytes 1-3) Header Byte:

→ Number of Gap Bytes (Bits 1-3) → Is the tail special? (Bit 4) → Number of verbatim bytes (if Bit 4=0) → Index of 1 bit in tail byte (if Bit 4=1)

No gap length bytes since gap length < 7 No verbatim bytes since tail is special

(010)(1)(0100) #1

slide-79
SLIDE 79

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Chunk #2 (Bytes 4-18) Header Byte:

→ 13 gap bytes, two tail bytes → # of gaps is > 7, so have to use extra byte

One gap length byte gives gap length = 13 Two verbatim bytes for tail.

(010)(1)(0100) #1

slide-80
SLIDE 80

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Chunk #2 (Bytes 4-18) Header Byte:

→ 13 gap bytes, two tail bytes → # of gaps is > 7, so have to use extra byte

One gap length byte gives gap length = 13 Two verbatim bytes for tail.

(010)(1)(0100) #1 (111)(0)(0010) 00001101 01000000 00100010 #2

slide-81
SLIDE 81

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Chunk #2 (Bytes 4-18) Header Byte:

→ 13 gap bytes, two tail bytes → # of gaps is > 7, so have to use extra byte

One gap length byte gives gap length = 13 Two verbatim bytes for tail.

(010)(1)(0100) #1 (111)(0)(0010) 00001101 01000000 00100010 #2 Gap Length

slide-82
SLIDE 82

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Chunk #2 (Bytes 4-18) Header Byte:

→ 13 gap bytes, two tail bytes → # of gaps is > 7, so have to use extra byte

One gap length byte gives gap length = 13 Two verbatim bytes for tail.

(010)(1)(0100) #1 (111)(0)(0010) 00001101 01000000 00100010 #2 Verbatim Tail Bytes

slide-83
SLIDE 83

CMU 15-721 (Spring 2016)

BYTE-ALIGNED BITMAP CODES

28

Source: Brian Babcock

00000000 00000000 00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00100010

Bitmap Compressed Bitmap

Chunk #2 (Bytes 4-18) Header Byte:

→ 13 gap bytes, two tail bytes → # of gaps is > 7, so have to use extra byte

One gap length byte gives gap length = 13 Two verbatim bytes for tail.

(010)(1)(0100) #1 (111)(0)(0010) 00001101 01000000 00100010 #2 Verbatim Tail Bytes

Original: 18 bytes BBC Compressed: 5 bytes.

slide-84
SLIDE 84

CMU 15-721 (Spring 2016)

OBSERVATION

Oracle's BBC is an obsolete format

→ Although it provides good compression, it is likely much slower than more recent alternatives due to excessive branching. → Word-Aligned Hybrid (WAH) is a patented variation

  • n BBC that provides better performance.

None of these support random access.

→ If you want to check whether a given value is present, you have to start from the beginning and uncompress the whole thing.

29

slide-85
SLIDE 85

CMU 15-721 (Spring 2016)

ROARING BITMAPS

Store 32-bit integers in a compact two-level indexing data structure.

→ Dense chunks are stored using bitmaps → Sparse chunks use packed arrays of 16-bit integers.

Now used in Lucene, Hive, Spark.

30

BETTER BITMAP PERFORMANCE WITH ROARING BITMAPS Software: Practice and Experience 2015

slide-86
SLIDE 86

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

001 001 110 100 000 000 100 001 000 000

Containers

slide-87
SLIDE 87

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216.

001 001 110 100 000 000 100 001 000 000

Containers

slide-88
SLIDE 88

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container.

001 001 110 100 000 000 100 001 000 000

Containers

slide-89
SLIDE 89

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container. If # of values in container is less than 4096, store as array. Otherwise, store as Bitmap.

001 001 110 100 000 000 100 001 000 000

Containers

slide-90
SLIDE 90

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container. If # of values in container is less than 4096, store as array. Otherwise, store as Bitmap. N=1000

001 001 110 100 000 000 100 001 000 000

Containers

slide-91
SLIDE 91

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container. If # of values in container is less than 4096, store as array. Otherwise, store as Bitmap. N=1000 1000/216=0

001 001 110 100 000 000 100 001 000 000

Containers

slide-92
SLIDE 92

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container. If # of values in container is less than 4096, store as array. Otherwise, store as Bitmap. N=1000 1000/216=0 1000%216=1000

001 001 110 100 000 000 100 001 000 000 1000

Containers

slide-93
SLIDE 93

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container. If # of values in container is less than 4096, store as array. Otherwise, store as Bitmap. N=1000 1000/216=0 1000%216=1000

001 001 110 100 000 000 100 001 000 000

N=199658

1000

Containers

slide-94
SLIDE 94

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container. If # of values in container is less than 4096, store as array. Otherwise, store as Bitmap. N=1000 1000/216=0 1000%216=1000

001 001 110 100 000 000 100 001 000 000

N=199658 199658/216=3

1000

Containers

slide-95
SLIDE 95

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container. If # of values in container is less than 4096, store as array. Otherwise, store as Bitmap. N=1000 1000/216=0 1000%216=1000

001 001 110 100 000 000 100 001 000 000

N=199658 199658/216=3 199658%216=50

1000

Containers

slide-96
SLIDE 96

CMU 15-721 (Spring 2016)

ROARING BITMAPS

31

Chunk Partitions

1 2 3

For each value N, assign it to a chunk based on N/216. Only store N%216 in container. If # of values in container is less than 4096, store as array. Otherwise, store as Bitmap. N=1000 1000/216=0 1000%216=1000

001 001 110 100 000 000 100 001 000 000

N=199658 199658/216=3 199658%216=50

1000

Set bit #50 to 1

Containers

slide-97
SLIDE 97

CMU 15-721 (Spring 2016)

PARTING THOUGHTS

These require that the position in the Bitmap corresponds to the tuple’s position in the table.

→ This is not possible in a MVCC DBMS using the Insert Method unless there is a look-up table.

Maintaining a Bitmap Index is wasteful if there are a large number of unique values for a column and if those values are ephemeral. We’re ignoring multi-dimensional indexes…

32

slide-98
SLIDE 98

CMU 15-721 (Spring 2016)

PROJECT #2

Implement a latch-free Bw-Tree in Peloton.

→ CAS Mapping Table → Delta Chains → Split / Merge / Consolidation → Cooperative Garbage Collection

Must be able to support both unique and non- unique keys.

33

slide-99
SLIDE 99

CMU 15-721 (Spring 2016)

PROJECT #2 – DESIGN

We will provide you with a header file with the index API that you have to implement.

→ Data serialization and predicate evaluation will be taken care of for you.

There are several design decisions that you are going to have to make.

→ There is no right answer. → Do not expect us to guide you at every step of the development process.

34

slide-100
SLIDE 100

CMU 15-721 (Spring 2016)

PROJECT #2 – TESTING

We are providing you with C++ unit tests for you to check your implementation. We also have a B+Tree implementation using stx::btree with a coarse-grained lock. We strongly encourage you to do your own additional testing.

35

slide-101
SLIDE 101

CMU 15-721 (Spring 2016)

PROJECT #2 – DOCUMENTATION

You must write sufficient documentation and comments in your code to explain what you are doing in all different parts. We will inspect the submissions manually.

36

slide-102
SLIDE 102

CMU 15-721 (Spring 2016)

PROJECT #2 – GRADING

We will run additional tests beyond what we provided you for grading.

→ Bonus points will be given to the student with the fastest implementation. → We will use Valgrind when testing your code.

All source code must pass ClangFormat syntax formatting checker.

→ See Peloton documentation for formatting guidelines.

37

slide-103
SLIDE 103

CMU 15-721 (Spring 2016)

PROJECT #2 – GROUPS

We have exactly 10 groups of 3 people each. Everyone should contribute equally. This isn’t a game. This is real life. Protect your neck.

38

slide-104
SLIDE 104

CMU 15-721 (Spring 2016)

PROJECT #2

Due Date: March 2nd, 2016 @ 11:59pm Projects will be turned in using Autolab. Full description and instructions: http://15721.courses.cs.cmu.edu/spring2016/p roject2.html

39

slide-105
SLIDE 105

CMU 15-721 (Spring 2016)

NEXT CLASS

Storage Models Performance Profiling for Project #2

40