evaluating relational operators part ii
play

Evaluating Relational Operators: Part II From Chapter 14 - PDF document

Evaluating Relational Operators: Part II From Chapter 14


  1. Evaluating Relational Operators: Part II From Chapter 14 �������������������������������������������� ������������������� Relational Operators � Select � Project � Join � Set operations (union, intersect, except) � Aggregation �������������������������������������������� ������������������� Example SELECT * Reserves R, Sailor S, FROM WHERE R.sid = S.sid � No indices on Sailor or Reserves �������������������������������������������� �������������������

  2. Tuple Nested Loop Join ������� ����� ��������� ������� ����� ��������� �������� �������� �������������� ���������� � R is “outer” relation � S is “inner” relation �������������������������������������������� ������������������� Analysis � Assume � M pages in R, p R tuples per page � M = 1000, p R = 100 � N pages in S, p S tuples per page � N = 500, p S = 80 � Total cost = ___________ � #��������������$����������������� � �������������%����������� � ������������!������������"������� �������� �������������������������������������������� ������������������� Page Nested Loops Join ������� ������&�������� ������� ������'�������� ������� ������&��� ������� ������'������������� �������� �������� �������������� ���������� � R is “outer” relation � S is “inner” relation �������������������������������������������� �������������������

  3. Analysis � Assume � M pages in R, p R tuples per page � M = 1000, p R = 100 � N pages in S, p S tuples per page � N = 500, p S = 80 � Total cost = _________ � (���!�))))))))��������������������*�����+ � ,����������))�������*�����+ ������������- � ������������!������������������������������ �������������������������������������������� ������������������� Block Nested Loops Join � Use one page as an input buffer for scanning the inner S, one page as the output buffer, and use all remaining pages to hold ``block ’’ of outer R. � For each matching tuple r in R-block, s in S-page, add <r, s> to result. Then read next R-block, scan S, etc. ��.�� ����������� Hash table for block of R (k < B-1 pages) ����� ����� ����� Input buffer for S Output buffer �������������������������������������������� ������������������� Analysis � Assume � M pages in R, p R tuples per page � M = 1000, p R = 100 � N pages in S, p S tuples per page � N = 500, p S = 80 � BS is the block size � Total cost = __________ � With sequential reads , analysis changes: may be best to divide buffers evenly between R and S. �������������������������������������������� �������������������

  4. Example SELECT * Reserves R, Sailor S, FROM WHERE R.sid = S.sid � No indices on Sailor or Reserves �������������������������������������������� ������������������� Sort-Merge Join � Sort R on the join attributes � Sort S on the join attributes � Merge sorted relations to produce join result � Advance r in R until r.sid >= s.sid � Advance s in S until s.sid >= r.sid � If r.sid = s.sid � All R tuples with same value as r.sid is current R group � All S tuples with same value as s.sid is current S group � Output all <rg, sg> pairs, where rg is in current R group, sg is in current S group � Repeat �������������������������������������������� ������������������� Example of Sort-Merge Join sid bid day rname sid sname rating age 28 103 12/4/96 guppy 22 dustin 7 45.0 28 103 11/3/96 yuppy 28 yuppy 9 35.0 31 101 10/10/96 dustin 31 lubber 8 55.5 31 102 10/12/96 lubber 44 guppy 5 35.0 31 101 10/11/96 lubber 58 rusty 10 35.0 58 103 11/12/96 dustin �������������������������������������������� �������������������

  5. Analysis � Assume � M pages in R, p R tuples per page � M = 1000, p R = 100 � N pages in S, p S tuples per page � N = 500, p S = 80 � Total cost = � Note: (M + N) could be (M * N) in worst case � With 300 buffer pages, R and S sorted in __ passes � Sort-merge join cost: ________ � BNL join cost: _______ �������������������������������������������� ������������������� Refinement of Sort-Merge Join � We can combine the merging phases in the sorting of R and S with the merging required for the join. ������� M/2B Runs of R ����� ������� ����� ����� ������ N/2B Runs ��������� of S ���� ���� ��������������������� � ��/��������!��0',�1�(0',����,�2 & �������������������������������������������� ������������������� Analysis � Assume � M pages in R, p R tuples per page � M = 1000, p R = 100 � N pages in S, p S tuples per page Select � N = 500, p S = 80 � Total cost = __________ � 3�����&!�)))))))))))� � 3�����'!�))))))))))) �������������������������������������������� �������������������

  6. Example SELECT * Reserves R, Sailor S, FROM WHERE R.sid = S.sid � No indices on Sailor or Reserves �������������������������������������������� ������������������� Original Hash-Join Relation OUTPUT Partitions 1 1 � Partition both 2 INPUT 2 relations using hash hash ����� function fn h : R tuples in h B-1 partition i will only B-1 match S tuples in Disk B main memory buffers Disk partition i. Partitions Join Result of R & S Hash table for partition � �������������������� Ri (k < B-1 pages) hash �������������������� fn h2 ���������� ������� ������������������� h2 ����������������� Input buffer Output for Si buffer �������� B main memory buffers Disk Disk �������������������������������������������� ������������������� Analysis (without recursive partitioning) � Assume � M pages in R, p R tuples per page � M = 1000, p R = 100 � N pages in S, p S tuples per page � N = 500, p S = 80 � Total cost = __________ � 3�����&!�)))))))))) � 3�����'!�)))))))))) � ��/��������!��04,�2 &5����,�2 ' �������������������������������������������� �������������������

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend