shamim8888 / asterixdb

Automatically exported from code.google.com/p/asterixdb
0 stars 0 forks source link

CancelUnnestWithNestedListifyRule eliminates an assign to a variable that is used upstream #847

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Query:
drop dataverse channels if exists;
create dataverse channels;
use dataverse channels;

//subscriptions
create type TweetHistorySubscription as open{
    subscription-id: int32,
    location: point
}

create type TweetMessageType as closed {
    tweetid: int64,
    sender-location: point
}

//Subscription datasets
create dataset TweetHistorySubscriptions(TweetHistorySubscription)
primary key subscription-id;

create index testa on TweetHistorySubscriptions(location) type rtree;

create dataset TweetMessages(TweetMessageType)
primary key tweetid;

create index locationIdx on TweetMessages(sender-location) type rtree;

create function NearbyTweets($location) {
  for $tweet in dataset TweetMessages
    where spatial-intersect($tweet.sender-location, $location)
    return $tweet.message-text 
};

for $sub in dataset TweetHistorySubscriptions
for $result in NearbyTweets($sub.location)
return {
    "subscription-id":$sub.subscription-id,
    "changeSet":1,
    "execution-time":current-datetime(),
    "message-text":$result
}

Here is the bad firing of the rule:
Variable $$6 is needed in the record constructor for the result, but its source 
($$18) is obliterated by the rule:

FINE: >>>> Before plan
distribute result [%0->$$20] -- |UNPARTITIONED|
  project ([$$20]) -- |UNPARTITIONED|
    assign [$$20] <- [function-call: asterix:open-record-constructor, Args:[AString: {subscription-id}, function-call: asterix:field-access-by-name, Args:[%0->$$5, AString: {subscription-id}], AString: {changeSet}, AInt32: {1}, AString: {execution-time}, ADateTime: { 2015-01-07T20:18:05.512Z }, AString: {message-text}, %0->$$6]] -- |UNPARTITIONED|
      unnest $$6 <- function-call: asterix:scan-collection, Args:[%0->$$19] -- |UNPARTITIONED|
        group by ([$$23 := %0->$$26]) decor ([%0->$$5; %0->$$7; %0->$$10]) {
                  aggregate [$$19] <- [function-call: asterix:listify, Args:[%0->$$18]] -- |UNPARTITIONED|
                    assign [$$18] <- [function-call: asterix:field-access-by-name, Args:[%0->$$9, AString: {message-text}]] -- |UNPARTITIONED|
                      select (function-call: algebricks:not, Args:[function-call: algebricks:is-null, Args:[%0->$$25]]) -- |UNPARTITIONED|
                        nested tuple source -- |UNPARTITIONED|
               } -- |UNPARTITIONED|
          left outer join (function-call: asterix:spatial-intersect, Args:[function-call: asterix:field-access-by-name, Args:[%0->$$9, AString: {sender-location}], %0->$$10]) -- |UNPARTITIONED|
            assign [$$10] <- [function-call: asterix:create-circle, Args:[%0->$$7, ADouble: {30.0}]] -- |UNPARTITIONED|
              assign [$$7] <- [function-call: asterix:field-access-by-name, Args:[%0->$$5, AString: {location}]] -- |UNPARTITIONED|
                data-scan []<-[$$26, $$5] <- channels:TweetHistorySubscriptions -- |UNPARTITIONED|
                  empty-tuple-source -- |UNPARTITIONED|
            assign [$$25] <- [TRUE] -- |UNPARTITIONED|
              data-scan []<-[$$24, $$9] <- twitter:TweetMessageuuids -- |UNPARTITIONED|
                empty-tuple-source -- |UNPARTITIONED|

FINE: >>>> After plan
distribute result [%0->$$20] -- |UNPARTITIONED|
  project ([$$20]) -- |UNPARTITIONED|
    assign [$$20] <- [function-call: asterix:open-record-constructor, Args:[AString: {subscription-id}, function-call: asterix:field-access-by-name, Args:[%0->$$5, AString: {subscription-id}], AString: {changeSet}, AInt32: {1}, AString: {execution-time}, ADateTime: { 2015-01-07T20:18:05.512Z }, AString: {message-text}, %0->$$6]] -- |UNPARTITIONED|
      assign [$$6] <- [%0->$$18] -- |UNPARTITIONED|
        order (ASC, %0->$$26)  -- |UNPARTITIONED|
          assign [$$23] <- [%0->$$26] -- |UNPARTITIONED|
            left outer join (function-call: asterix:spatial-intersect, Args:[function-call: asterix:field-access-by-name, Args:[%0->$$9, AString: {sender-location}], %0->$$10]) -- |UNPARTITIONED|
              assign [$$10] <- [function-call: asterix:create-circle, Args:[%0->$$7, ADouble: {30.0}]] -- |UNPARTITIONED|
                assign [$$7] <- [function-call: asterix:field-access-by-name, Args:[%0->$$5, AString: {location}]] -- |UNPARTITIONED|
                  data-scan []<-[$$26, $$5] <- channels:TweetHistorySubscriptions -- |UNPARTITIONED|
                    empty-tuple-source -- |UNPARTITIONED|
              assign [$$25] <- [TRUE] -- |UNPARTITIONED|
                data-scan []<-[$$24, $$9] <- twitter:TweetMessageuuids -- |UNPARTITIONED|
                  empty-tuple-source -- |UNPARTITIONED|

Original issue reported on code.google.com by sjaco...@ucr.edu on 7 Jan 2015 at 9:47

GoogleCodeExporter commented 9 years ago

Original comment by sjaco...@ucr.edu on 9 Jan 2015 at 7:59

GoogleCodeExporter commented 9 years ago

Original comment by sjaco...@ucr.edu on 3 Feb 2015 at 9:21