For the purpose of tuning your database that has begun to slow down for some que
ID: 3854854 • Letter: F
Question
For the purpose of tuning your database that has begun to slow down for some queries, you are looking for the best plan to execute the following queries on the relation described below: The relation you are dealing with is Employee with attributes ename, title, dname, and address; all are string fields of the same length. The ename attribute is a candidate key.
The relation contains 10,000 pages. There are 10 buffer pages. (When answering the questions, make sure to describe the plan you have in mind.)
The first query is: SELECT E.title, E.ename FROM Employee E WHERE E.title=‘Administrator’ Assume that only 10% of Employee tuples meet the selection condition. a. Suppose that a clustered B+ tree index on ename is (the only index) available. What is the cost of the best plan? (5 marks)
Candidate key is ename Relation contains 10,000 pages, 10 buffer pages Therefore, the cost G is the best plan = 10,000 b. Suppose that a clustered B+ tree index on title is (the only index) available. What is the cost of the best plan? (5 marks)
c. Suppose that a clustered B+ tree index on dname is (the only index) available. What is the cost of the best plan? (5 marks)
d. Suppose that a clustered B+ tree index on is (the only index) available. What is the cost of the best plan? (5 marks)
Explanation / Answer
Hi,
The main concept to note here, there are 2 cases
1. If there is no suitable index is present then the query will always do a table scan.
2. If there is such index and then query does 2 steps
a. scan for that index in the B tree or B+ tree
b. for each row get the primary key from above tree and extract the data
Given query is "SELECT E.title, E.ename FROM Employee E WHERE E.title=‘Administrator’ "
So, now to answer your questions
a. Suppose that a clustered B+ tree index on ename is (the only index) available. What is the cost of the best plan?
since we have index on ename and we are filtering for title, it wont be used and it will do a table scan so the cost is 10000
b. Suppose that a clustered B+ tree index on title is (the only index) available. What is the cost of the best plan?
since now that the index is available on title we can use that tree,
as mentioned above, first we have to find the title administrator, cost = 2, then due to the clustering of the index we can get the all the 10k reference pages at cost 10000* (10/100) + 2500 * (10/100) (scanning index) = 1252
c. Suppose that a clustered B+ tree index on dname is (the only index) available. What is the cost of the best plan?
we are not using dname in the where clause so no index is used, cost= table scan=10000
d. i think the question is incomplete, but i assume its address as its the only key left,
if address index is formed then also no use, cost=10000
Thumbs up if this was helpful, otherwise let me know in comments. Good Day.