Lect ure # 22 ADVANCED DATABASE SYSTEMS Vectorized Execution - - PowerPoint PPT Presentation

lect ure 22 advanced database
SMART_READER_LITE
LIVE PREVIEW

Lect ure # 22 ADVANCED DATABASE SYSTEMS Vectorized Execution - - PowerPoint PPT Presentation

Lect ure # 22 ADVANCED DATABASE SYSTEMS Vectorized Execution (Part II) @ Andy_Pavlo // 15- 721 // Spring 2018 2 Bit-Slicing Bit-Weaving Relaxed Operator Fusion (Prashanth) CMU 15-721 (Spring 2018) 3 BITM AP EN CO DIN G Original Data


slide-1
SLIDE 1

Vectorized Execution (Part II)

@ Andy_Pavlo // 15- 721 // Spring 2018

ADVANCED DATABASE SYSTEMS Lect ure # 22

slide-2
SLIDE 2

CMU 15-721 (Spring 2018)

Bit-Slicing Bit-Weaving Relaxed Operator Fusion (Prashanth)

2

slide-3
SLIDE 3

CMU 15-721 (Spring 2018)

BITM AP EN CO DIN G

3

Original Data

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

slide-4
SLIDE 4

CMU 15-721 (Spring 2018)

BITM AP EN CO DIN G

3

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-5
SLIDE 5

CMU 15-721 (Spring 2018)

BITM AP IN DEX: EN CO DIN G

Approach #1: Equality Encoding

→ Basic scheme with one Bitmap per unique value.

Approach #2: Range Encoding

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

Approach #3: Hierarchical Encoding

→ Use a tree to identify empty key ranges.

Approach #4: Bit-sliced Encoding

→ Use a Bitmap per bit location across all values.

4

slide-6
SLIDE 6

CMU 15-721 (Spring 2018)

H IERARCH ICAL EN CO DIN G

5

1010 1011 0100

1010 1100 1001 0101 0000 0000 0000 0000

0000 0000

0000 0000 0000 0000 0000 0000 0000 0000

HIERARCHICAL BITMAP INDEX: AN EFFICIENT AND SCALABLE INDEXING TECHNIQUE FOR SET- VALUED ATTRIBUTES Advances in Databases and Information Systems 2003

1 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64

Keys: 1, 3, 9, 12, 13, 14, 38, 40

slide-7
SLIDE 7

CMU 15-721 (Spring 2018)

H IERARCH ICAL EN CO DIN G

5

1010 1011 0100

1010 1100 1001 0101

HIERARCHICAL BITMAP INDEX: AN EFFICIENT AND SCALABLE INDEXING TECHNIQUE FOR SET- VALUED ATTRIBUTES Advances in Databases and Information Systems 2003

1 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64

Original: 8 bytes Encoded: 4 bytes

Keys: 1, 3, 9, 12, 13, 14, 38, 40

slide-8
SLIDE 8

CMU 15-721 (Spring 2018)

Bit-Slices

BIT- SLICED EN CO DIN G

6

Original Data

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

Source: Jignesh Patel

slide-9
SLIDE 9

CMU 15-721 (Spring 2018)

Bit-Slices

BIT- SLICED EN CO DIN G

6

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 N?

bin(21042)→ 00101001000110010

Source: Jignesh Patel

slide-10
SLIDE 10

CMU 15-721 (Spring 2018)

Bit-Slices

BIT- SLICED EN CO DIN G

6

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 N?

bin(21042)→ 00101001000110010

Source: Jignesh Patel

slide-11
SLIDE 11

CMU 15-721 (Spring 2018)

Bit-Slices

BIT- SLICED EN CO DIN G

6

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 N? 1 1 1 1 1 1

bin(21042)→ 00101001000110010

Source: Jignesh Patel

slide-12
SLIDE 12

CMU 15-721 (Spring 2018)

Bit-Slices

BIT- SLICED EN CO DIN G

6

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 N? 1 1 1 1 1 1

SELECT * FROM customer_dim WHERE zipcode < 15217

Source: Jignesh Patel

slide-13
SLIDE 13

CMU 15-721 (Spring 2018)

Bit-Slices

BIT- SLICED EN CO DIN G

6

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 N? 1 1 1 1 1 1

SELECT * FROM customer_dim WHERE zipcode < 15217

Walk each slice and construct a result bitmap.

Source: Jignesh Patel

slide-14
SLIDE 14

CMU 15-721 (Spring 2018)

Bit-Slices

BIT- SLICED EN CO DIN G

6

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 N? 1 1 1 1 1 1

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-15
SLIDE 15

CMU 15-721 (Spring 2018)

BIT- SLICED EN CO DIN G

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

→ First, count the number of 1s in slice17and 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…

Intel added POPCNT SIMD instruction in 2008.

7

slide-16
SLIDE 16

CMU 15-721 (Spring 2018)

O BSERVATIO N

The bit width of compressed data does not always fit naturally into SIMD register lanes.

→ This means that the DBMS has to do extra work to transform data into the proper format.

Just because the lanes are fully utilized does not mean the bits are fully utilized…

8

A B C D

SIMD Compare

X B X D 0 1 0 1

slide-17
SLIDE 17

CMU 15-721 (Spring 2018)

O BSERVATIO N

The bit width of compressed data does not always fit naturally into SIMD register lanes.

→ This means that the DBMS has to do extra work to transform data into the proper format.

Just because the lanes are fully utilized does not mean the bits are fully utilized…

8

A B C D

SIMD Compare

X B X D 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 1 0 0 0

slide-18
SLIDE 18

CMU 15-721 (Spring 2018)

BITWEAVIN G

Alternative storage layout for columnar databases that is designed for efficient predicate evaluation

  • n compressed data using SIMD.

→ Order-preserving dictionary encoding. → Bit-level parallelization. → Only require common instructions (no scatter/gather)

Implemented in Wisconsin’s QuickStep engine. Became an Apache Incubator project in 2016.

9

BITWEAVING: FAST SCANS FOR MAIN MEMORY DATA P PROCESSING SIGMOD 2013

slide-19
SLIDE 19

CMU 15-721 (Spring 2018)

BITWEAVIN G

Alternative storage layout for columnar databases that is designed for efficient predicate evaluation

  • n compressed data using SIMD.

→ Order-preserving dictionary encoding. → Bit-level parallelization. → Only require common instructions (no scatter/gather)

Implemented in Wisconsin’s QuickStep engine. Became an Apache Incubator project in 2016.

9

BITWEAVING: FAST SCANS FOR MAIN MEMORY DATA P PROCESSING SIGMOD 2013

slide-20
SLIDE 20

CMU 15-721 (Spring 2018)

BITWEAVIN G STO RAGE LAYO UTS

Approach #1: Horizontal

→ Row-oriented storage at the bit-level

Approach #2: Vertical

→ Column-oriented storage at the bit-level

10

slide-21
SLIDE 21

CMU 15-721 (Spring 2018)

H O RIZO N TAL STO RAGE

11

1 1 1 1 1 1 1 1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7

1 1 1

t8 t9 Segment #1 Segment #2 =1 =5 =1 =6 =6 =4 =7 =0 =3 =4

slide-22
SLIDE 22

CMU 15-721 (Spring 2018)

Segment #2

H O RIZO N TAL STO RAGE

11

1 1 1 1 1 1 1 1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7

1 1 1

t8 t9 Segment #1 Segment #2

Segment #1

v0 0

1 1 1

t0 t4 v1 0

1 1 1

t1 t5 v2 0

1 1

t2 t6 v3 0

1 1 1 1

t3 t7 v4 0

1 1 1

t8 t9

slide-23
SLIDE 23

CMU 15-721 (Spring 2018)

Segment #2

H O RIZO N TAL STO RAGE

11

1 1 1 1 1 1 1 1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7

1 1 1

t8 t9 Segment #1 Segment #2

Segment #1

v0 0

1 1 1

t0 t4 v1 0

1 1 1

t1 t5 v2 0

1 1

t2 t6 v3 0

1 1 1 1

t3 t7 v4 0

1 1 1

t8 t9 Processor Word Processor Word

slide-24
SLIDE 24

CMU 15-721 (Spring 2018)

Segment #2

H O RIZO N TAL STO RAGE

11

1 1 1 1 1 1 1 1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7

1 1 1

t8 t9 Segment #1 Segment #2

Segment #1

v0 0

1 1 1

