|< < 30 > >|

Rearranging Relational Algebra Expressions

Comparison: Optimizing high-level vs. low-level language

We rely on the mathematical properties of relational algebra operators to do this transformation:

Before After
project( select( join(Artist, Album), name == 'The Detroit Cobras') [title]) project( join( select(Artist, name == 'The Detroit Cobras'), Album), [title])

Compare to this low-level query, which also does a join and a select

From lecture 01:

tweets = {} // map from date to int // Clear count for each date for each date between '2016/03/01' and today: tweets[date] = 0 // How many accounts started on 3/1/16? Record tweets by date for each. accounts = 0 for each account in allAccounts: if account.created == '2016/03/01': accounts += 1 for each tweet in account.tweets: tweets[date(tweet.timestamp)] += 1 // Print results, sorted by date for each date between '2016/03/01' and today: averageTweets = tweets[date] / accounts print date, averageTweets

|< < 30 > >|