LSM Rtree Optimization
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_b b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_b
new file mode 100644
index 0000000..e929192
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_b
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_d b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_d
new file mode 100644
index 0000000..86b254e
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_d
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_f b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_f
new file mode 100644
index 0000000..6d17cf9
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_f
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_i b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_i
new file mode 100644
index 0000000..32a748d
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060025932/device_id_0/2014-03-13-18-00-26-469_2014-03-13-18-00-26-469_i
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_b b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_b
new file mode 100644
index 0000000..62f7c44
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_b
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_d b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_d
new file mode 100644
index 0000000..86b254e
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_d
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_f b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_f
new file mode 100644
index 0000000..6d17cf9
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_f
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_i b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_i
new file mode 100644
index 0000000..409bf7a
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-060029121/device_id_0/2014-03-13-18-00-29-657_2014-03-13-18-00-29-657_i
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_b b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_b
new file mode 100644
index 0000000..e929192
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_b
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_d b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_d
new file mode 100644
index 0000000..86b254e
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_d
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_f b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_f
new file mode 100644
index 0000000..6d17cf9
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_f
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_i b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_i
new file mode 100644
index 0000000..32a748d
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070436429/device_id_0/2014-03-13-19-04-36-989_2014-03-13-19-04-36-989_i
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_b b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_b
new file mode 100644
index 0000000..62f7c44
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_b
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_d b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_d
new file mode 100644
index 0000000..86b254e
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_d
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_f b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_f
new file mode 100644
index 0000000..6d17cf9
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_f
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_i b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_i
new file mode 100644
index 0000000..409bf7a
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-070439620/device_id_0/2014-03-13-19-04-40-195_2014-03-13-19-04-40-195_i
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_b b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_b
new file mode 100644
index 0000000..e929192
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_b
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_d b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_d
new file mode 100644
index 0000000..86b254e
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_d
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_f b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_f
new file mode 100644
index 0000000..6d17cf9
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_f
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_i b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_i
new file mode 100644
index 0000000..32a748d
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105003450/device_id_0/2014-03-13-22-50-03-981_2014-03-13-22-50-03-981_i
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_b b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_b
new file mode 100644
index 0000000..62f7c44
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_b
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_d b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_d
new file mode 100644
index 0000000..86b254e
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_d
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_f b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_f
new file mode 100644
index 0000000..6d17cf9
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_f
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_i b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_i
new file mode 100644
index 0000000..409bf7a
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/invIndexBtree130314-105006534/device_id_0/2014-03-13-22-50-07-110_2014-03-13-22-50-07-110_i
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-060025932/device_id_0 b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-060025932/device_id_0
new file mode 100644
index 0000000..78654fc
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-060025932/device_id_0
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-060029121/device_id_0 b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-060029121/device_id_0
new file mode 100644
index 0000000..78654fc
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-060029121/device_id_0
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-070436429/device_id_0 b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-070436429/device_id_0
new file mode 100644
index 0000000..78654fc
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-070436429/device_id_0
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-070439620/device_id_0 b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-070439620/device_id_0
new file mode 100644
index 0000000..78654fc
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-070439620/device_id_0
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-105003450/device_id_0 b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-105003450/device_id_0
new file mode 100644
index 0000000..78654fc
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-105003450/device_id_0
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-105006534/device_id_0 b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-105006534/device_id_0
new file mode 100644
index 0000000..78654fc
--- /dev/null
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/primaryBtree130314-105006534/device_id_0
Binary files differ
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeOperatorTestHelper.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeOperatorTestHelper.java
index 79b8eb7..e848c7d 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeOperatorTestHelper.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeOperatorTestHelper.java
@@ -45,10 +45,12 @@
 
     public IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] valueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory) {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) {
         return new LSMRTreeDataflowHelperFactory(valueProviderFactories, rtreePolicyType, btreeComparatorFactories,
                 virtualBufferCacheProvider, new ConstantMergePolicyFactory(), MERGE_POLICY_PROPERTIES,
                 ThreadCountingOperationTrackerProvider.INSTANCE, SynchronousSchedulerProvider.INSTANCE,
-                NoOpIOOperationCallback.INSTANCE, linearizerCmpFactory, DEFAULT_BLOOM_FILTER_FALSE_POSITIVE_RATE);
+                NoOpIOOperationCallback.INSTANCE, linearizerCmpFactory, DEFAULT_BLOOM_FILTER_FALSE_POSITIVE_RATE,
+                btreeFields);
     }
 }
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeSecondaryIndexInsertOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeSecondaryIndexInsertOperatorTest.java
index ab6ffdd..8e53269 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeSecondaryIndexInsertOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeSecondaryIndexInsertOperatorTest.java
@@ -26,6 +26,11 @@
 import edu.uci.ics.hyracks.tests.am.rtree.RTreeSecondaryIndexInsertOperatorTest;
 
 public class LSMRTreeSecondaryIndexInsertOperatorTest extends RTreeSecondaryIndexInsertOperatorTest {
+
+    public LSMRTreeSecondaryIndexInsertOperatorTest() {
+        this.rTreeType = RTreeType.LSMRTREE;
+    }
+
     protected ITreeIndexOperatorTestHelper createTestHelper() throws HyracksException {
         return new LSMRTreeOperatorTestHelper(TestStorageManagerComponentHolder.getIOManager());
     }
@@ -33,8 +38,9 @@
     @Override
     protected IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory) {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) {
         return ((LSMRTreeOperatorTestHelper) testHelper).createDataFlowHelperFactory(secondaryValueProviderFactories,
-                rtreePolicyType, btreeComparatorFactories, linearizerCmpFactory);
+                rtreePolicyType, btreeComparatorFactories, linearizerCmpFactory, btreeFields);
     }
 }
\ No newline at end of file
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeSecondaryIndexSearchOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeSecondaryIndexSearchOperatorTest.java
index 591a75d..67691ea 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeSecondaryIndexSearchOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeSecondaryIndexSearchOperatorTest.java
@@ -26,6 +26,10 @@
 import edu.uci.ics.hyracks.tests.am.rtree.RTreeSecondaryIndexSearchOperatorTest;
 
 public class LSMRTreeSecondaryIndexSearchOperatorTest extends RTreeSecondaryIndexSearchOperatorTest {
+    public LSMRTreeSecondaryIndexSearchOperatorTest() {
+        this.rTreeType = RTreeType.LSMRTREE;
+    }
+
     protected ITreeIndexOperatorTestHelper createTestHelper() throws HyracksException {
         return new LSMRTreeOperatorTestHelper(TestStorageManagerComponentHolder.getIOManager());
     }
@@ -33,8 +37,9 @@
     @Override
     protected IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory) {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) {
         return ((LSMRTreeOperatorTestHelper) testHelper).createDataFlowHelperFactory(secondaryValueProviderFactories,
-                rtreePolicyType, btreeComparatorFactories, linearizerCmpFactory);
+                rtreePolicyType, btreeComparatorFactories, linearizerCmpFactory, btreeFields);
     }
 }
\ No newline at end of file
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesSecondaryIndexInsertOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesSecondaryIndexInsertOperatorTest.java
index 29816e3..ddd6e10 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesSecondaryIndexInsertOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesSecondaryIndexInsertOperatorTest.java
@@ -26,6 +26,10 @@
 import edu.uci.ics.hyracks.tests.am.rtree.RTreeSecondaryIndexInsertOperatorTest;
 
 public class LSMRTreeWithAntiMatterTuplesSecondaryIndexInsertOperatorTest extends RTreeSecondaryIndexInsertOperatorTest {
+    public LSMRTreeWithAntiMatterTuplesSecondaryIndexInsertOperatorTest() {
+        this.rTreeType = RTreeType.LSMRTREE_WITH_ANTIMATTER;
+    }
+
     protected ITreeIndexOperatorTestHelper createTestHelper() throws HyracksException {
         return new LSMRTreeWithAntiMatterTuplesOperatorTestHelper(TestStorageManagerComponentHolder.getIOManager());
     }
@@ -33,7 +37,8 @@
     @Override
     protected IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory) {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) {
         return ((LSMRTreeWithAntiMatterTuplesOperatorTestHelper) testHelper).createDataFlowHelperFactory(
                 secondaryValueProviderFactories, rtreePolicyType, btreeComparatorFactories, linearizerCmpFactory);
     }
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesSecondaryIndexSearchOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesSecondaryIndexSearchOperatorTest.java
index 2cf1418..f4fad79 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesSecondaryIndexSearchOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesSecondaryIndexSearchOperatorTest.java
@@ -26,6 +26,10 @@
 import edu.uci.ics.hyracks.tests.am.rtree.RTreeSecondaryIndexSearchOperatorTest;
 
 public class LSMRTreeWithAntiMatterTuplesSecondaryIndexSearchOperatorTest extends RTreeSecondaryIndexSearchOperatorTest {
+    public LSMRTreeWithAntiMatterTuplesSecondaryIndexSearchOperatorTest() {
+            this.rTreeType = RTreeType.LSMRTREE_WITH_ANTIMATTER;
+        }
+    
     protected ITreeIndexOperatorTestHelper createTestHelper() throws HyracksException {
         return new LSMRTreeWithAntiMatterTuplesOperatorTestHelper(TestStorageManagerComponentHolder.getIOManager());
     }
@@ -33,7 +37,8 @@
     @Override
     protected IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory) {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) {
         return ((LSMRTreeWithAntiMatterTuplesOperatorTestHelper) testHelper).createDataFlowHelperFactory(
                 secondaryValueProviderFactories, rtreePolicyType, btreeComparatorFactories, linearizerCmpFactory);
     }
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/AbstractRTreeOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/AbstractRTreeOperatorTest.java
index d1c682c..ee08868 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/AbstractRTreeOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/AbstractRTreeOperatorTest.java
@@ -76,6 +76,14 @@
         TestStorageManagerComponentHolder.init(8192, 20, 20);
     }
 
+    protected enum RTreeType {
+        LSMRTREE,
+        LSMRTREE_WITH_ANTIMATTER,
+        RTREE
+    };
+
+    protected RTreeType rTreeType;
+
     protected final IStorageManagerInterface storageManager = new TestStorageManagerInterface();
     protected final IIndexLifecycleManagerProvider lcManagerProvider = new TestIndexLifecycleManagerProvider();
     protected IIndexDataflowHelperFactory rtreeDataflowHelperFactory;
@@ -111,8 +119,8 @@
 
     // This is only used for the LSMRTree. We need a comparator Factories for
     // the BTree component of the LSMRTree.
-    protected final int btreeKeyFieldCount = 5;
-    protected final IBinaryComparatorFactory[] btreeComparatorFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+    protected int btreeKeyFieldCount = 5;
+    protected IBinaryComparatorFactory[] btreeComparatorFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
 
     protected String secondaryFileName;
     protected IFileSplitProvider secondarySplitProvider;
@@ -159,24 +167,35 @@
         secondaryComparatorFactories[3] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
 
         // This only used for LSMRTree
-        btreeComparatorFactories[0] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeComparatorFactories[1] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeComparatorFactories[2] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeComparatorFactories[3] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeComparatorFactories[4] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+        int[] btreeFields = null;
+        if (rTreeType == RTreeType.LSMRTREE) {
+            btreeKeyFieldCount = 1;
+            btreeComparatorFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeComparatorFactories[0] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+            btreeFields = new int[1];
+            btreeFields[0] = 4;
+
+        } else {
+            btreeComparatorFactories[0] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeComparatorFactories[1] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeComparatorFactories[2] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeComparatorFactories[3] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeComparatorFactories[4] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+        }
 
         IPrimitiveValueProviderFactory[] secondaryValueProviderFactories = RTreeUtils
                 .createPrimitiveValueProviderFactories(secondaryComparatorFactories.length, DoublePointable.FACTORY);
 
         rtreeDataflowHelperFactory = createDataFlowHelperFactory(secondaryValueProviderFactories,
                 RTreePolicyType.RSTARTREE, btreeComparatorFactories,
-                LSMRTreeUtils.proposeBestLinearizer(secondaryTypeTraits, secondaryComparatorFactories.length));
+                LSMRTreeUtils.proposeBestLinearizer(secondaryTypeTraits, secondaryComparatorFactories.length), btreeFields);
 
     }
 
     protected abstract IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory)
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields)
             throws TreeIndexException;
 
     protected void createPrimaryIndex() throws Exception {
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexInsertOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexInsertOperatorTest.java
index a888538..32380de 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexInsertOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexInsertOperatorTest.java
@@ -45,6 +45,10 @@
 
 public class RTreeSecondaryIndexInsertOperatorTest extends AbstractRTreeOperatorTest {
 
+    public RTreeSecondaryIndexInsertOperatorTest() {
+        this.rTreeType = RTreeType.RTREE;
+    }
+
     @Before
     public void setup() throws Exception {
         super.setup();
@@ -118,8 +122,8 @@
     @Override
     protected IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory)
-            throws TreeIndexException {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) throws TreeIndexException {
         return ((RTreeOperatorTestHelper) testHelper).createDataFlowHelperFactory(secondaryValueProviderFactories,
                 rtreePolicyType, null);
     }
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexScanOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexScanOperatorTest.java
index 9ec0f7a..40d9e5b 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexScanOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexScanOperatorTest.java
@@ -43,6 +43,10 @@
 
 public class RTreeSecondaryIndexScanOperatorTest extends AbstractRTreeOperatorTest {
 
+    public RTreeSecondaryIndexScanOperatorTest() {
+        this.rTreeType = RTreeType.RTREE;
+    }
+
     @Before
     public void setup() throws Exception {
         super.setup();
@@ -102,11 +106,12 @@
     @Override
     protected IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory) {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) {
         return ((RTreeOperatorTestHelper) testHelper).createDataFlowHelperFactory(secondaryValueProviderFactories,
                 rtreePolicyType, null);
     }
-    
+
     @Override
     public void cleanup() throws Exception {
         destroyPrimaryIndex();
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexSearchOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexSearchOperatorTest.java
index 9613920d..b6f1000 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexSearchOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexSearchOperatorTest.java
@@ -44,6 +44,9 @@
 import edu.uci.ics.hyracks.storage.am.rtree.frames.RTreePolicyType;
 
 public class RTreeSecondaryIndexSearchOperatorTest extends AbstractRTreeOperatorTest {
+    public RTreeSecondaryIndexSearchOperatorTest() {
+        this.rTreeType = RTreeType.RTREE;
+    }
 
     @Before
     public void setup() throws Exception {
@@ -117,8 +120,8 @@
     @Override
     protected IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory)
-            throws TreeIndexException {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) throws TreeIndexException {
         return ((RTreeOperatorTestHelper) testHelper).createDataFlowHelperFactory(secondaryValueProviderFactories,
                 rtreePolicyType, null);
     }
diff --git a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexStatsOperatorTest.java b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexStatsOperatorTest.java
index ab48d39..438e17d 100644
--- a/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexStatsOperatorTest.java
+++ b/hyracks/hyracks-examples/hyracks-integration-tests/src/test/java/edu/uci/ics/hyracks/tests/am/rtree/RTreeSecondaryIndexStatsOperatorTest.java
@@ -35,6 +35,9 @@
 import edu.uci.ics.hyracks.storage.am.rtree.frames.RTreePolicyType;
 
 public class RTreeSecondaryIndexStatsOperatorTest extends AbstractRTreeOperatorTest {
+    public RTreeSecondaryIndexStatsOperatorTest() {
+        this.rTreeType = RTreeType.RTREE;
+    }
 
     @Before
     public void setup() throws Exception {
@@ -66,7 +69,8 @@
     @Override
     protected IIndexDataflowHelperFactory createDataFlowHelperFactory(
             IPrimitiveValueProviderFactory[] secondaryValueProviderFactories, RTreePolicyType rtreePolicyType,
-            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory) {
+            IBinaryComparatorFactory[] btreeComparatorFactories, ILinearizeComparatorFactory linearizerCmpFactory,
+            int[] btreeFields) {
         return ((RTreeOperatorTestHelper) testHelper).createDataFlowHelperFactory(secondaryValueProviderFactories,
                 rtreePolicyType, null);
     }
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/tuples/DualTupleReference.java b/hyracks/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/tuples/DualTupleReference.java
new file mode 100644
index 0000000..0733216
--- /dev/null
+++ b/hyracks/hyracks-storage-am-common/src/main/java/edu/uci/ics/hyracks/storage/am/common/tuples/DualTupleReference.java
@@ -0,0 +1,42 @@
+package edu.uci.ics.hyracks.storage.am.common.tuples;
+
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.ITupleReference;
+
+public class DualTupleReference implements ITupleReference {
+
+    private PermutingTupleReference permutingTuple;
+    private ITupleReference tuple;
+
+    public DualTupleReference(int[] fieldPermutation) {
+        permutingTuple = new PermutingTupleReference(fieldPermutation);
+    }
+
+    @Override
+    public int getFieldCount() {
+        return tuple.getFieldCount();
+    }
+
+    @Override
+    public byte[] getFieldData(int fIdx) {
+        return tuple.getFieldData(fIdx);
+    }
+
+    @Override
+    public int getFieldStart(int fIdx) {
+        return tuple.getFieldStart(fIdx);
+    }
+
+    @Override
+    public int getFieldLength(int fIdx) {
+        return tuple.getFieldLength(fIdx);
+    }
+
+    public void reset(ITupleReference tuple) {
+        this.tuple = tuple;
+        permutingTuple.reset(tuple);
+    }
+
+    public ITupleReference getPermutingTuple() {
+        return permutingTuple;
+    }
+}
\ No newline at end of file
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/dataflow/LSMRTreeDataflowHelper.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/dataflow/LSMRTreeDataflowHelper.java
index 92364fa..8d6c0da 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/dataflow/LSMRTreeDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/dataflow/LSMRTreeDataflowHelper.java
@@ -39,15 +39,17 @@
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class LSMRTreeDataflowHelper extends AbstractLSMRTreeDataflowHelper {
+    private int[] btreeFields;
 
     public LSMRTreeDataflowHelper(IIndexOperatorDescriptor opDesc, IHyracksTaskContext ctx, int partition,
             List<IVirtualBufferCache> virtualBufferCaches, IBinaryComparatorFactory[] btreeComparatorFactories,
             IPrimitiveValueProviderFactory[] valueProviderFactories, RTreePolicyType rtreePolicyType,
             ILSMMergePolicy mergePolicy, ILSMOperationTrackerProvider opTrackerFactory,
             ILSMIOOperationScheduler ioScheduler, ILSMIOOperationCallbackFactory ioOpCallbackFactory,
-            ILinearizeComparatorFactory linearizeCmpFactory) {
+            ILinearizeComparatorFactory linearizeCmpFactory, int[] btreeFields) {
         super(opDesc, ctx, partition, virtualBufferCaches, btreeComparatorFactories, valueProviderFactories,
                 rtreePolicyType, mergePolicy, opTrackerFactory, ioScheduler, ioOpCallbackFactory, linearizeCmpFactory);
+        this.btreeFields = btreeFields;
     }
 
     public LSMRTreeDataflowHelper(IIndexOperatorDescriptor opDesc, IHyracksTaskContext ctx, int partition,
@@ -56,10 +58,11 @@
             IPrimitiveValueProviderFactory[] valueProviderFactories, RTreePolicyType rtreePolicyType,
             ILSMMergePolicy mergePolicy, ILSMOperationTrackerProvider opTrackerFactory,
             ILSMIOOperationScheduler ioScheduler, ILSMIOOperationCallbackFactory ioOpCallbackFactory,
-            ILinearizeComparatorFactory linearizeCmpFactory) {
+            ILinearizeComparatorFactory linearizeCmpFactory, int[] btreeFields) {
         super(opDesc, ctx, partition, virtualBufferCaches, bloomFilterFalsePositiveRate, btreeComparatorFactories,
                 valueProviderFactories, rtreePolicyType, mergePolicy, opTrackerFactory, ioScheduler,
                 ioOpCallbackFactory, linearizeCmpFactory);
+        this.btreeFields = btreeFields;
     }
 
     @Override
@@ -73,7 +76,7 @@
             return LSMRTreeUtils.createLSMTree(virtualBufferCaches, file, diskBufferCache, diskFileMapProvider,
                     typeTraits, rtreeCmpFactories, btreeCmpFactories, valueProviderFactories, rtreePolicyType,
                     bloomFilterFalsePositiveRate, mergePolicy, opTracker, ioScheduler,
-                    ioOpCallbackFactory.createIOOperationCallback(), linearizeCmpFactory);
+                    ioOpCallbackFactory.createIOOperationCallback(), linearizeCmpFactory, btreeFields);
         } catch (TreeIndexException e) {
             throw new HyracksDataException(e);
         }
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/dataflow/LSMRTreeDataflowHelperFactory.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/dataflow/LSMRTreeDataflowHelperFactory.java
index 7b54f19..beb6c20 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/dataflow/LSMRTreeDataflowHelperFactory.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/dataflow/LSMRTreeDataflowHelperFactory.java
@@ -39,19 +39,21 @@
     private final IPrimitiveValueProviderFactory[] valueProviderFactories;
     private final RTreePolicyType rtreePolicyType;
     private final ILinearizeComparatorFactory linearizeCmpFactory;
+    private final int[] btreeFields;
 
     public LSMRTreeDataflowHelperFactory(IPrimitiveValueProviderFactory[] valueProviderFactories,
             RTreePolicyType rtreePolicyType, IBinaryComparatorFactory[] btreeComparatorFactories,
             IVirtualBufferCacheProvider virtualBufferCacheProvider, ILSMMergePolicyFactory mergePolicyFactory,
             Map<String, String> mergePolicyProperties, ILSMOperationTrackerProvider opTrackerFactory,
             ILSMIOOperationSchedulerProvider ioSchedulerProvider, ILSMIOOperationCallbackFactory ioOpCallbackFactory,
-            ILinearizeComparatorFactory linearizeCmpFactory, double bloomFilterFalsePositiveRate) {
+            ILinearizeComparatorFactory linearizeCmpFactory, double bloomFilterFalsePositiveRate, int[] btreeFields) {
         super(virtualBufferCacheProvider, mergePolicyFactory, mergePolicyProperties, opTrackerFactory,
                 ioSchedulerProvider, ioOpCallbackFactory, bloomFilterFalsePositiveRate);
         this.btreeComparatorFactories = btreeComparatorFactories;
         this.valueProviderFactories = valueProviderFactories;
         this.rtreePolicyType = rtreePolicyType;
         this.linearizeCmpFactory = linearizeCmpFactory;
+        this.btreeFields = btreeFields;
     }
 
     @Override
@@ -61,6 +63,6 @@
                 virtualBufferCacheProvider.getVirtualBufferCaches(ctx), bloomFilterFalsePositiveRate,
                 btreeComparatorFactories, valueProviderFactories, rtreePolicyType,
                 mergePolicyFactory.createMergePolicy(mergePolicyProperties), opTrackerFactory,
-                ioSchedulerProvider.getIOScheduler(ctx), ioOpCallbackFactory, linearizeCmpFactory);
+                ioSchedulerProvider.getIOScheduler(ctx), ioOpCallbackFactory, linearizeCmpFactory, btreeFields);
     }
 }
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
index 673c7ae..7142929 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/AbstractLSMRTree.java
@@ -97,8 +97,8 @@
             BTree memBTree = new BTree(virtualBufferCache,
                     ((IVirtualBufferCache) virtualBufferCache).getFileMapProvider(), new VirtualFreePageManager(
                             virtualBufferCache.getNumPages()), btreeInteriorFrameFactory, btreeLeafFrameFactory,
-                    btreeCmpFactories, fieldCount, new FileReference(new File(fileManager.getBaseDir() + "_virtual_b_"
-                            + i)));
+                    btreeCmpFactories, btreeCmpFactories.length, new FileReference(new File(fileManager.getBaseDir()
+                            + "_virtual_b_" + i)));
             LSMRTreeMemoryComponent mutableComponent = new LSMRTreeMemoryComponent(memRTree, memBTree,
                     virtualBufferCache, i == 0 ? true : false);
             memoryComponents.add(mutableComponent);
@@ -152,8 +152,7 @@
         }
 
         if (flushOnExit) {
-            BlockingIOOperationCallbackWrapper cb = new BlockingIOOperationCallbackWrapper(
-                    ioOpCallback);
+            BlockingIOOperationCallbackWrapper cb = new BlockingIOOperationCallbackWrapper(ioOpCallback);
             ILSMIndexAccessor accessor = createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
             accessor.scheduleFlush(cb);
             try {
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java
index 2be6d57..b348793 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/LSMRTree.java
@@ -31,6 +31,7 @@
 import edu.uci.ics.hyracks.storage.am.btree.impls.RangePredicate;
 import edu.uci.ics.hyracks.storage.am.common.api.IIndexBulkLoader;
 import edu.uci.ics.hyracks.storage.am.common.api.IIndexCursor;
+import edu.uci.ics.hyracks.storage.am.common.api.IIndexOperationContext;
 import edu.uci.ics.hyracks.storage.am.common.api.IModificationOperationCallback;
 import edu.uci.ics.hyracks.storage.am.common.api.ISearchOperationCallback;
 import edu.uci.ics.hyracks.storage.am.common.api.ISearchPredicate;
@@ -39,9 +40,11 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndexFrameFactory;
 import edu.uci.ics.hyracks.storage.am.common.api.IndexException;
 import edu.uci.ics.hyracks.storage.am.common.api.TreeIndexException;
+import edu.uci.ics.hyracks.storage.am.common.exceptions.TreeIndexDuplicateKeyException;
 import edu.uci.ics.hyracks.storage.am.common.impls.NoOpOperationCallback;
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.IndexOperation;
 import edu.uci.ics.hyracks.storage.am.common.ophelpers.MultiComparator;
+import edu.uci.ics.hyracks.storage.am.common.tuples.DualTupleReference;
 import edu.uci.ics.hyracks.storage.am.lsm.common.api.ILSMComponent;
 import edu.uci.ics.hyracks.storage.am.lsm.common.api.ILSMHarness;
 import edu.uci.ics.hyracks.storage.am.lsm.common.api.ILSMIOOperation;
@@ -63,6 +66,7 @@
 import edu.uci.ics.hyracks.storage.common.file.IFileMapProvider;
 
 public class LSMRTree extends AbstractLSMRTree {
+    private int[] buddyBTreeFields;
 
     public LSMRTree(List<IVirtualBufferCache> virtualBufferCaches, ITreeIndexFrameFactory rtreeInteriorFrameFactory,
             ITreeIndexFrameFactory rtreeLeafFrameFactory, ITreeIndexFrameFactory btreeInteriorFrameFactory,
@@ -72,13 +76,14 @@
             IFileMapProvider diskFileMapProvider, int fieldCount, IBinaryComparatorFactory[] rtreeCmpFactories,
             IBinaryComparatorFactory[] btreeCmpFactories, ILinearizeComparatorFactory linearizer,
             int[] comparatorFields, IBinaryComparatorFactory[] linearizerArray, ILSMMergePolicy mergePolicy,
-            ILSMOperationTracker opTracker, ILSMIOOperationScheduler ioScheduler,
-            ILSMIOOperationCallback ioOpCallback) {
+            ILSMOperationTracker opTracker, ILSMIOOperationScheduler ioScheduler, ILSMIOOperationCallback ioOpCallback,
+            int[] buddyBTreeFields) {
         super(virtualBufferCaches, rtreeInteriorFrameFactory, rtreeLeafFrameFactory, btreeInteriorFrameFactory,
                 btreeLeafFrameFactory, fileNameManager, new LSMRTreeDiskComponentFactory(diskRTreeFactory,
                         diskBTreeFactory, bloomFilterFactory), diskFileMapProvider, fieldCount, rtreeCmpFactories,
                 btreeCmpFactories, linearizer, comparatorFields, linearizerArray, bloomFilterFalsePositiveRate,
                 mergePolicy, opTracker, ioScheduler, ioOpCallback);
+        this.buddyBTreeFields = buddyBTreeFields;
     }
 
     /**
@@ -321,10 +326,11 @@
 
             BTree btree = mergedComponent.getBTree();
             IIndexBulkLoader btreeBulkLoader = btree.createBulkLoader(1.0f, true, 0L, false);
-            
+
             long numElements = 0L;
             for (int i = 0; i < mergeOp.getMergingComponents().size(); ++i) {
-                numElements += ((LSMRTreeDiskComponent) mergeOp.getMergingComponents().get(i)).getBloomFilter().getNumElements();
+                numElements += ((LSMRTreeDiskComponent) mergeOp.getMergingComponents().get(i)).getBloomFilter()
+                        .getNumElements();
             }
 
             int maxBucketsPerElement = BloomCalculations.maxBucketsPerElement(numElements);
@@ -332,7 +338,7 @@
                     bloomFilterFalsePositiveRate);
             IIndexBulkLoader builder = mergedComponent.getBloomFilter().createBuilder(numElements,
                     bloomFilterSpec.getNumHashes(), bloomFilterSpec.getNumBucketsPerElements());
-            
+
             try {
                 while (btreeCursor.hasNext()) {
                     btreeCursor.next();
@@ -368,13 +374,22 @@
     }
 
     public class LSMRTreeAccessor extends LSMTreeIndexAccessor {
+        private DualTupleReference dualTuple = new DualTupleReference(buddyBTreeFields);
+
         public LSMRTreeAccessor(ILSMHarness lsmHarness, ILSMIndexOperationContext ctx) {
             super(lsmHarness, ctx);
         }
 
         @Override
         public ITreeIndexCursor createSearchCursor(boolean exclusive) {
-            return new LSMRTreeSearchCursor(ctx);
+            return new LSMRTreeSearchCursor(ctx, buddyBTreeFields);
+        }
+
+        @Override
+        public void delete(ITupleReference tuple) throws HyracksDataException, IndexException {
+            dualTuple.reset(tuple);
+            ctx.setOperation(IndexOperation.DELETE);
+            lsmHarness.modify(ctx, false, dualTuple);
         }
 
         public MultiComparator getMultiComparator() {
@@ -399,6 +414,30 @@
         }
     }
 
+    // This function is modified for R-Trees without antimatter tuples to allow buddy B-Tree to have only primary keys
+    @Override
+    public void modify(IIndexOperationContext ictx, ITupleReference tuple) throws HyracksDataException, IndexException {
+        LSMRTreeOpContext ctx = (LSMRTreeOpContext) ictx;
+        if (ctx.getOperation() == IndexOperation.PHYSICALDELETE) {
+            throw new UnsupportedOperationException("Physical delete not supported in the LSM-RTree");
+        }
+
+        ctx.modificationCallback.before(tuple);
+        ctx.modificationCallback.found(null, tuple);
+        if (ctx.getOperation() == IndexOperation.INSERT) {
+            ctx.currentMutableRTreeAccessor.insert(tuple);
+        } else {
+            // First remove all entries in the in-memory rtree (if any).
+            ctx.currentMutableRTreeAccessor.delete(tuple);
+            try {
+                ctx.currentMutableBTreeAccessor.insert(((DualTupleReference) tuple).getPermutingTuple());
+            } catch (TreeIndexDuplicateKeyException e) {
+                // Do nothing, because one delete tuple is enough to indicate
+                // that all the corresponding insert tuples are deleted
+            }
+        }
+    }
+
     public class LSMRTreeBulkLoader implements IIndexBulkLoader {
         private final ILSMComponent component;
         private final IIndexBulkLoader bulkLoader;
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/LSMRTreeSearchCursor.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/LSMRTreeSearchCursor.java
index f669585..ec9921c 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/LSMRTreeSearchCursor.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/impls/LSMRTreeSearchCursor.java
@@ -20,15 +20,18 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ICursorInitialState;
 import edu.uci.ics.hyracks.storage.am.common.api.ISearchPredicate;
 import edu.uci.ics.hyracks.storage.am.common.api.IndexException;
+import edu.uci.ics.hyracks.storage.am.common.tuples.PermutingTupleReference;
 import edu.uci.ics.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext;
 
 public class LSMRTreeSearchCursor extends LSMRTreeAbstractCursor {
 
     private int currentCursor;
+    private PermutingTupleReference btreeTuple;
 
-    public LSMRTreeSearchCursor(ILSMIndexOperationContext opCtx) {
+    public LSMRTreeSearchCursor(ILSMIndexOperationContext opCtx, int[] buddyBTreeFields) {
         super(opCtx);
         currentCursor = 0;
+        this.btreeTuple = new PermutingTupleReference(buddyBTreeFields);
     }
 
     @Override
@@ -77,12 +80,12 @@
             while (rtreeCursors[currentCursor].hasNext()) {
                 rtreeCursors[currentCursor].next();
                 ITupleReference currentTuple = rtreeCursors[currentCursor].getTuple();
-
+                btreeTuple.reset(rtreeCursors[currentCursor].getTuple());
                 boolean killerTupleFound = false;
                 for (int i = 0; i < currentCursor; i++) {
                     btreeCursors[i].reset();
-                    btreeRangePredicate.setHighKey(currentTuple, true);
-                    btreeRangePredicate.setLowKey(currentTuple, true);
+                    btreeRangePredicate.setHighKey(btreeTuple, true);
+                    btreeRangePredicate.setLowKey(btreeTuple, true);
                     btreeAccessors[i].search(btreeCursors[i], btreeRangePredicate);
                     try {
                         if (btreeCursors[i].hasNext()) {
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/utils/LSMRTreeUtils.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/utils/LSMRTreeUtils.java
index ee942e7..13ecc84 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/utils/LSMRTreeUtils.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/utils/LSMRTreeUtils.java
@@ -66,9 +66,16 @@
             IPrimitiveValueProviderFactory[] valueProviderFactories, RTreePolicyType rtreePolicyType,
             double bloomFilterFalsePositiveRate, ILSMMergePolicy mergePolicy, ILSMOperationTracker opTracker,
             ILSMIOOperationScheduler ioScheduler, ILSMIOOperationCallback ioOpCallback,
-            ILinearizeComparatorFactory linearizeCmpFactory) throws TreeIndexException {
+            ILinearizeComparatorFactory linearizeCmpFactory, int[] buddyBTreeFields) throws TreeIndexException {
+
+        ITypeTraits[] btreeTypeTraits = new ITypeTraits[buddyBTreeFields.length];
+        for (int i = 0; i < btreeTypeTraits.length; i++) {
+            btreeTypeTraits[i] = typeTraits[buddyBTreeFields[i]];
+        }
+
         LSMTypeAwareTupleWriterFactory rtreeTupleWriterFactory = new LSMTypeAwareTupleWriterFactory(typeTraits, false);
-        LSMTypeAwareTupleWriterFactory btreeTupleWriterFactory = new LSMTypeAwareTupleWriterFactory(typeTraits, true);
+        LSMTypeAwareTupleWriterFactory btreeTupleWriterFactory = new LSMTypeAwareTupleWriterFactory(btreeTypeTraits,
+                true);
 
         ITreeIndexFrameFactory rtreeInteriorFrameFactory = new RTreeNSMInteriorFrameFactory(rtreeTupleWriterFactory,
                 valueProviderFactories, rtreePolicyType);
@@ -87,7 +94,7 @@
                 typeTraits.length);
         TreeIndexFactory<BTree> diskBTreeFactory = new BTreeFactory(diskBufferCache, diskFileMapProvider,
                 freePageManagerFactory, btreeInteriorFrameFactory, btreeLeafFrameFactory, btreeCmpFactories,
-                typeTraits.length);
+                btreeTypeTraits.length);
 
         int[] comparatorFields = { 0 };
         IBinaryComparatorFactory[] linearizerArray = { linearizeCmpFactory };
@@ -105,7 +112,7 @@
                 btreeInteriorFrameFactory, btreeLeafFrameFactory, fileNameManager, diskRTreeFactory, diskBTreeFactory,
                 bloomFilterFactory, bloomFilterFalsePositiveRate, diskFileMapProvider, typeTraits.length,
                 rtreeCmpFactories, btreeCmpFactories, linearizeCmpFactory, comparatorFields, linearizerArray,
-                mergePolicy, opTracker, ioScheduler, ioOpCallback);
+                mergePolicy, opTracker, ioScheduler, ioOpCallback, buddyBTreeFields);
         return lsmTree;
     }
 
diff --git a/hyracks/hyracks-test-support/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/AbstractRTreeExamplesTest.java b/hyracks/hyracks-test-support/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/AbstractRTreeExamplesTest.java
index 6a519d0..ff3d21c 100644
--- a/hyracks/hyracks-test-support/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/AbstractRTreeExamplesTest.java
+++ b/hyracks/hyracks-test-support/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/AbstractRTreeExamplesTest.java
@@ -52,12 +52,20 @@
 
 @SuppressWarnings("rawtypes")
 public abstract class AbstractRTreeExamplesTest {
+
+    public static enum RTreeType {
+        LSMRTREE,
+        LSMRTREE_WITH_ANTIMATTER,
+        RTREE
+    };
+
     protected static final Logger LOGGER = Logger.getLogger(AbstractRTreeExamplesTest.class.getName());
     protected final Random rnd = new Random(50);
+    protected RTreeType rTreeType;
 
     protected abstract ITreeIndex createTreeIndex(ITypeTraits[] typeTraits,
             IBinaryComparatorFactory[] rtreeCmpFactories, IBinaryComparatorFactory[] btreeCmpFactories,
-            IPrimitiveValueProviderFactory[] valueProviderFactories, RTreePolicyType rtreePolicyType)
+            IPrimitiveValueProviderFactory[] valueProviderFactories, RTreePolicyType rtreePolicyType, int[] btreeFields)
             throws TreeIndexException;
 
     /**
@@ -96,21 +104,37 @@
         rtreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
 
         // Declare BTree keys, this will only be used for LSMRTree
-        int btreeKeyFieldCount = 6;
-        IBinaryComparatorFactory[] btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
-        btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[5] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+        int btreeKeyFieldCount;
+        IBinaryComparatorFactory[] btreeCmpFactories;
+        int[] btreeFields = null;
+        if (rTreeType == RTreeType.LSMRTREE) {
+            //Parameters look different for LSM RTREE from LSM RTREE WITH ANTI MATTER TUPLES
+            btreeKeyFieldCount = 2;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeFields = new int[btreeKeyFieldCount];
+            for (int i = 0; i < btreeKeyFieldCount; i++) {
+                btreeFields[i] = rtreeKeyFieldCount + i;
+            }
+
+        } else {
+            btreeKeyFieldCount = 6;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[5] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+        }
 
         // create value providers
         IPrimitiveValueProviderFactory[] valueProviderFactories = RTreeUtils.createPrimitiveValueProviderFactories(
                 rtreeCmpFactories.length, IntegerPointable.FACTORY);
 
         ITreeIndex treeIndex = createTreeIndex(typeTraits, rtreeCmpFactories, btreeCmpFactories,
-                valueProviderFactories, RTreePolicyType.RTREE);
+                valueProviderFactories, RTreePolicyType.RTREE, btreeFields);
         treeIndex.create();
         treeIndex.activate();
 
@@ -192,20 +216,36 @@
         rtreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
 
         // Declare BTree keys, this will only be used for LSMRTree
-        int btreeKeyFieldCount = 5;
-        IBinaryComparatorFactory[] btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
-        btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+        int btreeKeyFieldCount;
+        IBinaryComparatorFactory[] btreeCmpFactories;
+        int[] btreeFields = null;
+        if (rTreeType == RTreeType.LSMRTREE) {
+            //Parameters look different for LSM RTREE from LSM RTREE WITH ANTI MATTER TUPLES
+            btreeKeyFieldCount = 1;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+            btreeFields = new int[btreeKeyFieldCount];
+            for (int i = 0; i < btreeKeyFieldCount; i++) {
+                btreeFields[i] = rtreeKeyFieldCount + i;
+            }
+
+        } else {
+            btreeKeyFieldCount = 5;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+        }
 
         // create value providers
         IPrimitiveValueProviderFactory[] valueProviderFactories = RTreeUtils.createPrimitiveValueProviderFactories(
                 rtreeCmpFactories.length, IntegerPointable.FACTORY);
 
+        //2
         ITreeIndex treeIndex = createTreeIndex(typeTraits, rtreeCmpFactories, btreeCmpFactories,
-                valueProviderFactories, RTreePolicyType.RTREE);
+                valueProviderFactories, RTreePolicyType.RTREE, btreeFields);
 
         treeIndex.create();
         treeIndex.activate();
@@ -316,20 +356,35 @@
         rtreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
 
         // Declare BTree keys, this will only be used for LSMRTree
-        int btreeKeyFieldCount = 5;
-        IBinaryComparatorFactory[] btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
-        btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+        int btreeKeyFieldCount;
+        IBinaryComparatorFactory[] btreeCmpFactories;
+        int[] btreeFields = null;
+        if (rTreeType == RTreeType.LSMRTREE) {
+            //Parameters look different for LSM RTREE from LSM RTREE WITH ANTI MATTER TUPLES
+            btreeKeyFieldCount = 1;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+            btreeFields = new int[btreeKeyFieldCount];
+            for (int i = 0; i < btreeKeyFieldCount; i++) {
+                btreeFields[i] = rtreeKeyFieldCount + i;
+            }
+
+        } else {
+            btreeKeyFieldCount = 5;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(UTF8StringPointable.FACTORY);
+        }
 
         // create value providers
         IPrimitiveValueProviderFactory[] valueProviderFactories = RTreeUtils.createPrimitiveValueProviderFactories(
                 rtreeCmpFactories.length, IntegerPointable.FACTORY);
 
         ITreeIndex treeIndex = createTreeIndex(typeTraits, rtreeCmpFactories, btreeCmpFactories,
-                valueProviderFactories, RTreePolicyType.RSTARTREE);
+                valueProviderFactories, RTreePolicyType.RSTARTREE, btreeFields);
 
         treeIndex.create();
         treeIndex.activate();
@@ -447,23 +502,39 @@
         rtreeCmpFactories[4] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
         rtreeCmpFactories[5] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
 
-        // Declare RTree keys.
-        int btreeKeyFieldCount = 7;
-        IBinaryComparatorFactory[] btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
-        btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeCmpFactories[5] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
-        btreeCmpFactories[6] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+        // Declare BTree keys, this will only be used for LSMRTree
+        int btreeKeyFieldCount;
+        IBinaryComparatorFactory[] btreeCmpFactories;
+        int[] btreeFields = null;
+        if (rTreeType == RTreeType.LSMRTREE) {
+            //Parameters look different for LSM RTREE from LSM RTREE WITH ANTI MATTER TUPLES
+            btreeKeyFieldCount = 1;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeFields = new int[btreeKeyFieldCount];
+            for (int i = 0; i < btreeKeyFieldCount; i++) {
+                btreeFields[i] = rtreeKeyFieldCount + i;
+            }
+
+        } else {
+            btreeKeyFieldCount = 7;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeCmpFactories[5] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+            btreeCmpFactories[6] = PointableBinaryComparatorFactory.of(DoublePointable.FACTORY);
+        }
 
         // create value providers
         IPrimitiveValueProviderFactory[] valueProviderFactories = RTreeUtils.createPrimitiveValueProviderFactories(
                 rtreeCmpFactories.length, DoublePointable.FACTORY);
 
+        //4
         ITreeIndex treeIndex = createTreeIndex(typeTraits, rtreeCmpFactories, btreeCmpFactories,
-                valueProviderFactories, RTreePolicyType.RTREE);
+                valueProviderFactories, RTreePolicyType.RTREE, btreeFields);
         treeIndex.create();
         treeIndex.activate();
 
@@ -541,21 +612,36 @@
         rtreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
         rtreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
 
-        // Declare BTree keys.
-        int btreeKeyFieldCount = 5;
-        IBinaryComparatorFactory[] btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
-        btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+        // Declare BTree keys, this will only be used for LSMRTree
+        int btreeKeyFieldCount;
+        IBinaryComparatorFactory[] btreeCmpFactories;
+        int[] btreeFields = null;
+        if (rTreeType == RTreeType.LSMRTREE) {
+            //Parameters look different for LSM RTREE from LSM RTREE WITH ANTI MATTER TUPLES
+            btreeKeyFieldCount = 1;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeFields = new int[btreeKeyFieldCount];
+            for (int i = 0; i < btreeKeyFieldCount; i++) {
+                btreeFields[i] = rtreeKeyFieldCount + i;
+            }
+
+        } else {
+            btreeKeyFieldCount = 5;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+        }
 
         // create value providers
         IPrimitiveValueProviderFactory[] valueProviderFactories = RTreeUtils.createPrimitiveValueProviderFactories(
                 rtreeCmpFactories.length, IntegerPointable.FACTORY);
 
         ITreeIndex treeIndex = createTreeIndex(typeTraits, rtreeCmpFactories, btreeCmpFactories,
-                valueProviderFactories, RTreePolicyType.RTREE);
+                valueProviderFactories, RTreePolicyType.RTREE, btreeFields);
         treeIndex.create();
         treeIndex.activate();
 
@@ -662,21 +748,37 @@
         rtreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
         rtreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
 
-        // Declare BTree keys.
-        int btreeKeyFieldCount = 5;
-        IBinaryComparatorFactory[] btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
-        btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
-        btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+        // Declare BTree keys, this will only be used for LSMRTree
+        int btreeKeyFieldCount;
+        IBinaryComparatorFactory[] btreeCmpFactories;
+        int[] btreeFields = null;
+        if (rTreeType == RTreeType.LSMRTREE) {
+            //Parameters look different for LSM RTREE from LSM RTREE WITH ANTI MATTER TUPLES
+            btreeKeyFieldCount = 1;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeFields = new int[btreeKeyFieldCount];
+            for (int i = 0; i < btreeKeyFieldCount; i++) {
+                btreeFields[i] = rtreeKeyFieldCount + i;
+            }
+
+        } else {
+            btreeKeyFieldCount = 5;
+            btreeCmpFactories = new IBinaryComparatorFactory[btreeKeyFieldCount];
+            btreeCmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[2] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[3] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+            btreeCmpFactories[4] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
+        }
 
         // create value providers
         IPrimitiveValueProviderFactory[] valueProviderFactories = RTreeUtils.createPrimitiveValueProviderFactories(
                 rtreeCmpFactories.length, IntegerPointable.FACTORY);
 
+        //6
         ITreeIndex treeIndex = createTreeIndex(typeTraits, rtreeCmpFactories, btreeCmpFactories,
-                valueProviderFactories, RTreePolicyType.RTREE);
+                valueProviderFactories, RTreePolicyType.RTREE, btreeFields);
         treeIndex.create();
         treeIndex.activate();
 
diff --git a/hyracks/hyracks-test-support/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/AbstractRTreeMultiThreadTest.java b/hyracks/hyracks-test-support/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/AbstractRTreeMultiThreadTest.java
index d97a2d7..4aa24c6 100644
--- a/hyracks/hyracks-test-support/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/AbstractRTreeMultiThreadTest.java
+++ b/hyracks/hyracks-test-support/src/main/java/edu/uci/ics/hyracks/storage/am/rtree/AbstractRTreeMultiThreadTest.java
@@ -38,6 +38,7 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndex;
 import edu.uci.ics.hyracks.storage.am.common.api.TreeIndexException;
 import edu.uci.ics.hyracks.storage.am.config.AccessMethodTestsConfig;
+import edu.uci.ics.hyracks.storage.am.rtree.AbstractRTreeExamplesTest.RTreeType;
 import edu.uci.ics.hyracks.storage.am.rtree.frames.RTreePolicyType;
 import edu.uci.ics.hyracks.storage.am.rtree.util.RTreeUtils;
 
@@ -45,9 +46,11 @@
 public abstract class AbstractRTreeMultiThreadTest {
 
     protected final boolean testRstarPolicy;
+    protected final RTreeType rTreeType;
 
-    public AbstractRTreeMultiThreadTest(boolean testRstarPolicy) {
+    public AbstractRTreeMultiThreadTest(boolean testRstarPolicy, RTreeType rTreeType) {
         this.testRstarPolicy = testRstarPolicy;
+        this.rTreeType = rTreeType;
     }
 
     protected final Logger LOGGER = Logger.getLogger(AbstractRTreeMultiThreadTest.class.getName());
@@ -66,7 +69,7 @@
 
     protected abstract ITreeIndex createTreeIndex(ITypeTraits[] typeTraits,
             IBinaryComparatorFactory[] rtreeCmpFactories, IBinaryComparatorFactory[] btreeCmpFactories,
-            IPrimitiveValueProviderFactory[] valueProviderFactories, RTreePolicyType rtreePolicyType)
+            IPrimitiveValueProviderFactory[] valueProviderFactories, RTreePolicyType rtreePolicyType, int[] btreeFields)
             throws TreeIndexException;
 
     protected abstract IIndexTestWorkerFactory getWorkerFactory();
@@ -89,11 +92,23 @@
 
         ITypeTraits[] typeTraits = SerdeUtils.serdesToTypeTraits(fieldSerdes);
         IBinaryComparatorFactory[] rtreeCmpFactories = SerdeUtils.serdesToComparatorFactories(fieldSerdes, numKeys);
-        IBinaryComparatorFactory[] btreeCmpFactories = SerdeUtils.serdesToComparatorFactories(fieldSerdes,
-                fieldSerdes.length);
+        int[] btreeFields = null;
+        IBinaryComparatorFactory[] btreeCmpFactories;
+        if (rTreeType == RTreeType.LSMRTREE) {
+            int numBtreeFields = fieldSerdes.length - numKeys;
+            ISerializerDeserializer[] btreeFieldSerdes = new ISerializerDeserializer[numBtreeFields];
+            btreeFields = new int[numBtreeFields];
+            for (int i = 0; i < numBtreeFields; i++) {
+                btreeFields[i] = numKeys + i;
+                btreeFieldSerdes[i] = fieldSerdes[numKeys + i];
+            }
+            btreeCmpFactories = SerdeUtils.serdesToComparatorFactories(btreeFieldSerdes, numBtreeFields);
+        } else {
+            btreeCmpFactories = SerdeUtils.serdesToComparatorFactories(fieldSerdes, fieldSerdes.length);
+        }
 
         ITreeIndex index = createTreeIndex(typeTraits, rtreeCmpFactories, btreeCmpFactories, valueProviderFactories,
-                rtreePolicyType);
+                rtreePolicyType, btreeFields);
         IIndexTestWorkerFactory workerFactory = getWorkerFactory();
 
         // 4 batches per thread.
diff --git a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/LSMRTreeExamplesTest.java b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/LSMRTreeExamplesTest.java
index b04ae16..2b02656 100644
--- a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/LSMRTreeExamplesTest.java
+++ b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/LSMRTreeExamplesTest.java
@@ -33,16 +33,21 @@
 public class LSMRTreeExamplesTest extends AbstractRTreeExamplesTest {
     private final LSMRTreeTestHarness harness = new LSMRTreeTestHarness();
 
+    public LSMRTreeExamplesTest() {
+        super();
+        this.rTreeType = RTreeType.LSMRTREE;
+    }
+
     @Override
     protected ITreeIndex createTreeIndex(ITypeTraits[] typeTraits, IBinaryComparatorFactory[] rtreeCmpFactories,
             IBinaryComparatorFactory[] btreeCmpFactories, IPrimitiveValueProviderFactory[] valueProviderFactories,
-            RTreePolicyType rtreePolicyType) throws TreeIndexException {
+            RTreePolicyType rtreePolicyType, int[] btreeFields) throws TreeIndexException {
         return LSMRTreeUtils.createLSMTree(harness.getVirtualBufferCaches(), harness.getFileReference(),
                 harness.getDiskBufferCache(), harness.getDiskFileMapProvider(), typeTraits, rtreeCmpFactories,
                 btreeCmpFactories, valueProviderFactories, rtreePolicyType, harness.getBoomFilterFalsePositiveRate(),
                 harness.getMergePolicy(), harness.getOperationTracker(), harness.getIOScheduler(),
                 harness.getIOOperationCallback(),
-                LSMRTreeUtils.proposeBestLinearizer(typeTraits, rtreeCmpFactories.length));
+                LSMRTreeUtils.proposeBestLinearizer(typeTraits, rtreeCmpFactories.length), btreeFields);
     }
 
     @Before
diff --git a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesExamplesTest.java b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesExamplesTest.java
index a51abef..3ce30c5 100644
--- a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesExamplesTest.java
+++ b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/LSMRTreeWithAntiMatterTuplesExamplesTest.java
@@ -33,10 +33,15 @@
 public class LSMRTreeWithAntiMatterTuplesExamplesTest extends AbstractRTreeExamplesTest {
     private final LSMRTreeTestHarness harness = new LSMRTreeTestHarness();
 
+    public LSMRTreeWithAntiMatterTuplesExamplesTest() {
+        super();
+        this.rTreeType = RTreeType.LSMRTREE_WITH_ANTIMATTER;
+    }
+
     @Override
     protected ITreeIndex createTreeIndex(ITypeTraits[] typeTraits, IBinaryComparatorFactory[] rtreeCmpFactories,
             IBinaryComparatorFactory[] btreeCmpFactories, IPrimitiveValueProviderFactory[] valueProviderFactories,
-            RTreePolicyType rtreePolicyType) throws TreeIndexException {
+            RTreePolicyType rtreePolicyType, int[] btreeFields) throws TreeIndexException {
         return LSMRTreeUtils.createLSMTreeWithAntiMatterTuples(harness.getVirtualBufferCaches(),
                 harness.getFileReference(), harness.getDiskBufferCache(), harness.getDiskFileMapProvider(), typeTraits,
                 rtreeCmpFactories, btreeCmpFactories, valueProviderFactories, rtreePolicyType,
diff --git a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/multithread/LSMRTreeMultiThreadTest.java b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/multithread/LSMRTreeMultiThreadTest.java
index 077bd45..c3ec1b3 100644
--- a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/multithread/LSMRTreeMultiThreadTest.java
+++ b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/multithread/LSMRTreeMultiThreadTest.java
@@ -30,6 +30,7 @@
 import edu.uci.ics.hyracks.storage.am.common.datagen.ProbabilityHelper;
 import edu.uci.ics.hyracks.storage.am.lsm.rtree.util.LSMRTreeTestHarness;
 import edu.uci.ics.hyracks.storage.am.lsm.rtree.utils.LSMRTreeUtils;
+import edu.uci.ics.hyracks.storage.am.rtree.AbstractRTreeExamplesTest.RTreeType;
 import edu.uci.ics.hyracks.storage.am.rtree.AbstractRTreeMultiThreadTest;
 import edu.uci.ics.hyracks.storage.am.rtree.frames.RTreePolicyType;
 
@@ -40,7 +41,7 @@
     private LSMRTreeTestWorkerFactory workerFactory = new LSMRTreeTestWorkerFactory();
 
     public LSMRTreeMultiThreadTest() {
-        super(false);
+        super(false, RTreeType.LSMRTREE);
     }
 
     @Override
@@ -56,13 +57,13 @@
     @Override
     protected ITreeIndex createTreeIndex(ITypeTraits[] typeTraits, IBinaryComparatorFactory[] rtreeCmpFactories,
             IBinaryComparatorFactory[] btreeCmpFactories, IPrimitiveValueProviderFactory[] valueProviderFactories,
-            RTreePolicyType rtreePolicyType) throws TreeIndexException {
+            RTreePolicyType rtreePolicyType, int[] btreeFields) throws TreeIndexException {
         return LSMRTreeUtils.createLSMTree(harness.getVirtualBufferCaches(), harness.getFileReference(),
                 harness.getDiskBufferCache(), harness.getDiskFileMapProvider(), typeTraits, rtreeCmpFactories,
                 btreeCmpFactories, valueProviderFactories, rtreePolicyType, harness.getBoomFilterFalsePositiveRate(),
                 harness.getMergePolicy(), harness.getOperationTracker(), harness.getIOScheduler(),
                 harness.getIOOperationCallback(),
-                LSMRTreeUtils.proposeBestLinearizer(typeTraits, rtreeCmpFactories.length));
+                LSMRTreeUtils.proposeBestLinearizer(typeTraits, rtreeCmpFactories.length), btreeFields);
     }
 
     @Override
diff --git a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/multithread/LSMRTreeWithAntiMatterTuplesMultiThreadTest.java b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/multithread/LSMRTreeWithAntiMatterTuplesMultiThreadTest.java
index ef871dd..22a4b07 100644
--- a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/multithread/LSMRTreeWithAntiMatterTuplesMultiThreadTest.java
+++ b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/multithread/LSMRTreeWithAntiMatterTuplesMultiThreadTest.java
@@ -30,6 +30,7 @@
 import edu.uci.ics.hyracks.storage.am.common.datagen.ProbabilityHelper;
 import edu.uci.ics.hyracks.storage.am.lsm.rtree.util.LSMRTreeTestHarness;
 import edu.uci.ics.hyracks.storage.am.lsm.rtree.utils.LSMRTreeUtils;
+import edu.uci.ics.hyracks.storage.am.rtree.AbstractRTreeExamplesTest.RTreeType;
 import edu.uci.ics.hyracks.storage.am.rtree.AbstractRTreeMultiThreadTest;
 import edu.uci.ics.hyracks.storage.am.rtree.frames.RTreePolicyType;
 
@@ -40,7 +41,7 @@
     private LSMRTreeWithAntiMatterTuplesTestWorkerFactory workerFactory = new LSMRTreeWithAntiMatterTuplesTestWorkerFactory();
 
     public LSMRTreeWithAntiMatterTuplesMultiThreadTest() {
-        super(false);
+        super(false, RTreeType.LSMRTREE_WITH_ANTIMATTER);
     }
 
     @Override
@@ -56,7 +57,7 @@
     @Override
     protected ITreeIndex createTreeIndex(ITypeTraits[] typeTraits, IBinaryComparatorFactory[] rtreeCmpFactories,
             IBinaryComparatorFactory[] btreeCmpFactories, IPrimitiveValueProviderFactory[] valueProviderFactories,
-            RTreePolicyType rtreePolicyType) throws TreeIndexException {
+            RTreePolicyType rtreePolicyType, int[] btreeFields) throws TreeIndexException {
         return LSMRTreeUtils.createLSMTreeWithAntiMatterTuples(harness.getVirtualBufferCaches(),
                 harness.getFileReference(), harness.getDiskBufferCache(), harness.getDiskFileMapProvider(), typeTraits,
                 rtreeCmpFactories, btreeCmpFactories, valueProviderFactories, rtreePolicyType,
diff --git a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/util/LSMRTreeTestContext.java b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/util/LSMRTreeTestContext.java
index 42e793b..484ebc6 100644
--- a/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/util/LSMRTreeTestContext.java
+++ b/hyracks/hyracks-tests/hyracks-storage-am-lsm-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/lsm/rtree/util/LSMRTreeTestContext.java
@@ -75,12 +75,19 @@
         ITypeTraits[] typeTraits = SerdeUtils.serdesToTypeTraits(fieldSerdes);
         IBinaryComparatorFactory[] rtreeCmpFactories = SerdeUtils
                 .serdesToComparatorFactories(fieldSerdes, numKeyFields);
-        IBinaryComparatorFactory[] btreeCmpFactories = SerdeUtils.serdesToComparatorFactories(fieldSerdes,
-                fieldSerdes.length);
+        int numBtreeFields = fieldSerdes.length - numKeyFields;
+        ISerializerDeserializer[] btreeFieldSerdes = new ISerializerDeserializer[numBtreeFields];
+        int[] btreeFields = new int[numBtreeFields];
+        for (int i = 0; i < numBtreeFields; i++) {
+            btreeFields[i] = numKeyFields + i;
+            btreeFieldSerdes[i] = fieldSerdes[numKeyFields + i];
+        }
+        IBinaryComparatorFactory[] btreeCmpFactories = SerdeUtils.serdesToComparatorFactories(btreeFieldSerdes,
+                numBtreeFields);
         LSMRTree lsmTree = LSMRTreeUtils.createLSMTree(virtualBufferCaches, file, diskBufferCache, diskFileMapProvider,
                 typeTraits, rtreeCmpFactories, btreeCmpFactories, valueProviderFactories, rtreePolicyType,
                 bloomFilterFalsePositiveRate, mergePolicy, opTracker, ioScheduler, ioOpCallback,
-                LSMRTreeUtils.proposeBestLinearizer(typeTraits, rtreeCmpFactories.length));
+                LSMRTreeUtils.proposeBestLinearizer(typeTraits, rtreeCmpFactories.length), btreeFields);
         LSMRTreeTestContext testCtx = new LSMRTreeTestContext(fieldSerdes, lsmTree);
         return testCtx;
     }
diff --git a/hyracks/hyracks-tests/hyracks-storage-am-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/rtree/RTreeExamplesTest.java b/hyracks/hyracks-tests/hyracks-storage-am-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/rtree/RTreeExamplesTest.java
index d260ee2..8bec6d9 100644
--- a/hyracks/hyracks-tests/hyracks-storage-am-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/rtree/RTreeExamplesTest.java
+++ b/hyracks/hyracks-tests/hyracks-storage-am-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/rtree/RTreeExamplesTest.java
@@ -31,6 +31,11 @@
 public class RTreeExamplesTest extends AbstractRTreeExamplesTest {
     private final RTreeTestHarness harness = new RTreeTestHarness();
 
+    public RTreeExamplesTest() {
+        super();
+        this.rTreeType = RTreeType.RTREE;
+    }
+
     @Before
     public void setUp() throws HyracksDataException {
         harness.setUp();
@@ -44,7 +49,7 @@
     @Override
     protected ITreeIndex createTreeIndex(ITypeTraits[] typeTraits, IBinaryComparatorFactory[] rtreeCmpFactories,
             IBinaryComparatorFactory[] btreeCmpFactories, IPrimitiveValueProviderFactory[] valueProviderFactories,
-            RTreePolicyType rtreePolicyType) throws TreeIndexException {
+            RTreePolicyType rtreePolicyType, int[] btreeFields) throws TreeIndexException {
         return RTreeUtils.createRTree(harness.getBufferCache(), harness.getFileMapProvider(), typeTraits,
                 valueProviderFactories, rtreeCmpFactories, rtreePolicyType, harness.getFileReference());
     }
diff --git a/hyracks/hyracks-tests/hyracks-storage-am-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/rtree/multithread/RTreeMultiThreadTest.java b/hyracks/hyracks-tests/hyracks-storage-am-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/rtree/multithread/RTreeMultiThreadTest.java
index 0730bba..ba1113e 100644
--- a/hyracks/hyracks-tests/hyracks-storage-am-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/rtree/multithread/RTreeMultiThreadTest.java
+++ b/hyracks/hyracks-tests/hyracks-storage-am-rtree-test/src/test/java/edu/uci/ics/hyracks/storage/am/rtree/multithread/RTreeMultiThreadTest.java
@@ -27,6 +27,7 @@
 import edu.uci.ics.hyracks.storage.am.common.api.ITreeIndex;
 import edu.uci.ics.hyracks.storage.am.common.api.TreeIndexException;
 import edu.uci.ics.hyracks.storage.am.common.datagen.ProbabilityHelper;
+import edu.uci.ics.hyracks.storage.am.rtree.AbstractRTreeExamplesTest.RTreeType;
 import edu.uci.ics.hyracks.storage.am.rtree.AbstractRTreeMultiThreadTest;
 import edu.uci.ics.hyracks.storage.am.rtree.frames.RTreePolicyType;
 import edu.uci.ics.hyracks.storage.am.rtree.util.RTreeUtils;
@@ -35,7 +36,7 @@
 public class RTreeMultiThreadTest extends AbstractRTreeMultiThreadTest {
 
     public RTreeMultiThreadTest() {
-        super(true);
+        super(true, RTreeType.RTREE);
     }
 
     private RTreeTestHarness harness = new RTreeTestHarness();
@@ -55,7 +56,7 @@
     @Override
     protected ITreeIndex createTreeIndex(ITypeTraits[] typeTraits, IBinaryComparatorFactory[] rtreeCmpFactories,
             IBinaryComparatorFactory[] btreeCmpFactories, IPrimitiveValueProviderFactory[] valueProviderFactories,
-            RTreePolicyType rtreePolicyType) throws TreeIndexException {
+            RTreePolicyType rtreePolicyType, int[] btreeFields) throws TreeIndexException {
         return RTreeUtils.createRTree(harness.getBufferCache(), harness.getFileMapProvider(), typeTraits,
                 valueProviderFactories, rtreeCmpFactories, rtreePolicyType, harness.getFileReference());