Experimental realization of Tracy Widom distributions and ...
Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 -...
-
Upload
daisy-morrison -
Category
Documents
-
view
216 -
download
0
Transcript of Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 -...
![Page 1: Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 - 300.](https://reader035.fdocuments.in/reader035/viewer/2022072113/56649f275503460f94c3ece7/html5/thumbnails/1.jpg)
Index Example Index Example
From Garcia-Molina, Ullman, and Widom: From Garcia-Molina, Ullman, and Widom:
Database Systems, the Complete BookDatabase Systems, the Complete Book
pp. 298 - 300pp. 298 - 300
![Page 2: Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 - 300.](https://reader035.fdocuments.in/reader035/viewer/2022072113/56649f275503460f94c3ece7/html5/thumbnails/2.jpg)
What is an Index?What is an Index?
• Let’s say relation R has an attribute A• An index on A is a data structure that allows quick
access to tuples of R if you know the value of A• Implementation: hash table or similar data structure.
![Page 3: Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 - 300.](https://reader035.fdocuments.in/reader035/viewer/2022072113/56649f275503460f94c3ece7/html5/thumbnails/3.jpg)
Indices and database designIndices and database design
• Important fact: disk accesses are typically the highest cost operation for a DBMS
• Having an index on A speeds up database lookups involving A
• However, it slows down insertions and deletions involving A, because the index must also be updated
![Page 4: Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 - 300.](https://reader035.fdocuments.in/reader035/viewer/2022072113/56649f275503460f94c3ece7/html5/thumbnails/4.jpg)
Example from textbookExample from textbook
StarsIn(movieTitle, movieYear, StarName)• Query 1 (Q1): SELECT movieTitle, movieYear
FROM StarsIn
WHERE starName= s• Query 2 (Q2): SELECT starName
FROM StarsIn
WHERE movieTitle= t AND movieYear= y• Insertion (I): INSERT INTO StarsIn
SET StarName= s, movieTitle= t, movieYear= y
Assumptions: on average, each star has appeared in 3 movies, and each movie has 3 stars; table takes up 10 disk blocks
![Page 5: Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 - 300.](https://reader035.fdocuments.in/reader035/viewer/2022072113/56649f275503460f94c3ece7/html5/thumbnails/5.jpg)
Cost of QueriesCost of Queries
Action No index Star index
Movie Index
Both indices
Q1 10 4 10 4
Q2 10 10 4 4
I 2 4 4 6
![Page 6: Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 - 300.](https://reader035.fdocuments.in/reader035/viewer/2022072113/56649f275503460f94c3ece7/html5/thumbnails/6.jpg)
Conclusions:Conclusions:
• If lookups on an attribute A are much more common than insertions and deletions, it makes sense to add an index on A
• But if lookups are not common, the index may slow down database performance
![Page 7: Index Example From Garcia-Molina, Ullman, and Widom: Database Systems, the Complete Book pp. 298 - 300.](https://reader035.fdocuments.in/reader035/viewer/2022072113/56649f275503460f94c3ece7/html5/thumbnails/7.jpg)
ImplementationImplementation
• An index can be defined on multiple attributes A, B. In this case the domain is the set of ordered pairs (a, b) ε A x B
• Some DBMS implementers automatically add an index to each primary key attribute.
• This is useful because any insertion to a table with a key requires a lookup to ensure that the key remains unique.