simlaudato / asterixdb

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

Use an index for comparing datetime to current-datetime() #930

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Using the following DDL:

drop dataverse emergencyTest if exists;
create dataverse emergencyTest;
use dataverse emergencyTest;
create type CHPReport as {
    "id":int,
    "timestamp":datetime
}
create dataset CHPReports(CHPReport)
primary key timestamp;

This query will use an index search:
for $emergency in dataset CHPReports
where $emergency.timestamp >= datetime("2012-08-07T10:10:00.000Z")
return $emergency.message;

Whereas this will do a data scan:
for $emergency in dataset CHPReports
where $emergency.timestamp >= current-datetime()
return $emergency.message;

Both are build on BTREEs so both should be optimized to an index search. It 
seems like there should be a way to use the index when comparing to 
current-datetime, Although I suspect the solution is nontrivial because of the 
way that current-datetime is currently working.

Here are the plans, respectively:

distribute result [%0->$$5]
-- DISTRIBUTE_RESULT  |PARTITIONED|
  exchange 
  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
    project ([$$5])
    -- STREAM_PROJECT  |PARTITIONED|
      assign [$$5] <- [function-call: asterix:field-access-by-name, Args:[%0->$$0, AString: {message}]]
      -- ASSIGN  |PARTITIONED|
        project ([$$0])
        -- STREAM_PROJECT  |PARTITIONED|
          exchange 
          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
            unnest-map [$$6, $$0] <- function-call: asterix:index-search, Args:[AString: {CHPReports}, AInt32: {0}, AString: {emergencyTest}, AString: {CHPReports}, ABoolean: {false}, ABoolean: {false}, ABoolean: {false}, AInt32: {1}, %0->$$8, AInt32: {0}, TRUE, TRUE, FALSE]
            -- BTREE_SEARCH  |PARTITIONED|
              exchange 
              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                assign [$$8] <- [ADateTime: { 2012-08-07T10:10:00.000Z }]
                -- ASSIGN  |PARTITIONED|
                  empty-tuple-source
                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|

distribute result [%0->$$5]
-- DISTRIBUTE_RESULT  |PARTITIONED|
  exchange 
  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
    project ([$$5])
    -- STREAM_PROJECT  |PARTITIONED|
      assign [$$5] <- [function-call: asterix:field-access-by-name, Args:[%0->$$0, AString: {message}]]
      -- ASSIGN  |PARTITIONED|
        project ([$$0])
        -- STREAM_PROJECT  |PARTITIONED|
          select (function-call: algebricks:ge, Args:[%0->$$6, function-call: asterix:current-datetime, Args:[]])
          -- STREAM_SELECT  |PARTITIONED|
            exchange 
            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
              data-scan []<-[$$6, $$0] <- emergencyTest:CHPReports
              -- DATASOURCE_SCAN  |PARTITIONED|
                exchange 
                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                  empty-tuple-source
                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|

Original issue reported on code.google.com by sjaco...@ucr.edu on 11 Aug 2015 at 8:40

GoogleCodeExporter commented 8 years ago

Original comment by sjaco...@ucr.edu on 12 Aug 2015 at 12:07