Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This optimization tries to intersect multiple secondary indexes if the select conditions introduce them. Previously, as in the IntroduceSelectAccessMethodRule, we would pick the first index to contribute to the access path when there were multiple indexes available. Due to the lack of statistical information, the first one may not be the best choice. Moreover, even we chose the index of the lowest selectivity, it still may not be the best solution. Because we can further reduce the selectivity by intersecting it with the other secondary indexes. Having intersection into the plan will avoid the worst path. Furthermore, if we have statistical information later we can have another option to take into consideration.

Optimization Rule

The logical changes are in the IntroduceSelectAccessMethodRule. After we analyzed the interesting functions and indexes, we pair them up as one to one mapping. (E.g. BTreeAccessMethod -> BTreeIndex On Salary.).

...

-- DISTRIBUTE_RESULT  |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- STREAM_PROJECT |PARTITIONED|
-- STREAM_SELECT |PARTITIONED|
-- ASSIGN |PARTITIONED|
-- STREAM_PROJECT |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- BTREE_SEARCH |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- INTERSECT |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- STABLE_SORT [$$29(ASC)] |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- STREAM_PROJECT |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- BTREE_SEARCH |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- ASSIGN |PARTITIONED|
-- EMPTY_TUPLE_SOURCE |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- STABLE_SORT [$$31(ASC)] |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- STREAM_PROJECT |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- ASSIGN |PARTITIONED|
-- EMPTY_TUPLE_SOURCE |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- STABLE_SORT [$$40(ASC)] |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- STREAM_PROJECT |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- RTREE_SEARCH |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- ASSIGN |PARTITIONED|
-- EMPTY_TUPLE_SOURCE |PARTITIONED|

 

Hyracks Operator Implementation

Physically, each ETS node will introduce a thread. Thus, the intersection operator must synchronize the upstream input threads in order to generate the correct result. In order to have a pipeline operate, the intersection is implemented as a sort-merge manner. Therefore, each input is required to be sorted. The synchronization is handled by the thread of input zero, which means the thread 0 will call the writer.open/nextFrame/close functions. If we authorize arbitrary threads to do such task, the downstream operator will be confused to synchronize on their locks. The core logical intersection function is as below:

...

If any of the input is fully consumed, the operator is closed.

Experiment Evaluation

We did two group of experiments. The first one used a small dataset to test the intersection performance if everything is cached in memory. The second one used a large dataset to test the scenario of loading most of the work from the disk.

Dataset: Two real Twitter datasets. The smaller one is one million records of size 800M, The larger one is ten million record of size 8.2G.

Machine: 4 Cpu, 4G Memory, One disk.

Asterix Instance: 1CC, 2NC, 1 partition per NC.

...

The query selects on the tweet.create_at and the user.create_at.

Each test will run three times:

  • 1st. with BTree index on Tweet.create_at only, 
  • 2nd. with BTree index on User.create_at only, 
  • 3rd. with

...

  • both indexes presents, consequently,

...

  • the intersection is introduced.

In Memory

...

case:

Each query will run ten times. We record the time by average the last fives. 

Table 1. Fix the User.create_at $month_start = 01, $month_end = 02, increasing the Tweets.create_at selectivity

   ScanUserCreateAtIndexTweetCreateAt IndexIntersectionReduction
resultmonthminutesTime (Avg last 5)    
43101--0200-099291421325260.61%
92801--0200-199291432265660.84%
145801--0200-299341443287349.31%
199701--0200-399321434278044.06%
250401--0200-499301425289235.21%
298901--0200-5993314163110922.70%

Table 2. Fix the Tweet.create_at $min_start = 00, $min_end = 09, increasing the User.create_at selectivity

   ScanUserCreateAtIndexTweetCreateAt IndexIntersectionReduction
resultmonthminutesTime (Avg last 5)    
43101--0200-099291421325260.61%
67001--0300-099321891294862.79%
92901--0400-099282401246150.81%
114001--0500-099312911286946.09%
147101--0600-099333671266548.41%
185901--0700-099324491258432.80%
216601--0800-099315251268730.95%
243801--0900-099325801279425.98%
268201--1000-0993964812710418.11%
301101--1100-0993471012511012.00%
334601--1200-099337811271205.51%

Table 3. Both Tweet.create_at and User.create_at increasing the selectivity

   ScanUserCreateAtIndexTweetCreateAt IndexIntersectionReduction
resultmonthminutesTime (Avg last 5)    
43101--0200-099291421325260.61%
142901--0300-199331902286764.74%
194501--0400-199332392266770.35%
368601--0500-299342943228371.77%
481601--0600-2993637032410268.52%
832001--0700-3993145342512371.06%
1220201--0800-4993252252914672.03%
1379101--0900-4993458252715770.21%
1848901--1000-5993764463019169.68%

We can see that intersection is the best one under current settings. The total time reduction is from 5% to 70%. If the two indexes are vary a lot in the selectivity, then the benefit of intersection may not that much. If the two indexes are of the samilar selectivity the intersection can achieve 60% ~ 70% total time reduction.

On disk case

The test dataset is changing to the 8.2G dataset. In order to flush the cache, we load the same dataset to another ds_copy dataset. Every time when we run the selection, we scan this 8.2G ds_copy once to invalidate the cache pages. Due to the slowness of the on disk case, we warm up the query once and record the average time of the next three times.

 

Review Patch: 

https://asterix-gerrit.ics.uci.edu/#/c/577  and  https://asterix-gerrit.ics.uci.edu/#/c/578

...