# Prob.1 CSE 255 Query Optimization Problem  CustomerName (  BranchName=‘Storrs’^ Balance > 1000 ( Branch x Account x Depositor))  Consider the Three.

## Presentation on theme: "Prob.1 CSE 255 Query Optimization Problem  CustomerName (  BranchName=‘Storrs’^ Balance > 1000 ( Branch x Account x Depositor))  Consider the Three."— Presentation transcript:

prob.1 CSE 255 Query Optimization Problem  CustomerName (  BranchName=‘Storrs’^ Balance > 1000 ( Branch x Account x Depositor))  Consider the Three Relations: Branch (BranchName, BranchCity, Assets) Account(AccountNumber, BranchName, Balance) Depositor(CustomerName, AccountNumber)  Optimize the following Relational Express by  Drawing the Initial Expression Tree  Optimizing (Rewriting) the Tree  The Query Finds all Customers who have Accounts at the Storrs Branch with Balance > 1000

prob.2 CSE 255 Depositor BranchAccount   CustomerName BranchName = Storrs ^ Balance > 1000 X X Create the Initial Query Tree

prob.3 CSE 255 Algorithm 2  Algorithm 2 Problem  Apply Algorithm 2 to the Schedule of Transactions on the next Slide  In this Case, Wlock Implies Reading  For this Problem:  Draw the Precedence Graph  Check to See if the Schedule is Serializable  If So, Determine ALL Serial Schedules

prob.4 CSE 255 Algorithm 2: Read/Write Lock Model  Input: Schedule S for Transactions T 1, T 2, … T k  Output: Is S Serializable? If so, Serial Schedule  Method: Create a Directed Precedence Graph G:  Suppose in S, T i :Rlock A. If T j : Wlock A is the Next Transaction to Wlock A (if it exists) then place an Arc from T i to T j. Repeat for all T i ’s. Note for all Rlocks before the Wlock on A!  Suppose in S, T i :Wlock A. If T j : Wlock A is the Next Transaction to Wlock A (if it exists) then place an Arc from T i to T j. Further, if there exists T m :Rlock A after T i :Wlock A but before T j : Wlock A, then Draw an Arc from T i to T m.  Review the Resulting Precedence Graph  If G has Cycles - Non-Serializable  If G is Acyclic - Topological Sort for Serial Schedule

prob.5 CSE 255 Apply Algorithm 2 to Following Schedule T 1 T 2 T 3 T 4 (1) Rlock A (2)Rlock A (3)Wlock C (4) Unlock C (5)Rlock C (6) Wlock B (7)Unlock B (8)Rlock B (9)Unlock A (10)Unlock A (11)Wlock A (12)Rlock C (13)Wlock D (14)Unlock B (15)Unlock C (16)Rlock B (17)Unlock A (18)Wlock A (19)Unlock B (20)Wlock B (21)Unlock B (22)Unlock D (23)Unlock C (24)Unlock A

prob.6 CSE 255 Algorithm 3  Input: Schedule S for Transactions T 1, T 2, … T k  Output: Is S Serializable? If so, Serial Schedule  Method: Create a Directed Polygraph Graph P:  1. Augment S with Dummy T o (Write Every Item) an Dummy T f (Read Every Item)  2. Create Initial Polygraph P by Adding Nodes for T o, T f, and Each T i Transaction, in S  3. Place an Arc from T i to T j Whenever T j Reads A in Augmented S (with Dummy States) that was Last Written by T i. Repeat this Step for all Arcs. Don’t Forget to Consider Dummy States!  4. Discover Useless Transactions - T is Useless if there is no Path from T to T f  This is the “Initialization” Phase of Algorithm 3

prob.7 CSE 255 Algorithm 3  Method: Reassess the Initial Polygraph P:  5. For Each Remaining Arc T i to T j (meaning that T j Reads Item A Written by T i ), Consider all other T  T o and T  T f that Also Writes A:  If T i = T o and T j = T f then Add No Arcs  If T i = T o and T j  T f then Add Arc from T j to T  If T i  T o and T j = T f then Add Arc from T to T i  If T i  T o and T j  T f then Add Arc Pair from T to T i and T j to T  6. Determine if P is Acyclic by “Choosing” One Transaction Arc for Each Pair - Make Choices Carefully  7. If Acyclic - Serializable - Perform Topological Sort without T o, T f for Equivalent Serial Schedule. Else - Not Serializable

prob.8 CSE 255 Apply Algorithm 3 to Following Schedule T 1 T 2 T 3 T 4 (T 0 ) Write A, B (1) Wlock A (2)Rlock B (3)Unlock A (4) Rlock A (5)Unlock B (6) Wlock B (7)Rlock A (8)Unlock B (9)Wlock B (10)Unlock A (11)Unlock A (12)Wlock A (13)Unlock B (14)Rlock B (15)Unlock A (16)Unlock B (T F ) Read A, B

prob.9 CSE 255 Algorithm 4: Optimistic CC  Let T be a Transaction with Timestamp t Attempting to Perform Operation X on a Data Item I with Readtime t R and Writetime t W  If (X = Read and t  t W ) or (X = Write and t  t R ) then Perform Operation  If t > t R then set t R = t for Data Item I  If t > t W then set t W = t for Data Item I  If (X = Write and t R  t < t W ) the Do Nothing since Later Write will Cancel out the Write of T  If (X = Read and t < t W ) or (X = Write and t < t R ) then Abort the Operation  1st - T trying to Read Item Before it was Written  2nd - T trying to Write an Item Before it was Read

prob.10 CSE 255 Algorithm 4  Algorithm 4 Problem  Apply Algorithm 4 to the Schedule of Transactions on the next Slide  Assume the Following Transaction Times  T 1 = 175, T 2 = 150, T 3 = 200, T 4 = 225  Determine the RT and WT for A, B, C, and D at each Step  Indicate when a Transaction Aborts or has No Effect  Remember, RT=WT=0 for A, B, C, and D Prior to the 1st Step in the Schedule

prob.11 CSE 255 T 1 =175T 2 =150 T 3 =200 T 4 =225 A B C D (1) Read A (2)Read A (3)Write C (4) Read C (5) Write B (6) Read B (7) Write A (8) Read C (9)Write D (10)Read B (11) Write A (12) Write B Algorithm 4 Problem Initially RT/WT of A, B, C, and D are all Zero (0)

Download ppt "Prob.1 CSE 255 Query Optimization Problem  CustomerName (  BranchName=‘Storrs’^ Balance > 1000 ( Branch x Account x Depositor))  Consider the Three."

Similar presentations