>From Shahrzad Shirazi <[email protected]>:

Shahrzad Shirazi has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21089?usp=email )


Change subject: WIP:Fixing the index issue
......................................................................

WIP:Fixing the index issue

Change-Id: Iafb6e6ade19d0d669323a9a4488d8bfbbf160f85
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
A 
asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index-selection/hints-skip-index/hints-skip-index-14.sqlpp
A 
asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index-selection/hints-skip-index/hints-skip-index-15.sqlpp
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-14.plan
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-15.plan
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-14.plan
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-15.plan
M asterixdb/asterix-app/src/test/resources/runtimets/only_sqlpp.xml
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.00.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.01.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.02.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.03.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.01.plan
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.02.plan
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.03.plan
M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
16 files changed, 456 insertions(+), 2 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/89/21089/1

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
index 73e9be4..a2af649 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
@@ -387,7 +387,7 @@
             }
             List<List<String>> keyFieldNames = findKeyFieldNames(index);
             List<IAType> keyFieldTypes = findKeyTypes(index);
-
+            List<List<String>> typeMismatchedKeyFields = new ArrayList<>();
             boolean allUsed = true;
             int lastFieldMatched = -1;
             matchedExpressions.clear();
@@ -495,12 +495,19 @@

                     // Check if any field name in the optFuncExpr matches.
                     if (typeMatch && optFuncExpr.findFieldName(keyField) != -1
-                            && 
optFuncExpr.getOperatorSubTree(exprAndVarIdx.second).hasDataSourceScan()) {
+                            && 
optFuncExpr.getOperatorSubTree(exprAndVarIdx.second).hasDataSourceScan()
+                            && !typeMismatchedKeyFields.contains(keyField)) {
                         foundKeyField = true;
                         matchedExpressions.add(exprAndVarIdx.first);
                         hasIndexPreferences =
                                 hasIndexPreferences || 
accessMethod.getSecondaryIndexAnnotation(optFuncExpr) != null;
                     }
