Week 2 - Major Indexing Schemes Flashcards
Hash Indexes what is it good for ?
1) Hash-based indexes are good for equality selections
(age =16, id=2)
2) takes keys and puts data in data bucket
What kind of indexing scheme should be used in order to retrieve data on customers whose zip code is equal to 06902?
1) Equality index
2) Clustered index
3) Heap-based index1
4) Hash-based index
4) Hash-based index
Index entries have what
Have pointers to where that data is.
So, the index entries help you just navigate,
so it help you search,
and the data entries are the last level where you go ahead, and retrieve the data from where it’s stored in the database.
Ways to store data entries
1) key (record ID)
2) Key (list of record IDs)
We know that data is stored in the form of records. Every record has a?
key field
An ______ is a data structure that locates these key fields within the database file
index
What is a clustered index
Data records are sorted like the data is sorted. Stored by the attribute (like an id)
un-clustered index
The record is not sorted by the data.
Note same sorting order
What type of index should you use?
Depends on workload
Where should you put the index if all the queries access the same attribute
1) The index should be on that attribute (what is in the WHERE )
2) how what percentage of the data is selected Lower the better
IF the query selects 95% of data is that a good place to put and index
No
Lower is better (more refined)
Cost of Indexes
1) storage (hard disk space)
2) If there are lots of inserts can be slower
3) Maintain index (hard if updating it a lot)
If a database has m rows and n columns, what is the maximum number of clustered indexes for this table?
1) 1
2) n
3) mn
4) m
1) 1
A database table can only have one clustered index.
Four considerations for creating a new index
1) Consider the most important queries
2) Consider the best plan using the current indexes
3) Determine if a better plan is possible with an additional index
4) How often the index needs to be updated
4 Index selection Guidelines
1) Attribute in the WHERE clause
2) Keys (primary, unique attribute)
3) Searches on multiple attribute
4) If index will benefit multiple queries
B+ tree index are good for
IDs, numbers, group by
HASHed indexs are good for
Equality WHERE hobby = stamps
Composite Keys
Composite index (index on two or more values)
In a composite index which is given priority?
age
First item is given priority
Can you ever find all the info you need without going to the table
Yes, sometimes the index has everything you need.
Example:
Index based on departmentNumber
Select E.departmentNumber from Emp E GROUP BY E.departmentNumber ;
Creating indexes is not a straightforward decision because of the costs involved. One must answer certain questions before creating indexes. Which of the following questions is NOT relevant to creating an index?
1) Which field(s) should be part of an index?
2) Which tables should be indexed?
3) Should one build multiple indexes?
4) Which record(s) should be part of an index?
4) Which record(s) should be part of an index?
This question is irrelevant to building indexes; an index is built using fields, not records.
Which of the following database operations can be achieved by using hash-based indexes?
1) To retrieve student data where age is equal to 20.
2) To retrieve student data where age is between 18 and 20.
3) To retrieve student data where age is different than 20.
4) To retrieve student data where age is less than 20.
1) To retrieve student data where age is equal to 20.
Hash-based indexes are good for equality selections.
If a database table has m rows and n columns, what is the maximum number of clustered indexes for this table?
1) 1
2) m
3) n
4) mn
1) 1
A database table can only have one clustered index.
Which of the following is/are among the disadvantages of indexes? Choose all that apply.
1) Increased cost of storage.
2) Increased cost of maintenance.
3) Decrease in performance of select queries.
4) Decrease in performance of update queries.
1) Increased cost of storage.
2) Increased cost of maintenance.