Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review Jun 5th, 2002. HW#5.2 TableTupleTuple/pagePage R10000101000 S200010200 R R.a = S.b S (52buffers)

Similar presentations


Presentation on theme: "Review Jun 5th, 2002. HW#5.2 TableTupleTuple/pagePage R10000101000 S200010200 R R.a = S.b S (52buffers)"— Presentation transcript:

1 Review Jun 5th, 2002

2 HW#5.2 TableTupleTuple/pagePage R10000101000 S200010200 R R.a = S.b S (52buffers)

3 Page-Oriented Nested Loop Join For each page in the outer relation R, we scan the entire inner relation S. –Cost: M + M * N __________________... R & S Input buffer for S Output buffer... Join Result Input buffer for R

4 Nested Join v.s. Index Join Simple Nested Join –Cost: M + ( P R *M ) * N _______________________ Page-oriented Simple Nested Join –Cost: M + M * N _______________________ Index Join (Unclustered) –Cost: M + ( P R *M ) * (1.2 + 1) _______________________ When is Nested Join better than Index Join? _______________________

5 Blocked Nested Loop Join For each matching tuple r in R-block, s in S- page, add to result. Then read next R- block, scan S, etc. –Cost: M + ( M / (B-2) ) * N ____________________... R & S Input buffer for R ( k < B-1 pages) Input buffer for S Output buffer... Join Result

6 Hash-Join Partition both relations using hash fn h1: R tuples in partition i will only match S tuples in partition i. __________ Read in a partition of R, hash it using h2 (<> h1). Scan matching partition of S, search for matches. ________ Partitions of R & S Input buffer for Si Hash table for partition Ri (k < B-1 pages) B main memory buffers Disk Output buffer Disk Join Result hash fn h2 B main memory buffers Disk Original Relation OUTPUT 2 INPUT 1 hash function h1 B-1 Partitions 1 2 B-1...

7 Blocked Join v.s. Hash-Join Blocked Join –Cost: M + ( M / (B-2) ) * N ___________________ Hash Join –Cost: 3 * ( M + N ) ___________________ When is Blocked Join better than Hash Join? ___________________

8 Sort-Join Sorting both relations using Multi-way sort: ________ Read in each intermediate result of R and S, search for matches. ________ Partitions of R & S Disk Join Result Disk Original Relation Partitions (B-1) pages 1 2 M_ B-1... B main memory buffers INPUT 2 OUTPUT 1 Multi sorting B-1 B main memory buffers INPUT _ M_ B-1 OUTPUT 1 Merge Join _ N_ B-1 1

9 Sort-Merge Join v.s. Hash-Join Sort-Merge needs more buffer space –Sort-Merge Join Cost: 3 * ( M + N ) Buffer Size: ________________ –Hash Join Cost: 3 * ( M + N ) Buffer Size: ________________ Sort-Merge join is less sensitive to data skew Result of Sort-Merge join is sorted

10 HW#5.4 SQL Transformation SELECT DISTINCT F.FirstName, F.LastName FROM GradStudents AS G, Faculty AS F, Advise AS A WHERE G.LoginID = A.Student AND F.LoginID = A.Advisor AND G.Office = '224'; GradStudents: 157 tuples (20 distinct values for Office, uniform distribution) Faculty: 53 tuplesAdvise: 87 tuples

11 HW#5.4 SQL Transformation SELECT EntryYear, count(*) FROM GradStudents WHERE FirstName = 'David' GROUP BY EntryYear HAVING EntryYear >= 1995 ORDER BY EntryYear DESC SELECT EntryYear, COUNT(*) FROM GradStudents WHERE FirstName = 'David' GROUP BY EntryYear HAVING COUNT(*) >= 10 ORDER BY EntryYear DESC

12 HW#5.4 SQL Transformation SELECT FirstName FROM Faculty WHERE FirstName IN ( SELECT FirstName FROM GradStudents ) SELECT FirstName FROM Faculty WHERE FirstName NOT IN ( SELECT FirstName FROM gradStudents )

13 HW#5.4 SQL Transformation SELECT LoginID FROM UndergradStudents WHERE EntryYear >= ANY ( SELECT EntryYear FROM GradStudents) SELECT LoginID FROM UndergradStudents WHERE EntryYear >= ALL ( SELECT EntryYear FROM GradStudents)

14 HW#4.1 XML & XQuery Which products are sold at least in one store? What are the product-store pairs whose markup is no lower than 15%? Which stores sell some products with a price higher than 50? Which products (except “gizmo”) are sold in some store that also sells the product “gizmo”?

15 HW#4.1 XML & XQuery Returns the names and prices of all products that are sold in all stores with a markup of 25%. Returns the names and prices of all products that are sold at least at one store with a markup of 25%

16 HW#4.1 XML & XQuery { FOR $p IN documents(“database.xml”)//products/row RETURN {$p/name/text()} {$p/price/text()} {$p/description/text()} {FOR $x IN documents(“database.xml”)//sells/row[pid = $p/pid] FOR $s IN documents(“database.xml”)//stores/row[sid = $x/sid] RETURN {$s/name/text()} {$s/phone/text()} {$x/markup/text)()} }

17 Midterm 1

18 Company (DeptID, Name, Budget, CEOEmployID, CEOContratID, Since) Work-in (EmployID, Lot, DeptID, Name, Budget, CEOEmployID, Since)

19 HW#5.1 B+ Tree

20 B+ Tree – Insert 70

21 B+ Tree – Insert 155

22 B+ Tree – Insert 165

23 B+ Tree – Delete 10

24 B+ Tree – Delete 8


Download ppt "Review Jun 5th, 2002. HW#5.2 TableTupleTuple/pagePage R10000101000 S200010200 R R.a = S.b S (52buffers)"

Similar presentations


Ads by Google