SQL++ parser:
1. refactored asterix-aql to become asterix-lang-common and asterix-lang-aql, where the former is the common part for different languages;
2. added asterix-lang-sqlpp on top of asterix-lang-common;
3. ported parser tests, optimizer tests and runtime tests in asterix-app to their sql++ version, and added parser tests for all the queries.
Change-Id: Ie5af4e3b692ca017ec047a1ba3b404a51beb3a2e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/466
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01.sqlpp
new file mode 100644
index 0000000..674e149
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgTextIx on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_01.adm"
+select element {'tweetid1':t1.tweetid,'count1':t1.countA,'t2info':(
+ select element {'tweetid2':t2.tweetid,'count2':t2.countB}
+ from TweetMessages as t2
+ where (t1.countA /*+ indexnl */ = t2.countB)
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.sqlpp
new file mode 100644
index 0000000..46be922
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgTextIx on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_02.adm"
+select element {'tweetid1':t1.tweetid,'count1':t1.countA,'t2info':(
+ select element {'tweetid2':t2.tweetid,'count2':t2.countB}
+ from TweetMessages as t2
+ where ((t1.countA /*+ indexnl */ = t2.countB) and (t1.tweetid != t2.tweetid))
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_01.sqlpp
new file mode 100644
index 0000000..7852d42
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_01.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-join_01.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ > emp2.fname) and (emp1.lname /*+ indexnl */ > emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_02.sqlpp
new file mode 100644
index 0000000..004c2c8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_02.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-join_02.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ < emp2.fname) and (emp1.lname /*+ indexnl */ < emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_03.sqlpp
new file mode 100644
index 0000000..759c9e4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-join_03.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-join_03.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ = emp2.fname) and (emp1.lname /*+ indexnl */ = emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_01.sqlpp
new file mode 100644
index 0000000..b6cedb7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_01.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_01.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ < emp2.fname) and (emp1.lname /*+ indexnl */ > emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_02.sqlpp
new file mode 100644
index 0000000..467a6c0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_02.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_02.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ > emp2.fname) and (emp1.lname /*+ indexnl */ < emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_03.sqlpp
new file mode 100644
index 0000000..0c6f6d3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_03.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_03.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ > emp2.fname) and (emp1.lname /*+ indexnl */ = emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_04.sqlpp
new file mode 100644
index 0000000..0bfa882
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_04.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_04.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ < emp2.fname) and (emp1.lname /*+ indexnl */ = emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_05.sqlpp
new file mode 100644
index 0000000..389feb8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_05.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_05.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ = emp2.fname) and (emp1.lname /*+ indexnl */ > emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_06.sqlpp
new file mode 100644
index 0000000..f4e741b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-composite-key-prefix-join_06.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ fname : string,
+ lname : string
+}
+
+create table Names(Name) primary key fname,lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_06.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ = emp2.fname) and (emp1.lname /*+ indexnl */ < emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-multipred.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-multipred.sqlpp
new file mode 100644
index 0000000..4c57e9e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-multipred.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Equi joins two datasets, Customers and Orders, based on the customer id.
+ * Given the 'indexnl' hint we expect the join to be transformed
+ * into an indexed nested-loop join using Customers' primary index.
+ * We expect the additional predicates to be put into a select above the
+ * primary index search.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create type test.OrderType as
+ closed {
+ oid : int32,
+ cid : int32,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Orders(OrderType) primary key oid;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join-multipred.adm"
+select element {'customer':c,'order':o}
+from Customers as c,
+ Orders as o
+where ((c.cid /*+ indexnl */ = o.cid) and (c.name < o.orderstatus) and (c.age < o.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-neg_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-neg_01.sqlpp
new file mode 100644
index 0000000..1806d5d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-neg_01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : This is a negative test, mis-spelt/incorrect HINT should result in
+ * a plan not using an indexed-nested loops join strategy. We expect a hash join.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join-neg_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key1 = y.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-neg_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-neg_02.sqlpp
new file mode 100644
index 0000000..551bd8b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join-neg_02.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : This is a negative test, mis-spelt/incorrect HINT should result in
+ * a plan not using an indexed-nested loops join strategy. We expect a hash join.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join-neg_02.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key2 = y.key1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_01.sqlpp
new file mode 100644
index 0000000..4628891
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that hash-exchanges internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key1 /*+ indexnl */ = y.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_02.sqlpp
new file mode 100644
index 0000000..4022363
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_02.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that hash-exchanges internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_02.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key2 /*+ indexnl */ = y.key1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_03.sqlpp
new file mode 100644
index 0000000..0ce834c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_03.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Equi joins two datasets, Customers and Orders, based on the customer id.
+ * Given the 'indexnl' hint we expect the join to be transformed
+ * into an indexed nested-loop join using Customers' primary index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create type test.OrderType as
+ closed {
+ oid : int32,
+ cid : int32,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Orders(OrderType) primary key oid;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_04.adm"
+select element {'customer':c,'order':o}
+from Customers as c,
+ Orders as o
+where (c.cid /*+ indexnl */ = o.cid)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_04.sqlpp
new file mode 100644
index 0000000..3e198aa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_04.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Equi joins two datasets, Customers and Orders, based on the customer id.
+ * Given the 'indexnl' hint we expect the join to be transformed
+ * into an indexed nested-loop join using Customers' primary index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create type test.OrderType as
+ closed {
+ oid : int32,
+ cid : int32,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Orders(OrderType) primary key oid;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_05.adm"
+select element {'customer':c,'order':o}
+from Orders as o,
+ Customers as c
+where (o.cid /*+ indexnl */ = c.cid)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_05.sqlpp
new file mode 100644
index 0000000..3dbb8e3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-equi-join_05.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Self-equi joins a dataset, Customers, based on the customer id.
+ * Given the 'indexnl' hint we expect the join to be transformed
+ * into an indexed nested-loop join using Customers' primary index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create table Customers(CustomerType) primary key cid;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_06.adm"
+select element {'customer1':c1,'customer2':c2}
+from Customers as c1,
+ Customers as c2
+where (c1.cid /*+ indexnl */ = c2.cid)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-ge-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-ge-join_01.sqlpp
new file mode 100644
index 0000000..64f3c59
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-ge-join_01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-ge-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key1 /*+ indexnl */ >= y.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-ge-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-ge-join_02.sqlpp
new file mode 100644
index 0000000..3c2e9f3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-ge-join_02.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-ge-join_02.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key2 /*+ indexnl */ <= y.key1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-gt-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-gt-join_01.sqlpp
new file mode 100644
index 0000000..e1e5ce2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-gt-join_01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-gt-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key1 /*+ indexnl */ > y.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-gt-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-gt-join_02.sqlpp
new file mode 100644
index 0000000..49677d4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-gt-join_02.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-gt-join_02.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key2 /*+ indexnl */ < y.key1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-le-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-le-join_01.sqlpp
new file mode 100644
index 0000000..e22bed0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-le-join_01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-le-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key1 /*+ indexnl */ <= y.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-le-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-le-join_02.sqlpp
new file mode 100644
index 0000000..8bcbcff
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-le-join_02.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-le-join_02.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key2 /*+ indexnl */ >= y.key1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-lt-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-lt-join_01.sqlpp
new file mode 100644
index 0000000..1e70a4d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-lt-join_01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-lt-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key1 /*+ indexnl */ < y.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-lt-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-lt-join_02.sqlpp
new file mode 100644
index 0000000..0cd44d0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/primary-lt-join_02.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne’s primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestType as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create table test1.DsOne(TestType) primary key key1;
+
+create table test1.DsTwo(TestType) primary key key1;
+
+write output to nc1:"rttest/btree-index-join_primary-lt-join_02.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.key2 /*+ indexnl */ > y.key1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join-multiindex.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join-multiindex.sqlpp
new file mode 100644
index 0000000..c15319b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join-multiindex.sqlpp
@@ -0,0 +1,75 @@
+/*
+ * 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 : Equi joins two datasets, FacebookUsers and FacebookMessages, based on their user's id.
+ * We first expect FacebookUsers' primary index to be used
+ * to satisfy the range condition on it's primary key.
+ * FacebookMessages has a secondary btree index on author-id-copy, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.EmploymentType as
+ closed {
+ "organization-name" : string,
+ "start-date" : date,
+ "end-date" : date?
+}
+
+create type test.FacebookUserType as
+ closed {
+ id : int32,
+ "id-copy" : int32,
+ alias : string,
+ name : string,
+ "user-since" : datetime,
+ "user-since-copy" : datetime,
+ "friend-ids" : {{int32}},
+ employment : [EmploymentType]
+}
+
+create type test.FacebookMessageType as
+ closed {
+ "message-id" : int32,
+ "message-id-copy" : int32,
+ "author-id" : int32,
+ "author-id-copy" : int32,
+ "in-response-to" : int32?,
+ "sender-location" : point?,
+ message : string
+}
+
+create table FacebookUsers(FacebookUserType) primary key id;
+
+create table FacebookMessages(FacebookMessageType) primary key "message-id";
+
+create index fbmIdxAutId if not exists on FacebookMessages ("author-id-copy") type btree;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multiindex.adm"
+select element {'fbu-ID':user.id,'fbm-auth-ID':message."author-id",'uname':user.name,'message':message.message}
+from FacebookUsers as user,
+ FacebookMessages as message
+where ((user.id /*+ indexnl */ = message."author-id-copy") and (user.id >= 11000) and (user.id <= 12000))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join-multipred.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join-multipred.sqlpp
new file mode 100644
index 0000000..93cac14
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join-multipred.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the additional predicates to be put into a select above the
+ * primary index search.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index title_index on DBLP (title) type btree;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multipred.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.title /*+ indexnl */ = b.title) and (a.authors < b.authors) and (a.misc > b.misc))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_01.sqlpp
new file mode 100644
index 0000000..28d1996
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_01.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index title_index on DBLP (title) type btree;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.title /*+ indexnl */ = b.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_02.sqlpp
new file mode 100644
index 0000000..368d5de
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_02.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * CSX has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index title_index on CSX (title) type btree;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.title /*+ indexnl */ = b.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_03.sqlpp
new file mode 100644
index 0000000..817f1e5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index-join/secondary-equi-join_03.sqlpp
@@ -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 : Equi self-joins a dataset, DBLP, based on its title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index title_index on DBLP (title) type btree;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (a.title /*+ indexnl */ = b.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-01.sqlpp
new file mode 100644
index 0000000..390b32f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : for an invocation of current-datetime()
+ * Expected Result : Success
+ * Date : 27th Aug 2015
+ * Author : Steven Jacobs
+ */
+
+drop database emergencyTest if exists;
+create database emergencyTest;
+
+use emergencyTest;
+
+
+create type emergencyTest.CHPReport as
+{
+ id : int64,
+ timestamp : datetime,
+ title : string,
+ message : string
+}
+
+create table CHPReports(CHPReport) primary key timestamp;
+
+select element emergency.message
+from CHPReports as emergency
+where ((emergency.timestamp >= (emergencyTest."current-datetime"() - emergencyTest."day-time-duration"('PT10H'))) and (emergency.title = 'ghost'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-02.sqlpp
new file mode 100644
index 0000000..0f3577a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-02.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : for an invocation of current-datetime()
+ * Expected Result : Success
+ * Date : 27th Aug 2015
+ * Author : Steven Jacobs
+ */
+
+drop database emergencyTest if exists;
+create database emergencyTest;
+
+use emergencyTest;
+
+
+create type emergencyTest.CHPReport as
+{
+ id : int64,
+ timestamp : datetime,
+ title : string,
+ message : string
+}
+
+create table CHPReports(CHPReport) primary key timestamp;
+
+select element emergency
+from CHPReports as emergency
+with time as (emergencyTest."current-datetime"() - emergencyTest."day-time-duration"('PT10H'))
+where (emergency.timestamp >= time)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-03.sqlpp
new file mode 100644
index 0000000..ae94e7b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-03.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : for an invocation of current-datetime()
+ * Expected Result : Success
+ * Date : 27th Aug 2015
+ * Author : Steven Jacobs
+ */
+
+drop database emergencyTest if exists;
+create database emergencyTest;
+
+use emergencyTest;
+
+
+create type emergencyTest.CHPReport as
+{
+ id : int64,
+ timestamp : datetime,
+ title : string,
+ message : string
+}
+
+create table CHPReports(CHPReport) primary key timestamp;
+
+select element emergency
+from CHPReports as emergency
+where (emergency.timestamp >= emergencyTest."current-datetime"())
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-04.sqlpp
new file mode 100644
index 0000000..16b0fc6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-datetime-04.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : This test makes sure that the plan is still okay when not converted to index search
+ * Expected Result : Success
+ * Date : 27th Aug 2015
+ * Author : Steven Jacobs
+ */
+
+drop database emergencyTest if exists;
+create database emergencyTest;
+
+use emergencyTest;
+
+
+create type emergencyTest.CHPReport as
+{
+ id : int64,
+ timestamp : datetime,
+ title : string,
+ message : string
+}
+
+create table CHPReports(CHPReport) primary key id;
+
+select element emergency
+from CHPReports as emergency
+where (emergency.timestamp >= emergencyTest."current-datetime"())
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-01.sqlpp
new file mode 100644
index 0000000..ac242c9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-01.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-01.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where (emp.fname > 'Roger')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-02.sqlpp
new file mode 100644
index 0000000..078fbfc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-02.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-02.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where (emp.fname >= 'Susan')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-03.sqlpp
new file mode 100644
index 0000000..70ebdf5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-03.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-03.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where (emp.fname < 'Isa')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-04.sqlpp
new file mode 100644
index 0000000..d0938fd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-04.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-04.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where (emp.fname <= 'Vanpatten')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-05.sqlpp
new file mode 100644
index 0000000..5efab34
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-05.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-05.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where (emp.fname != 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-06.sqlpp
new file mode 100644
index 0000000..47aae4e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-06.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-06.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where (emp.fname = 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-07.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-07.sqlpp
new file mode 100644
index 0000000..dcfdcc6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-07.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-07.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where (emp.lname = 'Kim')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-08.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-08.sqlpp
new file mode 100644
index 0000000..c205a75
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-08.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-08.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Young Seok') and (emp.lname = 'Kim'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-09.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-09.sqlpp
new file mode 100644
index 0000000..2a1bbe2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-09.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-09.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') or (emp.lname = 'Malaika'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-10.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-10.sqlpp
new file mode 100644
index 0000000..7194424
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-10.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification (usage) test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-10.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Alex') and (emp.lname < 'Zach'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-11.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-11.sqlpp
new file mode 100644
index 0000000..764a57e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-11.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan for predicates.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-11.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Allan') and (emp.lname < 'Zubi'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-12.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-12.sqlpp
new file mode 100644
index 0000000..0e000ca
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-12.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification (usage) test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-12.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Allan') and (emp.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-13.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-13.sqlpp
new file mode 100644
index 0000000..31002c8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-13.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-13.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') and (emp.lname < 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-14.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-14.sqlpp
new file mode 100644
index 0000000..d5c0fab
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-14.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-14.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Michael') and (emp.lname <= 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-15.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-15.sqlpp
new file mode 100644
index 0000000..6fb032c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-15.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-15.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname < 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-16.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-16.sqlpp
new file mode 100644
index 0000000..f229494
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-16.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-16.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname >= 'Kevin') and (emp.fname <= 'Mary') and (emp.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-17.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-17.sqlpp
new file mode 100644
index 0000000..cea3c05
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-17.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-17.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname <= 'Craig') and (emp.lname > 'Kevin'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-18.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-18.sqlpp
new file mode 100644
index 0000000..9269f32
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-18.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-18.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname != 'Michael') and (emp.lname != 'Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-19.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-19.sqlpp
new file mode 100644
index 0000000..7a70c2a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-19.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-19.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname <= 'Mary') and (emp.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-20.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-20.sqlpp
new file mode 100644
index 0000000..23b158c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-20.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-20.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname >= 'Kevin') and (emp.fname < 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-21.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-21.sqlpp
new file mode 100644
index 0000000..c9de7fb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-21.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-21.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname;
+
+select element emp
+from testdst as emp
+where (emp.fname > 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-22.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-22.sqlpp
new file mode 100644
index 0000000..c290924
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-22.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-22.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname;
+
+select element emp
+from testdst as emp
+where (emp.fname >= 'Sofia')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-23.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-23.sqlpp
new file mode 100644
index 0000000..94366d8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-23.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-23.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname;
+
+select element emp
+from testdst as emp
+where (emp.fname < 'Chen')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-24.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-24.sqlpp
new file mode 100644
index 0000000..7f68270
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-24.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-24.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname;
+
+select element emp
+from testdst as emp
+where (emp.fname <= 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-25.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-25.sqlpp
new file mode 100644
index 0000000..17bfe7b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-25.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-25.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Neil') and (emp.fname < 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-26.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-26.sqlpp
new file mode 100644
index 0000000..4414710
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-26.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-26.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Max') and (emp.fname <= 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-27.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-27.sqlpp
new file mode 100644
index 0000000..1f5b044
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-27.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 5th Feb 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-27.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname <= 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-28.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-28.sqlpp
new file mode 100644
index 0000000..cfdd0f8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-28.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 5th Feb 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-28.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname < 'Mary') and (emp.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-29.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-29.sqlpp
new file mode 100644
index 0000000..1653fb8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-29.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 5th Feb 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-29.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname >= 'Kevin') and (emp.fname < 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-30.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-30.sqlpp
new file mode 100644
index 0000000..ab70312
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-30.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 5th Feb 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-30.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname > 'Kevin') and (emp.fname < 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-31.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-31.sqlpp
new file mode 100644
index 0000000..1f5341e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-31.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-31.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') and (emp.lname > 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-32.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-32.sqlpp
new file mode 100644
index 0000000..c579348
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-primary-32.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-32.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname < 'Julio') and (emp.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-33.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-33.sqlpp
new file mode 100644
index 0000000..1d588af
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-33.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-33.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname > 'Roger')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-34.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-34.sqlpp
new file mode 100644
index 0000000..7db2833
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-34.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-34.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname >= 'Susan')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-35.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-35.sqlpp
new file mode 100644
index 0000000..ae7992f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-35.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification (usage) test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-35.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname < 'Isa')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-36.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-36.sqlpp
new file mode 100644
index 0000000..bdd6630
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-36.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-36.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname <= 'Vanpatten')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-37.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-37.sqlpp
new file mode 100644
index 0000000..5dd5c02
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-37.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-37.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname != 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-38.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-38.sqlpp
new file mode 100644
index 0000000..20a4907
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-38.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-38.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname = 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-39.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-39.sqlpp
new file mode 100644
index 0000000..f6cea67
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-39.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-39.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.lname = 'Kim')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-40.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-40.sqlpp
new file mode 100644
index 0000000..a4ce4f9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-40.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-40.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Young Seok') and (emp.lname = 'Kim'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-41.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-41.sqlpp
new file mode 100644
index 0000000..26a412c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-41.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-41.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') or (emp.lname = 'Malaika'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-42.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-42.sqlpp
new file mode 100644
index 0000000..3242469
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-42.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-42.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Alex') and (emp.lname < 'Zach'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-43.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-43.sqlpp
new file mode 100644
index 0000000..88ca141
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-43.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-43.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Allan') and (emp.lname < 'Zubi'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-44.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-44.sqlpp
new file mode 100644
index 0000000..79a8c6b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-44.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-44.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Allan') and (emp.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-45.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-45.sqlpp
new file mode 100644
index 0000000..6b04a6c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-45.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-45.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') and (emp.lname < 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-46.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-46.sqlpp
new file mode 100644
index 0000000..17894da
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-46.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-46.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Michael') and (emp.lname <= 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-47.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-47.sqlpp
new file mode 100644
index 0000000..05f0eb0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-47.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-47.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname < 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-48.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-48.sqlpp
new file mode 100644
index 0000000..0d740e6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-48.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-48.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname >= 'Kevin') and (emp.fname <= 'Mary') and (emp.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-49.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-49.sqlpp
new file mode 100644
index 0000000..afd739f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-49.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-49.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname <= 'Craig') and (emp.lname > 'Kevin'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-50.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-50.sqlpp
new file mode 100644
index 0000000..a641886
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-50.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-50.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname != 'Michael') and (emp.lname != 'Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-51.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-51.sqlpp
new file mode 100644
index 0000000..48b4d8f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-51.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-51.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname <= 'Mary') and (emp.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-52.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-52.sqlpp
new file mode 100644
index 0000000..4b2f5df
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-52.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-52.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname >= 'Kevin') and (emp.fname < 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-53.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-53.sqlpp
new file mode 100644
index 0000000..8d1ec8a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-53.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-53.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname <= 'Kevin') and (emp.fname <= 'Mary') and (emp.lname >= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-54.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-54.sqlpp
new file mode 100644
index 0000000..3f0ba33
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-54.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-54.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname > 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-55.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-55.sqlpp
new file mode 100644
index 0000000..fdf8e02
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-55.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-55.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname >= 'Sofia')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-56.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-56.sqlpp
new file mode 100644
index 0000000..d7e6482
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-56.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-56.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname < 'Chen')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-57.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-57.sqlpp
new file mode 100644
index 0000000..e664250
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-57.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-57.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname <= 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-58.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-58.sqlpp
new file mode 100644
index 0000000..cafa0c8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-58.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-58.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Neil') and (emp.fname < 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-59.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-59.sqlpp
new file mode 100644
index 0000000..9f316b3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-59.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-59.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Max') and (emp.fname <= 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-60.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-60.sqlpp
new file mode 100644
index 0000000..2636b3c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-60.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-60.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.fname = 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-61.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-61.sqlpp
new file mode 100644
index 0000000..499b9ff
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-61.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-61.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname <= 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-62.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-62.sqlpp
new file mode 100644
index 0000000..45ef71b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-62.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-62.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') and (emp.lname > 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-63.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-63.sqlpp
new file mode 100644
index 0000000..b172a39
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/btree-index/btree-secondary-63.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-63.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname,lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname < 'Julio') and (emp.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/collocated.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/collocated.sqlpp
new file mode 100644
index 0000000..ee85e93
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/collocated.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+drop database colocated if exists;
+create database colocated;
+
+use colocated;
+
+
+create type colocated.UserType as
+{
+ uid : int32,
+ name : string,
+ lottery_numbers : {{int32}}
+}
+
+create type colocated.VisitorType as
+{
+ vid : int32,
+ name : string,
+ lottery_numbers : {{int32}}
+}
+
+create table Users(UserType) primary key uid;
+
+create table Visitors(VisitorType) primary key vid;
+
+write output to nc1:"/tmp/fuzzy1.adm"
+select element {'user_name':user.name,'visitor_name':visitor.name}
+from Users as user,
+ Visitors as visitor
+where (user.uid = visitor.vid)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/consolidate-selects-complex.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/consolidate-selects-complex.sqlpp
new file mode 100644
index 0000000..2580817
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/consolidate-selects-complex.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table DBLP(DBLPType) primary key id on group1;
+
+load table DBLP using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/dblp-small/dblp-small-id.txt"),("format"="delimited-text"),("delimiter"=":")) pre-sorted;
+
+write output to nc1:"rttest/consolidate-complex-selects.aql"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."word-tokens"(paper.title),
+ query_tokens as test."word-tokens"('Transactions for Cooperative Environments'),
+ jacca as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.800000f),
+ jaccb as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.500000f),
+ jaccc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.300000f)
+where (jacca[0] and jaccb[0] and (paper.authors = 'testauth') and jaccc)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/consolidate-selects-simple.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/consolidate-selects-simple.sqlpp
new file mode 100644
index 0000000..e034b8c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/consolidate-selects-simple.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Customers(CustomerType) primary key c_custkey on group1;
+
+write output to nc1:"rttest/consolidate-selects-simple.aql"
+select element c
+from Customers as c
+where ((c.c_name = 'testname') and (c.c_address = 'testaddr') and (c.c_nationkey = 1) and (c.c_phone = '123456789'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/const-folding.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/const-folding.sqlpp
new file mode 100644
index 0000000..f742174
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/const-folding.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/divide.adm"
+{'a':(1 + 2),'b':['foo','bar'][0]}.b;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/count-tweets.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/count-tweets.sqlpp
new file mode 100644
index 0000000..04a3b15
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/count-tweets.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+drop database twitter if exists;
+create database twitter;
+
+use twitter;
+
+
+create type twitter.Tweet as
+{
+ id : int32,
+ tweetid : int64,
+ loc : point,
+ time : datetime,
+ text : string
+}
+
+create external table TwitterData(Tweet) using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"(("path"="nc1://data/twitter/smalltweets.txt"),("format"="adm"));
+
+write output to nc1:"/tmp/count-tweets.adm"
+select element {'word':tok,'count':twitter.count(token)}
+from TwitterData as t,
+ tokens as token
+with tokens as twitter."word-tokens"(t.text)
+group by token as tok
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/cust_group_no_agg.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/cust_group_no_agg.sqlpp
new file mode 100644
index 0000000..bef6677
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/cust_group_no_agg.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+drop database group_no_agg if exists;
+create database group_no_agg;
+
+use group_no_agg;
+
+
+create type group_no_agg.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Customers(CustomerType) primary key c_custkey on group1;
+
+write output to nc1:"/tmp/.adm"
+select element name
+from Customers as c
+group by c.c_name as name
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/denorm-cust-order.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/denorm-cust-order.sqlpp
new file mode 100644
index 0000000..0bcdfaa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/denorm-cust-order.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+drop database custorder if exists;
+create database custorder;
+
+use custorder;
+
+
+create type custorder.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type custorder.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create type custorder.OrderType as
+ closed {
+ oid : int32,
+ cid : int32,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Customers(CustomerType) primary key cid on group1;
+
+create table Orders(OrderType) primary key oid on group1;
+
+write output to nc1:"/tmp/custorder.adm"
+select element {'cid':cid,'cust':cust,'cnt-orders':custorder.count(o),'orders':o}
+from Customers as c,
+ Orders as o
+where (c.cid = o.cid)
+group by c.cid as cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-1.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-1.sqlpp
new file mode 100644
index 0000000..421975b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-1.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TestType as
+{
+ id : string,
+ idx : string,
+ "no-idx" : string
+}
+
+create table TestSet(TestType) primary key id;
+
+create index TestSetIndex on TestSet (idx) type btree;
+
+delete x from TestSet
+ where ((x.id = 'one') or (x.id = 'two'));
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-2.sqlpp
new file mode 100644
index 0000000..f6407be
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-2.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TestType as
+{
+ id : string,
+ idx : string,
+ "no-idx" : string
+}
+
+create table TestSet(TestType) primary key id;
+
+create index TestSetIndex on TestSet (idx) type btree;
+
+delete x from TestSet
+ where ((x.idx = 'one') or (x.idx = 'two'));
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-3.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-3.sqlpp
new file mode 100644
index 0000000..e7185e8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/disjunction-to-join-delete-3.sqlpp
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TestType as
+{
+ id : string,
+ idx : string,
+ "no-idx" : string
+}
+
+create table TestSet(TestType) primary key id;
+
+create index TestSetIndex on TestSet (idx) type btree;
+
+delete x from TestSet
+ where ((x."no-idx" = 'one') or (x."no-idx" = 'two'));
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/distinct_aggregate.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/distinct_aggregate.sqlpp
new file mode 100644
index 0000000..22df976
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/distinct_aggregate.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems_q1(LineItemType) primary key l_orderkey,l_linenumber on group1;
+
+write output to nc1:"rttest/tpch_q1_pricing_summary_report_nt.adm"
+select element {'l_returnflag':l_returnflag,'l_linestatus':l_linestatus,'count_suppkey':tpch.count(g)}
+from (
+ select element {'l_returnflag':l_returnflag,'l_linestatus':l_linestatus,'l_suppkey':l_suppkey}
+ from LineItems_q1 as l
+ where (l.l_shipdate <= '1998-09-02')
+ group by l.l_returnflag as l_returnflag,l.l_linestatus as l_linestatus,l.l_suppkey as l_suppkey
+) as g
+group by g.l_returnflag as l_returnflag,g.l_linestatus as l_linestatus
+order by l_returnflag,l_linestatus
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/filter-nested.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/filter-nested.sqlpp
new file mode 100644
index 0000000..d9de921
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/filter-nested.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/filter-nested.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname with filter on nested.lname;
+
+select element emp.nested
+from testdst as emp
+where (emp.nested.lname > 'Roger')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-dblp-csx.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-dblp-csx.sqlpp
new file mode 100644
index 0000000..fc899bc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-dblp-csx.sqlpp
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+drop database "fj-dblp-csx" if exists;
+create database "fj-dblp-csx";
+
+use "fj-dblp-csx";
+
+
+create type "fj-dblp-csx".DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type "fj-dblp-csx".CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table DBLP(DBLPType) primary key id on group1;
+
+create table CSX(CSXType) primary key id on group1;
+
+write output to nc1:"rttest/fj-dblp-csx.adm"
+select element {'idDBLP':idDBLP,'idCSX':idCSX}
+from DBLP as paperDBLP,
+ tokensDBLP as prefixTokenDBLP,
+ CSX as paperCSX,
+ tokensCSX as prefixTokenCSX
+with idDBLP as paperDBLP.id,
+ unrankedTokensDBLP as "fj-dblp-csx"."counthashed-word-tokens"(paperDBLP.title),
+ tokensDBLP as (
+ select element i
+ from unrankedTokensDBLP as token,
+ (
+ select element paper.title
+ from DBLP as paper
+ ) as tokenRanked at i
+ where (token = tokenRanked)
+ order by i
+ ),
+ idCSX as paperCSX.id,
+ unrankedTokensCSX as "fj-dblp-csx"."counthashed-word-tokens"(paperCSX.title),
+ tokensCSX as (
+ select element i
+ from unrankedTokensCSX as token,
+ (
+ select element paper.title
+ from DBLP as paper
+ ) as tokenRanked at i
+ where (token = tokenRanked)
+ order by i
+ )
+where (prefixTokenDBLP = prefixTokenCSX)
+group by idDBLP as idDBLP,idCSX as idCSX
+order by idDBLP,idCSX
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-phase1.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-phase1.sqlpp
new file mode 100644
index 0000000..2b832ec
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-phase1.sqlpp
@@ -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.
+ */
+
+drop database rares03 if exists;
+create database rares03;
+
+use rares03;
+
+
+create type rares03.UserType as
+{
+ uid : int32,
+ name : string,
+ lottery_numbers : {{int32}}
+}
+
+create type rares03.VisitorType as
+{
+ vid : int32,
+ name : string,
+ lottery_numbers : {{int32}}
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Users(UserType) primary key uid on group1;
+
+create table Visitors(VisitorType) primary key vid on group1;
+
+write output to nc1:"/tmp/rares03.adm"
+select element {'uid':user.uid,'tokens':tokens}
+from Users as user
+with tokens as (
+ select element i
+ from user.lottery_numbers as lottery_number,
+ (
+ select element item
+ from Users as user,
+ user.lottery_numbers as lottery_number
+ group by lottery_number as item
+ with count as rares03.count(user)
+ order by count desc
+ ) as token at i
+ where (lottery_number = token)
+ order by token
+ )
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-phase2-with-hints.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-phase2-with-hints.sqlpp
new file mode 100644
index 0000000..96abac0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/fj-phase2-with-hints.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+drop database fuzzyjoin_078 if exists;
+create database fuzzyjoin_078;
+
+use fuzzyjoin_078;
+
+
+create type fuzzyjoin_078.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table DBLP_fuzzyjoin_078(DBLPType) primary key id on group1;
+
+write output to nc1:"rttest/fuzzyjoin_078.adm"
+select element {'id':paperDBLP.id,'tokens':tokensDBLP}
+from DBLP_fuzzyjoin_078 as paperDBLP
+with unrankedTokensDBLP as fuzzyjoin_078."counthashed-word-tokens"(paperDBLP.title),
+ tokensDBLP as (
+ select element i
+ from unrankedTokensDBLP as token,
+ (
+ select element tokenGroupped
+ from DBLP_fuzzyjoin_078 as paper,
+ fuzzyjoin_078."counthashed-word-tokens"(paper.title) as token
+ /* +hash */
+ group by token as tokenGroupped
+ order by fuzzyjoin_078.count(paper),tokenGroupped
+ ) as tokenRanked at i
+ where (token = tokenRanked)
+ order by i
+ )
+order by paperDBLP.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/hashjoin-with-unnest.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/hashjoin-with-unnest.sqlpp
new file mode 100644
index 0000000..b2b64fb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/hashjoin-with-unnest.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests that non-datascan unnests are pushed through join and
+ * : the query plan is rewritten as hybrid hash join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TestType as
+{
+ id : int32,
+ name : string
+}
+
+create table t1(TestType) primary key id;
+
+create table t2(TestType) primary key id;
+
+write output to nc1:"rttest/hahsjoin-with-unnest.adm"
+select element {'t1':m,'t2':n}
+from t1 as m,
+ t2 as n,
+ m.hobbies as a,
+ n.hobbies as b
+where (a = b)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inline-funs.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inline-funs.sqlpp
new file mode 100644
index 0000000..d815ea6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inline-funs.sqlpp
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"/tmp/inline_funs.adm"
+declare function f1() {
+(1 + test.f2())
+};
+declare function f2() {
+(2 + test.f3() + test.f3() + test.f3() + test.f4())
+};
+declare function f3() {
+(0 - 1)
+};
+declare function f4() {
+1001
+};
+select element test.f1();
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inlined_q18_large_volume_customer.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inlined_q18_large_volume_customer.sqlpp
new file mode 100644
index 0000000..a402585
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inlined_q18_large_volume_customer.sqlpp
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+drop database inlined_q18_large_volume_customer if exists;
+create database inlined_q18_large_volume_customer;
+
+use inlined_q18_large_volume_customer;
+
+
+create type inlined_q18_large_volume_customer.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type inlined_q18_large_volume_customer.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type inlined_q18_large_volume_customer.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems(LineItemType) primary key l_orderkey,l_linenumber on group1;
+
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+create table Customers(CustomerType) primary key c_custkey on group1;
+
+write output to nc1:"/tmp/inlined_q18_large_volume_customer.adm"
+select element {'c_name':c_name,'c_custkey':c_custkey,'o_orderkey':o_orderkey,'o_orderdate':o_orderdate,'o_totalprice':o_totalprice,'sum_quantity':inlined_q18_large_volume_customer.sum((
+ select element j.l_quantity
+ from l as j
+ ))}
+from Customers as c,
+ Orders as o,
+ (
+ select element {'l_orderkey':l_orderkey,'t_sum_quantity':inlined_q18_large_volume_customer.sum((
+ select element i.l_quantity
+ from l as i
+ ))}
+ from LineItems as l
+ group by l.l_orderkey as l_orderkey
+) as t,
+ LineItems as l
+where ((c.c_custkey = o.o_custkey) and ((o.o_orderkey = t.l_orderkey) and (t.t_sum_quantity > 300)) and (l.l_orderkey = o.o_orderkey))
+group by c.c_name as c_name,c.c_custkey as c_custkey,o.o_orderkey as o_orderkey,o.o_orderdate as o_orderdate,o.o_totalprice as o_totalprice
+order by o_totalprice desc,o_orderdate
+limit 100
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-dataset-with-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-dataset-with-index.sqlpp
new file mode 100644
index 0000000..f98e6b3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-dataset-with-index.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+/*
+ * Test case Name : insert-and-scan-dataset-with-index.aql
+ * Description : This test is intended to test inserting into a dataset that has a secondary index and scan
+ * the data at the same time where we insert a materializing to prevent the possibility of deadlatch.
+ * Expected Result : Success
+ * Date : July 11 2013
+ */
+
+drop database test if exists;
+create database test;
+
+create type test.Emp as
+ closed {
+ id : int32,
+ fname : string,
+ lname : string,
+ age : int32,
+ dept : string
+}
+
+create table test.employee(Emp) primary key id;
+
+create index idx_employee_first_name on test.employee (fname) type btree;
+
+insert into test.employee
+select element {'id':(x.id + 10000),'fname':x.fname,'lname':x.lname,'age':x.age,'dept':x.dept}
+from "test.employee" as x
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-dataset.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-dataset.sqlpp
new file mode 100644
index 0000000..c01c825
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-dataset.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+/*
+ * Test case Name : insert-and-scan-dataset.aql
+ * Description : This test is intended to test inserting into a dataset and scan it at the same time
+ * where we insert a materializing to prevent the possibility of deadlatch.
+ * Expected Result : Success
+ * Date : July 11 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.myDataType as
+{
+ id : int32
+}
+
+create table myData(myDataType) primary key id;
+
+insert into myData
+select element {'id':(x.id + 1)}
+from myData as x
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-joined-datasets.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-joined-datasets.sqlpp
new file mode 100644
index 0000000..b8f7f33
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/insert-and-scan-joined-datasets.sqlpp
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+/*
+ * Test case Name : insert-and-scan-joined-datasets.aql
+ * Description : This test is intended to test inserting into a dataset where the incoming stream
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.myDataType as
+{
+ id : int32
+}
+
+create table myData(myDataType) primary key id;
+
+create table myData2(myDataType) primary key id;
+
+insert into myData
+select element {'id':(x.id + 1)}
+from myData2 as x,
+ myData as y
+where (x.id = y.id)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/introhashpartitionmerge.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/introhashpartitionmerge.sqlpp
new file mode 100644
index 0000000..b3aa493
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/introhashpartitionmerge.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+drop database fuzzyjoin if exists;
+create database fuzzyjoin;
+
+use fuzzyjoin;
+
+
+create type fuzzyjoin.TOKENSRANKEDADMType as
+ closed {
+ token : int32,
+ rank : int32
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table TOKENSRANKEDADM(TOKENSRANKEDADMType) primary key rank on group1;
+
+write output to nc1:"rttest/introhashpartitionmerge.adm"
+select element token2.rank
+from TOKENSRANKEDADM as token1,
+ (
+ select element tokenRanked
+ from TOKENSRANKEDADM as tokenRanked
+ order by tokenRanked.rank
+) as token2
+where (token1.token = token2.token)
+order by token2.rank
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-contains-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-contains-panic.sqlpp
new file mode 100644
index 0000000..6146565
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-contains-panic.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the contains function.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains-panic.adm"
+select element o
+from DBLP as o
+where test.contains(o.title,'Mu')
+order by o.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-contains.sqlpp
new file mode 100644
index 0000000..ed755be
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-contains.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains.adm"
+select element o
+from DBLP as o
+where test.contains(o.title,'Multimedia')
+order by o.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp
new file mode 100644
index 0000000..be87443
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-check-panic.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.authors,'Amihay Motro',5)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-check.sqlpp
new file mode 100644
index 0000000..3d39e56
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-check.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-check.adm"
+select element o
+from DBLP as o
+where test."edit-distance-check"(o.authors,'Amihay Motro',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-panic.sqlpp
new file mode 100644
index 0000000..6c4993a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance-panic.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance function on strings.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-panic.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.authors,'Amihay Motro') <= 5)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance.sqlpp
new file mode 100644
index 0000000..dfa9dc7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-edit-distance.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance function on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.authors,'Amihay Motro') <= 1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp
new file mode 100644
index 0000000..49564bc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query with ~= using edit-distance on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-fuzzyeq-edit-distance.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "1";
+
+select element o
+from DBLP as o
+where (o.authors ~= 'Amihay Motro')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..0fa1bd5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query with ~= using Jaccard on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element o
+from DBLP as o
+where (test."gram-tokens"(o.title,3,false) ~= test."gram-tokens"('Transactions for Cooperative Environments',3,false))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-jaccard-check.sqlpp
new file mode 100644
index 0000000..b39d0f7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-jaccard-check.sqlpp
@@ -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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-jaccard-check.adm"
+select element o
+from DBLP as o
+where test."similarity-jaccard-check"(test."gram-tokens"(o.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false),0.500000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-jaccard.sqlpp
new file mode 100644
index 0000000..1c28b11
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ngram-jaccard.sqlpp
@@ -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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard function on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-jaccard.adm"
+select element o
+from DBLP as o
+where (test."similarity-jaccard"(test."gram-tokens"(o.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false)) >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-check-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-check-panic.sqlpp
new file mode 100644
index 0000000..859f585
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-check-panic.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the edit-distance-check function on lists.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-edit-distance-check-panic.adm"
+select element c
+from Customers as c
+where test."edit-distance-check"(c.interests,['computers','wine','walking'],3)[0]
+order by c.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-check.sqlpp
new file mode 100644
index 0000000..992933f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-check.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the edit-distance-check function on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-edit-distance-check.adm"
+select element c
+from Customers as c
+where test."edit-distance-check"(c.interests,['computers','wine','walking'],1)[0]
+order by c.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-panic.sqlpp
new file mode 100644
index 0000000..3397de8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance-panic.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the edit-distance function on lists.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-edit-distance-panic.adm"
+select element c
+from Customers as c
+where (test."edit-distance"(c.interests,['computers','wine','walking']) <= 3)
+order by c.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance.sqlpp
new file mode 100644
index 0000000..4f835d1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-edit-distance.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the edit-distance function on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-edit-distance.adm"
+select element c
+from Customers as c
+where (test."edit-distance"(c.interests,['computers','wine','walking']) <= 1)
+order by c.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-fuzzyeq-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-fuzzyeq-edit-distance.sqlpp
new file mode 100644
index 0000000..af22885
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-fuzzyeq-edit-distance.sqlpp
@@ -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 : Tests whether a keyword index is applied to optimize a selection query with ~= using edit-distance on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-fuzzyeq-edit-distance.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "1";
+
+select element c
+from Customers as c
+where (c.interests ~= ['computers','wine','walking'])
+order by c.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..40df5f9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-fuzzyeq-jaccard.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 : Tests whether a keyword is applied to optimize a selection query with ~= using Jaccard on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element c
+from Customers as c
+where (c.interests ~= ['databases','computers','wine'])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-jaccard-check.sqlpp
new file mode 100644
index 0000000..b30a924
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-jaccard-check.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-jaccard-check.adm"
+select element c
+from Customers as c
+where test."similarity-jaccard-check"(c.interests,['databases','computers','wine'],0.700000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-jaccard.sqlpp
new file mode 100644
index 0000000..635face
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/olist-jaccard.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard function on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-jaccard.adm"
+select element c
+from Customers as c
+where (test."similarity-jaccard"(c.interests,['databases','computers','wine']) >= 0.700000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..f56d978
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-fuzzyeq-jaccard.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 : Tests whether a keyword is applied to optimize a selection query with ~= using Jaccard on sets.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_ulist-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element c
+from Customers as c
+where (c.interests ~= {{'computers','wine','databases'}})
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-jaccard-check.sqlpp
new file mode 100644
index 0000000..266b18a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-jaccard-check.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on sets.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_ulist-jaccard.adm"
+select element c
+from Customers as c
+where test."similarity-jaccard-check"(c.interests,{{'computers','wine','databases'}},0.700000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-jaccard.sqlpp
new file mode 100644
index 0000000..1e3c845
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/ulist-jaccard.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard function on sets.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_ulist-jaccard.adm"
+select element c
+from Customers as c
+where (test."similarity-jaccard"(c.interests,{{'computers','databases','wine'}}) >= 0.700000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-contains.sqlpp
new file mode 100644
index 0000000..41f8234
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-contains.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the contains function.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-contains.adm"
+select element o
+from DBLP as o
+where test.contains(o.title,'Multimedia')
+order by o.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..5ff613d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether a keyword is applied to optimize a selection query with ~= using Jaccard on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element o
+from DBLP as o
+where (test."word-tokens"(o.title) ~= test."word-tokens"('Transactions for Cooperative Environments'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-jaccard-check.sqlpp
new file mode 100644
index 0000000..7317c59
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-jaccard-check.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard-check.adm"
+select element o
+from DBLP as o
+where test."similarity-jaccard-check"(test."word-tokens"(o.title),test."word-tokens"('Transactions for Cooperative Environments'),0.500000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-jaccard.sqlpp
new file mode 100644
index 0000000..faee18b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-basic/word-jaccard.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard function on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard.adm"
+select element o
+from DBLP as o
+where (test."similarity-jaccard"(test."word-tokens"(o.title),test."word-tokens"('Transactions for Cooperative Environments')) >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp
new file mode 100644
index 0000000..754e614
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using
+ * two edit-distance-check function of which only the first can be optimized with an index.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic-nopanic_01.adm"
+select element o
+from DBLP as o
+with eda as test."edit-distance-check"(o.authors,'Amihay Motro',3),
+ edb as test."edit-distance-check"(o.authors,'Amihay Motro',5)
+where (eda[0] and edb[0])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp
new file mode 100644
index 0000000..dacf18b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using
+ * two edit-distance-check function of which only the second can be optimized with an index.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic-nopanic_01.adm"
+select element o
+from DBLP as o
+with edb as test."edit-distance-check"(o.authors,'Amihay Motro',5),
+ eda as test."edit-distance-check"(o.authors,'Amihay Motro',3)
+where (edb[0] and eda[0])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp
new file mode 100644
index 0000000..31b1e23
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp
@@ -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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.authors,'Amihay Motro',5)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let.sqlpp
new file mode 100644
index 0000000..61925e7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-let.sqlpp
@@ -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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.authors,'Amihay Motro',1)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp
new file mode 100644
index 0000000..cddd14c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index index is applied to optimize a selection query using the similarity-edit-distance-check function on the substring of the field.
+ * Tests that the optimizer rule correctly drills through the substring function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-substring.adm"
+select element {'id':paper.id,'title':paper.title}
+from DBLP as paper
+where test."edit-distance-check"(test.substring(paper.title,0,8),'datbase',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp
new file mode 100644
index 0000000..72dbd3b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp
@@ -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 : Tests whether an ngram_index index is applied to optimize a selection query using the similarity-edit-distance-check function on individual word tokens.
+ * Tests that the optimizer rule correctly drills through the word-tokens function and existential query.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-word-tokens.adm"
+select element {'id':paper.id,'title':paper.title}
+from DBLP as paper,
+ test."word-tokens"(paper.title) as word
+where test."edit-distance-check"(word,'Multmedia',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..32ebdc6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-jaccard-check-let.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-jaccard-check-let.adm"
+select element o
+from DBLP as o
+with jacc as test."similarity-jaccard-check"(test."gram-tokens"(o.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false),0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp
new file mode 100644
index 0000000..f5886b3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-jaccard-check-multi-let.adm"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."gram-tokens"(paper.title,3,false),
+ query_tokens as test."gram-tokens"('Transactions for Cooperative Environments',3,false),
+ jacc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-edit-distance-check-let-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-edit-distance-check-let-panic.sqlpp
new file mode 100644
index 0000000..4be9f47
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-edit-distance-check-let-panic.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on lists.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_olist-edit-distance-check-let-panic.adm"
+select element c
+from Customers as c
+with ed as test."edit-distance-check"(c.interests,['computers','wine','walking'],3)
+where ed[0]
+order by c.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-edit-distance-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-edit-distance-check-let.sqlpp
new file mode 100644
index 0000000..f6c4ba1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-edit-distance-check-let.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on lists.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_olist-edit-distance-check-let.adm"
+select element c
+from Customers as c
+with ed as test."edit-distance-check"(c.interests,['computers','wine','walking'],1)
+where ed[0]
+order by c.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..5dbb332
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/olist-jaccard-check-let.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on lists.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_olist-jaccard-check-let.adm"
+select element c
+from Customers as c
+with jacc as test."similarity-jaccard-check"(c.interests,['databases','computers','wine'],0.700000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ulist-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ulist-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..05eaf9b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/ulist-jaccard-check-let.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on lists.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_ulist-jaccard-check-let.adm"
+select element c
+from Customers as c
+with jacc as test."similarity-jaccard-check"(c.interests,['databases','computers','wine'],0.700000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/word-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/word-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..9458c4c4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/word-jaccard-check-let.sqlpp
@@ -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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_word-jaccard-check-let.adm"
+select element o
+from DBLP as o
+with jacc as test."similarity-jaccard-check"(test."word-tokens"(o.title),test."word-tokens"('Transactions for Cooperative Environments'),0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/word-jaccard-check-multi-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/word-jaccard-check-multi-let.sqlpp
new file mode 100644
index 0000000..a1e3a82
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-complex/word-jaccard-check-multi-let.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_word-jaccard-check-multi-let.adm"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."word-tokens"(paper.title),
+ query_tokens as test."word-tokens"('Transactions for Cooperative Environments'),
+ jacc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.800000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-edit-distance-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-edit-distance-inline.sqlpp
new file mode 100644
index 0000000..7f1951e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-edit-distance-inline.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance function of its authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-edit-distance-inline.adm"
+select element {'aauthors':a.authors,'bauthors':b.authors,'ed':ed}
+from DBLP as a,
+ DBLP as b
+with ed as test."edit-distance"(a.authors,b.authors)
+where ((ed < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-edit-distance.sqlpp
new file mode 100644
index 0000000..82492f0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-edit-distance.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-edit-distance.adm"
+select element {'aauthors':a.authors,'bauthors':b.authors}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-fuzzyeq-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-fuzzyeq-edit-distance.sqlpp
new file mode 100644
index 0000000..e6d57c1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-fuzzyeq-edit-distance.sqlpp
@@ -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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-fuzzyeq-edit-distance.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'aauthors':a.authors,'bauthors':b.authors}
+from DBLP as a,
+ CSX as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..6a4e7b4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-fuzzyeq-jaccard.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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'atitle':a.title,'btitle':b.title}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.title,3,false) ~= test."gram-tokens"(b.title,3,false)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-jaccard-inline.sqlpp
new file mode 100644
index 0000000..4bdcb05
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-jaccard-inline.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-jaccard-inline.adm"
+select element {'atitle':a.title,'btitle':b.title,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false))
+where ((jacc >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-jaccard.sqlpp
new file mode 100644
index 0000000..0981ab2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ngram-jaccard.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-jaccard.adm"
+select element {'atitle':a.title,'btitle':b.title}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-edit-distance-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-edit-distance-inline.sqlpp
new file mode 100644
index 0000000..456eba1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-edit-distance-inline.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 : Fuzzy self joins a dataset, Customers, based on the edit-distance function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_olist-edit-distance-inline.adm"
+select element {'ainterests':a.interests,'binterests':b.interests,'ed':ed}
+from Customers as a,
+ Customers as b
+with ed as test."edit-distance"(a.interests,b.interests)
+where ((ed <= 2) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-edit-distance.sqlpp
new file mode 100644
index 0000000..89a9f07
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-edit-distance.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 : Fuzzy joins two datasets, Customer and Customer2, based on the edit-distance function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_olist-edit-distance.adm"
+select element {'ainterests':a.interests,'binterests':b.interests}
+from Customers as a,
+ Customers2 as b
+where ((test."edit-distance"(a.interests,b.interests) <= 2) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-fuzzyeq-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-fuzzyeq-edit-distance.sqlpp
new file mode 100644
index 0000000..16ddaf7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-fuzzyeq-edit-distance.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using edit distance of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_olist-fuzzyeq-edit-distance.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'ainterests':a.interests,'binterests':b.interests}
+from Customers as a,
+ Customers2 as b
+where ((a.interests ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..d5f9ad8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using Jaccard of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_olist-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'ainterests':a.interests,'binterests':b.interests}
+from Customers as a,
+ Customers2 as b
+where ((a.interests /*+ indexnl */ ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-jaccard-inline.sqlpp
new file mode 100644
index 0000000..ba1f784
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-jaccard-inline.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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_olist-jaccard-inline.adm"
+select element {'ainterests':a.interests,'binterests':b.interests,'jacc':jacc}
+from Customers as a,
+ Customers as b
+with jacc as /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests)
+where ((jacc >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-jaccard.sqlpp
new file mode 100644
index 0000000..c600a84
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/olist-jaccard.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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_olist-jaccard.adm"
+select element {'ainterests':a.interests,'binterests':b.interests}
+from Customers as a,
+ Customers2 as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..5039c74
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using Jaccard of their interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ulist-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'ainterests':a.interests,'binterests':b.interests}
+from Customers as a,
+ Customers2 as b
+where ((a.interests /*+ indexnl */ ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-jaccard-inline.sqlpp
new file mode 100644
index 0000000..5046dcf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-jaccard-inline.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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard function of its interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ulist-jaccard-inline.adm"
+select element {'ainterests':a.interests,'binterests':b.interests,'jacc':jacc}
+from Customers as a,
+ Customers as b
+with jacc as /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests)
+where ((jacc >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-jaccard.sqlpp
new file mode 100644
index 0000000..c8c310b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/ulist-jaccard.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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ulist-jaccard.adm"
+select element {'ainterests':a.interests,'binterests':b.interests}
+from Customers as a,
+ Customers2 as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..dc298c0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-fuzzyeq-jaccard.sqlpp
@@ -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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_word-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'atitle':a.title,'btitle':b.title}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.title) ~= test."word-tokens"(b.title)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-jaccard-inline.sqlpp
new file mode 100644
index 0000000..318b202
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-jaccard-inline.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_word-jaccard-inline.adm"
+select element {'atitle':a.title,'btitle':b.title,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title))
+where ((jacc >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-jaccard.sqlpp
new file mode 100644
index 0000000..1f07f4a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join-noeqjoin/word-jaccard.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_word-jaccard.adm"
+select element {'atitle':a.title,'btitle':b.title}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/issue741.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/issue741.sqlpp
new file mode 100644
index 0000000..f3ba2ab
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/issue741.sqlpp
@@ -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 : Test that left-outer-join may use an available inverted index in index subtree.
+ * Issue : 741
+ * Expected Res : Success
+ * Date : 16th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+{
+ screen_name : string,
+ lang : string,
+ friends_count : int32,
+ statuses_count : int32,
+ name : string,
+ followers_count : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ sender_location : point?,
+ send_time : datetime,
+ referred_topics : {{string}},
+ message_text : string
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index topicIIx on TweetMessages (referred_topics) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_issue741.adm"
+select element {'tweet':t.tweetid,'similar-tweets':(
+ select element t2.tweetid
+ from TweetMessages as t2
+ with sim as test."similarity-jaccard-check"(t.referred_topics,t2.referred_topics,0.600000f)
+ where (sim[0] and (t2.tweetid != t.tweetid))
+ )}
+from TweetMessages as t
+where ((t.send_time >= test.datetime('2011-06-18T14:10:17')) and (t.send_time < test.datetime('2011-06-18T15:10:17')))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp
new file mode 100644
index 0000000..d29180d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp
@@ -0,0 +1,79 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgKeywordIx on TweetMessages ("message-text") type keyword;
+
+create index msgNgramIx on TweetMessages ("message-text") type ngram (3);
+
+create index topicKeywordIx on TweetMessages ("referred-topics") type keyword;
+
+write output to nc1:"rttest/inverted-index-join_leftouterjoin-probe-pidx-with-join-edit-distance-check_idx_01.adm"
+select element {'tweet':{'id':t1.tweetid,'topics':t1."message-text"},'similar-tweets':(
+ select element {'id':t2.tweetid,'topics':t2."message-text"}
+ from TweetMessages as t2
+ with sim as test."edit-distance-check"(t1."message-text",t2."message-text",7)
+ where (sim[0] and (t2.tweetid != t1.tweetid))
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid > test.int64('240'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.sqlpp
new file mode 100644
index 0000000..5afe4b6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.sqlpp
@@ -0,0 +1,79 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgKeywordIx on TweetMessages ("message-text") type keyword;
+
+create index msgNgramIx on TweetMessages ("message-text") type ngram (3);
+
+create index topicKeywordIx on TweetMessages ("referred-topics") type keyword;
+
+write output to nc1:"rttest/inverted-index-join_leftouterjoin-probe-pidx-with-join-jaccard-check_idx_01.adm"
+select element {'tweet':{'id':t1.tweetid,'topics':t1."referred-topics"},'similar-tweets':(
+ select element {'id':t2.tweetid,'topics':t2."referred-topics"}
+ from TweetMessages as t2
+ with sim as test."similarity-jaccard-check"(t1."referred-topics",t2."referred-topics",0.500000f)
+ where (sim[0] and (t2.tweetid != t1.tweetid))
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid > test.int64('240'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-contains.sqlpp
new file mode 100644
index 0000000..38dccaf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-contains.sqlpp
@@ -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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from DBLP as o1,
+ DBLP as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..89f490c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_01.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_02.sqlpp
new file mode 100644
index 0000000..4353249
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_02.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * CSX has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_03.sqlpp
new file mode 100644
index 0000000..91a2c8e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance-check function of its authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."edit-distance-check"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_04.sqlpp
new file mode 100644
index 0000000..e32b243
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-check_04.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance-check function of its authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_04.adm"
+select element {'arec':a,'brec':b,'ed':ed[1]}
+from DBLP as a,
+ DBLP as b
+with ed as test."edit-distance-check"(a.authors,b.authors,3)
+where (ed[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-contains.sqlpp
new file mode 100644
index 0000000..01fffe4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance-contains.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-contains function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-contains.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-contains"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_01.sqlpp
new file mode 100644
index 0000000..84842a0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_01.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_02.sqlpp
new file mode 100644
index 0000000..bfd9111
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_02.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * CSX has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_03.sqlpp
new file mode 100644
index 0000000..c27456f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance function of its authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_04.sqlpp
new file mode 100644
index 0000000..e302d06
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-edit-distance_04.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance function of its authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_03.adm"
+select element {'arec':a,'brec':b,'ed':ed}
+from DBLP as a,
+ DBLP as b
+with ed as test."edit-distance"(a.authors,b.authors)
+where ((ed < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp
new file mode 100644
index 0000000..124f818
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_02.sqlpp
new file mode 100644
index 0000000..8fc2a0c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_02.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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * CSX has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp
new file mode 100644
index 0000000..55880e4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on ~= using edit distance of its authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_03.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..a561118
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp
@@ -0,0 +1,66 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.title,3,false) ~= test."gram-tokens"(b.title,3,false)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp
new file mode 100644
index 0000000..a91dd7b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp
@@ -0,0 +1,66 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard their titles' 3-gram tokens.
+ * CSX has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_02.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.title,3,false) ~= test."gram-tokens"(b.title,3,false)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp
new file mode 100644
index 0000000..fdd7f86
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on ~= using Jaccard of its titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_03.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."gram-tokens"(a.title,3,false) ~= test."gram-tokens"(b.title,3,false)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..9a3dd33
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_01.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..9c43865
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_02.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * CSX has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..3f3e334
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_03.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard-check function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..90497fc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard-check_04.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard-check function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc[1]}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)
+where (jacc[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_01.sqlpp
new file mode 100644
index 0000000..8a456c6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_01.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_02.sqlpp
new file mode 100644
index 0000000..b8bde23
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_02.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based the similarity-jaccard function of their titles' 3-gram tokens.
+ * CSX has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_03.sqlpp
new file mode 100644
index 0000000..63f919a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_03.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_04.sqlpp
new file mode 100644
index 0000000..a4ea206
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ngram-jaccard_04.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false))
+where ((jacc >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..ddabd13
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_01.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the edit-distance-check function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (test."edit-distance-check"(a.interests,b.interests,3)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_02.sqlpp
new file mode 100644
index 0000000..1ac5ba3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_02.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the edit-distance-check function of their interest lists.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance-check_02.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (test."edit-distance-check"(a.interests,b.interests,3)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_03.sqlpp
new file mode 100644
index 0000000..d3f3e68
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_03.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the edit-distance-check function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance-check_03.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where (test."edit-distance-check"(a.interests,b.interests,3)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_04.sqlpp
new file mode 100644
index 0000000..105b8df
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance-check_04.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the edit-distance-check function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance-check_04.adm"
+select element {'arec':a,'brec':b,'ed':ed[1]}
+from Customers as a,
+ Customers as b
+with ed as test."edit-distance-check"(a.interests,b.interests,3)
+where (ed[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_01.sqlpp
new file mode 100644
index 0000000..d5939e4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_01.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the edit-distance function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((test."edit-distance"(a.interests,b.interests) <= 2) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_02.sqlpp
new file mode 100644
index 0000000..f96eb88
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_02.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the edit-distance function of their interest lists.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance_02.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((test."edit-distance"(a.interests,b.interests) <= 2) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_03.sqlpp
new file mode 100644
index 0000000..69fff61
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_03.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the edit-distance function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance_03.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where ((test."edit-distance"(a.interests,b.interests) <= 2) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_04.sqlpp
new file mode 100644
index 0000000..b0176eb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-edit-distance_04.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the edit-distance function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance_04.adm"
+select element {'arec':a,'brec':b,'ed':ed}
+from Customers as a,
+ Customers as b
+with ed as test."edit-distance"(a.interests,b.interests)
+where ((ed <= 2) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_01.sqlpp
new file mode 100644
index 0000000..05a758c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_01.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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using edit distance of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-fuzzyeq-jaccard_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.interests ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_02.sqlpp
new file mode 100644
index 0000000..e3282e8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_02.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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using edit distance of their interest lists.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-fuzzyeq-jaccard_02.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.interests ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_03.sqlpp
new file mode 100644
index 0000000..7d1fbf8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-edit-distance_03.sqlpp
@@ -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 : Fuzzy self joins a dataset, Customers, based on ~= using edit distance of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-fuzzyeq-jaccard_03.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where ((a.interests ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..56ec6d7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_01.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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using Jaccard of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.interests /*+ indexnl */ ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_02.sqlpp
new file mode 100644
index 0000000..a9a066a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_02.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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using Jaccard of their interest lists.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-fuzzyeq-jaccard_02.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.interests /*+ indexnl */ ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_03.sqlpp
new file mode 100644
index 0000000..92608a3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-fuzzyeq-jaccard_03.sqlpp
@@ -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 : Fuzzy self joins a dataset, Customers, based on ~= using Jaccard of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-fuzzyeq-jaccard_03.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where ((a.interests /*+ indexnl */ ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..bbb9906
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_01.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard-check function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ( /*+ indexnl */ test."similarity-jaccard-check"(a.interests,b.interests,0.700000f)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..e173199
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_02.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard-check function of their interest lists.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard-check_02.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ( /*+ indexnl */ test."similarity-jaccard-check"(a.interests,b.interests,0.700000f)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..0281d93
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_03.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard-check function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard-check_03.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where ( /*+ indexnl */ test."similarity-jaccard-check"(a.interests,b.interests,0.700000f)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..49801dd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard-check_04.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard-check function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard-check_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc[1]}
+from Customers as a,
+ Customers as b
+with jacc as /*+ indexnl */ test."similarity-jaccard-check"(a.interests,b.interests,0.700000f)
+where (jacc[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_01.sqlpp
new file mode 100644
index 0000000..b1e40f0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_01.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_02.sqlpp
new file mode 100644
index 0000000..1165362
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_02.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest lists.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard_02.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_03.sqlpp
new file mode 100644
index 0000000..d30cfb0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_03.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard_03.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_04.sqlpp
new file mode 100644
index 0000000..ff40544
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/olist-jaccard_04.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc}
+from Customers as a,
+ Customers as b
+with jacc as /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests)
+where ((jacc >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..bb6c1bc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_01.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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using Jaccard of their interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.interests /*+ indexnl */ ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_02.sqlpp
new file mode 100644
index 0000000..863280d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_02.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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using Jaccard of their interest sets.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-fuzzyeq-jaccard_02.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.interests /*+ indexnl */ ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_03.sqlpp
new file mode 100644
index 0000000..c333464
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-fuzzyeq-jaccard_03.sqlpp
@@ -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 : Fuzzy self joins a dataset, Customers, based on ~= using Jaccard of its interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-fuzzyeq-jaccard_03.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where ((a.interests /*+ indexnl */ ~= b.interests) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..6d91e5f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_01.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard-check function of their interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ( /*+ indexnl */ test."similarity-jaccard-check"(a.interests,b.interests,0.700000f)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..e2e6953
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_02.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard-check function of their interest sets.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard-check_02.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ( /*+ indexnl */ test."similarity-jaccard-check"(a.interests,b.interests,0.700000f)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..4165db4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_03.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard-check function of its interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard-check_03.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where ( /*+ indexnl */ test."similarity-jaccard-check"(a.interests,b.interests,0.700000f)[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..6e29270
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard-check_04.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard-check function of its interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard-check_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc[1]}
+from Customers as a,
+ Customers as b
+with jacc as /*+ indexnl */ test."similarity-jaccard-check"(a.interests,b.interests,0.700000f)
+where (jacc[0] and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_01.sqlpp
new file mode 100644
index 0000000..f468e97
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_01.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_02.sqlpp
new file mode 100644
index 0000000..57aa4c7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_02.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest sets.
+ * Customers2 has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create table Customers2(CustomerType) primary key cid;
+
+create index interests_index on Customers2 (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard_02.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_03.sqlpp
new file mode 100644
index 0000000..0a0e384
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_03.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard function of its interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard_03.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests) >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_04.sqlpp
new file mode 100644
index 0000000..60a47fe
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/ulist-jaccard_04.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard function of its interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index interests_index on Customers (interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc}
+from Customers as a,
+ Customers as b
+with jacc as /*+ indexnl */ test."similarity-jaccard"(a.interests,b.interests)
+where ((jacc >= 0.700000f) and (a.cid < b.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..07eafcc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.title) ~= test."word-tokens"(b.title)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_02.sqlpp
new file mode 100644
index 0000000..278e67b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_02.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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * CSX has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on CSX (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_02.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.title) ~= test."word-tokens"(b.title)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp
new file mode 100644
index 0000000..7059c4a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on ~= using Jaccard of its titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_03.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."word-tokens"(a.title) ~= test."word-tokens"(b.title)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp
new file mode 100644
index 0000000..a8af07c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Fuzzy self joins a dataset, TweetMessages, based on the similarity-jaccard-check function of its text-messages' word tokens.
+ * TweetMessages has a keyword index on text-message and btree index on the primary key tweetid, and we expect the join to be
+ * transformed into btree and inverted indexed nested-loop joins. We test whether the join condition can be transformed into
+ * multiple indexed nested loop joins of various type of indexes.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgTextIx on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check-after-btree-access.adm"
+select element {'t1':t1.tweetid,'t2':t2.tweetid,'sim':sim[1]}
+from TweetMessages as t1,
+ TweetMessages as t2
+with sim as test."similarity-jaccard-check"(test."word-tokens"(t1."message-text"),test."word-tokens"(t2."message-text"),0.600000f)
+where (sim[0] and (t1.tweetid < test.int64('20')) and (t2.tweetid != t1.tweetid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..d35694a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_01.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..963dee2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_02.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * CSX has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on CSX (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..9b7ffb2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard-check function of its titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..96fa6de
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard-check_04.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard-check function of its titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc[1]}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)
+where (jacc[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_01.sqlpp
new file mode 100644
index 0000000..8ba66ca
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_01.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_02.sqlpp
new file mode 100644
index 0000000..e525469
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_02.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * CSX has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on CSX (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_03.sqlpp
new file mode 100644
index 0000000..e9d670d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_04.sqlpp
new file mode 100644
index 0000000..2782951
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/inverted-index-join/word-jaccard_04.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title))
+where ((jacc >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/join-super-key_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/join-super-key_01.sqlpp
new file mode 100644
index 0000000..0a4bd2b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/join-super-key_01.sqlpp
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+drop database "join-super-key_1" if exists;
+create database "join-super-key_1";
+
+use "join-super-key_1";
+
+
+create type "join-super-key_1".SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type "join-super-key_1".NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type "join-super-key_1".LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type "join-super-key_1".PartType as
+ closed {
+ p_partkey : int32,
+ p_name : string,
+ p_mfgr : string,
+ p_brand : string,
+ p_type : string,
+ p_size : int32,
+ p_container : string,
+ p_retailprice : double,
+ p_comment : string
+}
+
+create type "join-super-key_1".PartSuppType as
+ closed {
+ ps_partkey : int32,
+ ps_suppkey : int32,
+ ps_availqty : int32,
+ ps_supplycost : double,
+ ps_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+write output to nc1:"/tmp/join-super-key_01.adm"
+create table LineItems(LineItemType) primary key l_partkey,l_linenumber on group1;
+
+create table PartSupp(PartSuppType) primary key ps_partkey,ps_suppkey on group1;
+
+select element {'l_partkey':li.l_partkey}
+from LineItems as li,
+ PartSupp as ps
+where ((li.l_partkey = ps.ps_partkey) and (li.l_suppkey = ps.ps_suppkey) and (li.l_extendedprice = ps.ps_supplycost))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/join-super-key_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/join-super-key_02.sqlpp
new file mode 100644
index 0000000..7aab555
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/join-super-key_02.sqlpp
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+drop database "join-super-key_01" if exists;
+create database "join-super-key_01";
+
+use "join-super-key_01";
+
+
+create type "join-super-key_01".SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type "join-super-key_01".NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type "join-super-key_01".LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type "join-super-key_01".PartType as
+ closed {
+ p_partkey : int32,
+ p_name : string,
+ p_mfgr : string,
+ p_brand : string,
+ p_type : string,
+ p_size : int32,
+ p_container : string,
+ p_retailprice : double,
+ p_comment : string
+}
+
+create type "join-super-key_01".PartSuppType as
+ closed {
+ ps_partkey : int32,
+ ps_suppkey : int32,
+ ps_availqty : int32,
+ ps_supplycost : double,
+ ps_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+write output to nc1:"/tmp/join-super-key_01.adm"
+create table LineItems(LineItemType) primary key l_partkey,l_linenumber on group1;
+
+create table PartSupp(PartSuppType) primary key ps_partkey,ps_suppkey on group1;
+
+select element {'l_partkey':li.l_partkey}
+from PartSupp as ps,
+ LineItems as li
+where ((li.l_partkey = ps.ps_partkey) and (li.l_suppkey = ps.ps_suppkey) and (li.l_extendedprice = ps.ps_supplycost))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/limit-issue353.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/limit-issue353.sqlpp
new file mode 100644
index 0000000..e0b1b89
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/limit-issue353.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : This test case is to verify the fix for issue353
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+write output to nc1:"/tmp/push_limit.adm"
+select element {'l_returnflag':l.l_returnflag,'l_linestatus':l.l_linestatus,'l_shipmode':l.l_shipmode}
+from LineItem as l
+limit 2
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/loj-super-key_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/loj-super-key_01.sqlpp
new file mode 100644
index 0000000..9215f6d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/loj-super-key_01.sqlpp
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+drop database "loj-super-key_01" if exists;
+create database "loj-super-key_01";
+
+use "loj-super-key_01";
+
+
+create type "loj-super-key_01".SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type "loj-super-key_01".NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type "loj-super-key_01".LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type "loj-super-key_01".PartType as
+ closed {
+ p_partkey : int32,
+ p_name : string,
+ p_mfgr : string,
+ p_brand : string,
+ p_type : string,
+ p_size : int32,
+ p_container : string,
+ p_retailprice : double,
+ p_comment : string
+}
+
+create type "loj-super-key_01".PartSuppType as
+ closed {
+ ps_partkey : int32,
+ ps_suppkey : int32,
+ ps_availqty : int32,
+ ps_supplycost : double,
+ ps_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+write output to nc1:"/tmp/loj-super-key_01.adm"
+create table LineItems(LineItemType) primary key l_partkey,l_linenumber on group1;
+
+create table PartSupp(PartSuppType) primary key ps_partkey,ps_suppkey on group1;
+
+select element {'li':li,'partsupp':partsupp}
+from LineItems as li
+with partsupp as (
+ select element ps
+ from PartSupp as ps
+ where ((li.l_partkey = ps.ps_partkey) and (li.l_suppkey = ps.ps_suppkey) and (li.l_extendedprice = ps.ps_supplycost))
+ )
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/loj-super-key_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/loj-super-key_02.sqlpp
new file mode 100644
index 0000000..a80fa61
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/loj-super-key_02.sqlpp
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+drop database "loj-super-key_02" if exists;
+create database "loj-super-key_02";
+
+use "loj-super-key_02";
+
+
+create type "loj-super-key_02".SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type "loj-super-key_02".NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type "loj-super-key_02".LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type "loj-super-key_02".PartType as
+ closed {
+ p_partkey : int32,
+ p_name : string,
+ p_mfgr : string,
+ p_brand : string,
+ p_type : string,
+ p_size : int32,
+ p_container : string,
+ p_retailprice : double,
+ p_comment : string
+}
+
+create type "loj-super-key_02".PartSuppType as
+ closed {
+ ps_partkey : int32,
+ ps_suppkey : int32,
+ ps_availqty : int32,
+ ps_supplycost : double,
+ ps_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+write output to nc1:"/tmp/loj-super-key_01.adm"
+create table LineItems(LineItemType) primary key l_partkey,l_linenumber on group1;
+
+create table PartSupp(PartSuppType) primary key ps_partkey,ps_suppkey on group1;
+
+select element {'partsupp':ps,'li':items}
+from PartSupp as ps
+with items as (
+ select element li
+ from LineItems as li
+ where ((li.l_partkey = ps.ps_partkey) and (li.l_suppkey = ps.ps_suppkey) and (li.l_extendedprice = ps.ps_supplycost))
+ )
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nest_aggregate.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nest_aggregate.sqlpp
new file mode 100644
index 0000000..2b67f09
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nest_aggregate.sqlpp
@@ -0,0 +1,137 @@
+/*
+ * 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 : This test case is to verify the fix for issue782
+ * https://code.google.com/p/asterixdb/issues/detail?id=782
+ * Expected Res : SUCCESS
+ * Date : 2nd Jun 2014
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+ r_regionkey : int32,
+ r_name : string,
+ r_comment : string
+}
+
+create type tpch.PartType as
+ closed {
+ p_partkey : int32,
+ p_name : string,
+ p_mfgr : string,
+ p_brand : string,
+ p_type : string,
+ p_size : int32,
+ p_container : string,
+ p_retailprice : double,
+ p_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+ ps_partkey : int32,
+ ps_suppkey : int32,
+ ps_availqty : int32,
+ ps_supplycost : double,
+ ps_comment : string
+}
+
+create table Orders(OrderType) primary key o_orderkey;
+
+create table Supplier(SupplierType) primary key s_suppkey;
+
+create table Region(RegionType) primary key r_regionkey;
+
+create table Nation(NationType) primary key n_nationkey;
+
+create table Part(PartType) primary key p_partkey;
+
+create table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create table Customer(CustomerType) primary key c_custkey;
+
+create table SelectedNation(NationType) primary key n_nationkey;
+
+select element {'nation_key':nation.n_nationkey,'name':nation.n_name,'aggregates':(
+ select element {'order_date':orderdate,'sum_price':sum}
+ from Orders as orders,
+ Customer as customer
+ where ((orders.o_custkey = customer.c_custkey) and (customer.c_nationkey = nation.n_nationkey))
+ group by orders.o_orderdate as orderdate
+ with sum as tpch.sum((
+ select element o.o_totalprice
+ from orders as o
+ ))
+ order by sum
+ limit 3
+ )}
+from Nation as nation,
+ SelectedNation as sn
+where (nation.n_nationkey = sn.n_nationkey)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/disjunction-to-join.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/disjunction-to-join.sqlpp
new file mode 100644
index 0000000..d5acf89
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/disjunction-to-join.sqlpp
@@ -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 : Disjunctive predicate should be transformed into collection scan.
+ * Secondary index should be used to probe the values retrieved from collection.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.NestedTestType as
+{
+ idx : string
+}
+
+create type test.TestType as
+{
+ id : string,
+ "no-idx" : string,
+ nested : NestedTestType
+}
+
+create table TestSet(TestType) primary key id;
+
+create index TestSetIndex on TestSet (nested.idx) type btree;
+
+select element x
+from TestSet as x
+where ((x.nested.idx = 'one') or (x.nested.idx = 'two'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01.sqlpp
new file mode 100644
index 0000000..36e4c79
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index msgCountBIx on TweetMessages (nested.countB) type btree;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_01.adm"
+select element {'tweetid1':t1.nested.tweetid,'count1':t1.nested.countA,'t2info':(
+ select element {'tweetid2':t2.nested.tweetid,'count2':t2.nested.countB}
+ from TweetMessages as t2
+ where (t1.nested.countA /*+ indexnl */ = t2.nested.countB)
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.sqlpp
new file mode 100644
index 0000000..bf0a60f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index msgCountBIx on TweetMessages (nested.countB) type btree;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_02.adm"
+select element {'tweetid1':t1.nested.tweetid,'count1':t1.nested.countA,'t2info':(
+ select element {'tweetid2':t2.nested.tweetid,'count2':t2.nested.countB}
+ from TweetMessages as t2
+ where ((t1.nested.countA /*+ indexnl */ = t2.nested.countB) and (t1.nested.tweetid != t2.nested.tweetid))
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_01.sqlpp
new file mode 100644
index 0000000..b5db202
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_01.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-join_01.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ > emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ > emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_02.sqlpp
new file mode 100644
index 0000000..f6b191a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_02.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-join_02.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ < emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ < emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_03.sqlpp
new file mode 100644
index 0000000..141fd42
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-join_03.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-join_03.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ = emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ = emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_01.sqlpp
new file mode 100644
index 0000000..c8aee57
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_01.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_01.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ < emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ > emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_02.sqlpp
new file mode 100644
index 0000000..c38f606
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_02.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_02.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ > emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ < emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_03.sqlpp
new file mode 100644
index 0000000..05f5d9f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_03.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_03.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ > emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ = emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_04.sqlpp
new file mode 100644
index 0000000..cd462d3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_04.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_04.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ < emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ = emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_05.sqlpp
new file mode 100644
index 0000000..2ef6a91
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_05.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_05.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ = emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ > emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_06.sqlpp
new file mode 100644
index 0000000..d95fe11
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-composite-key-prefix-join_06.sqlpp
@@ -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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its primary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.Name as
+{
+ nested : Nametmp
+}
+
+create table Names(Name) primary key nested.fname,nested.lname;
+
+write output to nc1:"rttest/btree-index-join_primary-composite-key-prefix-prefix-join_06.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ = emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ < emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join-multipred.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join-multipred.sqlpp
new file mode 100644
index 0000000..ded8580
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join-multipred.sqlpp
@@ -0,0 +1,83 @@
+/*
+ * 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 : Equi joins two datasets, Customers and Orders, based on the customer id.
+ * Given the 'indexnl' hint we expect the join to be transformed
+ * into an indexed nested-loop join using Customers' primary index.
+ * We expect the additional predicates to be put into a select above the
+ * primary index search.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create type test.OrderTypetmp as
+ closed {
+ oid : int32,
+ cid : int32,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create type test.OrderType as
+ closed {
+ nested : OrderTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Orders(OrderType) primary key nested.oid;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join-multipred.adm"
+select element {'customer':c.nested,'order':o.nested}
+from Customers as c,
+ Orders as o
+where ((c.nested.cid /*+ indexnl */ = o.nested.cid) and (c.nested.name < o.nested.orderstatus) and (c.nested.age < o.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join-neg_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join-neg_01.sqlpp
new file mode 100644
index 0000000..fcb60c3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join-neg_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : This is a negative test, mis-spelt/incorrect HINT should result in
+ * a plan not using an indexed-nested loops join strategy. We expect a hash join.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestTypetmp as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create type test1.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table test1.DsOne(TestType) primary key nested.key1;
+
+create table test1.DsTwo(TestType) primary key nested.key1;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join-neg_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.nested.key1 = y.nested.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_01.sqlpp
new file mode 100644
index 0000000..2602ff3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that hash-exchanges internal dataset DsTwo, then probes internal dataset DsOne's primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestTypetmp as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create type test1.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table test1.DsOne(TestType) primary key nested.key1;
+
+create table test1.DsTwo(TestType) primary key nested.key1;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.nested.key1 /*+ indexnl */ = y.nested.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_02.sqlpp
new file mode 100644
index 0000000..edac5f3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_02.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that hash-exchanges internal dataset DsTwo, then probes internal dataset DsOne's primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestTypetmp as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create type test1.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table test1.DsOne(TestType) primary key nested.key1;
+
+create table test1.DsTwo(TestType) primary key nested.key1;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_02.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.nested.key2 /*+ indexnl */ = y.nested.key1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_03.sqlpp
new file mode 100644
index 0000000..75e669a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_03.sqlpp
@@ -0,0 +1,81 @@
+/*
+ * 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 : Equi joins two datasets, Customers and Orders, based on the customer id.
+ * Given the 'indexnl' hint we expect the join to be transformed
+ * into an indexed nested-loop join using Customers' primary index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create type test.OrderTypetmp as
+ closed {
+ oid : int32,
+ cid : int32,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create type test.OrderType as
+ closed {
+ nested : OrderTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Orders(OrderType) primary key nested.oid;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_04.adm"
+select element {'customer':c.nested,'order':o.nested}
+from Customers as c,
+ Orders as o
+where (c.nested.cid /*+ indexnl */ = o.nested.cid)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_04.sqlpp
new file mode 100644
index 0000000..eb25a0c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_04.sqlpp
@@ -0,0 +1,81 @@
+/*
+ * 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 : Equi joins two datasets, Customers and Orders, based on the customer id.
+ * Given the 'indexnl' hint we expect the join to be transformed
+ * into an indexed nested-loop join using Customers' primary index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create type test.OrderTypetmp as
+ closed {
+ oid : int32,
+ cid : int32,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create type test.OrderType as
+ closed {
+ nested : OrderTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Orders(OrderType) primary key nested.oid;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_05.adm"
+select element {'customer':c.nested,'order':o.nested}
+from Orders as o,
+ Customers as c
+where (o.nested.cid /*+ indexnl */ = c.nested.cid)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_05.sqlpp
new file mode 100644
index 0000000..98eee3e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-equi-join_05.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 : Self-equi joins a dataset, Customers, based on the customer id.
+ * Given the 'indexnl' hint we expect the join to be transformed
+ * into an indexed nested-loop join using Customers' primary index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+write output to nc1:"rttest/btree-index-join_primary-equi-join_06.adm"
+select element {'customer1':c1.nested,'customer2':c2.nested}
+from Customers as c1,
+ Customers as c2
+where (c1.nested.cid /*+ indexnl */ = c2.nested.cid)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-ge-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-ge-join_01.sqlpp
new file mode 100644
index 0000000..a93546f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-ge-join_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOne's primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestTypetmp as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create type test1.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table test1.DsOne(TestType) primary key nested.key1;
+
+create table test1.DsTwo(TestType) primary key nested.key1;
+
+write output to nc1:"rttest/btree-index-join_primary-ge-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.nested.key1 /*+ indexnl */ >= y.nested.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-gt-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-gt-join_01.sqlpp
new file mode 100644
index 0000000..e478f8f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-gt-join_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOnes primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestTypetmp as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create type test1.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table test1.DsOne(TestType) primary key nested.key1;
+
+create table test1.DsTwo(TestType) primary key nested.key1;
+
+write output to nc1:"rttest/btree-index-join_primary-gt-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.nested.key1 /*+ indexnl */ > y.nested.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-le-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-le-join_01.sqlpp
new file mode 100644
index 0000000..ef88ee3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-le-join_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOnes primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestTypetmp as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create type test1.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table test1.DsOne(TestType) primary key nested.key1;
+
+create table test1.DsTwo(TestType) primary key nested.key1;
+
+write output to nc1:"rttest/btree-index-join_primary-le-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.nested.key1 /*+ indexnl */ <= y.nested.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-lt-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-lt-join_01.sqlpp
new file mode 100644
index 0000000..e72eb83
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/primary-lt-join_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan.
+ * : We expect a plan that broadcasts internal dataset DsTwo, then probes internal dataset DsOnes primary index.
+ * Expected Res : Success
+ * Date : 29th November 2012
+ */
+
+drop database test1 if exists;
+create database test1;
+
+create type test1.TestTypetmp as
+{
+ key1 : int32,
+ key2 : int32,
+ fname : string,
+ lname : string
+}
+
+create type test1.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table test1.DsOne(TestType) primary key nested.key1;
+
+create table test1.DsTwo(TestType) primary key nested.key1;
+
+write output to nc1:"rttest/btree-index-join_primary-lt-join_01.adm"
+select element x
+from "test1.DsOne" as x,
+ "test1.DsTwo" as y
+where (x.nested.key1 /*+ indexnl */ < y.nested.key2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join-multiindex.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join-multiindex.sqlpp
new file mode 100644
index 0000000..ddfcffb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join-multiindex.sqlpp
@@ -0,0 +1,85 @@
+/*
+ * 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 : Equi joins two datasets, FacebookUsers and FacebookMessages, based on their user's id.
+ * We first expect FacebookUsers' primary index to be used
+ * to satisfy the range condition on it's primary key.
+ * FacebookMessages has a secondary btree index on author-id-copy, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.EmploymentType as
+ closed {
+ "organization-name" : string,
+ "start-date" : date,
+ "end-date" : date?
+}
+
+create type test.FacebookUserTypetmp as
+ closed {
+ id : int32,
+ "id-copy" : int32,
+ alias : string,
+ name : string,
+ "user-since" : datetime,
+ "user-since-copy" : datetime,
+ "friend-ids" : {{int32}},
+ employment : [EmploymentType]
+}
+
+create type test.FacebookMessageTypetmp as
+ closed {
+ "message-id" : int32,
+ "message-id-copy" : int32,
+ "author-id" : int32,
+ "author-id-copy" : int32,
+ "in-response-to" : int32?,
+ "sender-location" : point?,
+ message : string
+}
+
+create type test.FacebookUserType as
+ closed {
+ nested : FacebookUserTypetmp
+}
+
+create type test.FacebookMessageType as
+ closed {
+ nested : FacebookMessageTypetmp
+}
+
+create table FacebookUsers(FacebookUserType) primary key nested.id;
+
+create table FacebookMessages(FacebookMessageType) primary key nested."message-id";
+
+create index fbmIdxAutId if not exists on FacebookMessages (nested."author-id-copy") type btree;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multiindex.adm"
+select element {'fbu-ID':user.nested.id,'fbm-auth-ID':message.nested."author-id",'uname':user.nested.name,'message':message.nested.message}
+from FacebookUsers as user,
+ FacebookMessages as message
+where ((user.nested.id /*+ indexnl */ = message.nested."author-id-copy") and (user.nested.id >= 11000) and (user.nested.id <= 12000))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join-multipred.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join-multipred.sqlpp
new file mode 100644
index 0000000..10adfc6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join-multipred.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the additional predicates to be put into a select above the
+ * primary index search.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index title_index on DBLP (nested.title) type btree;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multipred.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.nested.title /*+ indexnl */ = b.nested.title) and (a.nested.authors < b.nested.authors) and (a.nested.misc > b.nested.misc))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join_01.sqlpp
new file mode 100644
index 0000000..41af3b9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index-join/secondary-equi-join_01.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index title_index on DBLP (nested.title) type btree;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.nested.title /*+ indexnl */ = b.nested.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-01.sqlpp
new file mode 100644
index 0000000..653591f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-01.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-01.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where (emp.nested.fname > 'Roger')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-02.sqlpp
new file mode 100644
index 0000000..2450dd8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-02.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-02.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where (emp.nested.fname >= 'Susan')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-03.sqlpp
new file mode 100644
index 0000000..721e906
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-03.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where (emp.nested.fname < 'Isa')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-04.sqlpp
new file mode 100644
index 0000000..b770353
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-04.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-04.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where (emp.nested.fname <= 'Vanpatten')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-05.sqlpp
new file mode 100644
index 0000000..bea6079
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-05.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-05.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where (emp.nested.fname != 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-06.sqlpp
new file mode 100644
index 0000000..5e9feea
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-06.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-06.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where (emp.nested.fname = 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-07.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-07.sqlpp
new file mode 100644
index 0000000..b05b895
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-07.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-07.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where (emp.nested.lname = 'Kim')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-08.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-08.sqlpp
new file mode 100644
index 0000000..9a9f663
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-08.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-08.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Young Seok') and (emp.nested.lname = 'Kim'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-09.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-09.sqlpp
new file mode 100644
index 0000000..eb5c695
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-09.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-09.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where ((emp.nested.fname = 'Julio') or (emp.nested.lname = 'Malaika'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-10.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-10.sqlpp
new file mode 100644
index 0000000..46a5192
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-10.sqlpp
@@ -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 : BTree Index verification (usage) test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-10.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Alex') and (emp.nested.lname < 'Zach'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-11.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-11.sqlpp
new file mode 100644
index 0000000..f5b32e7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-11.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan for predicates.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-11.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where ((emp.nested.fname > 'Allan') and (emp.nested.lname < 'Zubi'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-12.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-12.sqlpp
new file mode 100644
index 0000000..1a48bd8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-12.sqlpp
@@ -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 : BTree Index verification (usage) test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-12.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where ((emp.nested.fname > 'Allan') and (emp.nested.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-13.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-13.sqlpp
new file mode 100644
index 0000000..f9a434f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-13.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-13.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where ((emp.nested.fname = 'Julio') and (emp.nested.lname < 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-14.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-14.sqlpp
new file mode 100644
index 0000000..6ce745d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-14.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-14.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where ((emp.nested.fname >= 'Michael') and (emp.nested.lname <= 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-15.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-15.sqlpp
new file mode 100644
index 0000000..93f1835
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-15.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-15.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-16.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-16.sqlpp
new file mode 100644
index 0000000..aa403aa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-16.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-16.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname >= 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-17.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-17.sqlpp
new file mode 100644
index 0000000..c85d28d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-17.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-17.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where ((emp.nested.fname <= 'Craig') and (emp.nested.lname > 'Kevin'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-18.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-18.sqlpp
new file mode 100644
index 0000000..228a3c3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-18.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is NOT used
+ * : in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-18.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp.nested
+from testdst as emp
+where ((emp.nested.fname != 'Michael') and (emp.nested.lname != 'Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-19.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-19.sqlpp
new file mode 100644
index 0000000..1e8cbe3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-19.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-19.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-20.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-20.sqlpp
new file mode 100644
index 0000000..5eb4acd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-20.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-20.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname >= 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-21.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-21.sqlpp
new file mode 100644
index 0000000..053f740
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-21.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-21.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname > 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-22.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-22.sqlpp
new file mode 100644
index 0000000..6fd56e4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-22.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-22.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname >= 'Sofia')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-23.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-23.sqlpp
new file mode 100644
index 0000000..870d33e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-23.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-23.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname < 'Chen')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-24.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-24.sqlpp
new file mode 100644
index 0000000..71fd2c7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-24.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-24.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname <= 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-25.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-25.sqlpp
new file mode 100644
index 0000000..a7bba9c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-25.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-25.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Neil') and (emp.nested.fname < 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-26.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-26.sqlpp
new file mode 100644
index 0000000..6f2e3d1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-26.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-26.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Max') and (emp.nested.fname <= 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-27.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-27.sqlpp
new file mode 100644
index 0000000..1b8a684
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-27.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 5th Feb 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-27.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-28.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-28.sqlpp
new file mode 100644
index 0000000..4fec8ca
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-28.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 5th Feb 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-28.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-29.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-29.sqlpp
new file mode 100644
index 0000000..cf82b34
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-29.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 5th Feb 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-29.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname >= 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-30.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-30.sqlpp
new file mode 100644
index 0000000..0984940
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-30.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 5th Feb 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-30.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-31.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-31.sqlpp
new file mode 100644
index 0000000..9980f11
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-31.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-31.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Julio') and (emp.nested.lname > 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-32.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-32.sqlpp
new file mode 100644
index 0000000..3b5c1eb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-primary-32.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-32.adm"
+create type test.TestTypetmp as
+{
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.fname,nested.lname;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname < 'Julio') and (emp.nested.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-33.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-33.sqlpp
new file mode 100644
index 0000000..62577dd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-33.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-31.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname > 'Roger')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-34.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-34.sqlpp
new file mode 100644
index 0000000..b946c58
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-34.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-32.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname >= 'Susan')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-35.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-35.sqlpp
new file mode 100644
index 0000000..a9cc94a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-35.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification (usage) test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-33.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname < 'Isa')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-36.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-36.sqlpp
new file mode 100644
index 0000000..04fcab2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-36.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-34.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname <= 'Vanpatten')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-37.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-37.sqlpp
new file mode 100644
index 0000000..590a533
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-37.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-35.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname != 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-38.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-38.sqlpp
new file mode 100644
index 0000000..c0fe4fd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-38.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-36.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname = 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-39.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-39.sqlpp
new file mode 100644
index 0000000..1523dab
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-39.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-37.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.lname = 'Kim')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-40.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-40.sqlpp
new file mode 100644
index 0000000..41f1ea1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-40.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-38.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Young Seok') and (emp.nested.lname = 'Kim'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-41.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-41.sqlpp
new file mode 100644
index 0000000..e327ebc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-41.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-39.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Julio') or (emp.nested.lname = 'Malaika'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-42.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-42.sqlpp
new file mode 100644
index 0000000..7fdade6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-42.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-40.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Alex') and (emp.nested.lname < 'Zach'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-43.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-43.sqlpp
new file mode 100644
index 0000000..aa7d980
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-43.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-41.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Allan') and (emp.nested.lname < 'Zubi'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-44.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-44.sqlpp
new file mode 100644
index 0000000..69e07c3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-44.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-42.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Allan') and (emp.nested.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-45.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-45.sqlpp
new file mode 100644
index 0000000..6045cad
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-45.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-43.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Julio') and (emp.nested.lname < 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-46.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-46.sqlpp
new file mode 100644
index 0000000..07f297e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-46.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-44.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Michael') and (emp.nested.lname <= 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-47.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-47.sqlpp
new file mode 100644
index 0000000..93e495b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-47.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-45.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-48.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-48.sqlpp
new file mode 100644
index 0000000..3471ac9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-48.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-46.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname >= 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-49.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-49.sqlpp
new file mode 100644
index 0000000..3c14bc7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-49.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-47.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname <= 'Craig') and (emp.nested.lname > 'Kevin'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-50.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-50.sqlpp
new file mode 100644
index 0000000..f9d5030
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-50.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-48.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname != 'Michael') and (emp.nested.lname != 'Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-51.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-51.sqlpp
new file mode 100644
index 0000000..16a6018
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-51.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-49.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-52.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-52.sqlpp
new file mode 100644
index 0000000..b04d18f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-52.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-50.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname >= 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-53.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-53.sqlpp
new file mode 100644
index 0000000..e2e860d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-53.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-51.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname <= 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname >= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-54.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-54.sqlpp
new file mode 100644
index 0000000..1cb7aea
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-54.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-52.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname > 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-55.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-55.sqlpp
new file mode 100644
index 0000000..7a17c0f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-55.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-53.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname >= 'Sofia')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-56.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-56.sqlpp
new file mode 100644
index 0000000..d4324f1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-56.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-54.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname < 'Chen')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-57.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-57.sqlpp
new file mode 100644
index 0000000..4fbc811
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-57.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-55.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname <= 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-58.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-58.sqlpp
new file mode 100644
index 0000000..3f312c7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-58.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-56.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Neil') and (emp.nested.fname < 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-59.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-59.sqlpp
new file mode 100644
index 0000000..d1ecbbf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-59.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-57.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Max') and (emp.nested.fname <= 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-60.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-60.sqlpp
new file mode 100644
index 0000000..d32e6d1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-60.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-58.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname) type btree;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname = 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-61.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-61.sqlpp
new file mode 100644
index 0000000..7767a27
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-61.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-61.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-62.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-62.sqlpp
new file mode 100644
index 0000000..386030e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-62.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-62.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Julio') and (emp.nested.lname > 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-63.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-63.sqlpp
new file mode 100644
index 0000000..1bd6d66
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/btree-index/btree-secondary-63.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-63.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname,nested.lname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname < 'Julio') and (emp.nested.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-contains-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-contains-panic.sqlpp
new file mode 100644
index 0000000..4a61bb6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-contains-panic.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the contains function.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains-panic.adm"
+select element o
+from DBLP as o
+where test.contains(o.nested.title,'Mu')
+order by o.nested.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-contains.sqlpp
new file mode 100644
index 0000000..5b0a0ac
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-contains.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains.adm"
+select element o
+from DBLP as o
+where test.contains(o.nested.title,'Multimedia')
+order by o.nested.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp
new file mode 100644
index 0000000..3b941cb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-check-panic.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.nested.authors,'Amihay Motro',5)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-check.sqlpp
new file mode 100644
index 0000000..aa56210
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-check.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-check.adm"
+select element o
+from DBLP as o
+where test."edit-distance-check"(o.nested.authors,'Amihay Motro',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-panic.sqlpp
new file mode 100644
index 0000000..aae398d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance-panic.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance function on strings.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-panic.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.nested.authors,'Amihay Motro') <= 5)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance.sqlpp
new file mode 100644
index 0000000..1d0cc53
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-edit-distance.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance function on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.nested.authors,'Amihay Motro') <= 1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp
new file mode 100644
index 0000000..b247363
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query with ~= using edit-distance on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-fuzzyeq-edit-distance.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "1";
+
+select element o
+from DBLP as o
+where (o.nested.authors ~= 'Amihay Motro')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..c387cb0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query with ~= using Jaccard on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element o
+from DBLP as o
+where (test."gram-tokens"(o.nested.title,3,false) ~= test."gram-tokens"('Transactions for Cooperative Environments',3,false))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-jaccard-check.sqlpp
new file mode 100644
index 0000000..8b97cb1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-jaccard-check.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-jaccard-check.adm"
+select element o
+from DBLP as o
+where test."similarity-jaccard-check"(test."gram-tokens"(o.nested.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false),0.500000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-jaccard.sqlpp
new file mode 100644
index 0000000..1400a11
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ngram-jaccard.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard function on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-jaccard.adm"
+select element o
+from DBLP as o
+where (test."similarity-jaccard"(test."gram-tokens"(o.nested.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false)) >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-check-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-check-panic.sqlpp
new file mode 100644
index 0000000..0ea3a7a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-check-panic.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the edit-distance-check function on lists.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-edit-distance-check-panic.adm"
+select element c
+from Customers as c
+where test."edit-distance-check"(c.nested.interests,['computers','wine','walking'],3)[0]
+order by c.nested.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-check.sqlpp
new file mode 100644
index 0000000..044d99a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-check.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the edit-distance-check function on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-edit-distance-check.adm"
+select element c
+from Customers as c
+where test."edit-distance-check"(c.nested.interests,['computers','wine','walking'],1)[0]
+order by c.nested.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-panic.sqlpp
new file mode 100644
index 0000000..62dcac7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance-panic.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the edit-distance function on lists.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-edit-distance-panic.adm"
+select element c
+from Customers as c
+where (test."edit-distance"(c.nested.interests,['computers','wine','walking']) <= 3)
+order by c.nested.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance.sqlpp
new file mode 100644
index 0000000..1eefdde
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-edit-distance.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the edit-distance function on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-edit-distance.adm"
+select element c
+from Customers as c
+where (test."edit-distance"(c.nested.interests,['computers','wine','walking']) <= 1)
+order by c.nested.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-fuzzyeq-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-fuzzyeq-edit-distance.sqlpp
new file mode 100644
index 0000000..4ab5a56
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-fuzzyeq-edit-distance.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query with ~= using edit-distance on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-fuzzyeq-edit-distance.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "1";
+
+select element c
+from Customers as c
+where (c.nested.interests ~= ['computers','wine','walking'])
+order by c.nested.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..7528155
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Tests whether a keyword is applied to optimize a selection query with ~= using Jaccard on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element c
+from Customers as c
+where (c.nested.interests ~= ['databases','computers','wine'])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-jaccard-check.sqlpp
new file mode 100644
index 0000000..02a1918
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-jaccard-check.sqlpp
@@ -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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-jaccard-check.adm"
+select element c
+from Customers as c
+where test."similarity-jaccard-check"(c.nested.interests,['databases','computers','wine'],0.700000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-jaccard.sqlpp
new file mode 100644
index 0000000..1d12e90
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/olist-jaccard.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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard function on lists.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_olist-jaccard.adm"
+select element c
+from Customers as c
+where (test."similarity-jaccard"(c.nested.interests,['databases','computers','wine']) >= 0.700000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..eb29a16
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Tests whether a keyword is applied to optimize a selection query with ~= using Jaccard on sets.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_ulist-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element c
+from Customers as c
+where (c.nested.interests ~= {{'computers','wine','databases'}})
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-jaccard-check.sqlpp
new file mode 100644
index 0000000..22e4922
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-jaccard-check.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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on sets.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_ulist-jaccard.adm"
+select element c
+from Customers as c
+where test."similarity-jaccard-check"(c.nested.interests,{{'computers','wine','databases'}},0.700000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-jaccard.sqlpp
new file mode 100644
index 0000000..0fb7440
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/ulist-jaccard.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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard function on sets.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_ulist-jaccard.adm"
+select element c
+from Customers as c
+where (test."similarity-jaccard"(c.nested.interests,{{'computers','databases','wine'}}) >= 0.700000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-contains.sqlpp
new file mode 100644
index 0000000..b2d2ba3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-contains.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the contains function.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-contains.adm"
+select element o
+from DBLP as o
+where test.contains(o.nested.title,'Multimedia')
+order by o.nested.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..54b0d56
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Tests whether a keyword is applied to optimize a selection query with ~= using Jaccard on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element o
+from DBLP as o
+where (test."word-tokens"(o.nested.title) ~= test."word-tokens"('Transactions for Cooperative Environments'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-jaccard-check.sqlpp
new file mode 100644
index 0000000..519fbdd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-jaccard-check.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard-check.adm"
+select element o
+from DBLP as o
+where test."similarity-jaccard-check"(test."word-tokens"(o.nested.title),test."word-tokens"('Transactions for Cooperative Environments'),0.500000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-jaccard.sqlpp
new file mode 100644
index 0000000..b4ac67e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-basic/word-jaccard.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard function on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard.adm"
+select element o
+from DBLP as o
+where (test."similarity-jaccard"(test."word-tokens"(o.nested.title),test."word-tokens"('Transactions for Cooperative Environments')) >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp
new file mode 100644
index 0000000..8b31bb1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using
+ * two edit-distance-check function of which only the first can be optimized with an index.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic-nopanic_01.adm"
+select element o
+from DBLP as o
+with eda as test."edit-distance-check"(o.nested.authors,'Amihay Motro',3),
+ edb as test."edit-distance-check"(o.nested.authors,'Amihay Motro',5)
+where (eda[0] and edb[0])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp
new file mode 100644
index 0000000..b45f4d3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using
+ * two edit-distance-check function of which only the second can be optimized with an index.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic-nopanic_01.adm"
+select element o
+from DBLP as o
+with edb as test."edit-distance-check"(o.nested.authors,'Amihay Motro',5),
+ eda as test."edit-distance-check"(o.nested.authors,'Amihay Motro',3)
+where (edb[0] and eda[0])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp
new file mode 100644
index 0000000..fdbd28a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.nested.authors,'Amihay Motro',5)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let.sqlpp
new file mode 100644
index 0000000..148f77b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-let.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.nested.authors,'Amihay Motro',1)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp
new file mode 100644
index 0000000..ba20bbe
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index index is applied to optimize a selection query using the similarity-edit-distance-check function on the substring of the field.
+ * Tests that the optimizer rule correctly drills through the substring function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPNestedType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPNestedType
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-substring.adm"
+select element {'id':paper.nested.id,'title':paper.nested.title}
+from DBLP as paper
+where test."edit-distance-check"(test.substring(paper.nested.title,0,8),'datbase',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp
new file mode 100644
index 0000000..95d27a8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Tests whether an ngram_index index is applied to optimize a selection query using the similarity-edit-distance-check function on individual word tokens.
+ * Tests that the optimizer rule correctly drills through the word-tokens function and existential query.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPNestedType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPNestedType
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-word-tokens.adm"
+select element {'id':paper.nested.id,'title':paper.nested.title}
+from DBLP as paper,
+ test."word-tokens"(paper.nested.title) as word
+where test."edit-distance-check"(word,'Multmedia',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..a3c19e1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-jaccard-check-let.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-jaccard-check-let.adm"
+select element o
+from DBLP as o
+with jacc as test."similarity-jaccard-check"(test."gram-tokens"(o.nested.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false),0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp
new file mode 100644
index 0000000..3da4ee5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-complex_ngram-jaccard-check-multi-let.adm"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."gram-tokens"(paper.nested.title,3,false),
+ query_tokens as test."gram-tokens"('Transactions for Cooperative Environments',3,false),
+ jacc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-edit-distance-check-let-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-edit-distance-check-let-panic.sqlpp
new file mode 100644
index 0000000..8c75008
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-edit-distance-check-let-panic.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on lists.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_olist-edit-distance-check-let-panic.adm"
+select element c
+from Customers as c
+with ed as test."edit-distance-check"(c.nested.interests,['computers','wine','walking'],3)
+where ed[0]
+order by c.nested.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-edit-distance-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-edit-distance-check-let.sqlpp
new file mode 100644
index 0000000..7c5ff03
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-edit-distance-check-let.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on lists.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_olist-edit-distance-check-let.adm"
+select element c
+from Customers as c
+with ed as test."edit-distance-check"(c.nested.interests,['computers','wine','walking'],1)
+where ed[0]
+order by c.nested.cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..fb9e5c2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/olist-jaccard-check-let.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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on lists.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_olist-jaccard-check-let.adm"
+select element c
+from Customers as c
+with jacc as test."similarity-jaccard-check"(c.nested.interests,['databases','computers','wine'],0.700000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ulist-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ulist-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..0adc2ba
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/ulist-jaccard-check-let.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on lists.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_ulist-jaccard-check-let.adm"
+select element c
+from Customers as c
+with jacc as test."similarity-jaccard-check"(c.nested.interests,['databases','computers','wine'],0.700000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/word-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/word-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..c2bc04a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/word-jaccard-check-let.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_word-jaccard-check-let.adm"
+select element o
+from DBLP as o
+with jacc as test."similarity-jaccard-check"(test."word-tokens"(o.nested.title),test."word-tokens"('Transactions for Cooperative Environments'),0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/word-jaccard-check-multi-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/word-jaccard-check-multi-let.sqlpp
new file mode 100644
index 0000000..fff2dc6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-complex/word-jaccard-check-multi-let.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-complex_word-jaccard-check-multi-let.adm"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."word-tokens"(paper.nested.title),
+ query_tokens as test."word-tokens"('Transactions for Cooperative Environments'),
+ jacc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.800000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp
new file mode 100644
index 0000000..f4fe12d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index msgNgramIx on TweetMessages (nested."message-text") type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_leftouterjoin-probe-pidx-with-join-edit-distance-check_idx_01.adm"
+select element {'tweet':{'id':t1.nested.tweetid,'topics':t1.nested."message-text"},'similar-tweets':(
+ select element {'id':t2.nested.tweetid,'topics':t2.nested."message-text"}
+ from TweetMessages as t2
+ with sim as test."edit-distance-check"(t1.nested."message-text",t2.nested."message-text",7)
+ where (sim[0] and (t2.nested.tweetid != t1.nested.tweetid))
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid > test.int64('240'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.sqlpp
new file mode 100644
index 0000000..a60538b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index topicKeywordIx on TweetMessages (nested."referred-topics") type keyword;
+
+write output to nc1:"rttest/inverted-index-join_leftouterjoin-probe-pidx-with-join-jaccard-check_idx_01.adm"
+select element {'tweet':{'id':t1.nested.tweetid,'topics':t1.nested."referred-topics"},'similar-tweets':(
+ select element {'id':t2.nested.tweetid,'topics':t2.nested."referred-topics"}
+ from TweetMessages as t2
+ with sim as test."similarity-jaccard-check"(t1.nested."referred-topics",t2.nested."referred-topics",0.500000f)
+ where (sim[0] and (t2.nested.tweetid != t1.nested.tweetid))
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid > test.int64('240'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..6308bb6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-check_01.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.nested.authors,b.nested.authors,3)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-contains.sqlpp
new file mode 100644
index 0000000..53b87e5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-contains.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-contains function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-contains.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-contains"(a.nested.authors,b.nested.authors,3)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-inline.sqlpp
new file mode 100644
index 0000000..2dac7e2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance-inline.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance function of its authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-edit-distance-inline.adm"
+select element {'aauthors':a.nested.authors,'bauthors':b.nested.authors,'ed':ed}
+from DBLP as a,
+ DBLP as b
+with ed as test."edit-distance"(a.nested.authors,b.nested.authors)
+where ((ed < 3) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance_01.sqlpp
new file mode 100644
index 0000000..1006106
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-edit-distance_01.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.nested.authors,b.nested.authors) < 3) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp
new file mode 100644
index 0000000..ac2c821
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.authors) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.nested.authors ~= b.nested.authors) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..23e6458
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp
@@ -0,0 +1,76 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.nested.title,3,false) ~= test."gram-tokens"(b.nested.title,3,false)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..acdc1e1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard-check_01.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard-inline.sqlpp
new file mode 100644
index 0000000..c829209
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard-inline.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-jaccard-inline.adm"
+select element {'atitle':a.nested.title,'btitle':b.nested.title,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false))
+where ((jacc >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard_01.sqlpp
new file mode 100644
index 0000000..94970e7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ngram-jaccard_01.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..013ee34
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance-check_01.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the edit-distance-check function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (test."edit-distance-check"(a.nested.interests,b.nested.interests,3)[0] and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance-inline.sqlpp
new file mode 100644
index 0000000..c218e34
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance-inline.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the edit-distance function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_olist-edit-distance-inline.adm"
+select element {'ainterests':a.nested.interests,'binterests':b.nested.interests,'ed':ed}
+from Customers as a,
+ Customers as b
+with ed as test."edit-distance"(a.nested.interests,b.nested.interests)
+where ((ed <= 2) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance_01.sqlpp
new file mode 100644
index 0000000..827c194
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-edit-distance_01.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the edit-distance function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((test."edit-distance"(a.nested.interests,b.nested.interests) <= 2) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-fuzzyeq-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-fuzzyeq-edit-distance_01.sqlpp
new file mode 100644
index 0000000..20ac47d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-fuzzyeq-edit-distance_01.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using edit distance of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-fuzzyeq-jaccard_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.nested.interests ~= b.nested.interests) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..b4cd886
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-fuzzyeq-jaccard_01.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using Jaccard of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.nested.interests /*+ indexnl */ ~= b.nested.interests) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..40d94ea
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard-check_01.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard-check function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ( /*+ indexnl */ test."similarity-jaccard-check"(a.nested.interests,b.nested.interests,0.700000f)[0] and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard-inline.sqlpp
new file mode 100644
index 0000000..3890206
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard-inline.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard function of its interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_olist-jaccard-inline.adm"
+select element {'ainterests':a.nested.interests,'binterests':b.nested.interests,'jacc':jacc}
+from Customers as a,
+ Customers as b
+with jacc as /*+ indexnl */ test."similarity-jaccard"(a.nested.interests,b.nested.interests)
+where ((jacc >= 0.700000f) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard_01.sqlpp
new file mode 100644
index 0000000..8a9d98a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/olist-jaccard_01.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest lists.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : [string],
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_olist-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.nested.interests,b.nested.interests) >= 0.700000f) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..b2007ad
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-fuzzyeq-jaccard_01.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on ~= using Jaccard of their interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.7f";
+
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ((a.nested.interests /*+ indexnl */ ~= b.nested.interests) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..4267ccd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard-check_01.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard-check function of their interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where ( /*+ indexnl */ test."similarity-jaccard-check"(a.nested.interests,b.nested.interests,0.700000f)[0] and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard-inline.sqlpp
new file mode 100644
index 0000000..80ad630
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard-inline.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Fuzzy self joins a dataset, Customers, based on the similarity-jaccard function of its interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ulist-jaccard-inline.adm"
+select element {'ainterests':a.nested.interests,'binterests':b.nested.interests,'jacc':jacc}
+from Customers as a,
+ Customers as b
+with jacc as /*+ indexnl */ test."similarity-jaccard"(a.nested.interests,b.nested.interests)
+where ((jacc >= 0.700000f) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard_01.sqlpp
new file mode 100644
index 0000000..9252836
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/ulist-jaccard_01.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, Customer and Customer2, based on the similarity-jaccard function of their interest sets.
+ * Customers has a keyword index on interests, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerTypetmp as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create type test.CustomerType as
+ closed {
+ nested : CustomerTypetmp
+}
+
+create table Customers(CustomerType) primary key nested.cid;
+
+create table Customers2(CustomerType) primary key nested.cid;
+
+create index interests_index on Customers (nested.interests) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_ulist-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from Customers as a,
+ Customers2 as b
+where (( /*+ indexnl */ test."similarity-jaccard"(a.nested.interests,b.nested.interests) >= 0.700000f) and (a.nested.cid < b.nested.cid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..f4630b4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.nested.title) ~= test."word-tokens"(b.nested.title)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp
new file mode 100644
index 0000000..143f848
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp
@@ -0,0 +1,76 @@
+/*
+ * 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 : Fuzzy self joins a dataset, TweetMessages, based on the similarity-jaccard-check function of its text-messages' word tokens.
+ * TweetMessages has a keyword index on text-message and btree index on the primary key tweetid, and we expect the join to be
+ * transformed into btree and inverted indexed nested-loop joins. We test whether the join condition can be transformed into
+ * multiple indexed nested loop joins of various type of indexes.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index twmSndLocIx on TweetMessages (nested."sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (nested.countA) type btree;
+
+create index msgCountBIx on TweetMessages (nested.countB) type btree;
+
+create index msgTextIx on TweetMessages (nested."message-text") type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check-after-btree-access.adm"
+select element {'t1':t1.nested.tweetid,'t2':t2.nested.tweetid,'sim':sim[1]}
+from TweetMessages as t1,
+ TweetMessages as t2
+with sim as test."similarity-jaccard-check"(test."word-tokens"(t1.nested."message-text"),test."word-tokens"(t2.nested."message-text"),0.600000f)
+where (sim[0] and (t1.nested.tweetid < test.int64('20')) and (t2.nested.tweetid != t1.nested.tweetid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..e6180ee
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-check_01.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-inline.sqlpp
new file mode 100644
index 0000000..55a3381
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard-inline.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_word-jaccard-inline.adm"
+select element {'atitle':a.nested.title,'btitle':b.nested.title,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title))
+where ((jacc >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard_01.sqlpp
new file mode 100644
index 0000000..db05dd2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/inverted-index-join/word-jaccard_01.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title) type keyword;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
new file mode 100644
index 0000000..7cb8b59
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
@@ -0,0 +1,80 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index twmSndLocIx on TweetMessages (nested."sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (nested.countA) type btree;
+
+create index msgCountBIx on TweetMessages (nested.countB) type btree;
+
+create index msgTextIx on TweetMessages (nested."message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_01.adm"
+select element {'tweetid1':t1.nested.tweetid,'loc1':t1.nested."sender-location",'nearby-message':(
+ select element {'tweetid2':t2.nested.tweetid,'loc2':t2.nested."sender-location"}
+ from TweetMessages as t2
+ where test."spatial-intersect"(t2.nested."sender-location",n)
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1.nested."sender-location",0.5)
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
new file mode 100644
index 0000000..03e3a34
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
@@ -0,0 +1,80 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index twmSndLocIx on TweetMessages (nested."sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (nested.countA) type btree;
+
+create index msgCountBIx on TweetMessages (nested.countB) type btree;
+
+create index msgTextIx on TweetMessages (nested."message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_02.adm"
+select element {'tweetid1':t1.nested.tweetid,'loc1':t1.nested."sender-location",'nearby-message':(
+ select element {'tweetid2':t2.nested.tweetid,'loc2':t2.nested."sender-location"}
+ from TweetMessages as t2
+ where (test."spatial-intersect"(t2.nested."sender-location",n) and (t1.nested.tweetid != t2.nested.tweetid))
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1.nested."sender-location",0.5)
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_01.sqlpp
new file mode 100644
index 0000000..0458c9f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_01.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * The dataset 'MyData1' has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordNested as
+ closed {
+ nested : MyRecord
+}
+
+create table MyData1(MyRecordNested) primary key nested.id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData1 (nested.point) type rtree;
+
+write output to nc1:"rttest/index-join_rtree-spatial-intersect-point.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.nested.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_02.sqlpp
new file mode 100644
index 0000000..7893c9b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_02.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * The dataset 'MyData2' has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordNested as
+ closed {
+ nested : MyRecord
+}
+
+create table MyData1(MyRecordNested) primary key nested.id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData2 (point) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.nested.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_03.sqlpp
new file mode 100644
index 0000000..35c6196
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-index/rtree-index-join/spatial-intersect-point_03.sqlpp
@@ -0,0 +1,58 @@
+/*
+ * 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 : Self-joins a dataset on the intersection of its point attribute.
+ * The dataset has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordNested as
+ closed {
+ nested : MyRecord
+}
+
+create table MyData(MyRecordNested) primary key nested.id;
+
+create index rtree_index on MyData (nested.point) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_03.adm"
+select element {'a':a,'b':b}
+from MyData as a,
+ MyData as b
+where test."spatial-intersect"(a.nested.point,b.nested.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/disjunction-to-join.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/disjunction-to-join.sqlpp
new file mode 100644
index 0000000..12514d2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/disjunction-to-join.sqlpp
@@ -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 : Disjunctive predicate should be transformed into collection scan.
+ * Secondary index should be used to probe the values retrieved from collection.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.NestedTestType as
+{
+
+}
+
+create type test.TestType as
+{
+ id : string,
+ "no-idx" : string,
+ nested : NestedTestType
+}
+
+create table TestSet(TestType) primary key id;
+
+create index TestSetIndex on TestSet (nested.idx:string) type btree enforced;
+
+select element x
+from TestSet as x
+where ((x.nested.idx = 'one') or (x.nested.idx = 'two'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1.sqlpp
new file mode 100644
index 0000000..66397ac6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index msgCountBIx on TweetMessages (nested.countB:int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_01.adm"
+select element {'tweetid1':t1.nested.tweetid,'count1':t1.nested.countA,'t2info':(
+ select element {'tweetid2':t2.nested.tweetid,'count2':t2.nested.countB}
+ from TweetMessages as t2
+ where (t1.nested.countA /*+ indexnl */ = t2.nested.countB)
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2.sqlpp
new file mode 100644
index 0000000..b704758
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index msgCountAIx on TweetMessages (nested.countA:int32) type btree enforced;
+
+create index msgCountBIx on TweetMessages (nested.countB:int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_01.adm"
+select element {'tweetid1':t1.nested.tweetid,'count1':t1.nested.countA,'t2info':(
+ select element {'tweetid2':t2.nested.tweetid,'count2':t2.nested.countB}
+ from TweetMessages as t2
+ where (t1.nested.countA /*+ indexnl */ = t2.nested.countB)
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1.sqlpp
new file mode 100644
index 0000000..32fb70c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index msgCountBIx on TweetMessages (nested.countB:int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_02.adm"
+select element {'tweetid1':t1.nested.tweetid,'count1':t1.nested.countA,'t2info':(
+ select element {'tweetid2':t2.nested.tweetid,'count2':t2.nested.countB}
+ from TweetMessages as t2
+ where ((t1.nested.countA /*+ indexnl */ = t2.nested.countB) and (t1.nested.tweetid != t2.nested.tweetid))
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2.sqlpp
new file mode 100644
index 0000000..53bcc3b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index msgCountAIx on TweetMessages (nested.countA:int32) type btree enforced;
+
+create index msgCountBIx on TweetMessages (nested.countB:int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_02.adm"
+select element {'tweetid1':t1.nested.tweetid,'count1':t1.nested.countA,'t2info':(
+ select element {'tweetid2':t2.nested.tweetid,'count2':t2.nested.countB}
+ from TweetMessages as t2
+ where ((t1.nested.countA /*+ indexnl */ = t2.nested.countB) and (t1.nested.tweetid != t2.nested.tweetid))
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_01.sqlpp
new file mode 100644
index 0000000..d006faf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-join_01.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ > emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ > emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_02.sqlpp
new file mode 100644
index 0000000..aa673af
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_02.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-join_02.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ < emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ < emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_03.sqlpp
new file mode 100644
index 0000000..ac00e9c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-join_03.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-join_03.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ = emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ = emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_01.sqlpp
new file mode 100644
index 0000000..41e6642
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_01.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ < emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ > emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_02.sqlpp
new file mode 100644
index 0000000..9dd20ba
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_02.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_02.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ > emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ < emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_03.sqlpp
new file mode 100644
index 0000000..8d384b4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_03.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_03.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ > emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ = emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_04.sqlpp
new file mode 100644
index 0000000..68e4f37
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_04.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_04.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ < emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ = emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_05.sqlpp
new file mode 100644
index 0000000..f551416
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_05.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_05.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ = emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ > emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_06.sqlpp
new file mode 100644
index 0000000..03fc651
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-composite-key-prefix-join_06.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Nametmp as
+{
+ id : int32
+}
+
+create type test.NameType as
+{
+ nested : Nametmp
+}
+
+create table Names(NameType) primary key nested.id;
+
+create index Name_idx on Names (nested.fname:string,lnested.name:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_06.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.nested.fname /*+ indexnl */ = emp2.nested.fname) and (emp1.nested.lname /*+ indexnl */ < emp2.nested.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join-multiindex.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join-multiindex.sqlpp
new file mode 100644
index 0000000..4a2f0b5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join-multiindex.sqlpp
@@ -0,0 +1,84 @@
+/*
+ * 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 : Equi joins two datasets, FacebookUsers and FacebookMessages, based on their user's id.
+ * We first expect FacebookUsers' primary index to be used
+ * to satisfy the range condition on it's primary key.
+ * FacebookMessages has a secondary btree index on author-id-copy, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.EmploymentType as
+ closed {
+ "organization-name" : string,
+ "start-date" : date,
+ "end-date" : date?
+}
+
+create type test.FacebookUserTypetmp as
+ closed {
+ id : int32,
+ "id-copy" : int32,
+ alias : string,
+ name : string,
+ "user-since" : datetime,
+ "user-since-copy" : datetime,
+ "friend-ids" : {{int32}},
+ employment : [EmploymentType]
+}
+
+create type test.FacebookMessageTypetmp as
+{
+ "message-id" : int32,
+ "message-id-copy" : int32,
+ "author-id" : int32,
+ "in-response-to" : int32?,
+ "sender-location" : point?,
+ message : string
+}
+
+create type test.FacebookUserType as
+ closed {
+ nested : FacebookUserTypetmp
+}
+
+create type test.FacebookMessageType as
+ closed {
+ nested : FacebookMessageTypetmp
+}
+
+create table FacebookUsers(FacebookUserType) primary key nested.id;
+
+create table FacebookMessages(FacebookMessageType) primary key nested."message-id";
+
+create index fbmIdxAutId if not exists on FacebookMessages (nested."author-id-copy":int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multiindex.adm"
+select element {'fbu-ID':user.nested.id,'fbm-auth-ID':message.nested."author-id",'uname':user.nested.name,'message':message.nested.message}
+from FacebookUsers as user,
+ FacebookMessages as message
+where ((user.nested.id /*+ indexnl */ = message.nested."author-id-copy") and (user.nested.id >= 11000) and (user.nested.id <= 12000))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join-multipred.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join-multipred.sqlpp
new file mode 100644
index 0000000..b2f3fa3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join-multipred.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the additional predicates to be put into a select above the
+ * primary index search.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index title_index on DBLP (nested.title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multipred.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.nested.title /*+ indexnl */ = b.nested.title) and (a.nested.authors < b.nested.authors) and (a.nested.misc > b.nested.misc))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_01.sqlpp
new file mode 100644
index 0000000..5ca59ca
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_01.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index title_index on DBLP (nested.title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.nested.title /*+ indexnl */ = b.nested.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_02.sqlpp
new file mode 100644
index 0000000..e6b59f1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_02.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Equi joins two datasets, closed DBLP and open CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index title_index on CSX (nested.title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.nested.title /*+ indexnl */ = b.nested.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_03.sqlpp
new file mode 100644
index 0000000..4ebdfc7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_03.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Equi joins two open datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index title_index_DBLP on DBLP (nested.title:string) type btree enforced;
+
+create index title_index_CSX on CSX (nested.title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.nested.title /*+ indexnl */ = b.nested.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_04.sqlpp
new file mode 100644
index 0000000..6877a7f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_04.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Self-joins dataset DBLP, based on it's title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+{
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index title_index on DBLP (nested.title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_04.adm"
+select element {'arec':a,'arec2':a2}
+from DBLP as a,
+ DBLP as a2
+where (a.nested.title /*+ indexnl */ = a2.nested.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_05.sqlpp
new file mode 100644
index 0000000..1dc52af
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index-join/secondary-equi-join_05.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Equi joins two open datasets, open DBLP and closed CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we *do not* expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index title_index on DBLP (nested.title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_05.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.nested.title /*+ indexnl */ = b.nested.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-33.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-33.sqlpp
new file mode 100644
index 0000000..66a680f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-33.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-39.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname > 'Roger')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-34.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-34.sqlpp
new file mode 100644
index 0000000..2e8b979
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-34.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-32.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname >= 'Susan')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-35.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-35.sqlpp
new file mode 100644
index 0000000..6a637cf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-35.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification (usage) test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-33.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname < 'Isa')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-36.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-36.sqlpp
new file mode 100644
index 0000000..6843fc8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-36.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-34.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname <= 'Vanpatten')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-37.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-37.sqlpp
new file mode 100644
index 0000000..2ca1b99f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-37.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-35.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname != 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-38.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-38.sqlpp
new file mode 100644
index 0000000..8e131b3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-38.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-36.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname = 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-39.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-39.sqlpp
new file mode 100644
index 0000000..64cf6ed
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-39.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-37.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.lname = 'Kim')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-40.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-40.sqlpp
new file mode 100644
index 0000000..a6866bd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-40.sqlpp
@@ -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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-38.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Young Seok') and (emp.nested.lname = 'Kim'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-41.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-41.sqlpp
new file mode 100644
index 0000000..4111bdb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-41.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-39.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Julio') or (emp.nested.lname = 'Malaika'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-42.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-42.sqlpp
new file mode 100644
index 0000000..ced0a75
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-42.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-40.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Alex') and (emp.nested.lname < 'Zach'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-43.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-43.sqlpp
new file mode 100644
index 0000000..99ab006
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-43.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-41.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Allan') and (emp.nested.lname < 'Zubi'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-44.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-44.sqlpp
new file mode 100644
index 0000000..409c15e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-44.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-42.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Allan') and (emp.nested.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-45.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-45.sqlpp
new file mode 100644
index 0000000..7be8ee7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-45.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-43.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Julio') and (emp.nested.lname < 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-46.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-46.sqlpp
new file mode 100644
index 0000000..2a439de
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-46.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-44.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Michael') and (emp.nested.lname <= 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-47.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-47.sqlpp
new file mode 100644
index 0000000..4555731
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-47.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-45.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-48.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-48.sqlpp
new file mode 100644
index 0000000..9488631
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-48.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-46.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname >= 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-49.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-49.sqlpp
new file mode 100644
index 0000000..c638c3e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-49.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-47.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname <= 'Craig') and (emp.nested.lname > 'Kevin'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-50.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-50.sqlpp
new file mode 100644
index 0000000..86a4e80
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-50.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-48.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname != 'Michael') and (emp.nested.lname != 'Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-51.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-51.sqlpp
new file mode 100644
index 0000000..d8ab1cc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-51.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-49.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-52.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-52.sqlpp
new file mode 100644
index 0000000..ab1a592
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-52.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-50.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname >= 'Kevin') and (emp.nested.fname < 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-53.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-53.sqlpp
new file mode 100644
index 0000000..be5fa7e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-53.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-51.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Craig') and (emp.nested.lname <= 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname >= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-54.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-54.sqlpp
new file mode 100644
index 0000000..72cdf55
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-54.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-52.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname > 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-55.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-55.sqlpp
new file mode 100644
index 0000000..847f47d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-55.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-53.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname >= 'Sofia')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-56.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-56.sqlpp
new file mode 100644
index 0000000..98aeb72
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-56.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-54.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname < 'Chen')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-57.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-57.sqlpp
new file mode 100644
index 0000000..0448bbb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-57.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-55.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname <= 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-58.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-58.sqlpp
new file mode 100644
index 0000000..0b1760c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-58.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-56.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Neil') and (emp.nested.fname < 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-59.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-59.sqlpp
new file mode 100644
index 0000000..25d2a86
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-59.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-57.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname >= 'Max') and (emp.nested.fname <= 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-60.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-60.sqlpp
new file mode 100644
index 0000000..6cb8dd2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-60.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-58.adm"
+create type test.TestTypetmp as
+{
+ id : int32,
+ lname : string
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.nested.fname = 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-61.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-61.sqlpp
new file mode 100644
index 0000000..33511e5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-61.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 13th Aug 2012
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-59.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname > 'Craig') and (emp.nested.lname > 'Kevin') and (emp.nested.fname <= 'Mary') and (emp.nested.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-62.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-62.sqlpp
new file mode 100644
index 0000000..d21967a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-62.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-62.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname = 'Julio') and (emp.nested.lname > 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-63.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-63.sqlpp
new file mode 100644
index 0000000..0fa570d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/btree-index/btree-secondary-63.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-63.adm"
+create type test.TestTypetmp as
+{
+ id : int32
+}
+
+create type test.TestType as
+{
+ nested : TestTypetmp
+}
+
+create table testdst(TestType) primary key nested.id;
+
+create index sec_Idx on testdst (nested.fname:string,nested.lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.nested.fname < 'Julio') and (emp.nested.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-contains-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-contains-panic.sqlpp
new file mode 100644
index 0000000..bbfaaaf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-contains-panic.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the contains function.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains-panic.adm"
+select element o
+from DBLP as o
+where test.contains(o.nested.title,'Mu')
+order by o.nested.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-contains.sqlpp
new file mode 100644
index 0000000..d62e983
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-contains.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains.adm"
+select element o
+from DBLP as o
+where test.contains(o.nested.title,'Multimedia')
+order by o.nested.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp
new file mode 100644
index 0000000..740f873
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-check-panic.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.nested.authors,'Amihay Motro',5)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-check.sqlpp
new file mode 100644
index 0000000..154bc8f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-check.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-check.adm"
+select element o
+from DBLP as o
+where test."edit-distance-check"(o.nested.authors,'Amihay Motro',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-panic.sqlpp
new file mode 100644
index 0000000..39bc4a5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance-panic.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance function on strings.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-panic.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.nested.authors,'Amihay Motro') <= 5)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance.sqlpp
new file mode 100644
index 0000000..214cefa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-edit-distance.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance function on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.nested.authors,'Amihay Motro') <= 1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp
new file mode 100644
index 0000000..59347e2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query with ~= using edit-distance on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-fuzzyeq-edit-distance.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "1";
+
+select element o
+from DBLP as o
+where (o.nested.authors ~= 'Amihay Motro')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..19fb844
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,58 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query with ~= using Jaccard on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element o
+from DBLP as o
+where (test."gram-tokens"(o.nested.title,3,false) ~= test."gram-tokens"('Transactions for Cooperative Environments',3,false))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-jaccard-check.sqlpp
new file mode 100644
index 0000000..4ceb420
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-jaccard-check.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-jaccard-check.adm"
+select element o
+from DBLP as o
+where test."similarity-jaccard-check"(test."gram-tokens"(o.nested.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false),0.500000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-jaccard.sqlpp
new file mode 100644
index 0000000..cba627f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/ngram-jaccard.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard function on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-jaccard.adm"
+select element o
+from DBLP as o
+where (test."similarity-jaccard"(test."gram-tokens"(o.nested.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false)) >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-contains.sqlpp
new file mode 100644
index 0000000..37f3e39
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-contains.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the contains function.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-basic_word-contains.adm"
+select element o
+from DBLP as o
+where test.contains(o.nested.title,'Multimedia')
+order by o.nested.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..ef5da6c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Tests whether a keyword is applied to optimize a selection query with ~= using Jaccard on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-basic_word-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element o
+from DBLP as o
+where (test."word-tokens"(o.nested.title) ~= test."word-tokens"('Transactions for Cooperative Environments'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-jaccard-check.sqlpp
new file mode 100644
index 0000000..dcba84e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-jaccard-check.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard-check.adm"
+select element o
+from DBLP as o
+where test."similarity-jaccard-check"(test."word-tokens"(o.nested.title),test."word-tokens"('Transactions for Cooperative Environments'),0.500000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-jaccard.sqlpp
new file mode 100644
index 0000000..e6bb7d7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-basic/word-jaccard.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard function on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard.adm"
+select element o
+from DBLP as o
+where (test."similarity-jaccard"(test."word-tokens"(o.nested.title),test."word-tokens"('Transactions for Cooperative Environments')) >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp
new file mode 100644
index 0000000..7845d93
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using
+ * two edit-distance-check function of which only the first can be optimized with an index.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic-nopanic_01.adm"
+select element o
+from DBLP as o
+with eda as test."edit-distance-check"(o.nested.authors,'Amihay Motro',3),
+ edb as test."edit-distance-check"(o.nested.authors,'Amihay Motro',5)
+where (eda[0] and edb[0])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp
new file mode 100644
index 0000000..dc939c1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using
+ * two edit-distance-check function of which only the second can be optimized with an index.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic-nopanic_01.adm"
+select element o
+from DBLP as o
+with edb as test."edit-distance-check"(o.nested.authors,'Amihay Motro',5),
+ eda as test."edit-distance-check"(o.nested.authors,'Amihay Motro',3)
+where (edb[0] and eda[0])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp
new file mode 100644
index 0000000..9668866
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.nested.authors,'Amihay Motro',5)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let.sqlpp
new file mode 100644
index 0000000..732c11d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-let.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.nested.authors,'Amihay Motro',1)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp
new file mode 100644
index 0000000..d96fbdf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index index is applied to optimize a selection query using the similarity-edit-distance-check function on the substring of the field.
+ * Tests that the optimizer rule correctly drills through the substring function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPNestedType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPNestedType
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-substring.adm"
+select element {'id':paper.nested.id,'title':paper.nested.title}
+from DBLP as paper
+where test."edit-distance-check"(test.substring(paper.nested.title,0,8),'datbase',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp
new file mode 100644
index 0000000..12fb658
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether an ngram_index index is applied to optimize a selection query using the similarity-edit-distance-check function on individual word tokens.
+ * Tests that the optimizer rule correctly drills through the word-tokens function and existential query.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPNestedType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPNestedType
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-word-tokens.adm"
+select element {'id':paper.nested.id,'title':paper.nested.title}
+from DBLP as paper,
+ test."word-tokens"(paper.nested.title) as word
+where test."edit-distance-check"(word,'Multmedia',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..b6bb119
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-jaccard-check-let.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-jaccard-check-let.adm"
+select element o
+from DBLP as o
+with jacc as test."similarity-jaccard-check"(test."gram-tokens"(o.nested.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false),0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp
new file mode 100644
index 0000000..fd2a1bb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp
@@ -0,0 +1,58 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-jaccard-check-multi-let.adm"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."gram-tokens"(paper.nested.title,3,false),
+ query_tokens as test."gram-tokens"('Transactions for Cooperative Environments',3,false),
+ jacc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/word-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/word-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..0c4929b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/word-jaccard-check-let.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-complex_word-jaccard-check-let.adm"
+select element o
+from DBLP as o
+with jacc as test."similarity-jaccard-check"(test."word-tokens"(o.nested.title),test."word-tokens"('Transactions for Cooperative Environments'),0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/word-jaccard-check-multi-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/word-jaccard-check-multi-let.sqlpp
new file mode 100644
index 0000000..8164077
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-complex/word-jaccard-check-multi-let.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-complex_word-jaccard-check-multi-let.adm"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."word-tokens"(paper.nested.title),
+ query_tokens as test."word-tokens"('Transactions for Cooperative Environments'),
+ jacc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.800000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp
new file mode 100644
index 0000000..fccb8d7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index msgNgramIx on TweetMessages (nested."message-text":string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_leftouterjoin-probe-pidx-with-join-edit-distance-check_idx_01.adm"
+select element {'tweet':{'id':t1.nested.tweetid,'topics':t1.nested."message-text"},'similar-tweets':(
+ select element {'id':t2.nested.tweetid,'topics':t2.nested."message-text"}
+ from TweetMessages as t2
+ with sim as test."edit-distance-check"(t1.nested."message-text",t2.nested."message-text",7)
+ where (sim[0] and (t2.nested.tweetid != t1.nested.tweetid))
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+where (t1.nested.tweetid > test.int64('240'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_01.sqlpp
new file mode 100644
index 0000000..34dd9fa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_01.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains-01.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from DBLP as o1,
+ CSX as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_02.sqlpp
new file mode 100644
index 0000000..f6447c8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_02.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains-02.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from CSX as o1,
+ DBLP as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_03.sqlpp
new file mode 100644
index 0000000..58ca48a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains-03.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from DBLP as o1,
+ DBLP as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_04.sqlpp
new file mode 100644
index 0000000..b1a581f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-contains_04.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index_DBLP on DBLP (title:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains-04.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from DBLP as o1,
+ CSX as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..98a552e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_01.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.nested.authors,b.nested.authors,3)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_02.sqlpp
new file mode 100644
index 0000000..6d908cf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_02.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where (test."edit-distance-check"(a.nested.authors,b.nested.authors,3)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_03.sqlpp
new file mode 100644
index 0000000..a6b1cd2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_03.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Self joins dataset DBLP, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."edit-distance-check"(a.nested.authors,b.nested.authors,3)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_04.sqlpp
new file mode 100644
index 0000000..2550577
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_04.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index_DBLP on DBLP (nested.authors:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.nested.authors,b.nested.authors,3)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_05.sqlpp
new file mode 100644
index 0000000..1688938
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-check_05.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram index on authors, and we *do not* expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.nested.authors,b.nested.authors,3)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-contains.sqlpp
new file mode 100644
index 0000000..163f151
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-contains.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-contains function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-contains.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-contains"(a.nested.authors,b.nested.authors,3)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-inline.sqlpp
new file mode 100644
index 0000000..356d816
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance-inline.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance function of its authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-edit-distance-inline.adm"
+select element {'aauthors':a.nested.authors,'bauthors':b.nested.authors,'ed':ed}
+from DBLP as a,
+ DBLP as b
+with ed as test."edit-distance"(a.nested.authors,b.nested.authors)
+where ((ed < 3) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_01.sqlpp
new file mode 100644
index 0000000..429958a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_01.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.nested.authors,b.nested.authors) < 3) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_02.sqlpp
new file mode 100644
index 0000000..b9e2bb9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_02.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where ((test."edit-distance"(a.nested.authors,b.nested.authors) < 3) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_03.sqlpp
new file mode 100644
index 0000000..dc53ff4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_03.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Self joins dataset DBLP, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."edit-distance"(a.nested.authors,b.nested.authors) < 3) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_04.sqlpp
new file mode 100644
index 0000000..ac087b7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_04.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index_DBLP on DBLP (nested.authors:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.nested.authors,b.nested.authors) < 3) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_05.sqlpp
new file mode 100644
index 0000000..28b0bfa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-edit-distance_05.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram index on authors, and we *do not* expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.nested.authors,b.nested.authors) < 3) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp
new file mode 100644
index 0000000..4c6646c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.nested.authors ~= b.nested.authors) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_02.sqlpp
new file mode 100644
index 0000000..4f391e1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_02.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where ((a.nested.authors ~= b.nested.authors) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp
new file mode 100644
index 0000000..d34082f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Self joins dataset DBLP, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((a.nested.authors ~= b.nested.authors) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_04.sqlpp
new file mode 100644
index 0000000..216aeb2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_04.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index_DBLP on DBLP (nested.authors:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.nested.authors ~= b.nested.authors) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_05.sqlpp
new file mode 100644
index 0000000..dcb2c4f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-edit-distance_05.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram index on authors, and we *do not* expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.nested.authors ~= b.nested.authors) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..ef02155
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp
@@ -0,0 +1,75 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.nested.title,3,false) ~= test."gram-tokens"(b.nested.title,3,false)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp
new file mode 100644
index 0000000..bae8d44
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp
@@ -0,0 +1,75 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where ((test."gram-tokens"(a.nested.title,3,false) ~= test."gram-tokens"(b.nested.title,3,false)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp
new file mode 100644
index 0000000..6f918a5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Self joins dataset DBLP, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."gram-tokens"(a.nested.title,3,false) ~= test."gram-tokens"(b.nested.title,3,false)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_04.sqlpp
new file mode 100644
index 0000000..42ffaeb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-fuzzyeq-jaccard_04.sqlpp
@@ -0,0 +1,76 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index_DBLP on DBLP (nested.title:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.nested.title,3,false) ~= test."gram-tokens"(b.nested.title,3,false)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..7c2d5d8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_01.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..37ff0e0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_02.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..877d872
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_03.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Self joins dataset DBLP, based on the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..ff308a7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-check_04.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index_DBLP on DBLP (nested.title:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-inline.sqlpp
new file mode 100644
index 0000000..198110f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard-inline.sqlpp
@@ -0,0 +1,58 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_ngram-jaccard-inline.adm"
+select element {'atitle':a.nested.title,'btitle':b.nested.title,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false))
+where ((jacc >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_01.sqlpp
new file mode 100644
index 0000000..13e2a0e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_01.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_02.sqlpp
new file mode 100644
index 0000000..90d0380
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_02.sqlpp
@@ -0,0 +1,71 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index on CSX (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_03.sqlpp
new file mode 100644
index 0000000..21ce12f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_03.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Self joins dataset DBLP, based on the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index ngram_index on DBLP (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_04.sqlpp
new file mode 100644
index 0000000..d503ef7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/ngram-jaccard_04.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index ngram_index_DBLP on DBLP (nested.title:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (nested.title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.nested.title,3,false),test."gram-tokens"(b.nested.title,3,false)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..f590056
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.nested.title) ~= test."word-tokens"(b.nested.title)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_02.sqlpp
new file mode 100644
index 0000000..b8b1606
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_02.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on CSX (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where ((test."word-tokens"(a.nested.title) ~= test."word-tokens"(b.nested.title)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp
new file mode 100644
index 0000000..70393dd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Self joins dataset DBLP, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."word-tokens"(a.nested.title) ~= test."word-tokens"(b.nested.title)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_04.sqlpp
new file mode 100644
index 0000000..004ebb1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-fuzzyeq-jaccard_04.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index_DBLP on DBLP (nested.title:string) type keyword enforced;
+
+create index keyword_index_CSX on CSX (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.nested.title) ~= test."word-tokens"(b.nested.title)) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp
new file mode 100644
index 0000000..d1861c2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp
@@ -0,0 +1,75 @@
+/*
+ * 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 : Fuzzy self joins a dataset, TweetMessages, based on the similarity-jaccard-check function of its text-messages' word tokens.
+ * TweetMessages has a keyword index on text-message and btree index on the primary key tweetid, and we expect the join to be
+ * transformed into btree and inverted indexed nested-loop joins. We test whether the join condition can be transformed into
+ * multiple indexed nested loop joins of various type of indexes.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index twmSndLocIx on TweetMessages (nested."sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (nested.countA) type btree;
+
+create index msgCountBIx on TweetMessages (nested.countB) type btree;
+
+create index msgTextIx on TweetMessages (nested."message-text":string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check-after-btree-access.adm"
+select element {'t1':t1.nested.tweetid,'t2':t2.nested.tweetid,'sim':sim[1]}
+from TweetMessages as t1,
+ TweetMessages as t2
+with sim as test."similarity-jaccard-check"(test."word-tokens"(t1.nested."message-text"),test."word-tokens"(t2.nested."message-text"),0.600000f)
+where (sim[0] and (t1.nested.tweetid < test.int64('20')) and (t2.nested.tweetid != t1.nested.tweetid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..8315087
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_01.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..2f1a193
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_02.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on CSX (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..574fa08
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_03.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Selg joins dataset DBLP, based on the similarity-jaccard-check function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index_DBLP on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..c39897a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-check_04.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+create index keyword_index on CSX (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title),0.500000f)[0] and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-inline.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-inline.sqlpp
new file mode 100644
index 0000000..2cea216
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard-inline.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * We expect the top-level equi join introduced because of surrogate optimization to be removed, since it is not necessary.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join-noeqjoin_word-jaccard-inline.adm"
+select element {'atitle':a.nested.title,'btitle':b.nested.title,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title))
+where ((jacc >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_01.sqlpp
new file mode 100644
index 0000000..8db124f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_01.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_02.sqlpp
new file mode 100644
index 0000000..f9bda14
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_02.sqlpp
@@ -0,0 +1,69 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on CSX (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from CSX as a,
+ DBLP as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_03.sqlpp
new file mode 100644
index 0000000..5bf70fa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_03.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Self joins dataset DBLP, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_04.sqlpp
new file mode 100644
index 0000000..3a8fb16
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/inverted-index-join/word-jaccard_04.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP has a keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPTypetmp as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXTypetmp as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.DBLPType as
+ closed {
+ nested : DBLPTypetmp
+}
+
+create type test.CSXType as
+ closed {
+ nested : CSXTypetmp
+}
+
+create table DBLP(DBLPType) primary key nested.id;
+
+create table CSX(CSXType) primary key nested.id;
+
+create index keyword_index on DBLP (nested.title:string) type keyword enforced;
+
+create index keyword_index on CSX (nested.title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.nested.title),test."word-tokens"(b.nested.title)) >= 0.500000f) and (a.nested.id < b.nested.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
new file mode 100644
index 0000000..4068562
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
@@ -0,0 +1,79 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index twmSndLocIx on TweetMessages (nested."sender-location":point) type rtree enforced;
+
+create index msgCountAIx on TweetMessages (nested.countA) type btree;
+
+create index msgCountBIx on TweetMessages (nested.countB) type btree;
+
+create index msgTextIx on TweetMessages (nested."message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_01.adm"
+select element {'tweetid1':t1.nested.tweetid,'loc1':t1.nested."sender-location",'nearby-message':(
+ select element {'tweetid2':t2.nested.tweetid,'loc2':t2.nested."sender-location"}
+ from TweetMessages as t2
+ where test."spatial-intersect"(t2.nested."sender-location",n)
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1.nested."sender-location",0.5)
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
new file mode 100644
index 0000000..00f174b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
@@ -0,0 +1,79 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageNestedType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create type test.TweetMessageType as
+{
+ nested : TweetMessageNestedType
+}
+
+create table TweetMessages(TweetMessageType) primary key nested.tweetid;
+
+create index twmSndLocIx on TweetMessages (nested."sender-location":point) type rtree enforced;
+
+create index msgCountAIx on TweetMessages (nested.countA) type btree;
+
+create index msgCountBIx on TweetMessages (nested.countB) type btree;
+
+create index msgTextIx on TweetMessages (nested."message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_02.adm"
+select element {'tweetid1':t1.nested.tweetid,'loc1':t1.nested."sender-location",'nearby-message':(
+ select element {'tweetid2':t2.nested.tweetid,'loc2':t2.nested."sender-location"}
+ from TweetMessages as t2
+ where (test."spatial-intersect"(t2.nested."sender-location",n) and (t1.nested.tweetid != t2.nested.tweetid))
+ order by t2.nested.tweetid
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1.nested."sender-location",0.5)
+where (t1.nested.tweetid < test.int64('10'))
+order by t1.nested.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_01.sqlpp
new file mode 100644
index 0000000..0458c9f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_01.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * The dataset 'MyData1' has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordNested as
+ closed {
+ nested : MyRecord
+}
+
+create table MyData1(MyRecordNested) primary key nested.id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData1 (nested.point) type rtree;
+
+write output to nc1:"rttest/index-join_rtree-spatial-intersect-point.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.nested.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_02.sqlpp
new file mode 100644
index 0000000..7893c9b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_02.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * The dataset 'MyData2' has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordNested as
+ closed {
+ nested : MyRecord
+}
+
+create table MyData1(MyRecordNested) primary key nested.id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData2 (point) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.nested.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_03.sqlpp
new file mode 100644
index 0000000..35c6196
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_03.sqlpp
@@ -0,0 +1,58 @@
+/*
+ * 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 : Self-joins a dataset on the intersection of its point attribute.
+ * The dataset has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordNested as
+ closed {
+ nested : MyRecord
+}
+
+create table MyData(MyRecordNested) primary key nested.id;
+
+create index rtree_index on MyData (nested.point) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_03.adm"
+select element {'a':a,'b':b}
+from MyData as a,
+ MyData as b
+where test."spatial-intersect"(a.nested.point,b.nested.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_04.sqlpp
new file mode 100644
index 0000000..fcd5ac4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_04.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * Both datasets 'MyData' and 'MyData2' have an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecordNestedOpen as
+{
+ id : int32,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordOpen as
+ closed {
+ nested : MyRecordNestedOpen
+}
+
+create table MyData1(MyRecordOpen) primary key nested.id;
+
+create table MyData2(MyRecordOpen) primary key nested.id;
+
+create index rtree_index on MyData1 (nested.point:point) type rtree enforced;
+
+create index rtree_index2 on MyData2 (nested.point:point) type rtree enforced;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.nested.point,b.nested.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_05.sqlpp
new file mode 100644
index 0000000..39a7c66
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested-open-index/rtree-index-join/spatial-intersect-point_05.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * Only dataset 'MyData1' has an enforced open RTree index, hence we
+ * *do not* expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecordNestedOpen as
+{
+ id : int32,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordOpen as
+ closed {
+ nested : MyRecordNestedOpen
+}
+
+create table MyData1(MyRecordOpen) primary key nested.id;
+
+create table MyData2(MyRecordOpen) primary key nested.id;
+
+create index rtree_index on MyData1 (nested.point:point) type rtree enforced;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.nested.point,b.nested.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested_loj2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested_loj2.sqlpp
new file mode 100644
index 0000000..1abe40e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested_loj2.sqlpp
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems(LineItemType) primary key l_orderkey,l_linenumber on group1;
+
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+create table Customers(CustomerType) primary key c_custkey on group1;
+
+write output to nc1:"/tmp/nested_loj.adm"
+select element {'cust':c,'orders':orders}
+from Customers as c
+with orders as (
+ select element {'order':o,'items':items}
+ from Orders as o
+ with items as (
+ select element l
+ from LineItems as l
+ where (l.l_orderkey = o.o_orderkey)
+ )
+ where (o.o_custkey = c.c_custkey)
+ )
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested_loj3.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested_loj3.sqlpp
new file mode 100644
index 0000000..93c153d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/nested_loj3.sqlpp
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create type tpch.PartSuppType as
+ closed {
+ ps_partkey : int32,
+ ps_suppkey : int32,
+ ps_availqty : int32,
+ ps_supplycost : double,
+ ps_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems(LineItemType) primary key l_orderkey,l_linenumber on group1;
+
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+create table Customers(CustomerType) primary key c_custkey on group1;
+
+create table PartSupp(PartSuppType) primary key ps_partkey,ps_suppkey on group1;
+
+write output to nc1:"/tmp/nested_loj.adm"
+select element {'cust':c,'orders':orders}
+from Customers as c
+with orders as (
+ select element {'order':o,'items':items}
+ from Orders as o
+ with items as (
+ select element {'item':l,'part_supplier':partsupp}
+ from LineItems as l
+ with partsupp as (
+ select element ps
+ from PartSupp as ps
+ where ((ps.ps_partkey = l.l_partkey) and (ps.ps_suppkey = l.l_suppkey))
+ )
+ where (l.l_orderkey = o.o_orderkey)
+ )
+ where (o.o_custkey = c.c_custkey)
+ )
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/disjunction-to-join.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/disjunction-to-join.sqlpp
new file mode 100644
index 0000000..3e78b25
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/disjunction-to-join.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : Disjunctive predicate should be transformed into collection scan.
+ * Secondary index should be used to probe the values retrieved from collection.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TestType as
+{
+ id : string,
+ "no-idx" : string
+}
+
+create table TestSet(TestType) primary key id;
+
+create index TestSetIndex on TestSet (idx:string) type btree enforced;
+
+select element x
+from TestSet as x
+where ((x.idx = 'one') or (x.idx = 'two'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1.sqlpp
new file mode 100644
index 0000000..f3b1479
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1.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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index msgCountBIx on TweetMessages (countB:int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_01.adm"
+select element {'tweetid1':t1.tweetid,'count1':t1.countA,'t2info':(
+ select element {'tweetid2':t2.tweetid,'count2':t2.countB}
+ from TweetMessages as t2
+ where (t1.countA /*+ indexnl */ = t2.countB)
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2.sqlpp
new file mode 100644
index 0000000..60e721e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index msgCountAIx on TweetMessages (countA:int32) type btree enforced;
+
+create index msgCountBIx on TweetMessages (countB:int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_01.adm"
+select element {'tweetid1':t1.tweetid,'count1':t1.countA,'t2info':(
+ select element {'tweetid2':t2.tweetid,'count2':t2.countB}
+ from TweetMessages as t2
+ where (t1.countA /*+ indexnl */ = t2.countB)
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1.sqlpp
new file mode 100644
index 0000000..148a4f4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1.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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index msgCountBIx on TweetMessages (countB:int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_02.adm"
+select element {'tweetid1':t1.tweetid,'count1':t1.countA,'t2info':(
+ select element {'tweetid2':t2.tweetid,'count2':t2.countB}
+ from TweetMessages as t2
+ where ((t1.countA /*+ indexnl */ = t2.countB) and (t1.tweetid != t2.tweetid))
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2.sqlpp
new file mode 100644
index 0000000..ab89fab
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary btree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index msgCountAIx on TweetMessages (countA:int32) type btree enforced;
+
+create index msgCountBIx on TweetMessages (countB:int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_leftouterjoin-probe-pidx-with-join-btree-sidx_02.adm"
+select element {'tweetid1':t1.tweetid,'count1':t1.countA,'t2info':(
+ select element {'tweetid2':t2.tweetid,'count2':t2.countB}
+ from TweetMessages as t2
+ where ((t1.countA /*+ indexnl */ = t2.countB) and (t1.tweetid != t2.tweetid))
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_01.sqlpp
new file mode 100644
index 0000000..5533e0a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-join_01.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ > emp2.fname) and (emp1.lname /*+ indexnl */ > emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_02.sqlpp
new file mode 100644
index 0000000..0381eb5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_02.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-join_02.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ < emp2.fname) and (emp1.lname /*+ indexnl */ < emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_03.sqlpp
new file mode 100644
index 0000000..ea10df7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-join_03.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-join_03.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ = emp2.fname) and (emp1.lname /*+ indexnl */ = emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_01.sqlpp
new file mode 100644
index 0000000..06c22a3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_01.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_01.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ < emp2.fname) and (emp1.lname /*+ indexnl */ > emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_02.sqlpp
new file mode 100644
index 0000000..7e113f4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_02.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_02.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ > emp2.fname) and (emp1.lname /*+ indexnl */ < emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_03.sqlpp
new file mode 100644
index 0000000..cc1809f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_03.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_03.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ > emp2.fname) and (emp1.lname /*+ indexnl */ = emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_04.sqlpp
new file mode 100644
index 0000000..8513c6b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_04.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_04.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ < emp2.fname) and (emp1.lname /*+ indexnl */ = emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_05.sqlpp
new file mode 100644
index 0000000..c3aaad7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_05.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_05.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ = emp2.fname) and (emp1.lname /*+ indexnl */ > emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_06.sqlpp
new file mode 100644
index 0000000..0c6b8a3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-composite-key-prefix-join_06.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to use an indexed nested-loops join plan in both predicates.
+ * : We expect a plan to have a self-join, which probes dataset Names’s with a prefix of its secondary index.
+ * Expected Res : Success
+ * Date : 11th November 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.Name as
+{
+ id : int32
+}
+
+create table Names(Name) primary key id;
+
+create index Name_idx on Names (fname:string,lname:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_secondary-composite-key-prefix-prefix-join_06.adm"
+select element {'emp1':emp1,'emp2':emp2}
+from Names as emp1,
+ Names as emp2
+where ((emp1.fname /*+ indexnl */ = emp2.fname) and (emp1.lname /*+ indexnl */ < emp2.lname))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join-multiindex.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join-multiindex.sqlpp
new file mode 100644
index 0000000..97117f6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join-multiindex.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Equi joins two datasets, FacebookUsers and FacebookMessages, based on their user's id.
+ * We first expect FacebookUsers' primary index to be used
+ * to satisfy the range condition on it's primary key.
+ * FacebookMessages has a secondary btree open index on author-id-copy, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.EmploymentType as
+ closed {
+ "organization-name" : string,
+ "start-date" : date,
+ "end-date" : date?
+}
+
+create type test.FacebookUserType as
+ closed {
+ id : int32,
+ "id-copy" : int32,
+ alias : string,
+ name : string,
+ "user-since" : datetime,
+ "user-since-copy" : datetime,
+ "friend-ids" : {{int32}},
+ employment : [EmploymentType]
+}
+
+create type test.FacebookMessageType as
+{
+ "message-id" : int32,
+ "message-id-copy" : int32,
+ "author-id" : int32,
+ "in-response-to" : int32?,
+ "sender-location" : point?,
+ message : string
+}
+
+create table FacebookUsers(FacebookUserType) primary key id;
+
+create table FacebookMessages(FacebookMessageType) primary key "message-id";
+
+create index fbmIdxAutId if not exists on FacebookMessages ("author-id-copy":int32) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multiindex.adm"
+select element {'fbu-ID':user.id,'fbm-auth-ID':message."author-id",'uname':user.name,'message':message.message}
+from FacebookUsers as user,
+ FacebookMessages as message
+where ((user.id /*+ indexnl */ = message."author-id-copy") and (user.id >= 11000) and (user.id <= 12000))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join-multipred.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join-multipred.sqlpp
new file mode 100644
index 0000000..a24c904
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join-multipred.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * We expect the additional predicates to be put into a select above the
+ * primary index search.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index title_index on DBLP (title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join-multipred.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.title /*+ indexnl */ = b.title) and (a.authors < b.authors) and (a.misc > b.misc))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_01.sqlpp
new file mode 100644
index 0000000..370dfb4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_01.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree open index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index title_index on DBLP (title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.title /*+ indexnl */ = b.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_02.sqlpp
new file mode 100644
index 0000000..091c7ee
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_02.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * CSX has a secondary btree open index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index title_index on CSX (title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.title /*+ indexnl */ = b.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_03.sqlpp
new file mode 100644
index 0000000..dd0e8a2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Equi self-joins a dataset, DBLP, based on its title.
+ * DBLP has a secondary btree open index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index title_index on DBLP (title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (a.title /*+ indexnl */ = b.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_04.sqlpp
new file mode 100644
index 0000000..25ad745
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_04.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * Both DBLP and CSX have secondary btree open index on title, and given the 'indexnl' hint
+ * we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index title_index_DBLP on DBLP (title:string) type btree enforced;
+
+create index title_index on CSX (title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.title /*+ indexnl */ = b.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_05.sqlpp
new file mode 100644
index 0000000..d4e7952
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index-join/secondary-equi-join_05.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Equi joins two datasets, DBLP and CSX, based on their title.
+ * DBLP has a secondary btree open index on title, and given the 'indexnl' hint
+ * we *do not* expect the join to be transformed into an indexed nested-loop join,
+ * because CSX does not declare an enforced open index on field title.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index title_index on DBLP (title:string) type btree enforced;
+
+write output to nc1:"rttest/btree-index-join_title-secondary-equi-join_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (a.title /*+ indexnl */ = b.title)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-33.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-33.sqlpp
new file mode 100644
index 0000000..7db87d7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-33.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-31.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname > 'Roger')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-34.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-34.sqlpp
new file mode 100644
index 0000000..9241ab4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-34.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-32.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname >= 'Susan')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-35.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-35.sqlpp
new file mode 100644
index 0000000..d957ed4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-35.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification (usage) test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-33.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname < 'Isa')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-36.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-36.sqlpp
new file mode 100644
index 0000000..62f8eed
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-36.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-34.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname <= 'Vanpatten')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-37.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-37.sqlpp
new file mode 100644
index 0000000..12ab41f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-37.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-35.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname != 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-38.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-38.sqlpp
new file mode 100644
index 0000000..4b04e48
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-38.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-36.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname = 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-39.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-39.sqlpp
new file mode 100644
index 0000000..de76f42
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-39.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-37.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.lname = 'Kim')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-40.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-40.sqlpp
new file mode 100644
index 0000000..93a7d0a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-40.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used in the optimized query plan
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-38.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Young Seok') and (emp.lname = 'Kim'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-41.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-41.sqlpp
new file mode 100644
index 0000000..4fabbcc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-41.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-39.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') or (emp.lname = 'Malaika'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-42.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-42.sqlpp
new file mode 100644
index 0000000..57133c9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-42.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-40.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Alex') and (emp.lname < 'Zach'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-43.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-43.sqlpp
new file mode 100644
index 0000000..ea39a03
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-43.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-41.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Allan') and (emp.lname < 'Zubi'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-44.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-44.sqlpp
new file mode 100644
index 0000000..6845569
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-44.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-42.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Allan') and (emp.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-45.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-45.sqlpp
new file mode 100644
index 0000000..a574bf3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-45.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-43.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') and (emp.lname < 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-46.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-46.sqlpp
new file mode 100644
index 0000000..706afd7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-46.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-44.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Michael') and (emp.lname <= 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-47.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-47.sqlpp
new file mode 100644
index 0000000..878e264
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-47.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-45.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname < 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-48.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-48.sqlpp
new file mode 100644
index 0000000..11562fa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-48.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-46.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname >= 'Kevin') and (emp.fname <= 'Mary') and (emp.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-49.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-49.sqlpp
new file mode 100644
index 0000000..ea4f4fe
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-49.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-47.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname <= 'Craig') and (emp.lname > 'Kevin'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-50.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-50.sqlpp
new file mode 100644
index 0000000..1a1c090
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-50.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is NOT used
+ * : in the optimized query plan
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-48.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname != 'Michael') and (emp.lname != 'Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-51.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-51.sqlpp
new file mode 100644
index 0000000..a1f1135
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-51.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-49.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname <= 'Mary') and (emp.lname <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-52.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-52.sqlpp
new file mode 100644
index 0000000..fa3f16e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-52.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-50.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname >= 'Kevin') and (emp.fname < 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-53.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-53.sqlpp
new file mode 100644
index 0000000..1c5656b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-53.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-51.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Craig') and (emp.lname <= 'Kevin') and (emp.fname <= 'Mary') and (emp.lname >= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-54.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-54.sqlpp
new file mode 100644
index 0000000..4c764fe
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-54.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-52.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname > 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-55.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-55.sqlpp
new file mode 100644
index 0000000..5d2bd3f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-55.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-53.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname >= 'Sofia')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-56.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-56.sqlpp
new file mode 100644
index 0000000..b4d8ca6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-56.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-54.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname < 'Chen')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-57.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-57.sqlpp
new file mode 100644
index 0000000..d247975
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-57.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-55.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname <= 'Julio')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-58.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-58.sqlpp
new file mode 100644
index 0000000..062cd2d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-58.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : This test is intended to verify that the primary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-56.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Neil') and (emp.fname < 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-59.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-59.sqlpp
new file mode 100644
index 0000000..c6cfbdd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-59.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-57.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname >= 'Max') and (emp.fname <= 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-60.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-60.sqlpp
new file mode 100644
index 0000000..cf717f8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-60.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-58.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where (emp.fname = 'Max')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-61.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-61.sqlpp
new file mode 100644
index 0000000..05fedeb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-61.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 26th Mar 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-49.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname > 'Craig') and (emp.lname > 'Kevin') and (emp.fname <= 'Mary') and (emp.lname < 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-62.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-62.sqlpp
new file mode 100644
index 0000000..8b1ca74
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-62.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-62.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname = 'Julio') and (emp.lname > 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-63.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-63.sqlpp
new file mode 100644
index 0000000..582f8a7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/btree-index/btree-secondary-63.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : BTree Index verification test
+ * : This test is intended to verify that the secondary BTree index is used
+ * : in the optimized query plan.
+ * Expected Result : Success
+ * Date : 11th Nov 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-63.adm"
+create type test.TestType as
+{
+ id : int32
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname:string,lname:string) type btree enforced;
+
+select element emp
+from testdst as emp
+where ((emp.fname < 'Julio') and (emp.lname = 'Xu'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-contains-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-contains-panic.sqlpp
new file mode 100644
index 0000000..7245e87
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-contains-panic.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the contains function.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains-panic.adm"
+select element o
+from DBLP as o
+where test.contains(o.title,'Mu')
+order by o.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-contains.sqlpp
new file mode 100644
index 0000000..ba79dc4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-contains.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains.adm"
+select element o
+from DBLP as o
+where test.contains(o.title,'Multimedia')
+order by o.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp
new file mode 100644
index 0000000..275b63d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-check-panic.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-check-panic.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.authors,'Amihay Motro',5)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-check.sqlpp
new file mode 100644
index 0000000..0802881
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-check.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-check.adm"
+select element o
+from DBLP as o
+where test."edit-distance-check"(o.authors,'Amihay Motro',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-panic.sqlpp
new file mode 100644
index 0000000..93ef239
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance-panic.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance function on strings.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance-panic.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.authors,'Amihay Motro') <= 5)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance.sqlpp
new file mode 100644
index 0000000..0bdf6d1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-edit-distance.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance function on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-edit-distance.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.authors,'Amihay Motro') <= 1)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp
new file mode 100644
index 0000000..be662b1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-fuzzyeq-edit-distance.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query with ~= using edit-distance on strings.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-fuzzyeq-edit-distance.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "1";
+
+select element o
+from DBLP as o
+where (o.authors ~= 'Amihay Motro')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..59a4489
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query with ~= using Jaccard on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element o
+from DBLP as o
+where (test."gram-tokens"(o.title,3,false) ~= test."gram-tokens"('Transactions for Cooperative Environments',3,false))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-jaccard-check.sqlpp
new file mode 100644
index 0000000..78c7f4b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-jaccard-check.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-jaccard-check.adm"
+select element o
+from DBLP as o
+where test."similarity-jaccard-check"(test."gram-tokens"(o.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false),0.500000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-jaccard.sqlpp
new file mode 100644
index 0000000..db169b2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/ngram-jaccard.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard function on 3-gram tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-basic_ngram-jaccard.adm"
+select element o
+from DBLP as o
+where (test."similarity-jaccard"(test."gram-tokens"(o.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false)) >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-contains.sqlpp
new file mode 100644
index 0000000..d1da134
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-contains.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the contains function.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-basic_word-contains.adm"
+select element o
+from DBLP as o
+where test.contains(o.title,'Multimedia')
+order by o.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp
new file mode 100644
index 0000000..210f38f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-fuzzyeq-jaccard.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Tests whether a keyword is applied to optimize a selection query with ~= using Jaccard on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-basic_word-fuzzyeq-jaccard.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element o
+from DBLP as o
+where (test."word-tokens"(o.title) ~= test."word-tokens"('Transactions for Cooperative Environments'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-jaccard-check.sqlpp
new file mode 100644
index 0000000..bc3b644
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-jaccard-check.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard-check.adm"
+select element o
+from DBLP as o
+where test."similarity-jaccard-check"(test."word-tokens"(o.title),test."word-tokens"('Transactions for Cooperative Environments'),0.500000f)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-jaccard.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-jaccard.sqlpp
new file mode 100644
index 0000000..93c9882
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-basic/word-jaccard.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard function on word tokens.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard.adm"
+select element o
+from DBLP as o
+where (test."similarity-jaccard"(test."word-tokens"(o.title),test."word-tokens"('Transactions for Cooperative Environments')) >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp
new file mode 100644
index 0000000..b0a7e95
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using
+ * two edit-distance-check function of which only the first can be optimized with an index.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic-nopanic_01.adm"
+select element o
+from DBLP as o
+with eda as test."edit-distance-check"(o.authors,'Amihay Motro',3),
+ edb as test."edit-distance-check"(o.authors,'Amihay Motro',5)
+where (eda[0] and edb[0])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp
new file mode 100644
index 0000000..63752f1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using
+ * two edit-distance-check function of which only the second can be optimized with an index.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic-nopanic_01.adm"
+select element o
+from DBLP as o
+with edb as test."edit-distance-check"(o.authors,'Amihay Motro',5),
+ eda as test."edit-distance-check"(o.authors,'Amihay Motro',3)
+where (edb[0] and eda[0])
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp
new file mode 100644
index 0000000..3a4f02e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let-panic.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should *not* be applied (see below).
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let-panic.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.authors,'Amihay Motro',5)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let.sqlpp
new file mode 100644
index 0000000..f76aa93
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-let.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the edit-distance-check function on strings.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-let.adm"
+select element o
+from DBLP as o
+with ed as test."edit-distance-check"(o.authors,'Amihay Motro',1)
+where ed[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp
new file mode 100644
index 0000000..cdbcbc5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-substring.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Tests whether an ngram_index index is applied to optimize a selection query using the similarity-edit-distance-check function on the substring of the field.
+ * Tests that the optimizer rule correctly drills through the substring function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-substring.adm"
+select element {'id':paper.id,'title':paper.title}
+from DBLP as paper
+where test."edit-distance-check"(test.substring(paper.title,0,8),'datbase',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp
new file mode 100644
index 0000000..d1f8bf0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-edit-distance-check-word-tokens.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index index is applied to optimize a selection query using the similarity-edit-distance-check function on individual word tokens.
+ * Tests that the optimizer rule correctly drills through the word-tokens function and existential query.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-edit-distance-check-word-tokens.adm"
+select element {'id':paper.id,'title':paper.title}
+from DBLP as paper,
+ test."word-tokens"(paper.title) as word
+where test."edit-distance-check"(word,'Multmedia',1)[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..2faf06a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-jaccard-check-let.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-jaccard-check-let.adm"
+select element o
+from DBLP as o
+with jacc as test."similarity-jaccard-check"(test."gram-tokens"(o.title,3,false),test."gram-tokens"('Transactions for Cooperative Environments',3,false),0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp
new file mode 100644
index 0000000..9a7ea07
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/ngram-jaccard-check-multi-let.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a selection query using the similarity-jaccard-check function on 3-gram tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-complex_ngram-jaccard-check-multi-let.adm"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."gram-tokens"(paper.title,3,false),
+ query_tokens as test."gram-tokens"('Transactions for Cooperative Environments',3,false),
+ jacc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/word-jaccard-check-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/word-jaccard-check-let.sqlpp
new file mode 100644
index 0000000..05b253e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/word-jaccard-check-let.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-complex_word-jaccard-check-let.adm"
+select element o
+from DBLP as o
+with jacc as test."similarity-jaccard-check"(test."word-tokens"(o.title),test."word-tokens"('Transactions for Cooperative Environments'),0.500000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/word-jaccard-check-multi-let.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/word-jaccard-check-multi-let.sqlpp
new file mode 100644
index 0000000..0796a6a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-complex/word-jaccard-check-multi-let.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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 : Tests whether a keyword index is applied to optimize a selection query using the similarity-jaccard-check function on word tokens.
+ * Tests that the optimizer rule correctly drills through the let clauses.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-complex_word-jaccard-check-multi-let.adm"
+select element {'Paper':paper_tokens,'Query':query_tokens}
+from DBLP as paper
+with paper_tokens as test."word-tokens"(paper.title),
+ query_tokens as test."word-tokens"('Transactions for Cooperative Environments'),
+ jacc as test."similarity-jaccard-check"(paper_tokens,query_tokens,0.800000f)
+where jacc[0]
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp
new file mode 100644
index 0000000..549959d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index msgNgramIx on TweetMessages ("message-text":string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_leftouterjoin-probe-pidx-with-join-edit-distance-check_idx_01.adm"
+select element {'tweet':{'id':t1.tweetid,'topics':t1."message-text"},'similar-tweets':(
+ select element {'id':t2.tweetid,'topics':t2."message-text"}
+ from TweetMessages as t2
+ with sim as test."edit-distance-check"(t1."message-text",t2."message-text",7)
+ where (sim[0] and (t2.tweetid != t1.tweetid))
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+where (t1.tweetid > test.int64('240'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_01.sqlpp
new file mode 100644
index 0000000..34dd9fa
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_01.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains-01.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from DBLP as o1,
+ CSX as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_02.sqlpp
new file mode 100644
index 0000000..bbccf5e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_02.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains-02.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from DBLP as o1,
+ CSX as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_03.sqlpp
new file mode 100644
index 0000000..58ca48a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains-03.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from DBLP as o1,
+ DBLP as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_04.sqlpp
new file mode 100644
index 0000000..b1a581f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-contains_04.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Tests whether an ngram_index is applied to optimize a join query using the contains function.
+ * The index should be applied.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index_DBLP on DBLP (title:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-contains-04.adm"
+select element {'title1':o1.title,'title2':o2.title}
+from DBLP as o1,
+ CSX as o2
+where (test.contains(o1.title,o2.title) and (o1.id < o2.id))
+order by o1.id,o2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..aad6109
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_01.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_02.sqlpp
new file mode 100644
index 0000000..cdce39b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_02.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * CSX has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_03.sqlpp
new file mode 100644
index 0000000..2f9643b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_03.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance-check function of its authors.
+ * DBLP has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."edit-distance-check"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_04.sqlpp
new file mode 100644
index 0000000..8d9cc00
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_04.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP and CSX both have a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index_DBLP on DBLP (authors:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_05.sqlpp
new file mode 100644
index 0000000..2ebf73a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_05.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-check function of their authors.
+ * DBLP has a 3-gram enforced open index on authors, and we *do not* expect the join to be transformed
+ * into an indexed nested-loop join, because CSX does not declare an enforced open index on field authors.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-check"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_inline_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_inline_03.sqlpp
new file mode 100644
index 0000000..27e9de2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-check_inline_03.sqlpp
@@ -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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance-check function of its authors.
+ * DBLP has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-check_04.adm"
+select element {'arec':a,'brec':b,'ed':ed[1]}
+from DBLP as a,
+ DBLP as b
+with ed as test."edit-distance-check"(a.authors,b.authors,3)
+where (ed[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-contains.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-contains.sqlpp
new file mode 100644
index 0000000..ce38c41
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance-contains.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance-contains function of their authors.
+ * DBLP has a 3-gram index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance-contains.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."edit-distance-contains"(a.authors,b.authors,3)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_01.sqlpp
new file mode 100644
index 0000000..d488fae
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_01.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_02.sqlpp
new file mode 100644
index 0000000..0078883
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_02.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * CSX has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_03.sqlpp
new file mode 100644
index 0000000..d1bd58b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_03.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance function of its authors.
+ * DBLP has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_04.sqlpp
new file mode 100644
index 0000000..8f4f23e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_04.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP and CSX both have a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index_DBLP on DBLP (authors:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_05.sqlpp
new file mode 100644
index 0000000..c992c27
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_05.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the edit-distance function of their authors.
+ * DBLP has a 3-gram enforced open index on authors, and we *do not* expect the join to be transformed
+ * into an indexed nested-loop join, because CSX does not declare an enforced open index on field authors.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."edit-distance"(a.authors,b.authors) < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_inline_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_inline_03.sqlpp
new file mode 100644
index 0000000..8a1d662
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-edit-distance_inline_03.sqlpp
@@ -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 : Fuzzy self joins a dataset, DBLP, based on the edit-distance function of its authors.
+ * DBLP has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-edit-distance_03.adm"
+select element {'arec':a,'brec':b,'ed':ed}
+from DBLP as a,
+ DBLP as b
+with ed as test."edit-distance"(a.authors,b.authors)
+where ((ed < 3) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp
new file mode 100644
index 0000000..780cdd0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_01.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_02.sqlpp
new file mode 100644
index 0000000..e456889
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_02.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * CSX has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp
new file mode 100644
index 0000000..3151d92
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_03.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on ~= using edit distance of its authors.
+ * DBLP has a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_03.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_04.sqlpp
new file mode 100644
index 0000000..eb3a137
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_04.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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP and CSX both have a 3-gram enforced open index on authors, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index_DBLP on DBLP (authors:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_05.sqlpp
new file mode 100644
index 0000000..002c5d5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-edit-distance_05.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using edit distance of their authors.
+ * DBLP has a 3-gram enforced open index on authors, and we *do not* expect the join to be transformed
+ * into an indexed nested-loop join, because CSX does not declare an enforced open index on field authors.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ title : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (authors:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-edit-distance_01.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "3";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((a.authors ~= b.authors) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..79012f3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_01.sqlpp
@@ -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 : Fuzzy joins two datasets, open DBLP and closed CSX, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.title,3,false) ~= test."gram-tokens"(b.title,3,false)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp
new file mode 100644
index 0000000..dadeb9d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_02.sqlpp
@@ -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 : Fuzzy joins two datasets, closed DBLP and open CSX, based on ~= using Jaccard their titles' 3-gram tokens.
+ * CSX has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_02.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.title,3,false) ~= test."gram-tokens"(b.title,3,false)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp
new file mode 100644
index 0000000..a3d8a69
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_03.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on ~= using Jaccard of its titles' 3-gram tokens.
+ * DBLP has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_03.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."gram-tokens"(a.title,3,false) ~= test."gram-tokens"(b.title,3,false)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_04.sqlpp
new file mode 100644
index 0000000..441e382
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-fuzzyeq-jaccard_04.sqlpp
@@ -0,0 +1,66 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' 3-gram tokens.
+ * DBLP and CSX both have a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index_DBLP on DBLP (title:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."gram-tokens"(a.title,3,false) ~= test."gram-tokens"(b.title,3,false)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..67e43d5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_01.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy joins two datasets, open DBLP and closed CSX, based on the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..dfd8194
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_02.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy joins two datasets, closed DBLP and open CSX, based the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * CSX has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..526fb3a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_03.sqlpp
@@ -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 : Fuzzy self joins an open dataset DBLP, based on the similarity-jaccard-check function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..2b06b29
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_04.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based the similarity-jaccard-check function of their titles' 3-gram tokens.
+ * DBLP and CSX both have a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index_DBLP on DBLP (title:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_inline_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_inline_03.sqlpp
new file mode 100644
index 0000000..a085a61
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard-check_inline_03.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard-check function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard-check_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc[1]}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard-check"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false),0.500000f)
+where (jacc[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_01.sqlpp
new file mode 100644
index 0000000..1c681ec
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_01.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_02.sqlpp
new file mode 100644
index 0000000..e4db9e6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_02.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based the similarity-jaccard function of their titles' 3-gram tokens.
+ * CSX has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_03.sqlpp
new file mode 100644
index 0000000..d57a38b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_03.sqlpp
@@ -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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_04.sqlpp
new file mode 100644
index 0000000..59f521e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_04.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based the similarity-jaccard function of their titles' 3-gram tokens.
+ * DBLP and CSX both have a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index ngram_index_DBLP on DBLP (title:string) type ngram (3) enforced;
+
+create index ngram_index_CSX on CSX (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_inline_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_inline_03.sqlpp
new file mode 100644
index 0000000..7cc9969
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/ngram-jaccard_inline_03.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' 3-gram tokens.
+ * DBLP has a 3-gram enforced open index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+set "import-private-functions" "true";
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title:string) type ngram (3) enforced;
+
+write output to nc1:"rttest/inverted-index-join_ngram-jaccard_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."gram-tokens"(a.title,3,false),test."gram-tokens"(b.title,3,false))
+where ((jacc >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp
new file mode 100644
index 0000000..4e35c80
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_01.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.title) ~= test."word-tokens"(b.title)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_02.sqlpp
new file mode 100644
index 0000000..a33e9d0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_02.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * CSX has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on CSX (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_02.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.title) ~= test."word-tokens"(b.title)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp
new file mode 100644
index 0000000..9f09553
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_03.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on ~= using Jaccard of its titles' word tokens.
+ * DBLP has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_03.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."word-tokens"(a.title) ~= test."word-tokens"(b.title)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_04.sqlpp
new file mode 100644
index 0000000..6816885
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-fuzzyeq-jaccard_04.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 : Fuzzy joins two datasets, DBLP and CSX, based on ~= using Jaccard of their titles' word tokens.
+ * DBLP and CSX both have an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index_DBLP on DBLP (title:string) type keyword enforced;
+
+create index keyword_index_CSX on CSX (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-fuzzyeq-jaccard_01.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.5f";
+
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."word-tokens"(a.title) ~= test."word-tokens"(b.title)) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp
new file mode 100644
index 0000000..5620d1a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check-after-btree-access.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : Fuzzy self joins a dataset, TweetMessages, based on the similarity-jaccard-check function of its text-messages' word tokens.
+ * TweetMessages has a keyword index on text-message and btree index on the primary key tweetid, and we expect the join to be
+ * transformed into btree and inverted indexed nested-loop joins. We test whether the join condition can be transformed into
+ * multiple indexed nested loop joins of various type of indexes.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgTextIx on TweetMessages ("message-text":string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check-after-btree-access.adm"
+select element {'t1':t1.tweetid,'t2':t2.tweetid,'sim':sim[1]}
+from TweetMessages as t1,
+ TweetMessages as t2
+with sim as test."similarity-jaccard-check"(test."word-tokens"(t1."message-text"),test."word-tokens"(t2."message-text"),0.600000f)
+where (sim[0] and (t1.tweetid < test.int64('20')) and (t2.tweetid != t1.tweetid))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..b4df5ac
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_01.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * DBLP has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..54576d9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_02.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * CSX has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on CSX (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..e6b89bf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_03.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard-check function of its titles' word tokens.
+ * DBLP has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..c911894
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_04.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard-check function of their titles' word tokens.
+ * DBLP and CSX both have an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index_DBLP on DBLP (title:string) type keyword enforced;
+
+create index keyword_index_CSX on CSX (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where (test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_inline_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_inline_03.sqlpp
new file mode 100644
index 0000000..ad51a9d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard-check_inline_03.sqlpp
@@ -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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard-check function of its titles' word tokens.
+ * DBLP has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard-check_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc[1]}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard-check"(test."word-tokens"(a.title),test."word-tokens"(b.title),0.500000f)
+where (jacc[0] and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_01.sqlpp
new file mode 100644
index 0000000..c59290b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_01.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+ closed {
+ id : int32,
+ csxid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_02.sqlpp
new file mode 100644
index 0000000..21a1b75
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_02.sqlpp
@@ -0,0 +1,59 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * CSX has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index on CSX (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_02.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_03.sqlpp
new file mode 100644
index 0000000..597d60c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_03.sqlpp
@@ -0,0 +1,48 @@
+/*
+ * 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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' word tokens.
+ * DBLP has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_03.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ DBLP as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_04.sqlpp
new file mode 100644
index 0000000..8bfbcc1
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_04.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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 : Fuzzy joins two datasets, DBLP and CSX, based on the similarity-jaccard function of their titles' word tokens.
+ * DBLP and CSX both have an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create type test.CSXType as
+{
+ id : int32,
+ csxid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create table CSX(CSXType) primary key id;
+
+create index keyword_index_DBLP on DBLP (title:string) type keyword enforced;
+
+create index keyword_index_CSX on CSX (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_01.adm"
+select element {'arec':a,'brec':b}
+from DBLP as a,
+ CSX as b
+where ((test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title)) >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_inline_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_inline_03.sqlpp
new file mode 100644
index 0000000..c1cd43d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/inverted-index-join/word-jaccard_inline_03.sqlpp
@@ -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 : Fuzzy self joins a dataset, DBLP, based on the similarity-jaccard function of its titles' word tokens.
+ * DBLP has an enforced open keyword index on title, and we expect the join to be transformed into an indexed nested-loop join.
+ * We test the inlining of variables that enable the select to be pushed into the join for subsequent optimization with an index.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title:string) type keyword enforced;
+
+write output to nc1:"rttest/inverted-index-join_word-jaccard_04.adm"
+select element {'arec':a,'brec':b,'jacc':jacc}
+from DBLP as a,
+ DBLP as b
+with jacc as test."similarity-jaccard"(test."word-tokens"(a.title),test."word-tokens"(b.title))
+where ((jacc >= 0.500000f) and (a.id < b.id))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
new file mode 100644
index 0000000..0df4508
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location":point) type rtree enforced;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgTextIx on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_01.adm"
+select element {'tweetid1':t1.tweetid,'loc1':t1."sender-location",'nearby-message':(
+ select element {'tweetid2':t2.tweetid,'loc2':t2."sender-location"}
+ from TweetMessages as t2
+ where test."spatial-intersect"(t2."sender-location",n)
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1."sender-location",0.5)
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
new file mode 100644
index 0000000..09a8e9d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
@@ -0,0 +1,74 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location":point) type rtree enforced;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgTextIx on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_02.adm"
+select element {'tweetid1':t1.tweetid,'loc1':t1."sender-location",'nearby-message':(
+ select element {'tweetid2':t2.tweetid,'loc2':t2."sender-location"}
+ from TweetMessages as t2
+ where (test."spatial-intersect"(t2."sender-location",n) and (t1.tweetid != t2.tweetid))
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1."sender-location",0.5)
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_01.sqlpp
new file mode 100644
index 0000000..853cbcc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_01.sqlpp
@@ -0,0 +1,66 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * The dataset 'MyData1' has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordOpen as
+{
+ id : int32,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create table MyData1(MyRecordOpen) primary key id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData1 (point:point) type rtree enforced;
+
+write output to nc1:"rttest/index-join_rtree-spatial-intersect-point.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_02.sqlpp
new file mode 100644
index 0000000..d6aaacb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_02.sqlpp
@@ -0,0 +1,66 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * The dataset 'MyData2' has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create type test.MyRecordOpen as
+{
+ id : int32,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create table MyData1(MyRecord) primary key id;
+
+create table MyData2(MyRecordOpen) primary key id;
+
+create index rtree_index on MyData2 (point:point) type rtree enforced;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_03.sqlpp
new file mode 100644
index 0000000..7a0ff8a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_03.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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 : Self-joins a dataset on the intersection of its point attribute.
+ * The dataset has an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+{
+ id : int32,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create table MyData(MyRecord) primary key id;
+
+create index rtree_index on MyData (point:point) type rtree enforced;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_03.adm"
+select element {'a':a,'b':b}
+from MyData as a,
+ MyData as b
+where test."spatial-intersect"(a.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_04.sqlpp
new file mode 100644
index 0000000..051e695
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_04.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * Both datasets 'MyData' and 'MyData2' have an enforced open RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+{
+ id : int32,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create table MyData1(MyRecord) primary key id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData1 (point:point) type rtree enforced;
+
+create index rtree_index2 on MyData2 (point:point) type rtree enforced;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_05.sqlpp
new file mode 100644
index 0000000..01015ac
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/open-index-enforced/rtree-index-join/spatial-intersect-point_05.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * Only dataset 'MyData1' has an enforced open RTree index, hence we
+ * *do not* expect the join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+{
+ id : int32,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create table MyData1(MyRecord) primary key id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData1 (point:point) type rtree enforced;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orderby-desc-using-gby.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orderby-desc-using-gby.sqlpp
new file mode 100644
index 0000000..34a82ef
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orderby-desc-using-gby.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+drop database "gby-using-orderby-desc" if exists;
+create database "gby-using-orderby-desc";
+
+use "gby-using-orderby-desc";
+
+
+create type "gby-using-orderby-desc".AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type "gby-using-orderby-desc".CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Customers(CustomerType) primary key cid on group1;
+
+write output to nc1:"rttest/gby-using-orderby-desc.adm"
+select element {'name':name,'age':age}
+from Customers as c
+group by c.name as name
+order by name desc,age
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-aggreg.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-aggreg.sqlpp
new file mode 100644
index 0000000..4835a59
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-aggreg.sqlpp
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+drop database "orders-aggreg" if exists;
+create database "orders-aggreg";
+
+use "orders-aggreg";
+
+
+create type "orders-aggreg".OrderType as
+ closed {
+ oid : int32,
+ cid : int32,
+ orderstatus : string,
+ orderpriority : string,
+ clerk : string,
+ total : float
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key oid on group1;
+
+write output to nc1:"/tmp/orders-aggreg.adm"
+select element {'cid':cid,'ordpercust':"orders-aggreg".count(o),'totalcust':"orders-aggreg".sum((
+ select element i.total
+ from o as i
+ )),'avgcust':"orders-aggreg".avg((
+ select element i.total
+ from o as i
+ ))}
+from Orders as o
+group by o.cid as cid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-composite-index-search.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-composite-index-search.sqlpp
new file mode 100644
index 0000000..c8efddd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-composite-index-search.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+drop database index_search if exists;
+create database index_search;
+
+use index_search;
+
+
+create type index_search.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create table Orders(OrderType) primary key o_orderkey;
+
+create index idx_Custkey_Orderstatus on Orders (o_custkey,o_orderstatus) type btree;
+
+write output to nc1:"/tmp/index_search.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey,'o_orderstatus':o.o_orderstatus}
+from Orders as o
+where ((o.o_custkey = 40) and (o.o_orderstatus = 'P'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive-open_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive-open_01.sqlpp
new file mode 100644
index 0000000..faba2ef
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive-open_01.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+{
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+load table Orders using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/tpch0.001/orders.tbl"),("format"="delimited-text"),("delimiter"="|")) pre-sorted;
+
+create index idx_Orders_Custkey on Orders (o_custkey) type btree;
+
+write output to nc1:"/tmp/index_search-conjunctive.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey}
+from Orders as o
+where ((o.o_custkey = 40) and (o.o_totalprice > 150000.0))
+order by o.o_orderkey
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive-open_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive-open_02.sqlpp
new file mode 100644
index 0000000..90c5a52
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive-open_02.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+{
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+load table Orders using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/tpch0.001/orders.tbl"),("format"="delimited-text"),("delimiter"="|")) pre-sorted;
+
+create index idx_Orders_Custkey on Orders (o_custkey) type btree;
+
+write output to nc1:"/tmp/index_search-conjunctive.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey,'o_totalprice':o.o_totalprice}
+from Orders as o
+where ((o.o_custkey = 40) and (o.o_totalprice > 150000.0))
+order by o.o_orderkey
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive_01.sqlpp
new file mode 100644
index 0000000..0b06385
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive_01.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+load table Orders using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/tpch0.001/orders.tbl"),("format"="delimited-text"),("delimiter"="|")) pre-sorted;
+
+create index idx_Orders_Custkey on Orders (o_custkey) type btree;
+
+write output to nc1:"/tmp/index_search-conjunctive.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey}
+from Orders as o
+where ((o.o_custkey = 40) and (o.o_totalprice > 150000.0))
+order by o.o_orderkey
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive_02.sqlpp
new file mode 100644
index 0000000..62c3577
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-conjunctive_02.sqlpp
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+load table Orders using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/tpch0.001/orders.tbl"),("format"="delimited-text"),("delimiter"="|")) pre-sorted;
+
+create index idx_Orders_Custkey on Orders (o_custkey) type btree;
+
+write output to nc1:"/tmp/index_search-conjunctive.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey,'o_totalprice':o.o_totalprice}
+from Orders as o
+where ((o.o_custkey = 40) and (o.o_totalprice > 150000.0))
+order by o.o_orderkey
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-open.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-open.sqlpp
new file mode 100644
index 0000000..eae957f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search-open.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+drop database index_search if exists;
+create database index_search;
+
+use index_search;
+
+
+create type index_search.OrderType as
+{
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+create index idx_Orders_Custkey on Orders (o_custkey) type btree;
+
+write output to nc1:"/tmp/index_search.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey}
+from Orders as o
+where (o.o_custkey = 40)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search.sqlpp
new file mode 100644
index 0000000..a70f0ba
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/orders-index-search.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+drop database index_search if exists;
+create database index_search;
+
+use index_search;
+
+
+create type index_search.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+create index idx_Orders_Custkey on Orders (o_custkey) type btree;
+
+write output to nc1:"/tmp/index_search.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey}
+from Orders as o
+where (o.o_custkey = 40)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/prim-idx-search-open.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/prim-idx-search-open.sqlpp
new file mode 100644
index 0000000..8653b01
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/prim-idx-search-open.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+drop database prim_index_search if exists;
+create database prim_index_search;
+
+use prim_index_search;
+
+
+create type prim_index_search.OrderType as
+{
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+write output to nc1:"/tmp/prim_index_search.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey}
+from Orders as o
+where (o.o_orderkey = 34)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/prim-idx-search.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/prim-idx-search.sqlpp
new file mode 100644
index 0000000..1bf0d81
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/prim-idx-search.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+drop database prim_index_search if exists;
+create database prim_index_search;
+
+use prim_index_search;
+
+
+create type prim_index_search.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+write output to nc1:"/tmp/prim_index_search.adm"
+select element {'o_orderkey':o.o_orderkey,'o_custkey':o.o_custkey}
+from Orders as o
+where (o.o_orderkey = 34)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/pull_select_above_eq_join.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/pull_select_above_eq_join.sqlpp
new file mode 100644
index 0000000..2820784
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/pull_select_above_eq_join.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+drop database "pull-select-above-eq-join" if exists;
+create database "pull-select-above-eq-join";
+
+use "pull-select-above-eq-join";
+
+
+create type "pull-select-above-eq-join".UserType as
+{
+ uid : int32,
+ name : string,
+ city : string,
+ lottery_numbers : {{int32}}
+}
+
+create type "pull-select-above-eq-join".VisitorType as
+{
+ vid : int32,
+ name : string,
+ city : string,
+ lottery_numbers : {{int32}}
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Users(UserType) primary key uid on group1;
+
+create table Visitors(VisitorType) primary key vid on group1;
+
+write output to nc1:"/tmp/pull-select-above-eq-join.adm"
+select element {'uid':user.uid,'vid':visitor.vid}
+from Users as user,
+ Visitors as visitor
+where ((user.name = visitor.name) and (user.city != visitor.city))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/push-project-through-group.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/push-project-through-group.sqlpp
new file mode 100644
index 0000000..7516412
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/push-project-through-group.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+drop database fuzzyjoin_080 if exists;
+create database fuzzyjoin_080;
+
+use fuzzyjoin_080;
+
+
+create type fuzzyjoin_080.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table DBLP(DBLPType) primary key id on group1;
+
+write output to nc1:"rttest/fuzzyjoin_080.adm"
+select element {'id':paperDBLP.id,'matches':matches}
+from DBLP as paperDBLP
+with matches as (
+ select element paper.title
+ from DBLP as paper
+ where (paper.authors = paperDBLP.authors)
+ )
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/push_limit.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/push_limit.sqlpp
new file mode 100644
index 0000000..72b382f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/push_limit.sqlpp
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+write output to nc1:"/tmp/push_limit.adm"
+select element {'price':o.o_totalprice,'date':o.o_orderdate}
+from Orders as o
+where (o.o_totalprice > 100)
+order by o.o_orderkey
+limit 10 offset 5
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q01_pricing_summary_report_nt.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q01_pricing_summary_report_nt.sqlpp
new file mode 100644
index 0000000..d31815a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q01_pricing_summary_report_nt.sqlpp
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+load table LineItem using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/tpch0.001/lineitem.tbl"),("format"="delimited-text"),("delimiter"="|")) pre-sorted;
+
+write output to nc1:"rttest/tpch_q1_pricing_summary_report_nt.adm"
+select element {'l_returnflag':l_returnflag,'l_linestatus':l_linestatus,'sum_qty':tpch.sum((
+ select element i.l_quantity
+ from l as i
+ )),'sum_base_price':tpch.sum((
+ select element i.l_extendedprice
+ from l as i
+ )),'sum_disc_price':tpch.sum((
+ select element (i.l_extendedprice * (1 - i.l_discount))
+ from l as i
+ )),'sum_charge':tpch.sum((
+ select element (i.l_extendedprice * (1 - i.l_discount) * (1 + i.l_tax))
+ from l as i
+ )),'ave_qty':tpch.avg((
+ select element i.l_quantity
+ from l as i
+ )),'ave_price':tpch.avg((
+ select element i.l_extendedprice
+ from l as i
+ )),'ave_disc':tpch.avg((
+ select element i.l_discount
+ from l as i
+ )),'count_order':tpch.count(l)}
+from LineItem as l
+where (l.l_shipdate <= '1998-09-02')
+/* +hash */
+group by l.l_returnflag as l_returnflag,l.l_linestatus as l_linestatus
+order by l_returnflag,l_linestatus
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q03_shipping_priority.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q03_shipping_priority.sqlpp
new file mode 100644
index 0000000..6cc87f8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q03_shipping_priority.sqlpp
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+drop database q3_shipping_priority if exists;
+create database q3_shipping_priority;
+
+use q3_shipping_priority;
+
+
+create type q3_shipping_priority.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type q3_shipping_priority.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type q3_shipping_priority.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems(LineItemType) primary key l_orderkey,l_linenumber on group1;
+
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+create table Customers(CustomerType) primary key c_custkey on group1;
+
+write output to nc1:"/tmp/q3_shipping_priority.adm"
+select element {'l_orderkey':l_orderkey,'revenue':revenue,'o_orderdate':o_orderdate,'o_shippriority':o_shippriority}
+from Customers as c,
+ Orders as o,
+ LineItems as l
+where (((c.c_mktsegment = 'BUILDING') and (c.c_custkey = o.o_custkey)) and ((l.l_orderkey = o.o_orderkey) and (o.o_orderdate < '1995-03-15') and (l.l_shipdate > '1995-03-15')))
+/* +hash */
+group by l.l_orderkey as l_orderkey,o.o_orderdate as o_orderdate,o.o_shippriority as o_shippriority
+with revenue as q3_shipping_priority.sum((
+ select element (i.l_extendedprice * (1 - i.l_discount))
+ from l as i
+ ))
+order by revenue desc,o_orderdate
+limit 10
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q05_local_supplier_volume.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q05_local_supplier_volume.sqlpp
new file mode 100644
index 0000000..a18e7a9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q05_local_supplier_volume.sqlpp
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+
+drop database q5_local_supplier if exists;
+create database q5_local_supplier;
+
+use q5_local_supplier;
+
+
+create type q5_local_supplier.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type q5_local_supplier.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type q5_local_supplier.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create type q5_local_supplier.SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type q5_local_supplier.NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type q5_local_supplier.RegionType as
+ closed {
+ r_regionkey : int32,
+ r_name : string,
+ r_comment : string
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems(LineItemType) primary key l_orderkey,l_linenumber on group1;
+
+create table Orders(OrderType) primary key o_orderkey on group1;
+
+create table Customers(CustomerType) primary key c_custkey on group1;
+
+create table Suppliers(SupplierType) primary key s_suppkey on group1;
+
+create table Nations(NationType) primary key n_nationkey on group1;
+
+create table Regions(RegionType) primary key r_regionkey on group1;
+
+write output to nc1:"/tmp/q5_local_supplier.adm"
+select element {'n_name':n_name,'revenue':revenue}
+from Customers as c,
+ (
+ select element {'n_name':l1.n_name,'l_extendedprice':l1.l_extendedprice,'l_discount':l1.l_discount,'s_nationkey':l1.s_nationkey,'o_custkey':o.o_custkey}
+ from Orders as o,
+ (
+ select element {'n_name':s1.n_name,'l_extendedprice':l.l_extendedprice,'l_discount':l.l_discount,'l_orderkey':l.l_orderkey,'s_nationkey':s1.s_nationkey}
+ from LineItems as l,
+ (
+ select element {'n_name':n1.n_name,'s_suppkey':s.s_suppkey,'s_nationkey':s.s_nationkey}
+ from Suppliers as s,
+ (
+ select element {'n_name':n.n_name,'n_nationkey':n.n_nationkey}
+ from Nations as n,
+ Regions as r
+ where ((n.n_regionkey = r.r_regionkey) and (r.r_name = 'ASIA'))
+ ) as n1
+ where (s.s_nationkey = n1.n_nationkey)
+ ) as s1
+ where (l.l_suppkey = s1.s_suppkey)
+ ) as l1
+ where ((l1.l_orderkey = o.o_orderkey) and (o.o_orderdate >= '1994-01-01') and (o.o_orderdate < '1995-01-01'))
+) as o1
+where ((c.c_nationkey = o1.s_nationkey) and (c.c_custkey = o1.o_custkey))
+/* +hash */
+group by o1.n_name as n_name
+with revenue as q5_local_supplier.sum((
+ select element (i.l_extendedprice * (1 - i.l_discount))
+ from o1 as i
+ ))
+order by revenue desc
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q08_group_by.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q08_group_by.sqlpp
new file mode 100644
index 0000000..0c59c3c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q08_group_by.sqlpp
@@ -0,0 +1,153 @@
+/*
+ * 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.
+ */
+
+drop database q08_group_by if exists;
+create database q08_group_by;
+
+use q08_group_by;
+
+
+create type q08_group_by.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type q08_group_by.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type q08_group_by.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create type q08_group_by.SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type q08_group_by.NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type q08_group_by.RegionType as
+ closed {
+ r_regionkey : int32,
+ r_name : string,
+ r_comment : string
+}
+
+create type q08_group_by.PartType as
+ closed {
+ p_partkey : int32,
+ p_name : string,
+ p_mfgr : string,
+ p_brand : string,
+ p_type : string,
+ p_size : int32,
+ p_container : string,
+ p_retailprice : double,
+ p_comment : string
+}
+
+create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create table Orders(OrderType) primary key o_orderkey;
+
+create table Customer(CustomerType) primary key c_custkey;
+
+create table Supplier(SupplierType) primary key s_suppkey;
+
+create table Nation(NationType) primary key n_nationkey;
+
+create table Region(RegionType) primary key r_regionkey;
+
+create table Part(PartType) primary key p_partkey;
+
+select element {'o_orderdate':lnrcop.o_orderdate,'l_discount':lnrcop.l_discount,'l_extendedprice':lnrcop.l_extendedprice,'l_suppkey':lnrcop.l_suppkey,'s_nationkey':s.s_nationkey}
+from Supplier as s,
+ (
+ select element {'o_orderdate':lnrco.o_orderdate,'l_discount':lnrco.l_discount,'l_extendedprice':lnrco.l_extendedprice,'l_suppkey':lnrco.l_suppkey}
+ from (
+ select element {'o_orderdate':nrco.o_orderdate,'l_partkey':l.l_partkey,'l_discount':l.l_discount,'l_extendedprice':l.l_extendedprice,'l_suppkey':l.l_suppkey}
+ from LineItem as l,
+ (
+ select element {'o_orderdate':o.o_orderdate,'o_orderkey':o.o_orderkey}
+ from Orders as o,
+ (
+ select element {'c_custkey':c.c_custkey}
+ from Customer as c,
+ (
+ select element {'n_nationkey':n1.n_nationkey}
+ from Nation as n1,
+ Region as r1
+ where ((n1.n_regionkey = r1.r_regionkey) and (r1.r_name = 'AMERICA'))
+ ) as nr
+ where (c.c_nationkey = nr.n_nationkey)
+ ) as nrc
+ where (nrc.c_custkey = o.o_custkey)
+ ) as nrco
+ where ((l.l_orderkey = nrco.o_orderkey) and (nrco.o_orderdate >= '1995-01-01') and (nrco.o_orderdate <= '1996-12-31'))
+ ) as lnrco,
+ Part as p
+ where ((p.p_partkey = lnrco.l_partkey) and (p.p_type = 'ECONOMY ANODIZED STEEL'))
+) as lnrcop
+where (s.s_suppkey = lnrcop.l_suppkey)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q09_group_by.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q09_group_by.sqlpp
new file mode 100644
index 0000000..e0d1ac2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q09_group_by.sqlpp
@@ -0,0 +1,154 @@
+/*
+ * 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.
+ */
+
+drop database q09_group_by if exists;
+create database q09_group_by;
+
+use q09_group_by;
+
+
+create type q09_group_by.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : int32,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type q09_group_by.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type q09_group_by.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create type q09_group_by.SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type q09_group_by.NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type q09_group_by.RegionType as
+ closed {
+ r_regionkey : int32,
+ r_name : string,
+ r_comment : string
+}
+
+create type q09_group_by.PartType as
+ closed {
+ p_partkey : int32,
+ p_name : string,
+ p_mfgr : string,
+ p_brand : string,
+ p_type : string,
+ p_size : int32,
+ p_container : string,
+ p_retailprice : double,
+ p_comment : string
+}
+
+create type q09_group_by.PartSuppType as
+ closed {
+ ps_partkey : int32,
+ ps_suppkey : int32,
+ ps_availqty : int32,
+ ps_supplycost : double,
+ ps_comment : string
+}
+
+create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+create table Orders(OrderType) primary key o_orderkey;
+
+create table Supplier(SupplierType) primary key s_suppkey;
+
+create table Region(RegionType) primary key r_regionkey;
+
+create table Nation(NationType) primary key n_nationkey;
+
+create table Part(PartType) primary key p_partkey;
+
+create table Partsupp(PartSuppType) primary key ps_partkey,ps_suppkey;
+
+create table Customer(CustomerType) primary key c_custkey;
+
+select element {'l_extendedprice':l2.l_extendedprice,'l_discount':l2.l_discount,'l_quantity':l2.l_quantity,'l_orderkey':l2.l_orderkey,'n_name':l2.n_name,'ps_supplycost':l2.ps_supplycost}
+from Part as p,
+ (
+ select element {'l_extendedprice':l1.l_extendedprice,'l_discount':l1.l_discount,'l_quantity':l1.l_quantity,'l_partkey':l1.l_partkey,'l_orderkey':l1.l_orderkey,'n_name':l1.n_name,'ps_supplycost':ps.ps_supplycost}
+ from Partsupp as ps,
+ (
+ select element {'l_suppkey':l.l_suppkey,'l_extendedprice':l.l_extendedprice,'l_discount':l.l_discount,'l_quantity':l.l_quantity,'l_partkey':l.l_partkey,'l_orderkey':l.l_orderkey,'n_name':s1.n_name}
+ from (
+ select element {'s_suppkey':s.s_suppkey,'n_name':n.n_name}
+ from Supplier as s,
+ Nation as n
+ where (n.n_nationkey = s.s_nationkey)
+ ) as s1,
+ LineItem as l
+ where (s1.s_suppkey = l.l_suppkey)
+ ) as l1
+ where ((ps.ps_suppkey = l1.l_suppkey) and (ps.ps_partkey = l1.l_partkey))
+) as l2
+where (q09_group_by.contains(p.p_name,'green') and (p.p_partkey = l2.l_partkey))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q1.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q1.sqlpp
new file mode 100644
index 0000000..cb0f2d9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q1.sqlpp
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+drop database events if exists;
+create database events;
+
+use events;
+
+
+create type events.AddressType as
+ closed {
+ street : string,
+ city : string,
+ zip : string,
+ latlong : point
+}
+
+create type events.UserType as
+{
+ name : string,
+ email : string,
+ interests : {{string}},
+ address : AddressType,
+ member_of : {{{
+ sig_name : string,
+ chapter_name : string,
+ member_since : date
+ }
+}}
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table User(UserType) primary key name on group1;
+
+write output to nc1:"/tmp/q1.adm"
+select element {'name':user.name}
+from User as user
+where some i in user.interests satisfies (i = 'movies')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q2.sqlpp
new file mode 100644
index 0000000..162dd74
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/q2.sqlpp
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+drop database events if exists;
+create database events;
+
+use events;
+
+
+create type events.AddressType as
+ closed {
+ street : string,
+ city : string,
+ zip : string
+}
+
+create type events.EventType as
+ closed {
+ name : string,
+ location : AddressType?,
+ organizers : {{{
+ name : string,
+ role : string
+ }
+}},
+ sponsoring_sigs : [{
+ sig_name : string,
+ chapter_name : string
+ }
+],
+ interest_keywords : {{string}},
+ price : double?,
+ start_time : datetime,
+ end_time : datetime
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Event(EventType) primary key name on group1;
+
+write output to nc1:"/tmp/q2.adm"
+select element {'sig_name':sig_name,'total_count':sig_sponsorship_count,'chapter_breakdown':by_chapter}
+from Event as event,
+ event.sponsoring_sigs as sponsor
+with es as {'event':event,'sponsor':sponsor}
+group by sponsor.sig_name as sig_name
+with sig_sponsorship_count as events.count(es),
+ by_chapter as (
+ select element {'chapter_name':chapter_name,'escount':events.count(e)}
+ from es as e
+ group by e.sponsor.chapter_name as chapter_name
+ )
+order by sig_sponsorship_count desc
+limit 5
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue550.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue550.sqlpp
new file mode 100644
index 0000000..33c7947
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue550.sqlpp
@@ -0,0 +1,33 @@
+/*
+ * 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 : This test case is to verify the fix for issue550
+ * https://code.google.com/p/asterixdb/issues/detail?id=550
+ * Expected Result : Success
+ * Date : 25th October 2014
+ */
+
+with sample as {{{'r':1,'uid':'1a2b','t':datetime('2000-01-01T01:00:00'),'event':'e1'},{'r':2,'uid':'1a2b','t':datetime('2000-01-01T01:01:00'),'event':'e2'},{'r':3,'uid':'3c4d','t':datetime('2000-01-01T01:02:00'),'event':'e1'},{'r':4,'uid':'3c4d','t':datetime('2000-01-01T01:03:00'),'event':'e3'},{'r':5,'uid':'1a2b','t':datetime('2000-01-01T01:04:00'),'event':'e1'},{'r':6,'uid':'1a2b','t':datetime('2000-01-01T01:05:00'),'event':'e4'}}}
+select element {'u':u,'recs':(
+ select element srec
+ from s as srec
+ )}
+from sample as s
+group by s.uid as u
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue562.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue562.sqlpp
new file mode 100644
index 0000000..5fb9440
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue562.sqlpp
@@ -0,0 +1,107 @@
+/*
+ * 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 : This test case is to verify the fix for issue562
+ * https://code.google.com/p/asterixdb/issues/detail?id=562
+ * Expected Res : SUCCESS
+ * Date : 15th Jan. 2015
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : int32,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type tpch.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create table Orders(OrderType) primary key o_orderkey;
+
+create table Customer(CustomerType) primary key c_custkey;
+
+declare function q22_customer_tmp() {
+(
+ select element {'c_acctbal':c.c_acctbal,'c_custkey':c.c_custkey,'cntrycode':phone_substr}
+ from Customer as c
+ with phone_substr as tpch.substring(c.c_phone,1,2)
+ where ((phone_substr = '13') or (phone_substr = '31') or (phone_substr = '23') or (phone_substr = '29') or (phone_substr = '30') or (phone_substr = '18') or (phone_substr = '17'))
+)
+};
+with avg as tpch.avg((
+ select element c.c_acctbal
+ from Customer as c
+ with phone_substr as tpch.substring(c.c_phone,1,2)
+ where ((c.c_acctbal > 0.0) and ((phone_substr = '13') or (phone_substr = '31') or (phone_substr = '23') or (phone_substr = '29') or (phone_substr = '30') or (phone_substr = '18') or (phone_substr = '17')))
+ ))
+select element {'cntrycode':cntrycode,'numcust':tpch.count(ct),'totacctbal':tpch.sum((
+ select element i.c_acctbal
+ from ct as i
+ ))}
+from tpch.q22_customer_tmp() as ct
+where (tpch.count((
+ select element o
+ from Orders as o
+ where (ct.c_custkey = o.o_custkey)
+)) = 0)
+group by ct.cntrycode as cntrycode
+order by cntrycode
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue601.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue601.sqlpp
new file mode 100644
index 0000000..5f60eb0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue601.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : This test case is to verify the fix for issue601
+ * https://code.google.com/p/asterixdb/issues/detail?id=601
+ * Expected Res : SUCCESS
+ * Date : 10th Oct 2014
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+select element {'l_linenumber':l_linenumber,'count_order':tpch.count(l)}
+from LineItem as l
+group by l.l_linenumber as l_linenumber
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue697.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue697.sqlpp
new file mode 100644
index 0000000..5d23126
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue697.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : This test case is to verify the fix for issue697
+ * https://code.google.com/p/asterixdb/issues/detail?id=697
+ * Expected Result : Success
+ * Date : 16th Nov. 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TestType as
+ closed {
+ key1 : int32,
+ "value" : int32
+}
+
+create table test(TestType) primary key key1;
+
+select element {'gid':aid,'avg':test.avg((
+ select element j."value"
+ from i as j
+ where test.not(test."is-null"(j."value"))
+ ))}
+from test as i
+group by i.key1 as aid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue785.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue785.sqlpp
new file mode 100644
index 0000000..aecafb4
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue785.sqlpp
@@ -0,0 +1,121 @@
+/*
+ * 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 : This test case is to verify the fix for issue785
+ * https://code.google.com/p/asterixdb/issues/detail?id=785
+ * Expected Res : SUCCESS
+ * Date : 2nd Oct. 2014
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.OrderType as
+ closed {
+ o_orderkey : int32,
+ o_custkey : int32,
+ o_orderstatus : string,
+ o_totalprice : double,
+ o_orderdate : string,
+ o_orderpriority : string,
+ o_clerk : string,
+ o_shippriority : int32,
+ o_comment : string
+}
+
+create type tpch.CustomerType as
+ closed {
+ c_custkey : int32,
+ c_name : string,
+ c_address : string,
+ c_nationkey : int32,
+ c_phone : string,
+ c_acctbal : double,
+ c_mktsegment : string,
+ c_comment : string
+}
+
+create type tpch.SupplierType as
+ closed {
+ s_suppkey : int32,
+ s_name : string,
+ s_address : string,
+ s_nationkey : int32,
+ s_phone : string,
+ s_acctbal : double,
+ s_comment : string
+}
+
+create type tpch.NationType as
+ closed {
+ n_nationkey : int32,
+ n_name : string,
+ n_regionkey : int32,
+ n_comment : string
+}
+
+create type tpch.RegionType as
+ closed {
+ r_regionkey : int32,
+ r_name : string,
+ r_comment : string
+}
+
+create table Orders(OrderType) primary key o_orderkey;
+
+create table Supplier(SupplierType) primary key s_suppkey;
+
+create table Region(RegionType) primary key r_regionkey;
+
+create table Nation(NationType) primary key n_nationkey;
+
+create table Customer(CustomerType) primary key c_custkey;
+
+create table SelectedNation(NationType) primary key n_nationkey;
+
+with t as (
+ select element {'n_nationkey':nation.n_nationkey,'n_name':nation.n_name}
+ from Nation as nation,
+ SelectedNation as sn
+ where (nation.n_nationkey = sn.n_nationkey)
+ ),
+ X as (
+ select element {'nation_key':nation_key,'order_date':orderdate,'sum_price':sum}
+ from t as n,
+ Customer as customer,
+ Orders as orders
+ where ((orders.o_custkey = customer.c_custkey) and (customer.c_nationkey = n.n_nationkey))
+ group by orders.o_orderdate as orderdate,n.n_nationkey as nation_key
+ with sum as tpch.sum((
+ select element o.o_totalprice
+ from orders as o
+ ))
+ )
+select element {'nation_key':nation_key,'sum_price':(
+ select element {'orderdate':y.order_date,'sum_price':y.sum_price}
+ from x as y
+ order by y.sum_price desc
+ limit 3
+ )}
+from X as x
+group by x.nation_key as nation_key
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue810-2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue810-2.sqlpp
new file mode 100644
index 0000000..b2e4121
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue810-2.sqlpp
@@ -0,0 +1,78 @@
+/*
+ * 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 : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Res : SUCCESS
+ * Date : 24th Nov. 2014
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+select element {'l_returnflag':l_returnflag,'l_linestatus':l_linestatus,'count_cheaps':tpch.count(cheaps),'avg_expensive_discounts':tpch.avg(expensives),'sum_disc_prices':tpch.sum(disc_prices),'total_charges':tpch.sum(charges)}
+from LineItem as l
+where (l.l_shipdate <= '1998-09-02')
+/* +hash */
+group by l.l_returnflag as l_returnflag,l.l_linestatus as l_linestatus
+with expensives as (
+ select element i.l_discount
+ from l as i
+ where (i.l_discount <= 0.05)
+ ),
+ cheaps as (
+ select element i
+ from l as i
+ where (i.l_discount > 0.05)
+ ),
+ charges as (
+ select element (i.l_extendedprice * (1 - i.l_discount) * (1 + i.l_tax))
+ from l as i
+ ),
+ disc_prices as (
+ select element (i.l_extendedprice * (1 - i.l_discount))
+ from l as i
+ )
+order by l_returnflag,l_linestatus
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue810.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue810.sqlpp
new file mode 100644
index 0000000..da41e12
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue810.sqlpp
@@ -0,0 +1,70 @@
+/*
+ * 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 : This test case is to verify the fix for issue810
+ * https://code.google.com/p/asterixdb/issues/detail?id=810
+ * Expected Result : Success
+ * Date : 16th Nov. 2014
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+select element {'l_returnflag':l_returnflag,'l_linestatus':l_linestatus,'count_cheaps':tpch.count(cheap),'count_expensives':tpch.count(expensive)}
+from LineItem as l
+where (l.l_shipdate <= '1998-09-02')
+/* +hash */
+group by l.l_returnflag as l_returnflag,l.l_linestatus as l_linestatus
+with cheap as (
+ select element m
+ from l as m
+ where (m.l_discount > 0.05)
+ ),
+ expensive as (
+ select element a
+ from l as a
+ where (a.l_discount <= 0.05)
+ )
+order by l_returnflag,l_linestatus
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue827-2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue827-2.sqlpp
new file mode 100644
index 0000000..c5ad063
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query-issue827-2.sqlpp
@@ -0,0 +1,80 @@
+/*
+ * 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 : This test case is to verify the fix for issue827
+ * https://code.google.com/p/asterixdb/issues/detail?id=827
+ * Expected Res : SUCCESS
+ * Date : 3rd Dec. 2014
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create table LineItem(LineItemType) primary key l_orderkey,l_linenumber;
+
+{'sum_qty_partial':tpch.sum((
+ select element i.l_quantity
+ from LineItem as i
+ where (i.l_shipdate <= '1998-09-02')
+)),'sum_base_price':tpch.sum((
+ select element i.l_extendedprice
+ from LineItem as i
+)),'sum_disc_price':tpch.sum((
+ select element (i.l_extendedprice * (1 - i.l_discount))
+ from LineItem as i
+)),'sum_charge':tpch.sum((
+ select element (i.l_extendedprice * (1 - i.l_discount) * (1 + i.l_tax))
+ from LineItem as i
+)),'ave_qty':tpch.avg((
+ select element i.l_quantity
+ from LineItem as i
+ where (i.l_shipdate <= '1998-09-02')
+)),'ave_price':tpch.avg((
+ select element i.l_extendedprice
+ from LineItem as i
+)),'ave_disc':tpch.avg((
+ select element i.l_discount
+ from LineItem as i
+)),'count_order':tpch.count((
+ select element l
+ from LineItem as l
+))};
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849-2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849-2.sqlpp
new file mode 100644
index 0000000..1d0fda5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849-2.sqlpp
@@ -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 : This test case is to verify the fix for issue827
+ * https://code.google.com/p/asterixdb/issues/detail?id=849
+ * Expected Res : SUCCESS
+ * Date : 2nd Feb. 2015
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.sType as
+ closed {
+ b : int32
+}
+
+create table s(sType) primary key b;
+
+insert into s
+select element {'b':1};
+insert into s
+select element {'b':3};
+select element {'x':x,'y':y}
+from s as x,
+ (
+ select element z.c
+ from {{{'a':1,'c':1},{'a':2,'c':2},{'a':1,'c':null}}} as z
+ where (x.b = z.a)
+) as y
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849.sqlpp
new file mode 100644
index 0000000..a843dad
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849.sqlpp
@@ -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 : This test case is to verify the fix for issue827
+ * https://code.google.com/p/asterixdb/issues/detail?id=849
+ * Expected Res : SUCCESS
+ * Date : 2nd Feb. 2015
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.sType as
+ closed {
+ b : int32
+}
+
+create table s(sType) primary key b;
+
+insert into s
+select element {'b':1};
+insert into s
+select element {'b':3};
+select element {'x':x,'y':y}
+from {{{'a':1},{'a':2}}} as x,
+ (
+ select element z.b
+ from s as z
+ where (x.a = z.b)
+) as y
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric-desc.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric-desc.sqlpp
new file mode 100644
index 0000000..8cdc933
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric-desc.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : The hint is to use the range connector
+ * : This test is intended to verify that the range connector is used instead of single node merge.
+ * Expected Result : Success
+ * Date : 1th May 2015
+ */
+
+drop database TinySocial if exists;
+create database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.TwitterUserType as
+{
+ "screen-name" : string,
+ lang : string,
+ friends_count : int64,
+ statuses_count : int64,
+ name : string,
+ followers_count : int64
+}
+
+create table TwitterUsers(TwitterUserType) primary key "screen-name";
+
+select element user
+from TwitterUsers as user
+order by user.friends_count desc
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric.sqlpp
new file mode 100644
index 0000000..682d26b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : The hint is to use the range connector
+ * : This test is intended to verify that the range connector is used instead of single node merge.
+ * Expected Result : Success
+ * Date : 1th May 2015
+ */
+
+drop database TinySocial if exists;
+create database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.TwitterUserType as
+{
+ "screen-name" : string,
+ lang : string,
+ friends_count : int64,
+ statuses_count : int64,
+ name : string,
+ followers_count : int64
+}
+
+create table TwitterUsers(TwitterUserType) primary key "screen-name";
+
+select element user
+from TwitterUsers as user
+order by user.friends_count
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string-desc.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string-desc.sqlpp
new file mode 100644
index 0000000..cd1c196
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string-desc.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : The hint is to use the range connector
+ * : This test is intended to verify that the range connector is used instead of single node merge.
+ * Expected Result : Success
+ * Date : 1th May 2015
+ */
+
+drop database TinySocial if exists;
+create database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.TwitterUserType as
+{
+ "screen-name" : string,
+ lang : string,
+ friends_count : int64,
+ statuses_count : int64,
+ name : string,
+ followers_count : int64
+}
+
+create table TwitterUsers(TwitterUserType) primary key "screen-name";
+
+select element user
+from TwitterUsers as user
+order by user."screen-name" desc
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string.sqlpp
new file mode 100644
index 0000000..a400bd3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : The hint is to use the range connector
+ * : This test is intended to verify that the range connector is used instead of single node merge.
+ * Expected Result : Success
+ * Date : 1th May 2015
+ */
+
+drop database TinySocial if exists;
+create database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.TwitterUserType as
+{
+ "screen-name" : string,
+ lang : string,
+ friends_count : int64,
+ statuses_count : int64,
+ name : string,
+ followers_count : int64
+}
+
+create table TwitterUsers(TwitterUserType) primary key "screen-name";
+
+select element user
+from TwitterUsers as user
+order by user."screen-name"
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/record_access.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/record_access.sqlpp
new file mode 100644
index 0000000..84602a2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/record_access.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"/tmp/rec_access.adm"
+{'a':2}.a;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/issue730.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/issue730.sqlpp
new file mode 100644
index 0000000..a9a137d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/issue730.sqlpp
@@ -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 : Test that left-outer-join may use an available rtree index in index subtree.
+ * Issue : 730
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+{
+ screen_name : string,
+ lang : string,
+ friends_count : int32,
+ statuses_count : int32,
+ name : string,
+ followers_count : int32
+}
+
+create type test.TweetMessageType as
+{
+ tweetid : int64,
+ user : TwitterUserType,
+ sender_location : point?,
+ send_time : datetime,
+ referred_topics : {{string}},
+ message_text : string
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages (sender_location) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_issue730.adm"
+select element {'message':t1.tweetid,'nearby-message':(
+ select element t2.tweetid
+ from TweetMessages as t2
+ where test."spatial-intersect"(t2.sender_location,n)
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1.sender_location,5.0)
+where ((t1.send_time >= test.datetime('2011-06-18T14:10:17')) and (t1.send_time < test.datetime('2011-06-18T15:10:17')))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
new file mode 100644
index 0000000..f936fea
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
@@ -0,0 +1,75 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgTextIx on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_01.adm"
+select element {'tweetid1':t1.tweetid,'loc1':t1."sender-location",'nearby-message':(
+ select element {'tweetid2':t2.tweetid,'loc2':t2."sender-location"}
+ from TweetMessages as t2
+ where test."spatial-intersect"(t2."sender-location",n)
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1."sender-location",0.5)
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
new file mode 100644
index 0000000..160816f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
@@ -0,0 +1,75 @@
+/*
+ * 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 : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue : 730, 741
+ * Expected Res : Success
+ * Date : 8th May 2014
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+ "screen-name" : string,
+ lang : string,
+ "friends-count" : int32,
+ "statuses-count" : int32,
+ name : string,
+ "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+ tweetid : int64,
+ user : TwitterUserType,
+ "sender-location" : point,
+ "send-time" : datetime,
+ "referred-topics" : {{string}},
+ "message-text" : string,
+ countA : int32,
+ countB : int32
+}
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index twmSndLocIx on TweetMessages ("sender-location") type rtree;
+
+create index msgCountAIx on TweetMessages (countA) type btree;
+
+create index msgCountBIx on TweetMessages (countB) type btree;
+
+create index msgTextIx on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_02.adm"
+select element {'tweetid1':t1.tweetid,'loc1':t1."sender-location",'nearby-message':(
+ select element {'tweetid2':t2.tweetid,'loc2':t2."sender-location"}
+ from TweetMessages as t2
+ where (test."spatial-intersect"(t2."sender-location",n) and (t1.tweetid != t2.tweetid))
+ order by t2.tweetid
+ )}
+from TweetMessages as t1
+with n as test."create-circle"(t1."sender-location",0.5)
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/query-issue838.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/query-issue838.sqlpp
new file mode 100644
index 0000000..3a2364d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/query-issue838.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * 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 : This test case is to verify the fix for issue838
+ * https://code.google.com/p/asterixdb/issues/detail?id=838
+ * Expected Res : SUCCESS
+ * Date : 18 Dec. 2014
+ */
+
+drop database twitter if exists;
+create database twitter;
+
+use twitter;
+
+
+create type twitter.TweetMessageType as
+ closed {
+ tweetid : int64,
+ "sender-location" : point,
+ text : string
+}
+
+create type twitter.TweetHistorySubscription as
+{
+ "subscription-id" : int32,
+ location : point
+}
+
+create table TweetHistorySubscriptions(TweetHistorySubscription) primary key "subscription-id";
+
+create index testa on TweetHistorySubscriptions (location) type rtree;
+
+create table TweetMessages(TweetMessageType) primary key tweetid;
+
+create index locationIdx on TweetMessages ("sender-location") type rtree;
+
+write output to nc1:"rttest/query-issue838.adm"
+select element {'subscription-id':sub."subscription-id",'changeSet':1,'execution-time':twitter."current-datetime"(),'message-text':text}
+from TweetHistorySubscriptions as sub,
+ (
+ select element tweet
+ from TweetMessages as tweet
+ with circle as twitter."create-circle"(location,30.0)
+ where twitter."spatial-intersect"(tweet."sender-location",circle)
+) as text
+with location as sub.location
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_01.sqlpp
new file mode 100644
index 0000000..9319186
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_01.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * The dataset 'MyData1' has an RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create table MyData1(MyRecord) primary key id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData1 (point) type rtree;
+
+write output to nc1:"rttest/index-join_rtree-spatial-intersect-point.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_02.sqlpp
new file mode 100644
index 0000000..94d47b6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_02.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * 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 : Joins two datasets on the intersection of their point attributes.
+ * The dataset 'MyData2' has an RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create table MyData1(MyRecord) primary key id;
+
+create table MyData2(MyRecord) primary key id;
+
+create index rtree_index on MyData2 (point) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from MyData1 as a,
+ MyData2 as b
+where test."spatial-intersect"(a.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_03.sqlpp
new file mode 100644
index 0000000..b57ad65
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_03.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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 : Self-joins a dataset on the intersection of its point attribute.
+ * The dataset has an RTree index, and we expect the
+ * join to be transformed into an indexed nested-loop join.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle
+}
+
+create table MyData(MyRecord) primary key id;
+
+create index rtree_index on MyData (point) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_03.adm"
+select element {'a':a,'b':b}
+from MyData as a,
+ MyData as b
+where test."spatial-intersect"(a.point,b.point)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index-open.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index-open.sqlpp
new file mode 100644
index 0000000..c7b5d36
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index-open.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+{
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle,
+ circle : circle
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table MyData(MyRecord) primary key id on group1;
+
+load table MyData using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/spatial/spatialData.json"),("format"="adm")) pre-sorted;
+
+create index rtree_index_point on MyData (point) type rtree;
+
+write output to nc1:"rttest/index_rtree-secondary-index-open.adm"
+select element {'id':o.id}
+from MyData as o
+where test."spatial-intersect"(o.point,test."create-polygon"([4.0,1.0,4.0,4.0,12.0,4.0,12.0,1.0]))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index.sqlpp
new file mode 100644
index 0000000..0fae89e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle,
+ circle : circle
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table MyData(MyRecord) primary key id on group1;
+
+load table MyData using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/spatial/spatialData.json"),("format"="adm")) pre-sorted;
+
+create index rtree_index_point on MyData (point) type rtree;
+
+write output to nc1:"rttest/index_rtree-secondary-index.adm"
+select element {'id':o.id}
+from MyData as o
+where test."spatial-intersect"(o.point,test."create-polygon"([4.0,1.0,4.0,4.0,12.0,4.0,12.0,1.0]))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-all.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-all.sqlpp
new file mode 100644
index 0000000..1a277ce
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-all.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type tpch.LineIDType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems_q1(LineItemType) primary key l_orderkey on group1;
+
+create table LineID(LineIDType) primary key l_orderkey on group1;
+
+delete l from LineItems_q1
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-rtree-secondary-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-rtree-secondary-index.sqlpp
new file mode 100644
index 0000000..6266272
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-rtree-secondary-index.sqlpp
@@ -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.
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle,
+ circle : circle
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table MyData(MyRecord) primary key id on group1;
+
+load table MyData using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/spatial/spatialData.json"),("format"="adm")) pre-sorted;
+
+create index rtree_index_point on MyData (point) type rtree;
+
+delete m from MyData
+ where (m.id > 5);
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete.sqlpp
new file mode 100644
index 0000000..0185c84
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type tpch.LineIDType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems_q1(LineItemType) primary key l_orderkey on group1;
+
+create table LineID(LineIDType) primary key l_orderkey on group1;
+
+delete l from LineItems_q1
+ where (l.l_shipdate <= '1998-09-02');
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert-secondary-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert-secondary-index.sqlpp
new file mode 100644
index 0000000..020baf7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert-secondary-index.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type tpch.LineIDType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems_q1(LineItemType) primary key l_orderkey on group1;
+
+create table LineID(LineIDType) primary key l_orderkey on group1;
+
+create index idx_LineID_partkey on LineID (l_partkey) type btree;
+
+create index idx_LineID_suppkey on LineID (l_suppkey) type btree;
+
+insert into LineID
+select element {'l_orderkey':l.l_orderkey,'l_partkey':l.l_partkey,'l_suppkey':l.l_partkey}
+from LineItems_q1 as l
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert.sqlpp
new file mode 100644
index 0000000..2de1b31
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert.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.
+ */
+
+drop database tpch if exists;
+create database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32,
+ l_linenumber : int32,
+ l_quantity : double,
+ l_extendedprice : double,
+ l_discount : double,
+ l_tax : double,
+ l_returnflag : string,
+ l_linestatus : string,
+ l_shipdate : string,
+ l_commitdate : string,
+ l_receiptdate : string,
+ l_shipinstruct : string,
+ l_shipmode : string,
+ l_comment : string
+}
+
+create type tpch.LineIDType as
+ closed {
+ l_orderkey : int32,
+ l_partkey : int32,
+ l_suppkey : int32
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table LineItems_q1(LineItemType) primary key l_orderkey on group1;
+
+create table LineID(LineIDType) primary key l_orderkey on group1;
+
+insert into LineID
+select element {'l_orderkey':l.l_orderkey,'l_partkey':l.l_partkey,'l_suppkey':l.l_partkey}
+from LineItems_q1 as l
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..3e7ef15
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_01.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should happen because of a "<=" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_01.adm"
+select element ed
+from DBLP as o
+with ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (ed <= 2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_02.sqlpp
new file mode 100644
index 0000000..98506e9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_02.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should happen because of a reverse "<=" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_02.adm"
+select element ed
+from DBLP as o
+with ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (2 >= ed)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_03.sqlpp
new file mode 100644
index 0000000..c5a255a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should happen because of a "<" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_03.adm"
+select element ed
+from DBLP as o
+with ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (ed < 3)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_04.sqlpp
new file mode 100644
index 0000000..3ad6b13
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_04.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should happen because of a reverse "<" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_04.adm"
+select element ed
+from DBLP as o
+with ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (3 > ed)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_05.sqlpp
new file mode 100644
index 0000000..ba5ed31
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_05.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should *not* happen because of a ">=" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_05.adm"
+select element ed
+from DBLP as o
+with ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (ed >= 2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_06.sqlpp
new file mode 100644
index 0000000..2bc08b3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_06.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should *not* happen because of a reverse ">=" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_06.adm"
+select element ed
+from DBLP as o
+with ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (2 <= ed)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_07.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_07.sqlpp
new file mode 100644
index 0000000..7aac82d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_07.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should *not* happen because of a ">" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_07.adm"
+select element ed
+from DBLP as o
+with ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (ed > 2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_08.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_08.sqlpp
new file mode 100644
index 0000000..2758920
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_08.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should *not* happen because of a reverse ">" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_08.adm"
+select element ed
+from DBLP as o
+with ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (2 < ed)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..12eb414
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_01.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Replacement should happen because of a "<=" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_01.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.authors,'Michael J. Carey') <= 2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_02.sqlpp
new file mode 100644
index 0000000..41893bb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_02.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Replacement should happen because of a reverse "<=" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_02.adm"
+select element o
+from DBLP as o
+where (2 >= test."edit-distance"(o.authors,'Michael J. Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_03.sqlpp
new file mode 100644
index 0000000..10a0ef3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_03.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Replacement should happen because of a "<" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_03.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.authors,'Michael J. Carey') < 3)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_04.sqlpp
new file mode 100644
index 0000000..d9230b2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_04.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Replacement should happen because of a reverse "<" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_04.adm"
+select element o
+from DBLP as o
+where (3 > test."edit-distance"(o.authors,'Michael J. Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_05.sqlpp
new file mode 100644
index 0000000..90b3655
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_05.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Replacement should *not* happen because of a ">=" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_05.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.authors,'Michael J. Carey') >= 2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_06.sqlpp
new file mode 100644
index 0000000..2340250
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_06.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Replacement should *not* happen because of a reverse ">=" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_06.adm"
+select element o
+from DBLP as o
+where (2 <= test."edit-distance"(o.authors,'Michael J. Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_07.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_07.sqlpp
new file mode 100644
index 0000000..8b9f5c6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_07.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Replacement should *not* happen because of a ">" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_07.adm"
+select element o
+from DBLP as o
+where (test."edit-distance"(o.authors,'Michael J. Carey') > 2)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_08.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_08.sqlpp
new file mode 100644
index 0000000..713c2b7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_08.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold
+ * into edit-distance-check if possible.
+ * Replacement should *not* happen because of a reverse ">" condition on the edit distance.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_08.adm"
+select element o
+from DBLP as o
+where (2 < test."edit-distance"(o.authors,'Michael J. Carey'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-edit-distance-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-edit-distance-check.sqlpp
new file mode 100644
index 0000000..6d350d2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-edit-distance-check.sqlpp
@@ -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 : Tests that the FuzzyEqRule rewrites ~= using edit distance
+ * into edit-distance-check.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_fuzzyeq-to-edit-distance-check.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "1";
+
+select element o
+from DBLP as o
+where (o.authors ~= 'Michael J. Carey')
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-jaccard-check.sqlpp
new file mode 100644
index 0000000..266c2fd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-jaccard-check.sqlpp
@@ -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 : Tests that the FuzzyEqRule rewrites ~= using Jaccard
+ * into edit-distance-check.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_fuzzyeq-to-jaccard-check.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element paper
+from DBLP as paper
+where (test."word-tokens"(paper.title) ~= test."word-tokens"('Transactions for Cooperative Environments'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..3ea9c76
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_01.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should happen because of a ">=" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-let-to-jaccard-check_01.adm"
+select element jacc
+from DBLP as paper
+with jacc as test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (jacc >= 0.800000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..380d68d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_02.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should happen because of a reverse ">=" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-let-to-jaccard-check_01.adm"
+select element jacc
+from DBLP as paper
+with jacc as test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (0.800000f <= jacc)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..93827db
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should happen because of a ">" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-let-to-jaccard-check_01.adm"
+select element jacc
+from DBLP as paper
+with jacc as test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (jacc > 0.800000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..0c63957
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_04.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should happen because of a reverse ">" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-let-to-jaccard-check_01.adm"
+select element jacc
+from DBLP as paper
+with jacc as test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (0.800000f < jacc)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_05.sqlpp
new file mode 100644
index 0000000..8cec9c9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_05.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should *not* happen because of a "<=" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-let-to-jaccard-check_01.adm"
+select element jacc
+from DBLP as paper
+with jacc as test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (jacc <= 0.800000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_06.sqlpp
new file mode 100644
index 0000000..85f9d4a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_06.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should *not* happen because of a reverse "<=" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-let-to-jaccard-check_01.adm"
+select element jacc
+from DBLP as paper
+with jacc as test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (0.800000f >= jacc)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_07.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_07.sqlpp
new file mode 100644
index 0000000..c95130d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_07.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should *not* happen because of a "<" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-let-to-jaccard-check_01.adm"
+select element jacc
+from DBLP as paper
+with jacc as test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (jacc < 0.800000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_08.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_08.sqlpp
new file mode 100644
index 0000000..67d1f31
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-let-to-jaccard-check_08.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Tests that the optimizer drills through the let clause.
+ * Replacement should *not* happen because of a reverse "<" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-let-to-jaccard-check_01.adm"
+select element jacc
+from DBLP as paper
+with jacc as test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (0.800000f > jacc)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_01.sqlpp
new file mode 100644
index 0000000..65e63ba
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_01.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Replacement should happen because of a ">=" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-to-jaccard-check_01.adm"
+select element paper
+from DBLP as paper
+where (test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments')) >= 0.800000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_02.sqlpp
new file mode 100644
index 0000000..f40628fe
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_02.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Replacement should happen because of a reverse ">=" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-to-jaccard-check_02.adm"
+select element paper
+from DBLP as paper
+where (0.800000f <= test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments')))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_03.sqlpp
new file mode 100644
index 0000000..c9f9bcf
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_03.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Replacement should happen because of a ">" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-to-jaccard-check_02.adm"
+select element paper
+from DBLP as paper
+where (test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments')) > 0.800000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_04.sqlpp
new file mode 100644
index 0000000..e5e283b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_04.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Replacement should happen because of a reverse ">" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-to-jaccard-check_03.adm"
+select element paper
+from DBLP as paper
+where (0.800000f < test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments')))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_05.sqlpp
new file mode 100644
index 0000000..36d67d8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_05.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Replacement should *not* happen because of a "<=" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-to-jaccard-check_05.adm"
+select element paper
+from DBLP as paper
+where (test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments')) <= 0.800000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_06.sqlpp
new file mode 100644
index 0000000..19418f0
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_06.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Replacement should *not* happen because of a reverse "<=" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-to-jaccard-check_06.adm"
+select element paper
+from DBLP as paper
+where (0.800000f >= test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments')))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_07.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_07.sqlpp
new file mode 100644
index 0000000..0be0017
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_07.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Replacement should *not* happen because of a "<" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-to-jaccard-check_07.adm"
+select element paper
+from DBLP as paper
+where (test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments')) < 0.800000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_08.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_08.sqlpp
new file mode 100644
index 0000000..63eb76d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/jaccard-to-jaccard-check_08.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * 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 : Tests that the SimilarityCheckRule rewrites the similarity-jaccard function with a threshold
+ * into similarity-jaccard-check-check if possible.
+ * Replacement should *not* happen because of a reverse "<" condition on the similarity.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_jaccard-to-jaccard-check_08.adm"
+select element paper
+from DBLP as paper
+where (0.800000f > test."similarity-jaccard"(test."word-tokens"(paper.title),test."word-tokens"('Transactions for Cooperative Environments')))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/dont-skip-primary-index-search-in-delete.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/dont-skip-primary-index-search-in-delete.sqlpp
new file mode 100644
index 0000000..b7f8751
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/dont-skip-primary-index-search-in-delete.sqlpp
@@ -0,0 +1,56 @@
+/*
+ * 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 : The hint to skip secondary indexes don't apply to the primary index
+ * : This test is intended to verify that the primary index is still used instead of a scan
+ * Expected Result : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+delete c from Customers
+ where (c.cid /*+ skip-index */ < 10);
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/dont-skip-primary-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/dont-skip-primary-index.sqlpp
new file mode 100644
index 0000000..5917ad8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/dont-skip-primary-index.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * 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 : The hint to skip secondary indexes don't apply to the primary index
+ * : This test is intended to verify that the primary index is still used instead of a scan
+ * Expected Result : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-primary-16.adm"
+create type test.TestType as
+{
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key fname,lname;
+
+select element emp
+from testdst as emp
+where ((emp.fname /*+ skip-index */ >= 'Craig') and (emp.lname /*+ skip-index */ >= 'Kevin') and (emp.fname /*+ skip-index */ <= 'Mary') and (emp.lname /*+ skip-index */ <= 'Tomes'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-ngram-index-search-in-delete.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-ngram-index-search-in-delete.sqlpp
new file mode 100644
index 0000000..9111891
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-ngram-index-search-in-delete.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+delete o from DBLP
+ where /*+ skip-index */ test.contains(o.title,'Multimedia');
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-ngram-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-ngram-index.sqlpp
new file mode 100644
index 0000000..a79796d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-ngram-index.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index ngram_index on DBLP (title) type ngram (3);
+
+write output to nc1:"rttest/inverted-index-basic_ngram-contains.adm"
+select element o
+from DBLP as o
+where /*+ skip-index */ test.contains(o.title,'Multimedia')
+order by o.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-rtree-index-search-in-delete.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-rtree-index-search-in-delete.sqlpp
new file mode 100644
index 0000000..a91f5b8
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-rtree-index-search-in-delete.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle,
+ circle : circle
+}
+
+create table MyData(MyRecord) primary key id;
+
+create index rtree_index_point on MyData (point) type rtree;
+
+delete m from MyData
+ where /*+ skip-index */ test."spatial-intersect"(m.point,test."create-polygon"([0.0,1.0,0.0,4.0,12.0,4.0,12.0,1.0]));
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-rtree-secondary-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-rtree-secondary-index.sqlpp
new file mode 100644
index 0000000..da48031
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-rtree-secondary-index.sqlpp
@@ -0,0 +1,58 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+ id : int32,
+ point : point,
+ kwds : string,
+ line1 : line,
+ line2 : line,
+ poly1 : polygon,
+ poly2 : polygon,
+ rec : rectangle,
+ circle : circle
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table MyData(MyRecord) primary key id on group1;
+
+load table MyData using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/spatial/spatialData.json"),("format"="adm")) pre-sorted;
+
+create index rtree_index_point on MyData (point) type rtree;
+
+write output to nc1:"rttest/index_rtree-secondary-index.adm"
+select element {'id':o.id}
+from MyData as o
+where /*+ skip-index */ test."spatial-intersect"(o.point,test."create-polygon"([4.0,1.0,4.0,4.0,12.0,4.0,12.0,1.0]))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index-2.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index-2.sqlpp
new file mode 100644
index 0000000..0c0170b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index-2.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-57.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname /*+ skip-index */ >= 'Max') and (emp.fname <= 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index-search-in-delete.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index-search-in-delete.sqlpp
new file mode 100644
index 0000000..b54fc9c
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index-search-in-delete.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type test.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32,
+ address : AddressType?,
+ interests : {{string}},
+ children : [{
+ name : string,
+ age : int32?
+ }
+]
+}
+
+create table Customers(CustomerType) primary key cid;
+
+create index age_index on Customers (age) type btree;
+
+delete c from Customers
+ where (c.age /*+ skip-index */ < 20);
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index.sqlpp
new file mode 100644
index 0000000..c7c6505
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-secondary-btree-index.sqlpp
@@ -0,0 +1,46 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/btree-index_btree-secondary-57.adm"
+create type test.TestType as
+{
+ id : int32,
+ fname : string,
+ lname : string
+}
+
+create table testdst(TestType) primary key id;
+
+create index sec_Idx on testdst (fname) type btree;
+
+select element emp
+from testdst as emp
+where ((emp.fname /*+ skip-index */ >= 'Max') and (emp.fname /*+ skip-index */ <= 'Roger'))
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-word-index-search-in-delete.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-word-index-search-in-delete.sqlpp
new file mode 100644
index 0000000..36a9716
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-word-index-search-in-delete.sqlpp
@@ -0,0 +1,45 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+delete o from DBLP
+ where ( /*+ skip-index */ test."similarity-jaccard"(test."word-tokens"(o.title),test."word-tokens"('Transactions for Cooperative Environments')) >= 0.500000f);
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-word-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-word-index.sqlpp
new file mode 100644
index 0000000..8b957ed
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/skip-index/skip-word-index.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * 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 : Notice the query hint to avoid using any secondary index to evaluate the predicate in the where clause
+ * Expected Res : Success
+ * Date : 21th December 2013
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+create index keyword_index on DBLP (title) type keyword;
+
+write output to nc1:"rttest/inverted-index-basic_word-jaccard.adm"
+select element o
+from DBLP as o
+with jacc as /*+ skip-index */ test."similarity-jaccard"(test."word-tokens"(o.title),test."word-tokens"('Transactions for Cooperative Environments'))
+where (jacc >= 0.500000f)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/sort-cust.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/sort-cust.sqlpp
new file mode 100644
index 0000000..cad7ac5
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/sort-cust.sqlpp
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+drop database custlimit if exists;
+create database custlimit;
+
+use custlimit;
+
+
+create type custlimit.AddressType as
+ closed {
+ number : int32,
+ street : string,
+ city : string
+}
+
+create type custlimit.CustomerType as
+ closed {
+ cid : int32,
+ name : string,
+ age : int32?,
+ address : AddressType?,
+ lastorder : {
+ oid : int32,
+ total : float
+ }
+
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table Customers(CustomerType) primary key cid on group1;
+
+write output to nc1:"/tmp/custlimit.adm"
+select element {'custname':c.name,'custage':c.age}
+from Customers as c
+order by c.age
+limit 10
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/split-materialization-above-join.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/split-materialization-above-join.sqlpp
new file mode 100644
index 0000000..07ccedc
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/split-materialization-above-join.sqlpp
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+drop database fuzzyjoin if exists;
+create database fuzzyjoin;
+
+use fuzzyjoin;
+
+
+create type fuzzyjoin.DBLPType as
+{
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create table DBLP(DBLPType) primary key id;
+
+set "import-private-functions" "true";
+
+select element {'left':paperLeft,'right':paperRight,'sim':ridpair.sim}
+from DBLP as paperLeft,
+ DBLP as paperRight,
+ (
+ select element {'idLeft':idLeft,'idRight':idRight,'sim':sim[0]}
+ from DBLP as paperLeft,
+ fuzzyjoin."subset-collection"(tokensLeft,0,fuzzyjoin."prefix-len-jaccard"(lenLeft,0.500000f)) as prefixTokenLeft,
+ DBLP as paperRight,
+ fuzzyjoin."subset-collection"(tokensRight,0,fuzzyjoin."prefix-len-jaccard"(lenRight,0.500000f)) as prefixTokenRight
+ with lenLeft as fuzzyjoin.len(fuzzyjoin."counthashed-word-tokens"(paperLeft.title)),
+ tokensLeft as (
+ select element i
+ from fuzzyjoin."counthashed-word-tokens"(paperLeft.title) as tokenUnranked,
+ (
+ select element tokenGroupped
+ from DBLP as paper,
+ fuzzyjoin."counthashed-word-tokens"(paper.title) as token
+ group by token as tokenGroupped
+ order by fuzzyjoin.count(paper),tokenGroupped
+ ) as tokenRanked at i
+ where (tokenUnranked = tokenRanked)
+ order by i
+ ),
+ lenRight as fuzzyjoin.len(fuzzyjoin."counthashed-word-tokens"(paperRight.title)),
+ tokensRight as (
+ select element i
+ from fuzzyjoin."counthashed-word-tokens"(paperRight.title) as tokenUnranked,
+ (
+ select element tokenGroupped
+ from DBLP as paper,
+ fuzzyjoin."counthashed-word-tokens"(paper.title) as token
+ group by token as tokenGroupped
+ order by fuzzyjoin.count(paper),tokenGroupped
+ ) as tokenRanked at i
+ where (tokenUnranked = tokenRanked)
+ order by i
+ ),
+ sim as fuzzyjoin."similarity-jaccard-prefix"(lenLeft,tokensLeft,lenRight,tokensRight,prefixTokenLeft,0.500000f)
+ where ((prefixTokenLeft = prefixTokenRight) and ((sim >= 0.500000f) and (paperLeft.id < paperRight.id)))
+ group by paperLeft.id as idLeft,paperRight.id as idRight
+) as ridpair
+where ((ridpair.idLeft = paperLeft.id) and (ridpair.idRight = paperRight.id))
+order by paperLeft.id,paperRight.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/split-materialization.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/split-materialization.sqlpp
new file mode 100644
index 0000000..9f9d609
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/split-materialization.sqlpp
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+drop database TinySocial if exists;
+create database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.EmploymentType as
+{
+ "organization-name" : string,
+ "start-date" : date,
+ "end-date" : date?
+}
+
+create type TinySocial.FacebookUserType as
+ closed {
+ id : int32,
+ alias : string,
+ name : string,
+ "user-since" : datetime,
+ "friend-ids" : {{int32}},
+ employment : [EmploymentType]
+}
+
+create table FacebookUsers(FacebookUserType) primary key id;
+
+with lonelyusers as (
+ select element d
+ from FacebookUsers as d
+ where (TinySocial.count(d."friend-ids") < 2)
+ ),
+ lonelyusers2 as (
+ select element d
+ from FacebookUsers as d
+ where (TinySocial.count(d."friend-ids") < 2)
+ )
+select element {'user1':{'id':l1.id,'name':l1.name},'user2':{'id':l2.id,'name':l2.name}}
+from lonelyusers as l1,
+ lonelyusers2 as l2
+where (l1.id < l2.id)
+order by l1.id,l2.id
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest-to-join_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest-to-join_01.sqlpp
new file mode 100644
index 0000000..8f3b759
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest-to-join_01.sqlpp
@@ -0,0 +1,35 @@
+/*
+ * 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 : Tests that non-datascan unnests are rewritten into joins.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/unnest-to-join_01.adm"
+select element y
+from [1,2,3,4,5,6] as x,
+ [4,5,6,7,8,9] as y
+where (x = y)
+;
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest-to-join_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest-to-join_02.sqlpp
new file mode 100644
index 0000000..5b025be
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest-to-join_02.sqlpp
@@ -0,0 +1,32 @@
+/*
+ * 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 : Tests that non-datascan unnests in a subplan are rewritten into joins.
+ * Success : Yes
+ */
+
+drop database test if exists;
+create database test;
+
+use test;
+
+
+write output to nc1:"rttest/unnest-to-join_02.adm"
+select element some x in [1,2,3,4,5,6],
+y in [4,5,6,7,8,9] satisfies (x = y);
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest_list_in_subplan.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest_list_in_subplan.sqlpp
new file mode 100644
index 0000000..fa22c8f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/unnest_list_in_subplan.sqlpp
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+drop database fuzzyjoin if exists;
+create database fuzzyjoin;
+
+use fuzzyjoin;
+
+
+create type fuzzyjoin.DBLPType as
+ closed {
+ id : int32,
+ dblpid : string,
+ title : string,
+ authors : string,
+ misc : string
+}
+
+create type fuzzyjoin.TOKENSRANKEDADMType as
+ closed {
+ token : int32,
+ rank : int32
+}
+
+create nodegroup group1 if not exists on
+ nc1,
+ nc2
+;
+create table DBLP(DBLPType) primary key id on group1;
+
+create table TOKENSRANKEDADM(TOKENSRANKEDADMType) primary key rank on group1;
+
+write output to nc1:"rttest/unnest_list_in_subplan.adm"
+select element {'id':idDBLP,'tokens':tokensDBLP}
+from DBLP as paperDBLP
+with idDBLP as paperDBLP.id,
+ tokensUnrankedDBLP as fuzzyjoin."counthashed-word-tokens"(paperDBLP.title),
+ tokensDBLP as (
+ select element tokenRanked.rank
+ from tokensUnrankedDBLP as tokenUnranked,
+ TOKENSRANKEDADM as tokenRanked
+ where (tokenUnranked = tokenRanked.token)
+ order by tokenRanked.rank
+ )
+;