alexander.behm | 8a3e3c0 | 2012-11-21 07:27:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Description : Equi joins two datasets, FacebookUsers and FacebookMessages, based on their user's id. |
| 3 | * We first expect FacebookUsers' primary index to be used |
| 4 | * to satisfy the range condition on it's primary key. |
| 5 | * FacebookMessages has a secondary btree index on author-id-copy, and given the 'indexnl' hint |
| 6 | * we expect the join to be transformed into an indexed nested-loop join. |
| 7 | * Success : Yes |
| 8 | */ |
| 9 | |
| 10 | drop dataverse test if exists; |
| 11 | create dataverse test; |
| 12 | use dataverse test; |
| 13 | |
| 14 | create type EmploymentType as closed { |
| 15 | organization-name: string, |
| 16 | start-date: date, |
| 17 | end-date: date? |
| 18 | } |
| 19 | |
| 20 | create type FacebookUserType as closed { |
| 21 | id: int32, |
| 22 | id-copy: int32, |
| 23 | alias: string, |
| 24 | name: string, |
| 25 | user-since: datetime, |
| 26 | user-since-copy: datetime, |
| 27 | friend-ids: {{ int32 }}, |
| 28 | employment: [EmploymentType] |
| 29 | } |
| 30 | |
| 31 | create type FacebookMessageType as closed { |
| 32 | message-id: int32, |
| 33 | message-id-copy: int32, |
| 34 | author-id: int32, |
| 35 | author-id-copy: int32, |
| 36 | in-response-to: int32?, |
| 37 | sender-location: point?, |
| 38 | message: string |
| 39 | } |
| 40 | |
| 41 | create dataset FacebookUsers(FacebookUserType) |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 42 | primary key id; |
alexander.behm | 8a3e3c0 | 2012-11-21 07:27:47 +0000 | [diff] [blame] | 43 | |
| 44 | create dataset FacebookMessages(FacebookMessageType) |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 45 | primary key message-id; |
alexander.behm | 8a3e3c0 | 2012-11-21 07:27:47 +0000 | [diff] [blame] | 46 | |
| 47 | create index fbmIdxAutId if not exists on FacebookMessages(author-id-copy); |
| 48 | |
| 49 | write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multiindex.adm"; |
| 50 | |
| 51 | for $user in dataset('FacebookUsers') |
| 52 | for $message in dataset('FacebookMessages') |
| 53 | where $user.id /*+ indexnl */ = $message.author-id-copy |
| 54 | and $user.id >= 11000 and $user.id <= 12000 |
| 55 | return { |
| 56 | "fbu-ID": $user.id, |
| 57 | "fbm-auth-ID": $message.author-id, |
| 58 | "uname": $user.name, |
| 59 | "message": $message.message |
| 60 | } |