>From Ali Alsuliman <[email protected]>:

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


Change subject: [NO ISSUE][COMP] Push limit to index-search of UNNEST_MAP op
......................................................................

[NO ISSUE][COMP] Push limit to index-search of UNNEST_MAP op

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
Push limit to index-search of UNNEST_MAP op.

Change-Id: I4a7d0fe690fcefd845f60814d5a4477cd6bc4e6f
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushLimitIntoPrimarySearchRule.java
A 
asterixdb/asterix-app/src/test/resources/optimizerts/queries/limit/pushdown_to_index_search.sqlpp
A 
asterixdb/asterix-app/src/test/resources/optimizerts/results/limit/pushdown_to_index_search.plan
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.01.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.02.update.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.03.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.99.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.03.adm
M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
9 files changed, 221 insertions(+), 1 deletion(-)



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

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushLimitIntoPrimarySearchRule.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushLimitIntoPrimarySearchRule.java
index d95a952..e0f068c 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushLimitIntoPrimarySearchRule.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/PushLimitIntoPrimarySearchRule.java
@@ -180,7 +180,7 @@
             return false;
         }
         ILogicalExpression unnestExpr = op.getExpressionRef().getValue();
-        if (op.propagatesInput() || unnestExpr.getExpressionTag() != 
LogicalExpressionTag.FUNCTION_CALL) {
+        if (unnestExpr.getExpressionTag() != 
LogicalExpressionTag.FUNCTION_CALL) {
             return false;
         }
         AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) 
unnestExpr;
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/limit/pushdown_to_index_search.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/limit/pushdown_to_index_search.sqlpp
new file mode 100644
index 0000000..abdc0a4
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/limit/pushdown_to_index_search.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: Tests that LIMIT is pushed down to index-search in indexnl join
+ */
+
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+CREATE TYPE openType AS OPEN {
+  id:string
+};
+
+CREATE DATASET ds1(openType) PRIMARY KEY id;
+CREATE DATASET ds2(openType) PRIMARY KEY id;
+
+SELECT
+    ds1.field1,
+    ds1.field2,
+    ds1.field3,
+    ds1.field4,
+    comp_field,
+    ds2.fieldX
+FROM ds1 AS ds1
+JOIN ds2 AS ds2
+    ON ds2.id /*+ indexnl */ = (ds1.field2 || ":" || TO_STRING(ds1.field3) || 
":" || ds1.field4)
+    LET comp_field = (REPLACE(ds1.field1, "-", "") || "03")
+LIMIT 2;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/optimizerts/results/limit/pushdown_to_index_search.plan
 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/limit/pushdown_to_index_search.plan