t0 t4 v1 0

1 1 1

t1 t5 v2 0

1 1

t2 t6 v3 0

1 1 1 1

t3 t7 v4 0

1 1 1

t8 t9 Processor Word Delimiter Processor Word

slide-25
SLIDE 25

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

12

SELECT * FROM table WHERE val < 5

t0 t4

1 1 1

X = Y =

1 1 1 1

5 5

Source: Jignesh Patel

slide-26
SLIDE 26

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

12

SELECT * FROM table WHERE val < 5

t0 t4

1 1 1

X = Y =

1 1 1 1

5 5

mask =

1 1 1 1 1 1

(Y+(X⊕mask))∧¬mask=

1

Source: Jignesh Patel

slide-27
SLIDE 27

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

12

SELECT * FROM table WHERE val < 5

t0 t4

1 1 1

X = Y =

1 1 1 1

5 5

mask =

1 1 1 1 1 1

(Y+(X⊕mask))∧¬mask=

1

Source: Jignesh Patel

Selection Vector

slide-28
SLIDE 28

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

12

SELECT * FROM table WHERE val < 5

t0 t4

1 1 1

X = Y =

1 1 1 1

5 5

mask =

1 1 1 1 1 1

(Y+(X⊕mask))∧¬mask=

1

1 < 5 5 < 6

Source: Jignesh Patel

slide-29
SLIDE 29

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

Only requires three instructions to evaluate a single word. Works on any word size and encoding length. Paper contains algorithms for other operators.

12

SELECT * FROM table WHERE val < 5

t0 t4

1 1 1

X = Y =

1 1 1 1

5 5

mask =

1 1 1 1 1 1

(Y+(X⊕mask))∧¬mask=

1

1 < 5 5 < 6

Source: Jignesh Patel

slide-30
SLIDE 30

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

13

SELECT * FROM table WHERE val < 5

Source: Jignesh Patel

v0 0

1 1 1

t0 t4 v1 0

1 1 1

t1 t5 v2 0

1 1

t2 t6 v3 0

1 1 1 1

t3 t7

slide-31
SLIDE 31

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

13

SELECT * FROM table WHERE val < 5

Source: Jignesh Patel

v0 0

1 1 1

t0 t4 v1 0

1 1 1

t1 t5 v2 0

1 1

t2 t6 v3 0

1 1 1 1

t3 t7

1 1 1 1

< 5 < 5 < 5 < 5

slide-32
SLIDE 32

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

13

SELECT * FROM table WHERE val < 5

Source: Jignesh Patel

v0 0

1 1 1

t0 t4 v1 0

1 1 1

t1 t5 v2 0

1 1

t2 t6 v3 0

1 1 1 1

t3 t7

1 1 1 1

< 5 < 5 < 5 < 5

1 1 1 1

>>3 >>2 >>1 >>0

slide-33
SLIDE 33

CMU 15-721 (Spring 2018)

BITWEAVIN G/ H EXAM PLE

13

SELECT * FROM table WHERE val < 5

Source: Jignesh Patel

v0 0

1 1 1

t0 t4 v1 0

1 1 1

t1 t5 v2 0

1 1

t2 t6 v3 0

1 1 1 1

t3 t7

1 1 1 1

< 5 < 5 < 5 < 5

1 1 1 1

>>3 >>2 >>1 >>0

1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7

slide-34
SLIDE 34

CMU 15-721 (Spring 2018)

SELECTIO N VECTO R

SIMD comparison operators produce a bit mask that specifies which tuples satisfy a predicate. Have to convert it into offsets / positions.

→ Approach #1: Iteration → Approach #2: Pre-compute Positions Table

14

slide-35
SLIDE 35

CMU 15-721 (Spring 2018)

SELECTIO N VECTO R

SIMD comparison operators produce a bit mask that specifies which tuples satisfy a predicate. Have to convert it into offsets / positions.

→ Approach #1: Iteration → Approach #2: Pre-compute Positions Table

14

1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 Selection Vector

slide-36
SLIDE 36

CMU 15-721 (Spring 2018)

SELECTIO N VECTO R

SIMD comparison operators produce a bit mask that specifies which tuples satisfy a predicate. Have to convert it into offsets / positions.

