1 / 2

In-Class Query Optimization Exercise

In-Class Query Optimization Exercise. p sname. p sname. Reserves. Sailors. Boats. Each tuple 40 bytes long 100 tuples per page, M = 1000 pages total. Each tuple 50 bytes long 80 tuples per page, N = 500 pages total. Each tuple 45 bytes long 90 tuples per page,

Télécharger la présentation

In-Class Query Optimization Exercise

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. In-Class Query Optimization Exercise psname p sname Reserves Sailors Boats Each tuple 40 bytes long 100 tuples per page, M = 1000 pages total. Each tuple 50 bytes long 80 tuples per page, N = 500 pages total. Each tuple 45 bytes long 90 tuples per page, P = 500 pages total. 1) How many left-deep query trees can you find for R S B? Assume no indexes. There are 4 left-deep trees: B B S S B. s rating = 5 R S S R B R R B sid = sid File Scan File Scan Reserves Salesperson A. p sname C. Block Nested Loop Join Sort-merge Join sid = sid sid = sid s rating =5 File Scan s rating=5 File Scan Use Clustered B-Tree Index Use Clustered B-Tree Index Reserves Reserves Sailors Sailors

  2. psname p sname B. s rating = 5 sid = sid File Scan File Scan Reserves Salesperson 2) What is the lowest cost query plan for the query: SELECT S.sname FROM Sailors S, Reserves R WHERE S.sid = R.sid AND S.rating = “5”? (You have 10 buffers of memory) A. p sname C. Block Nested Loop Join Sort-merge Join sid = sid sid = sid s rating =5 File Scan s rating=5 File Scan Use Clustered B-Tree Index Use Clustered B-Tree Index Reserves Reserves Sailors Sailors • Solution: • Steps: • B-tree Index for rating =5, cost 2-3 IOs, + access all matching tuples, which are 10% of Sailor’s 500 pages, which is 50. • Sort-merge join, cost about 3*(M+N) = 3*(50 + 1000) = 3150 • Project sname done on the fly, no additional IO cost • B. Steps • No join algorithm specified, lets use sort-merge, for 3*(500 + 1000) = 4500 • Selection, projection done on the fly, no additional IO • C. Steps • Select rating = 5, cost same as in plan A, 53 IOs • Blocked nested loops join is M + ceiling(M/B-1)*N = 50 + ceiling(50/9)*1000 = 50 + 6*1000 = 6050 • Projection done on the fly, no additional IO cost

More Related