Download presentation
Presentation is loading. Please wait.
Published byKristin Gibson Modified over 9 years ago
1
6.830 Lecture 6 9/28/2015 Cost Estimation and Indexing
2
Database Internals Outline Front End Admission Control Connection Management (sql) Parser (parse tree) Rewriter (parse tree) Planner & Optimizer (query plan) Executor Query System Storage System Access Methods Lock Manager Buffer Manager Log Manager Last time This time
3
Example SELECT * FROM emp, dept, kids WHERE e.sal > 10k AND emp.dno = dept.dno AND e.eid = kids.eid 100 tuples / page 10 pages RAM 10 KB/page 10 ms seek time 100 MB/sec I/o |dept| = 100 = 1 page |emp| = 10K = 100 pages |kids| = 30K = 300 pages
4
Study Break Assuming disk can do 100 MB/sec I/O And the following schema: grades (cid int, g_sid int, grade char(2)) students (s_int, name char(100)) 1.Estimate time to sequentially scan grades, assuming it contains 1M records (Consider: field sizes, headers) 1.Estimate time to join these two tables, using nested loops, assuming students fits in memory but grades does not, and students contains 10K records.
5
Hash Index On Disk Hash Table n buckets, on n disk pages Disk page 1 … Disk Page n H(f1) (‘sam’, 10k, …) (‘joe’, 20k, …) Issues How big to make table? If we get it wrong, either waste space, or end up with long overflow chains, or have to rehash e.g., H(x) = x mod n
6
Extensible Hashing Create a family of hash tables parameterized by k H k (x) = H(x) mod 2 k Start with k = 1 (2 hash buckets) Use a directory structure to keep track of which bucket (page) each hash value maps to When a bucket overflows, increment k (if needed), create a new bucket, rehash keys in overflowing bucket, and update directory
7
Example H k (x)Page 00 11 Directory k=1 Hash Table Page NumberPage Contents 0 1 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k
8
Example H k (x)Page 00 11 Directory k=1 Hash Table Page NumberPage Contents 0 1 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod 2^k 0 mod 2 = 0 0
9
Example H k (x)Page 00 11 Directory k=1 Hash Table Page NumberPage Contents 000 1 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k 0 mod 2 = 0
10
Example H k (x)Page 00 11 Directory k=1 Hash Table Page NumberPage Contents 0002 1 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k 2 mod 2 = 0
11
Example H k (x)Page 00 11 Directory k=1 Hash Table Page NumberPage Contents 0002 13 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k 3 mod 2 = 1
12
Example H k (x)Page 00 11 Directory k=1 Hash Table Page NumberPage Contents 0002 13 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k 2 mod 2 = 0 - FULL!
13
Example H k (x)Page 00 11 2 3 Directory k=1 2 Hash Table Page NumberPage Contents 0002 13 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k
14
Example H k (x)Page 00 11 22 3 Directory k=1 2 Hash Table Page NumberPage Contents 0002 13 2 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k Allocate new page!
15
Example H k (x)Page 00 11 22 31 Directory k=1 2 Hash Table Page NumberPage Contents 0002 13 2 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k Only allocate 1 new page! Rehash
16
Example H k (x)Page 00 11 22 31 Directory k=1 2 Hash Table Page NumberPage Contents 000 13 22 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k 2 mod 4 = 2
17
Example H k (x)Page 00 11 22 31 Directory k=1 2 Hash Table Page NumberPage Contents 000 13 222 Insert records with keys 0, 0, 2, 3, 2 H k (x) = x mod k 2 mod 4 = 2 Extra bookkeeping needed to keep track of fact that pages 0/2 have split and page 1 hasn’t
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.