Indexes
Database Systems: The Complete Book
- Ch. 13.1-13.3, 14.1-14.2
1
Indexes Database Systems: The Complete Book Ch. 13.1-13.3, - - PowerPoint PPT Presentation
Indexes Database Systems: The Complete Book Ch. 13.1-13.3, 14.1-14.2 1 2 3 $88 $24 4 $88 $24 Hardcover (heavy) Paperback (light) 5 $88 $24 Hardcover (heavy) Paperback (light) Bigger Small 6 $88 $24 Hardcover (heavy) Paperback
Database Systems: The Complete Book
1
2
3
4
$88 $24
5
$88 $24 Hardcover (heavy) Paperback (light)
6
$88 $24 Hardcover (heavy) Paperback (light) Bigger Small
7
$88 $24 Hardcover (heavy) Paperback (light) Bigger Small Good ToC/Index Bad ToC/Index
8
Records grouped together or stored in sorted order,
9
10
What is an equivalent Relational Algebra expression?
What is the maximum working set size? What is the time complexity?
11
12
How would you evaluate this query? How would you organize the data for this query?
13
14
Select searches for data Checking every data value is correct, but not efficient
Organize the data!
What are some ways of organizing the data?
What are some pros and cons for each solution?
15
16
(clustered index)
(unclustered index)
17
How would you sort your data for… (and how would you evaluate it)
18
predicate (these predicates)
19
20
Let’s say you have 220 blocks (~4GB) of data sorted on A How many IOs are required to find one A? In general, for N blocks, how many IOs? log2(N)
21
Things < 2 2 < Things < 5
“Find 3”
As you search, you are effectively building a binary tree.
22
Binary Tree → Log 2 Depth N-ary Tree → Log N Depth
23
24
… … … … … … …
p0 p1 p2 p3 p4 k1 k2 k3 k4 … Non-Leaf Page
Leaf Pages contain <K, RID> or <K, Record> pairs
25
1) Allocate (sequential) leaf pages 2) Ensure that the data on the leaf pages is sorted 3) Build the non-leaf pages (in arbitrary order)
… … … … … … …
26
Equality: Start at root, use key comparisons to find leaf Range: Use key comparisons to find start and end page Scan all pages in between start/end leaves.
… … … … … … …
27
… … … … … … …
Do you see any problems with this?
28
… … … … … … …
1) When creating the index leave free space in each leaf page 2) The index stays the same, new data is added to the free space 3) If a leaf page overflows, we create an overflow page (or more)
29
10,15 33 20 40 63 51 20,27 33,37 40,46 23 , 48 41 42 51,55 63,97
30
Data pages not sequential - Need linked list for traversals
31
2, 3,5, 7
17 13 30 24
14,16,_,_ 19,20,22,_ 24,27,29,_ 33,34,38,39
32
33
Inner Nodes: 4 values, 5 pointers Data Nodes: 4 values
17 13 30 24
34
2, 3,5, 7 14,16 19,20,22 24,27,29 33,34,38,39
17 13 30 24
35
2, 3,5, 7 2, 3 5,7,8 ,
5
17 13 30 24
36
5
17 13 30 24
37
5
38
5, 7,8 14,16 19,20,22 24,27,29 33,34,38,39
13 30 24 5 17
2, 3
39
5, 7,8 14,16 19,20,22 24,27,29 33,34,38,39
13 30 24 5 17
2, 3
20,22 22 22,24 27,29
27
27
40
5, 7,8 14,16 33,34,38,39
13 30 5 17
2, 3
22,24 27,29 22 22,27,29
41
5, 7,8 14,16 22,27,29
20 13 5 17 22
2, 3 17,18 20,21
30
33,34,38
42
5, 7,8 14,16 22,27,29
20 13 5 17 22
2, 3 17,18 20,21
30
33,34,38