Thus the total cost is less than 3 n 1312 show that

Info icon This preview shows pages 7–10. Sign up to view the full content.

View Full Document Right Arrow Icon
2. Thus the total cost is less than 3 n . 13.12 Show that, if only left-deep join trees are considered, as in the System R optimizer, the time taken to find the most efficient join order is around n 2 n . Assume that there is only one interesting sort order. Answer: The derivation of time taken is similar to the general case, except that instead of considering 2 k + 1 2 subsets of size less than or equal to
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
8 Chapter 13 Query Optimization k for A , we only need to consider k + 1 subsets of size exactly equal to k . That is because the right hand operand of the topmost join has to be a single relation. Therefore the total cost for finding the best join order for all subsets of size k + 1 is ( n k + 1 ) ( k + 1), which is equal to n ( n 1 k ) . Summing over all k from 1 to n 1 using the binomial expansion of (1 + x ) n 1 with x = 1, gives a total cost of less than n 2 n 1 . 13.13 Consider the bank database of Figure 13.9, where the primary keys are un- derlined. Construct the following SQL queries for this relational database. a. Write a nested query on the relation account to find, for each branch with name starting with B, all accounts with the maximum balance at the branch. b. Rewrite the preceding query, without using a nested subquery; in other words, decorrelate the query. c. Give a procedure (similar to that described in Section 13.4.4) for decorrelating such queries. Answer: a. The nested query is as follows: select S . acount number from account S where S . branch name like ’B%’ and S.balance = ( select max ( T.balance ) from account T where T.branch name = S.branch name ) b. The decorrelated query is as follows: create table t 1 as select branch name , max ( balance ) from account group by branch name select account number from account , t 1 where account.branch name like ’B%’ and account.branch name = t 1 .branch name and account.balance = t 1 .balance c. In general, consider the queries of the form:
Image of page 8
Exercises 9 select · · · from L 1 where P 1 and A 1 op ( select f ( A 2 ) from L 2 where P 2 ) where, f is some aggregate function on attributes A 2 , and op is some boolean binary operator. It can be rewritten as create table t 1 as select f ( A 2 ), V from L 2 where P 1 2 group by V select · · · from L 1 , t 1 where P 1 and P 2 2 and A 1 op t 1 . A 2 where P 1 2 contains predicates in P 2 without selections involving correlation variables, and P 2 2 introduces the selections involving the correlation variables. V contains all the attributes that are used in the selections involving correlation variables in the nested query. 13.14 The set version of the semijoin operator is defined as follows: r H9258 s = Pi1 R ( r a49 H9258 s ) where R is the set of attributes in the schema of r . The multiset version of the semijoin operation returns the same set of tuples, but each tuple has exactly as many copies as it had in r .
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern