http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-01-disable-idxonly.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-01-disable-idxonly.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-01-disable-idxonly.sqlpp
new file mode 100644
index 0000000..0be684e
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-01-disable-idxonly.sqlpp
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *                  : However, we set the "noindexonly" option to true. So, 
the index-only plan should not be triggered.
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+};
+
+create dataset MyData(MyRecord) primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+set noindexonly 'true';
+
+select element {"pk":o.id, "sk":o.docid}
+from MyData o
+where o.docid < 3
+order by o.id;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-01.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-01.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-01.sqlpp
new file mode 100644
index 0000000..af1a099
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-01.sqlpp
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+};
+
+create dataset MyData(MyRecord) primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+select element {"pk":o.id, "sk":o.docid}
+from MyData o
+where o.docid < 3
+order by o.id;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-02.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-02.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-02.aql
new file mode 100644
index 0000000..77633fb
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-02.aql
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+for $o in dataset('MyData')
+where $o.docid < 3
+order by $o.id
+return {"pk":$o.id}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-03.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-03.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-03.aql
new file mode 100644
index 0000000..dc271af
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-03.aql
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+for $o in dataset('MyData')
+where $o.docid < 3
+order by $o.id
+return {"sk":$o.docid}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-04.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-04.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-04.aql
new file mode 100644
index 0000000..b1297f1
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-04.aql
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+count(
+for $o in dataset('MyData')
+where $o.docid < 3
+order by $o.id
+return {"pk":$o.id, "sk":$o.docid}
+);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-05.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-05.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-05.aql
new file mode 100644
index 0000000..3d1d1fb
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-05.aql
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+count(
+for $o in dataset('MyData')
+where $o.docid < 3
+order by $o.id
+return {"pk":$o.id}
+);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-06.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-06.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-06.aql
new file mode 100644
index 0000000..3aea6ee
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-06.aql
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+count(
+for $o in dataset('MyData')
+where $o.docid < 3
+order by $o.id
+return {"sk":$o.docid}
+);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-07.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-07.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-07.aql
new file mode 100644
index 0000000..06d89b5
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-07.aql
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+count(
+for $o in dataset('MyData')
+where $o.docid < 3
+order by $o.id
+return {"rec":$o, "pk":$o.id}
+);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-08.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-08.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-08.aql
new file mode 100644
index 0000000..0892b7e
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-08.aql
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+count(
+for $o in dataset('MyData')
+where $o.docid < 3
+order by $o.id
+return $o
+);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-09.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-09.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-09.aql
new file mode 100644
index 0000000..a0cdc2b
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index/btree-sidx-idxonly-09.aql
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary BTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary BTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
          -> union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type testType as {
+   id: uuid,
+   sid: int32
+}
+
+create dataset testDataset(testType) primary key id autogenerated
+create index testIdx on testDataset(sid)
+
+for $y in [0,2,4,6,8]
+return { "quantile":$y,
+         "count": count(for $x in dataset testDataset
+                        where $x.sid /* +indexnl */ <= $y
+                        return $x.sid)
+};

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-01-disable-indexonly-plan.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-01-disable-indexonly-plan.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-01-disable-indexonly-plan.sqlpp
deleted file mode 100644
index dae4f0a..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-01-disable-indexonly-plan.sqlpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *                  : However, we set the "noindexonly" option to true. So, 
the index-only plan should not be triggered.
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-};
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-set noindexonly 'true';
-
-select count(*) from (
-select x.location
-from Fragile_raw x
-where spatial_intersect(x.location, create_polygon([0.0,0.0, 2.0,2.0, 0.0,2.0, 
2.0,0.0]))
-) a;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-01.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-01.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-01.sqlpp
deleted file mode 100644
index 7a37b2d..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-01.sqlpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-};
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-select count(*) from (
-select x.location
-from Fragile_raw x
-where spatial_intersect(x.location, create_polygon([0.0,0.0, 2.0,2.0, 0.0,2.0, 
2.0,0.0]))
-) a;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-02.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-02.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-02.aql
deleted file mode 100644
index e82a527..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-02.aql
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use dataverse test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-}
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
-for $o in dataset('MyData')
-where spatial-intersect($o.point, $area)
-order by $o.id
-return {"id":$o.id}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-03.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-03.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-03.aql
deleted file mode 100644
index abb15e1..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-03.aql
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use dataverse test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-}
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
-for $o in dataset('MyData')
-where spatial-intersect($o.point, $area)
-order by $o.id
-return {"point":$o.point}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-04.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-04.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-04.aql
deleted file mode 100644
index 27e9509..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-04.aql
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use dataverse test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-}
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-count(
-let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
-for $o in dataset('MyData')
-where spatial-intersect($o.point, $area)
-order by $o.id
-return {"id":$o.id, "point":$o.point}
-);
-

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-05.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-05.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-05.aql
deleted file mode 100644
index ad94c18..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-05.aql
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use dataverse test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-}
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-count(
-let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
-for $o in dataset('MyData')
-where spatial-intersect($o.point, $area)
-order by $o.id
-return {"id":$o.id}
-);
-

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-06.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-06.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-06.aql
deleted file mode 100644
index d4e4d46..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-06.aql
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use dataverse test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-}
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-count(
-let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
-for $o in dataset('MyData')
-where spatial-intersect($o.point, $area)
-order by $o.id
-return {"point":$o.point}
-);
-

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-07.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-07.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-07.aql
deleted file mode 100644
index 6564565..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-07.aql
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use dataverse test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-}
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-count(
-let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
-for $o in dataset('MyData')
-where spatial-intersect($o.point, $area)
-order by $o.id
-return {"rec":$o, "id":$o.id}
-);
-

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-08.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-08.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-08.aql
deleted file mode 100644
index 6c67c49..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-08.aql
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use dataverse test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-}
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-count(
-let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
-for $o in dataset('MyData')
-where spatial-intersect($o.point, $area)
-order by $o.id
-return $o
-);
-

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-09.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-09.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-09.aql
deleted file mode 100644
index d6ec571..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-secondary-index-indexonly-plan-09.aql
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/*
- *  Description     : Secondary RTree Index index-only selection plan 
verification test
- *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
- *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
- *                  : The plan should have two paths after the secondary 
index-lookup.
- *                  : The left path:
- *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
- *                  : The right path:
- *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
- *  Expected Result : Success
- *
-*/
-
-drop dataverse test if exists;
-create dataverse test;
-use dataverse test;
-
-/* For raw Fragile data */
-create type FragileTypeRaw as closed {
-  row_id: int32,
-  sid: int32,
-  date: string,
-  day: int32,
-  time: string,
-  bpm: int32,
-  RR: float,
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-
-};
-
-/* For cleaned Fragile data */
-create type FragileType as closed {
-  row_id: int32,
-  sid: int32,
-  date: date,
-  day: int32,
-  time: time,
-  bpm: int32,
-  RR: float,
-
-  /* new string field and location field*/
-  text: string,
-  location: point,
-  text2: string
-};
-
-/* Create dataset for loading raw Fragile data */
-create dataset Fragile_raw (FragileTypeRaw)
-primary key row_id;
-
-/* Create dataset for cleaned Fragile data */
-create dataset Fragile (FragileType)
-primary key row_id;
-
-
-/* Create rtree secondary index on dataset clean Fragile */
-create index cfLocation on Fragile(location) type rtree;
-create index cfLocation on Fragile_raw(location) type rtree;
-
-create type MyRecord as closed {
-  id: int64,
-  docid: int64,
-  val1: int64,
-  title: string,
-  point: point,
-  kwds: string,
-  line1: line,
-  line2: line,
-  poly1: polygon,
-  poly2: polygon,
-  rec: rectangle,
-  circle: circle
-}
-
-create dataset MyData(MyRecord)
-  primary key id;
-
-create index btree_index_docid on MyData(docid) type btree;
-create index btree_index_val1 on MyData(val1) type btree;
-create index rtree_index_point on MyData(point) type rtree;
-create index rtree_index_rec on MyData(rec) type rtree;
-create index ngram_index_title on MyData(title) type ngram(3);
-create index keyword_index_title on MyData(title) type keyword;
-
-let $area:=create-circle(create-point(4.0,3.0), 5.0)
-for $o in dataset('MyData')
-where spatial-intersect($o.point, $area)
-order by $o.id
-return {"id":$o.id}
-

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.sqlpp
new file mode 100644
index 0000000..dae4f0a
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.sqlpp
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary RTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
+ *                  : However, we set the "noindexonly" option to true. So, 
the index-only plan should not be triggered.
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+/* For raw Fragile data */
+create type FragileTypeRaw as closed {
+  row_id: int32,
+  sid: int32,
+  date: string,
+  day: int32,
+  time: string,
+  bpm: int32,
+  RR: float,
+  /* new string field and location field*/
+  text: string,
+  location: point,
+  text2: string
+
+};
+
+/* For cleaned Fragile data */
+create type FragileType as closed {
+  row_id: int32,
+  sid: int32,
+  date: date,
+  day: int32,
+  time: time,
+  bpm: int32,
+  RR: float,
+
+  /* new string field and location field*/
+  text: string,
+  location: point,
+  text2: string
+};
+
+/* Create dataset for loading raw Fragile data */
+create dataset Fragile_raw (FragileTypeRaw)
+primary key row_id;
+
+/* Create dataset for cleaned Fragile data */
+create dataset Fragile (FragileType)
+primary key row_id;
+
+
+/* Create rtree secondary index on dataset clean Fragile */
+create index cfLocation on Fragile(location) type rtree;
+create index cfLocation on Fragile_raw(location) type rtree;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+};
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+set noindexonly 'true';
+
+select count(*) from (
+select x.location
+from Fragile_raw x
+where spatial_intersect(x.location, create_polygon([0.0,0.0, 2.0,2.0, 0.0,2.0, 
2.0,0.0]))
+) a;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-01.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-01.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-01.sqlpp
new file mode 100644
index 0000000..7a37b2d
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-01.sqlpp
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary RTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+/* For raw Fragile data */
+create type FragileTypeRaw as closed {
+  row_id: int32,
+  sid: int32,
+  date: string,
+  day: int32,
+  time: string,
+  bpm: int32,
+  RR: float,
+  /* new string field and location field*/
+  text: string,
+  location: point,
+  text2: string
+
+};
+
+/* For cleaned Fragile data */
+create type FragileType as closed {
+  row_id: int32,
+  sid: int32,
+  date: date,
+  day: int32,
+  time: time,
+  bpm: int32,
+  RR: float,
+
+  /* new string field and location field*/
+  text: string,
+  location: point,
+  text2: string
+};
+
+/* Create dataset for loading raw Fragile data */
+create dataset Fragile_raw (FragileTypeRaw)
+primary key row_id;
+
+/* Create dataset for cleaned Fragile data */
+create dataset Fragile (FragileType)
+primary key row_id;
+
+
+/* Create rtree secondary index on dataset clean Fragile */
+create index cfLocation on Fragile(location) type rtree;
+create index cfLocation on Fragile_raw(location) type rtree;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+};
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+select count(*) from (
+select x.location
+from Fragile_raw x
+where spatial_intersect(x.location, create_polygon([0.0,0.0, 2.0,2.0, 0.0,2.0, 
2.0,0.0]))
+) a;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-02.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-02.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-02.aql
new file mode 100644
index 0000000..e82a527
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-02.aql
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary RTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+/* For raw Fragile data */
+create type FragileTypeRaw as closed {
+  row_id: int32,
+  sid: int32,
+  date: string,
+  day: int32,
+  time: string,
+  bpm: int32,
+  RR: float,
+  /* new string field and location field*/
+  text: string,
+  location: point,
+  text2: string
+
+};
+
+/* For cleaned Fragile data */
+create type FragileType as closed {
+  row_id: int32,
+  sid: int32,
+  date: date,
+  day: int32,
+  time: time,
+  bpm: int32,
+  RR: float,
+
+  /* new string field and location field*/
+  text: string,
+  location: point,
+  text2: string
+};
+
+/* Create dataset for loading raw Fragile data */
+create dataset Fragile_raw (FragileTypeRaw)
+primary key row_id;
+
+/* Create dataset for cleaned Fragile data */
+create dataset Fragile (FragileType)
+primary key row_id;
+
+
+/* Create rtree secondary index on dataset clean Fragile */
+create index cfLocation on Fragile(location) type rtree;
+create index cfLocation on Fragile_raw(location) type rtree;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
+for $o in dataset('MyData')
+where spatial-intersect($o.point, $area)
+order by $o.id
+return {"id":$o.id}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/06cec01b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-03.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-03.aql
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-03.aql
new file mode 100644
index 0000000..abb15e1
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/rtree-index/rtree-sidx-idxonly-03.aql
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ *  Description     : Secondary RTree Index index-only selection plan 
verification test
+ *                  : The test is intended to verify that the secondary RTree 
index is used in the optimized query plan.
+ *                  : In this plan, we fetch PK and SK based on a select 
condition that utilizes a secondary index.
+ *                  : The plan should have two paths after the secondary 
index-lookup.
+ *                  : The left path:
+ *                      ... -> unnest-map (sidx) -> split -> unnest-map (pidx) 
-> select -> union -> ...
+ *                  : The right path:
+ *                      ... -> unnest-map (sidx) -> split ->                   
             union -> ...
