2015-12-101 Index Tuning Conventional index. Overview.

20
22/8/30 1 Index Tuning Conventional index

Transcript of 2015-12-101 Index Tuning Conventional index. Overview.

Page 1: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 1

Index Tuning

Conventional index

Page 2: 2015-12-101 Index Tuning Conventional index. Overview.

Overview

Page 3: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 3

Duplicate keys

1010

2010

3020

3030

4540

Page 4: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 4

1010

2010

3020

3030

4540

10101020

20303030

1010

2010

3020

3030

4540

10101020

20303030

Dense index, one way to implement?

• Query– Look for

the first K, then search forward

Duplicate keys

Page 5: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 5

1010

2010

3020

3030

4540

10203040

Dense index, better way?

Duplicate keys

• Each pointer points to the first of records with key K

• Query– Find the

first occurrence, then move forward

Page 6: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 6

1010

2010

3020

3030

4540

10102030

Sparse index, one way?

Duplicate keysca

refu

l if lookin

gfo

r 2

0 o

r 3

0!

• Find the last index entry with key <=K

• Then, search backward until coming to the first entry or meeting an index entry E2

with key strictly less than k

Page 7: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 7

1010

2010

3020

3030

4540

10203030

Sparse index, another way?

Duplicate keys

– place first new key from block

Page 8: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 8

Duplicate values, primary index

• Index may point to first instance ofeach value only

File

Index

Summary

aaa

b

Page 9: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 9

Deletion from sparse index

2010

4030

6050

8070

10305070

90110130150

Page 10: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 10

Deletion from sparse index

2010

4030

6050

8070

10305070

90110130150

– delete record 40

Page 11: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 11

Deletion from sparse index

2010

4030

6050

8070

10305070

90110130150

– delete record 30

4040

Page 12: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 12

Deletion from sparse index

2010

4030

6050

8070

10305070

90110130150

– delete records 30 & 40

5070

Page 13: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 13

Deletion from dense index

2010

4030

6050

8070

10203040

50607080

Page 14: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 14

Deletion from dense index

2010

4030

6050

8070

10203040

50607080

– delete record 30

4040

Page 15: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 15

Insertion, sparse index case

2010

30

5040

60

10304060

Page 16: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 16

Insertion, sparse index case

2010

30

5040

60

10304060

– insert record 34

34

• our lucky day! we have free space where we need it!

Page 17: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 17

Insertion, sparse index case

2010

30

5040

60

10304060

– insert record 15

15

2030

20

• Illustrated: Immediate reorganization

•In principle, we may have had to slide every record to the end of the file

• Variation:– insert new block (chained file)– update index

Page 18: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 18

Insertion, sparse index case

2010

30

5040

60

10304060

– insert record 25

25

overflow blocks(reorganize later...)

• No index entry for overflow blocks, which is considered as an extension of data block

Page 19: 2015-12-101 Index Tuning Conventional index. Overview.

23/4/21 19

Insertion, dense index case

• Similar

• Often more expensive . . .

Page 20: 2015-12-101 Index Tuning Conventional index. Overview.

summary