alexander.behm | 8a3e3c0 | 2012-11-21 07:27:47 +0000 | [diff] [blame] | 1 | /* |
Ian Maxon | 857dc13 | 2015-09-25 17:13:19 -0700 | [diff] [blame] | 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | /* |
alexander.behm | 8a3e3c0 | 2012-11-21 07:27:47 +0000 | [diff] [blame] | 20 | * Description : Equi joins two datasets, FacebookUsers and FacebookMessages, based on their user's id. |
| 21 | * We first expect FacebookUsers' primary index to be used |
| 22 | * to satisfy the range condition on it's primary key. |
| 23 | * FacebookMessages has a secondary btree index on author-id-copy, and given the 'indexnl' hint |
| 24 | * we expect the join to be transformed into an indexed nested-loop join. |
| 25 | * Success : Yes |
| 26 | */ |
| 27 | |
| 28 | drop dataverse test if exists; |
| 29 | create dataverse test; |
| 30 | use dataverse test; |
| 31 | |
| 32 | create type EmploymentType as closed { |
| 33 | organization-name: string, |
| 34 | start-date: date, |
| 35 | end-date: date? |
| 36 | } |
| 37 | |
| 38 | create type FacebookUserType as closed { |
| 39 | id: int32, |
| 40 | id-copy: int32, |
| 41 | alias: string, |
| 42 | name: string, |
| 43 | user-since: datetime, |
| 44 | user-since-copy: datetime, |
| 45 | friend-ids: {{ int32 }}, |
| 46 | employment: [EmploymentType] |
| 47 | } |
| 48 | |
| 49 | create type FacebookMessageType as closed { |
| 50 | message-id: int32, |
| 51 | message-id-copy: int32, |
| 52 | author-id: int32, |
| 53 | author-id-copy: int32, |
| 54 | in-response-to: int32?, |
| 55 | sender-location: point?, |
| 56 | message: string |
| 57 | } |
| 58 | |
| 59 | create dataset FacebookUsers(FacebookUserType) |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 60 | primary key id; |
alexander.behm | 8a3e3c0 | 2012-11-21 07:27:47 +0000 | [diff] [blame] | 61 | |
| 62 | create dataset FacebookMessages(FacebookMessageType) |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 63 | primary key message-id; |
alexander.behm | 8a3e3c0 | 2012-11-21 07:27:47 +0000 | [diff] [blame] | 64 | |
| 65 | create index fbmIdxAutId if not exists on FacebookMessages(author-id-copy); |
| 66 | |
| 67 | write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multiindex.adm"; |
| 68 | |
| 69 | for $user in dataset('FacebookUsers') |
| 70 | for $message in dataset('FacebookMessages') |
| 71 | where $user.id /*+ indexnl */ = $message.author-id-copy |
| 72 | and $user.id >= 11000 and $user.id <= 12000 |
| 73 | return { |
| 74 | "fbu-ID": $user.id, |
| 75 | "fbm-auth-ID": $message.author-id, |
| 76 | "uname": $user.name, |
| 77 | "message": $message.message |
| 78 | } |