+ *  Expected Result : Success
+ *
+*/
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+/* For raw Fragile data */
+create type FragileTypeRaw as closed {
+  row_id: int32,
+  sid: int32,
+  date: string,
+  day: int32,
+  time: string,
+  bpm: int32,
+  RR: float,
+  /* new string field and location field*/
+  text: string,
+  location: point,
+  text2: string
+
+};
+
+/* For cleaned Fragile data */
+create type FragileType as closed {
+  row_id: int32,
+  sid: int32,
+  date: date,
+  day: int32,
+  time: time,
+  bpm: int32,
+  RR: float,
+
+  /* new string field and location field*/
+  text: string,
+  location: point,
+  text2: string
+};
+
+/* Create dataset for loading raw Fragile data */
+create dataset Fragile_raw (FragileTypeRaw)
+primary key row_id;
+
+/* Create dataset for cleaned Fragile data */
+create dataset Fragile (FragileType)
+primary key row_id;
+
+
+/* Create rtree secondary index on dataset clean Fragile */
+create index cfLocation on Fragile(location) type rtree;
+create index cfLocation on Fragile_raw(location) type rtree;
+
+create type MyRecord as closed {
+  id: int64,
+  docid: int64,
+  val1: int64,
+  title: string,
+  point: point,
+  kwds: string,
+  line1: line,
+  line2: line,
+  poly1: polygon,
+  poly2: polygon,
+  rec: rectangle,
+  circle: circle
+}
+
+create dataset MyData(MyRecord)
+  primary key id;
+
+create index btree_index_docid on MyData(docid) type btree;
+create index btree_index_val1 on MyData(val1) type btree;
+create index rtree_index_point on MyData(point) type rtree;
+create index rtree_index_rec on MyData(rec) type rtree;
+create index ngram_index_title on MyData(title) type ngram(3);
+create index keyword_index_title on MyData(title) type keyword;
+
+let $area:=create-rectangle(point("0.0,0.0"), point("4.0,4.0"))
+for $o in dataset('MyData')
+where spatial-intersect($o.point, $area)
+order by $o.id
+return {"point":$o.point}

Reply via email to