→ Approach #1: Iteration → Approach #2: Pre-compute Positions Table

14

tuples = [ ] for (i=0; i<n; i++) { if sv[i] == 1 tuples.add(i); } 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 Selection Vector

slide-37
SLIDE 37

CMU 15-721 (Spring 2018)

SELECTIO N VECTO R

SIMD comparison operators produce a bit mask that specifies which tuples satisfy a predicate. Have to convert it into offsets / positions.

→ Approach #1: Iteration → Approach #2: Pre-compute Positions Table

14

1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 Selection Vector

slide-38
SLIDE 38

CMU 15-721 (Spring 2018)

SELECTIO N VECTO R

SIMD comparison operators produce a bit mask that specifies which tuples satisfy a predicate. Have to convert it into offsets / positions.

→ Approach #1: Iteration → Approach #2: Pre-compute Positions Table

14

1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 Selection Vector

PAYLOAD KEY

Positions Table

150

{0,3,5,6}

slide-39
SLIDE 39

CMU 15-721 (Spring 2018)

VERTICAL STO RAGE

15

1 1 1 1 1 1 1 1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7

1 1 1

t8 t9 Segment #1 Segment #2

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

slide-40
SLIDE 40

CMU 15-721 (Spring 2018)

VERTICAL STO RAGE

15

1 1 1 1 1 1 1 1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7

1 1 1

t8 t9 Segment #1 Segment #2

slide-41
SLIDE 41

CMU 15-721 (Spring 2018)

Segment #2

VERTICAL STO RAGE

15

1 1 1 1 1 1 1 1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7

1 1 1

t8 t9 Segment #1 Segment #2

Segment #1

v0 0

1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 v1 0

1 1 1

v2 1

1 1 1

Processor Word v3 1 t8 t9 -

  • v4 0

1

v5 0

1

slide-42
SLIDE 42

CMU 15-721 (Spring 2018)

BITWEAVIN G/ V EXAM PLE

16

Segment #1

v0 0

1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 v1 0

1 1 1

v2 1

1 1 1 SELECT * FROM table WHERE key = 2

slide-43
SLIDE 43

CMU 15-721 (Spring 2018)

BITWEAVIN G/ V EXAM PLE

16

Segment #1

v0 0

1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 v1 0

1 1 1

v2 1

1 1 1 SELECT * FROM table WHERE key = 2 1

slide-44
SLIDE 44

CMU 15-721 (Spring 2018)

BITWEAVIN G/ V EXAM PLE

16

Segment #1

v0 0

1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 v1 0

1 1 1

v2 1

1 1 1 SELECT * FROM table WHERE key = 2 1 1 1 1

SIMD Compare

slide-45
SLIDE 45

CMU 15-721 (Spring 2018)

BITWEAVIN G/ V EXAM PLE

16

Segment #1

v0 0

1 1 1 1 1

t0 t1 t2 t3 t4 t5 t6 t7 v1 0

1 1 1

v2 1

1 1 1 SELECT * FROM table WHERE key = 2 1 1 1 1

Can perform early pruning just like in BitMap indexes. The last vector is skipped because all bits in previous comparison are zero.

SIMD Compare

1 1 1 1 1 1 1 1

SIMD Compare

slide-46
SLIDE 46

CMU 15-721 (Spring 2018)

EVALUATIO N

Single-threaded execution of a single query derived from TPC-H benchmark.

→ Selectivity: 10%

10GB TPC-H Database

→ 1 billion tuples → Uniform distribution

17

Source: Jignesh Patel

SELECT COUNT(*) FROM R WHERE R.a < C

slide-47
SLIDE 47

CMU 15-721 (Spring 2018)

EVALUATIO N

18

2 4 6 8 10 1 11 21 31

Cycles / Code Size of Code (# of Bits)

Naïve SIMD Scan BitWeaving/V BitWeaving/H

TPC-H Aggregation Query Intel Xeon X5650 @ 2.66 GHz

Source: Jignesh Patel

SIMD Parallelization Fewer Cache Misses Early Pruning

slide-48
SLIDE 48

CMU 15-721 (Spring 2018)

PARTIN G TH O UGH TS

Just like in query compilation, getting the best performance with vectorization requires the DBMS to store data in a way that is best for the CPU and not the best for humans’ understanding.

19