+                    if (!typeMatch && optFuncExpr.findFieldName(keyField) != -1
+                            && 
optFuncExpr.getOperatorSubTree(exprAndVarIdx.second).hasDataSourceScan()) {
+                        typeMismatchedKeyFields.add(keyField);
+                        foundKeyField = false; // reset
+                        matchedExpressions.clear();
+                    }
                 }
                 if (foundKeyField) {
                     numMatchedKeys++;
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index-selection/hints-skip-index/hints-skip-index-14.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index-selection/hints-skip-index/hints-skip-index-14.sqlpp
new file mode 100644
index 0000000..c1e2584
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index-selection/hints-skip-index/hints-skip-index-14.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  dataverse test if exists;
+create  dataverse test;
+SET `rewrite_or_as_join` "false";
+
+use test;
+
+create type tenkType as closed {
+  unique1         : integer,
+  unique2         : integer,
+  two             : integer,
+  four            : integer,
+  ten             : integer,
+  twenty          : integer,
+  hundred         : integer,
+  thousand        : integer,
+  twothousand     : integer,
+  fivethous       : integer,
+  tenthous        : integer,
+  odd100          : integer,
+  even100         : integer,
+  stringu1        : string,
+  stringu2        : string,
+  string4         : string
+};
+
+create dataset tenk(tenkType) primary key unique2;
+
+create index idx_1k on tenk(thousand);
+
+create index idx_1k_2k on tenk(thousand, twothousand);
+
+create index idx_2k on tenk(twothousand);
+
+/*
+ * skip-index hint with invalid parameter syntax -> the whole hint is ignored.
+ * explain plan -> idx_1k is used.
+ */
+
+select value unique1
+from tenk
+where thousand = 1 or thousand /* +skip-index(idx_1k) */ = 0
+order by unique1;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index-selection/hints-skip-index/hints-skip-index-15.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index-selection/hints-skip-index/hints-skip-index-15.sqlpp
new file mode 100644
index 0000000..9d58b26
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/btree-index-selection/hints-skip-index/hints-skip-index-15.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  dataverse test if exists;
+create  dataverse test;
+
+SET `rewrite_or_as_join` "false";
+
+use test;
+
+create type tenkType as closed {
+  unique1         : integer,
+  unique2         : integer,
+  two             : integer,
+  four            : integer,
+  ten             : integer,
+  twenty          : integer,
+  hundred         : integer,
+  thousand        : integer,
+  twothousand     : integer,
+  fivethous       : integer,
+  tenthous        : integer,
+  odd100          : integer,
+  even100         : integer,
+  stringu1        : string,
+  stringu2        : string,
+  string4         : string
+};
+
+create dataset tenk(tenkType) primary key unique2;
+
+create index idx_1k on tenk(thousand);
+
+create index idx_1k_2k on tenk(thousand, twothousand);
+
+create index idx_2k on tenk(twothousand);
+
+/*
+ * skip-index hint with invalid parameter syntax -> the whole hint is ignored.
+ * explain plan -> idx_1k is used.
+ */
+
+select value unique1
+from tenk
+where thousand = 1 or thousand /* +skip-index*/ = 0
+order by unique1;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-14.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-14.plan
new file mode 100644
index 0000000..eae5df1
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-14.plan
@@ -0,0 +1,36 @@
+distribute result [$$23]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
+    -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        select (or(eq($$21, 1), eq($$21, 0))) project: [$$23]
+        -- STREAM_SELECT  |PARTITIONED|
+          assign [$$23, $$21] <- [$$tenk.getField(0), $$tenk.getField(7)] 
project: [$$23, $$21]
+          -- ASSIGN  |PARTITIONED|
+            project ([$$tenk])
+            -- STREAM_PROJECT  |PARTITIONED|
+              exchange
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                unnest-map [$$22, $$tenk] <- index-search("tenk", 0, 
"Default", "test", "tenk", false, false, 1, $$28, 1, $$28, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$28)
+                    -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                      exchange
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$28])
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            unnest-map [$$26, $$27, $$28] <- 
index-search("idx_1k_2k", 0, "Default", "test", "tenk", false, false, 1, $$24, 
1, $$24, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                unnest $$24 <- scan-collection(array: [ 1, 0 ])
+                                -- UNNEST  |PARTITIONED|
+                                  empty-tuple-source
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-15.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-15.plan
new file mode 100644
index 0000000..b8feb1b
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-15.plan
@@ -0,0 +1,22 @@
+distribute result [$$23]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
+    -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        select (or(eq($$21, 1), eq($$21, 0))) project: [$$23]
+        -- STREAM_SELECT  |PARTITIONED|
+          assign [$$23, $$21] <- [$$tenk.getField(0), $$tenk.getField(7)] 
project: [$$23, $$21]
+          -- ASSIGN  |PARTITIONED|
+            project ([$$tenk])
+            -- STREAM_PROJECT  |PARTITIONED|
+              exchange
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                data-scan []<-[$$22, $$tenk] <- test.tenk
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
+                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-14.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-14.plan
new file mode 100644
index 0000000..eae5df1
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-14.plan
@@ -0,0 +1,36 @@
+distribute result [$$23]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
+    -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        select (or(eq($$21, 1), eq($$21, 0))) project: [$$23]
+        -- STREAM_SELECT  |PARTITIONED|
+          assign [$$23, $$21] <- [$$tenk.getField(0), $$tenk.getField(7)] 
project: [$$23, $$21]
+          -- ASSIGN  |PARTITIONED|
+            project ([$$tenk])
+            -- STREAM_PROJECT  |PARTITIONED|
+              exchange
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                unnest-map [$$22, $$tenk] <- index-search("tenk", 0, 
"Default", "test", "tenk", false, false, 1, $$28, 1, $$28, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$28)
+                    -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                      exchange
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$28])
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            unnest-map [$$26, $$27, $$28] <- 
index-search("idx_1k_2k", 0, "Default", "test", "tenk", false, false, 1, $$24, 
1, $$24, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                unnest $$24 <- scan-collection(array: [ 1, 0 ])
+                                -- UNNEST  |PARTITIONED|
+                                  empty-tuple-source
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-15.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-15.plan
new file mode 100644
index 0000000..b8feb1b
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-15.plan
@@ -0,0 +1,22 @@
+distribute result [$$23]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
+  -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
+    -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
+      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        select (or(eq($$21, 1), eq($$21, 0))) project: [$$23]
+        -- STREAM_SELECT  |PARTITIONED|
+          assign [$$23, $$21] <- [$$tenk.getField(0), $$tenk.getField(7)] 
project: [$$23, $$21]
+          -- ASSIGN  |PARTITIONED|
+            project ([$$tenk])
+            -- STREAM_PROJECT  |PARTITIONED|
+              exchange
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                data-scan []<-[$$22, $$tenk] <- test.tenk
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
+                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/only_sqlpp.xml 
b/asterixdb/asterix-app/src/test/resources/runtimets/only_sqlpp.xml
index 334dd52..2522dbe 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/only_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/only_sqlpp.xml
@@ -19,5 +19,10 @@
  !-->
 <test-suite xmlns="urn:xml.testframework.asterix.apache.org" 
ResultOffsetPath="results" QueryOffsetPath="queries_sqlpp" 
QueryFileExtension=".sqlpp">
   <test-group name="failed">
+    <test-case FilePath="index-selection">
+      <compilation-unit name="miss-match-type-predicate">
+        <output-dir compare="Text">miss-match-type-predicate</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
 </test-suite>
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.00.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.00.ddl.sqlpp
new file mode 100644
index 0000000..b534e9d
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.00.ddl.sqlpp
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT 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  dataverse test if exists;
+create  dataverse test;
+SET `rewrite_or_as_join` "true";
+use test;
+
+create type tenkType as  {
+  unique1         : integer,
+  unique2         : integer
+};
+
+create dataset tenk(tenkType) primary key unique2;
+
+create index idx_1k on tenk(thousand:int);
+
+create index idx_1k_2k on tenk(thousand:int, twothousand:string);
+
+create index idx_2k on tenk(twothousand);
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.01.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.01.query.sqlpp
new file mode 100644
index 0000000..7947853
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.01.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+explain select value unique1
+from tenk
+where thousand ="1" or thousand = 0;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.02.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.02.query.sqlpp
new file mode 100644
index 0000000..1956bbf
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.02.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+explain select value unique1
+from tenk
+where thousand <"1" and thousand > 0;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.03.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.03.query.sqlpp
new file mode 100644
index 0000000..04b92c1
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/index-selection/miss-match-type-predicate/miss-match-type-predicate.03.query.sqlpp
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+explain select value unique1
+from tenk
+where thousand <1 and twothousand="33" ;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.01.plan
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.01.plan
new file mode 100644
index 0000000..45078ce
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.01.plan
@@ -0,0 +1,18 @@
+distribute result [$$19] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (or(eq($$20, "1"), eq($$20, 0))) project: [$$19] [cardinality: 0.0, 
doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+    -- STREAM_SELECT  |PARTITIONED|
+      assign [$$19, $$20] <- [$$tenk.getField(0), $$tenk.getField("thousand")] 
project: [$$19, $$20] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+      -- ASSIGN  |PARTITIONED|
+        project ([$$tenk]) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+        -- STREAM_PROJECT  |PARTITIONED|
+          exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 
0.0]
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            data-scan []<-[$$21, $$tenk] <- test.tenk [cardinality: 0.0, 
doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source [cardinality: 0.0, doc-size: 0.0, op-cost: 
0.0, total-cost: 0.0]
+                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.02.plan
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.02.plan
new file mode 100644
index 0000000..97f523c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.02.plan
@@ -0,0 +1,18 @@
+distribute result [$$19] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(lt($$20, "1"), gt($$20, 0))) project: [$$19] [cardinality: 
0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+    -- STREAM_SELECT  |PARTITIONED|
+      assign [$$19, $$20] <- [$$tenk.getField(0), $$tenk.getField("thousand")] 
project: [$$19, $$20] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+      -- ASSIGN  |PARTITIONED|
+        project ([$$tenk]) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+        -- STREAM_PROJECT  |PARTITIONED|
+          exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 
0.0]
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            data-scan []<-[$$21, $$tenk] <- test.tenk [cardinality: 0.0, 
doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source [cardinality: 0.0, doc-size: 0.0, op-cost: 
0.0, total-cost: 0.0]
+                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.03.plan
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.03.plan
new file mode 100644
index 0000000..098f081
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/index-selection/miss-match-type-predicate/miss-match-type-predicate.03.plan
@@ -0,0 +1,54 @@
+distribute result [$$19] [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+-- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(lt($$tenk.getField("thousand"), 1), 
eq($$tenk.getField("twothousand"), "33"))) project: [$$19] [cardinality: 0.0, 
doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+    -- STREAM_SELECT  |PARTITIONED|
+      assign [$$19] <- [$$tenk.getField(0)] [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+      -- ASSIGN  |PARTITIONED|
+        project ([$$tenk]) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+        -- STREAM_PROJECT  |PARTITIONED|
+          exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 
0.0]
+          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "Default", 
"test", "tenk", false, false, 1, $$31, 1, $$31, true, true, true) [cardinality: 
0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                intersect [$$31] <- [[$$26], [$$30]] [cardinality: 0.0, 
doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                -- INTERSECT  |PARTITIONED|
+                  exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$26) [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                    -- STABLE_SORT [$$26(ASC)]  |PARTITIONED|
+                      exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$26]) [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 
0.0, total-cost: 0.0]
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            unnest-map [$$24, $$25, $$26] <- 
index-search("idx_1k_2k", 0, "Default", "test", "tenk", false, false, 0, 1, 
$$23, true, true, true) [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$23] <- [1] [cardinality: 0.0, 
doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                -- ASSIGN  |PARTITIONED|
+                                  empty-tuple-source [cardinality: 0.0, 
doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$30) [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                    -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                      exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, 
total-cost: 0.0]
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$30]) [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                        -- STREAM_PROJECT  |PARTITIONED|
+                          exchange [cardinality: 0.0, doc-size: 0.0, op-cost: 
0.0, total-cost: 0.0]
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            unnest-map [$$29, $$30] <- index-search("idx_2k", 
0, "Default", "test", "tenk", false, false, 1, $$27, 1, $$28, true, true, true) 
[cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange [cardinality: 0.0, doc-size: 0.0, 
op-cost: 0.0, total-cost: 0.0]
+                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$27, $$28] <- ["33", "33"] 
[cardinality: 0.0, doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                -- ASSIGN  |PARTITIONED|
+                                  empty-tuple-source [cardinality: 0.0, 
doc-size: 0.0, op-cost: 0.0, total-cost: 0.0]
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml 
b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
index 7e988a7..d3be365 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
@@ -6758,6 +6758,11 @@
         <output-dir 
compare="Text">heterogeneous-index-complex-types</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="index-selection">
+      <compilation-unit name="miss-match-type-predicate">
+        <output-dir compare="Text">miss-match-type-predicate</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="inverted-index-join">
     <test-case FilePath="inverted-index-join">

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/21089?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: asterixdb
Gerrit-Branch: phoenix
Gerrit-Change-Id: Iafb6e6ade19d0d669323a9a4488d8bfbbf160f85
Gerrit-Change-Number: 21089
Gerrit-PatchSet: 1
Gerrit-Owner: Shahrzad Shirazi <[email protected]>

Reply via email to