new file mode 100644
index 0000000..1728331
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/optimizerts/results/limit/pushdown_to_index_search.plan
@@ -0,0 +1,44 @@
+distribute result [$$54]
+-- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
+  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 2
+    -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$54])
+      -- STREAM_PROJECT  |PARTITIONED|
+        exchange
+        -- SORT_MERGE_EXCHANGE [$$60(ASC) ]  |PARTITIONED|
+          project ([$$60, $$54])
+          -- STREAM_PROJECT  |PARTITIONED|
+            assign [$$54] <- [{"field1": $$55, "field2": $$56, "field3": $$57, 
"field4": $$58, "comp_field": 
string-concat(ordered-list-constructor(replace($$55, "-", ""), "03")), 
"fieldX": $$ds2.getField("fieldX")}]
+            -- ASSIGN  |PARTITIONED|
+              limit 2
+              -- STREAM_LIMIT  |PARTITIONED|
+                project ([$$55, $$58, $$57, $$56, $$60, $$ds2])
+                -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
+                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    unnest-map [$$60, $$ds2] <- index-search("ds2", 0, "test", 
"ds2", true, true, 1, $$62, 1, $$62, true, true, true) limit 2
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$62)
+                        -- STABLE_SORT [$$62(ASC)]  |PARTITIONED|
+                          exchange
+                          -- HASH_PARTITION_EXCHANGE [$$62]  |PARTITIONED|
+                            assign [$$62] <- 
[string-concat(ordered-list-constructor($$56, ":", to-string($$57), ":", $$58))]
+                            -- ASSIGN  |PARTITIONED|
+                              project ([$$55, $$58, $$57, $$56])
+                              -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$55, $$58, $$57, $$56] <- 
[$$ds1.getField("field1"), $$ds1.getField("field4"), $$ds1.getField("field3"), 
$$ds1.getField("field2")]
+                                -- ASSIGN  |PARTITIONED|
+                                  project ([$$ds1])
+                                  -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
+                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      data-scan []<-[$$59, $$ds1] <- test.ds1
+                                      -- 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/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.01.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.01.ddl.sqlpp
new file mode 100644
index 0000000..25bfa4e
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.01.ddl.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: Tests that LIMIT is pushed down to index-search in indexnl join
+ */
+
+DROP DATAVERSE test IF EXISTS;
+CREATE DATAVERSE test;
+USE test;
+
+CREATE TYPE openType AS OPEN {
+  id:string
+};
+
+CREATE DATASET ds1(openType) PRIMARY KEY id;
+CREATE DATASET ds2(openType) PRIMARY KEY id;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.02.update.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.02.update.sqlpp
new file mode 100644
index 0000000..868ce4e
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.02.update.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT 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;
+
+UPSERT INTO ds1([
+{"id": "1", "field1": "f1", "field2": "1", "field3": "1", "field4": "1"},
+{"id": "2", "field1": "f2", "field2": "1", "field3": "1", "field4": "2"},
+{"id": "3", "field1": "f3", "field2": "1", "field3": "1", "field4": "3"},
+{"id": "4", "field1": "f4", "field2": "1", "field3": "1", "field4": "4"},
+{"id": "5", "field1": "f5", "field2": "1", "field3": "1", "field4": "5"},
+{"id": "6", "field1": "f6", "field2": "1", "field3": "1", "field4": "6"}
+]
+);
+
+UPSERT INTO ds2([
+{"id": "1:1:1", "fieldX": 10},
+{"id": "1:1:2", "fieldX": 11},
+{"id": "1:1:3", "fieldX": 12}
+]
+);
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.03.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.03.query.sqlpp
new file mode 100644
index 0000000..39e4ce9
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.03.query.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.
+ */
+
+USE test;
+
+SELECT
+    ds1.field1,
+    ds1.field2,
+    ds1.field3,
+    ds1.field4,
+    comp_field,
+    ds2.fieldX
+FROM ds1 AS ds1
+JOIN ds2 AS ds2
+    ON ds2.id /*+ indexnl */ = (ds1.field2 || ":" || TO_STRING(ds1.field3) || 
":" || ds1.field4)
+    LET comp_field = (REPLACE(ds1.field1, "-", "") || "03")
+LIMIT 2;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.99.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.99.ddl.sqlpp
new file mode 100644
index 0000000..36b2bab
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.99.ddl.sqlpp
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT 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;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.03.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.03.adm
new file mode 100644
index 0000000..c61af0f
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/limit/push-limit-to-join-primary-lookup/push-limit-to-join-primary-lookup.03.adm
@@ -0,0 +1,2 @@
+{ "comp_field": "f103", "field1": "f1", "field2": "1", "field3": "1", 
"field4": "1", "fieldX": 10 }
+{ "comp_field": "f203", "field1": "f2", "field2": "1", "field3": "1", 
"field4": "2", "fieldX": 11 }
\ No newline at end of file
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 44bbeac..d19a3a1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml
@@ -15509,6 +15509,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="limit">
+      <compilation-unit name="push-limit-to-join-primary-lookup">
+        <output-dir 
compare="Text">push-limit-to-join-primary-lookup</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="limit">
       <compilation-unit name="push-limit-to-primary-scan">
         <output-dir compare="Text">push-limit-to-primary-scan</output-dir>
       </compilation-unit>

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/20592?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: trinity
Gerrit-Change-Id: I4a7d0fe690fcefd845f60814d5a4477cd6bc4e6f
Gerrit-Change-Number: 20592
Gerrit-PatchSet: 1
Gerrit-Owner: Ali Alsuliman <[email protected]>

Reply via email to