>From <[email protected]>: [email protected] has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19321 )
Change subject: [ASTERIXDB-3550][COMP] Change Used Variables implementation for Subplan operator ...................................................................... [ASTERIXDB-3550][COMP] Change Used Variables implementation for Subplan operator - user model changes: no - storage format changes: no - interface changes: no Details: Do not include locally produced variables in UsedVariables for a subplan operator. This will cause InlineSingleReferenceVariables rule to get fired inside the nested plans. Ext-ref: MB-49756 Change-Id: I236a52923c181395cf7501926010ca9899cae9e8 --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.2.update.sqlpp M hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java A asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.5.plan M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.5.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.6.adm A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.4.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.6.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.3.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.1.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.3.plan A asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.4.adm 12 files changed, 313 insertions(+), 1 deletion(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/21/19321/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.1.ddl.sqlpp new file mode 100644 index 0000000..06bc37e --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.1.ddl.sqlpp @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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; +USE test; + + +CREATE TYPE LogType AS { + id: integer +}; + +CREATE COLLECTION Logs(LogType) PRIMARY KEY id; + diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.2.update.sqlpp new file mode 100644 index 0000000..9ae9f36 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.2.update.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. + */ + +use test; + +INSERT INTO Logs ([ + { + "id": 3, + "entries": [ + { + "outcomes": { + "auditors": { + "Retrieval Timestamp": { + "raw": "2025-02-12T08:30:00Z" + } + } + } + }, + { + "outcomes": { + "auditors": { + "Retrieval Timestamp": { + "raw": "2025-02-10T15:45:00Z" + } + } + } + }, + { + "outcomes": { + "auditors": { + "Retrieval Timestamp": { + "raw": "2025-02-11T09:00:00Z" + } + } + } + } + ] +}, +{ + "id": 4, + "entries": [ + { + "outcomes": { + "auditors": { + "Retrieval Timestamp": { + "raw": "2025-02-13T10:15:00Z" + } + } + } + }, + { + "outcomes": { + "auditors": { + "Retrieval Timestamp": { + "raw": "2025-02-14T16:30:00Z" + } + } + } + } + ] +} +]); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.3.query.sqlpp new file mode 100644 index 0000000..883af83 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.3.query.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. + */ + + +use test; + +EXPLAIN +SELECT ARRAY_MIN(( +SELECT RAW entry.outcomes.auditors.`Retrieval Timestamp`.`raw` +FROM s.entries entry)) AS earliest +FROM Logs s; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.4.query.sqlpp new file mode 100644 index 0000000..b48a3d1 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.4.query.sqlpp @@ -0,0 +1,28 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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; + +use test; + +SELECT ARRAY_MIN(( + SELECT RAW entry.outcomes.auditors.`Retrieval Timestamp`.`raw` + FROM s.entries entry)) AS earliest +FROM Logs s +ORDER BY earliest; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.5.query.sqlpp new file mode 100644 index 0000000..5e5bfef --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.5.query.sqlpp @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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 ARRAY_MIN(( + SELECT RAW entry.outcomes.auditors.`Retrieval Timestamp`.`raw` + FROM s.entries entry)) AS earliest, + ARRAY_LENGTH(entries) AS entry_count +FROM Logs s; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.6.query.sqlpp new file mode 100644 index 0000000..868713c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.6.query.sqlpp @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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 ARRAY_MIN(( + SELECT RAW entry.outcomes.auditors.`Retrieval Timestamp`.`raw` + FROM s.entries entry)) AS earliest, + ARRAY_LENGTH(entries) AS entry_count +FROM Logs s +ORDER BY entry_count; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.3.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.3.plan new file mode 100644 index 0000000..1aca244 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.3.plan @@ -0,0 +1,31 @@ +distribute result [$$34] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] +-- DISTRIBUTE_RESULT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + assign [$$34] <- [{"earliest": $$36}] project: [$$34] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ASSIGN |PARTITIONED| + project ([$$36]) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_PROJECT |PARTITIONED| + subplan { + aggregate [$$36] <- [agg-sql-min($$32)] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- AGGREGATE |LOCAL| + assign [$$32] <- [$$entry.getField("outcomes").getField("auditors").getField("Retrieval Timestamp").getField("raw")] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ASSIGN |LOCAL| + unnest $$entry <- scan-collection($$37) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- UNNEST |LOCAL| + nested tuple source [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- NESTED_TUPLE_SOURCE |LOCAL| + } [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- SUBPLAN |PARTITIONED| + assign [$$37] <- [$$s.getField("entries")] project: [$$37] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ASSIGN |PARTITIONED| + project ([$$s]) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_PROJECT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + data-scan []<-[$$35, $$s] <- test.Logs [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- DATASOURCE_SCAN |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + empty-tuple-source [cardinality: 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/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.4.adm new file mode 100644 index 0000000..4d6fd41 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.4.adm @@ -0,0 +1,2 @@ +{ "earliest": "2025-02-10T15:45:00Z" } +{ "earliest": "2025-02-13T10:15:00Z" } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.5.plan b/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.5.plan new file mode 100644 index 0000000..a40e192 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.5.plan @@ -0,0 +1,29 @@ +distribute result [$$36] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] +-- DISTRIBUTE_RESULT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + assign [$$36] <- [{"earliest": $$38, "entry_count": len($$39)}] project: [$$36] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ASSIGN |PARTITIONED| + subplan { + aggregate [$$38] <- [agg-sql-min($$32)] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- AGGREGATE |LOCAL| + assign [$$32] <- [$$entry.getField("outcomes").getField("auditors").getField("Retrieval Timestamp").getField("raw")] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ASSIGN |LOCAL| + unnest $$entry <- scan-collection($$39) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- UNNEST |LOCAL| + nested tuple source [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- NESTED_TUPLE_SOURCE |LOCAL| + } [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- SUBPLAN |PARTITIONED| + assign [$$39] <- [$$s.getField("entries")] project: [$$39] [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ASSIGN |PARTITIONED| + project ([$$s]) [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- STREAM_PROJECT |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + data-scan []<-[$$37, $$s] <- test.Logs [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- DATASOURCE_SCAN |PARTITIONED| + exchange [cardinality: 0.0, op-cost: 0.0, total-cost: 0.0] + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + empty-tuple-source [cardinality: 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/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.6.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.6.adm new file mode 100644 index 0000000..4910543 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/subquery/query-ASTERIXDB-3550/query-ASTERIXDB-3550.6.adm @@ -0,0 +1,2 @@ +{ "entry_count": 2, "earliest": "2025-02-13T10:15:00Z" } +{ "entry_count": 3, "earliest": "2025-02-10T15:45:00Z" } 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 bbeb517..f881128 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml @@ -11818,6 +11818,11 @@ <output-dir compare="Text">query-ASTERIXDB-3006</output-dir> </compilation-unit> </test-case> + <test-case FilePath="subquery"> + <compilation-unit name="query-ASTERIXDB-3550"> + <output-dir compare="Text">query-ASTERIXDB-3550</output-dir> + </compilation-unit> + </test-case> </test-group> <test-group name="subset-collection"> <test-case FilePath="subset-collection"> diff --git a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java index 7186f7e..347924e 100644 --- a/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java +++ b/hyracks-fullstack/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/operators/logical/visitors/UsedVariableVisitor.java @@ -18,6 +18,7 @@ */ package org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -536,7 +537,12 @@ private void visitNestedPlans(AbstractOperatorWithNestedPlans op) throws AlgebricksException { for (ILogicalPlan p : op.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { - VariableUtilities.getUsedVariablesInDescendantsAndSelf(r.getValue(), usedVariables); + List<LogicalVariable> usedVariablesInNestedPlan = new ArrayList<>(); + VariableUtilities.getUsedVariablesInDescendantsAndSelf(r.getValue(), usedVariablesInNestedPlan); + List<LogicalVariable> producedVariablesInNestedPlan = new ArrayList<>(); + VariableUtilities.getProducedVariablesInDescendantsAndSelf(r.getValue(), producedVariablesInNestedPlan); + usedVariablesInNestedPlan.removeAll(producedVariablesInNestedPlan); + usedVariables.addAll(usedVariablesInNestedPlan); } } } -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19321 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I236a52923c181395cf7501926010ca9899cae9e8 Gerrit-Change-Number: 19321 Gerrit-PatchSet: 1 Gerrit-Owner: [email protected] Gerrit-MessageType: newchange
