Dmitry Lychagin has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/2024
Change subject: [ASTERIXDB-2105][COMP] Support broadcast join hint with multiple predicates ...................................................................... [ASTERIXDB-2105][COMP] Support broadcast join hint with multiple predicates - user model changes: no - storage format changes: no - interface changes: no Details: - Broadcast hint now works if join condition has multiple predicates. Only one predicate needs to be annotated. Change-Id: Id1475c5e574be2632c92ae619f3a36c56c222514 --- M asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java A asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_1.sqlpp A asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_2.sqlpp A asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_3.sqlpp A asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_1.plan A asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_2.plan A asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_3.plan M hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/util/JoinUtils.java 8 files changed, 250 insertions(+), 25 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/24/2024/1 diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java index 409bbdc..d1c3ce4 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java @@ -172,6 +172,8 @@ LOGGER.info("RUN TEST: \"" + queryFile.getPath() + "\""); Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFile), "UTF-8")); + LOGGER.info("ACTUAL RESULT FILE: " + actualFile.getAbsolutePath()); + // Forces the creation of actualFile. actualFile.getParentFile().mkdirs(); diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_1.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_1.sqlpp new file mode 100644 index 0000000..02ba35d --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_1.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 : Test broadcast join hint. +* Hint on one conjunct +* Expected Res : Success +* Date : 09/22/2017 +*/ + +drop dataverse test if exists; +create dataverse test; + +use test; + +create type TT as closed { + c_key : integer, + c_1 : integer, + c_2 : integer, + c_3 : integer, + c_4 : integer +}; + +create dataset t1(TT) primary key c_key; + +create dataset t2(TT) primary key c_key; + +select t1.c_4 as c0, t2.c_4 as c1 +from t1 join t2 +on t1.c_1 = t2.c_1 and t1.c_2 /*+ bcast */ = t2.c_2 and t1.c_3 = t2.c_3 +; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_2.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_2.sqlpp new file mode 100644 index 0000000..1feb21f --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_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 : Test broadcast join hint +* Hint on each conjunct +* Expected Res : Success +* Date : 09/22/2017 +*/ + +drop dataverse test if exists; +create dataverse test; + +use test; + +create type TT as closed { + c_key : integer, + c_1 : integer, + c_2 : integer, + c_3 : integer, + c_4 : integer +}; + +create dataset t1(TT) primary key c_key; + +create dataset t2(TT) primary key c_key; + +select t1.c_4 as c0, t2.c_4 as c1 +from t1 join t2 +on t1.c_1 /*+ bcast */ = t2.c_1 and t1.c_2 /*+ bcast */ = t2.c_2 and t1.c_3 /*+ bcast */ = t2.c_3 +; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_3.sqlpp b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_3.sqlpp new file mode 100644 index 0000000..a3fd4f6 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/optimizerts/queries/hints/broadcast_hint_3.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 : Test broadcast join hint +* Incompatible broadcast sides -> no broadcast +* Expected Res : Success +* Date : 09/22/2017 +*/ + +drop dataverse test if exists; +create dataverse test; + +use test; + +create type TT as closed { + c_key : integer, + c_1 : integer, + c_2 : integer, + c_3 : integer, + c_4 : integer +}; + +create dataset t1(TT) primary key c_key; + +create dataset t2(TT) primary key c_key; + +select t1.c_4 as c0, t2.c_4 as c1 +from t1 join t2 +on t1.c_1 /*+ bcast */ = t2.c_1 and t1.c_2 /*+ bcast */ = t2.c_2 and t2.c_3 /*+ bcast */ = t1.c_3 +; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_1.plan new file mode 100644 index 0000000..d45ccfe --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_1.plan @@ -0,0 +1,23 @@ +-- DISTRIBUTE_RESULT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- HYBRID_HASH_JOIN [$$21, $$23, $$25][$$22, $$24, $$26] |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- DATASOURCE_SCAN |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| + -- BROADCAST_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- DATASOURCE_SCAN |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_2.plan new file mode 100644 index 0000000..d45ccfe --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_2.plan @@ -0,0 +1,23 @@ +-- DISTRIBUTE_RESULT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- HYBRID_HASH_JOIN [$$21, $$23, $$25][$$22, $$24, $$26] |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- DATASOURCE_SCAN |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| + -- BROADCAST_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- DATASOURCE_SCAN |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_3.plan new file mode 100644 index 0000000..b7669dd --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_hint_3.plan @@ -0,0 +1,23 @@ +-- DISTRIBUTE_RESULT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- HYBRID_HASH_JOIN [$$21, $$24, $$25][$$22, $$23, $$26] |PARTITIONED| + -- HASH_PARTITION_EXCHANGE [$$21, $$24, $$25] |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- DATASOURCE_SCAN |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| + -- HASH_PARTITION_EXCHANGE [$$22, $$23, $$26] |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ASSIGN |PARTITIONED| + -- STREAM_PROJECT |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- DATASOURCE_SCAN |PARTITIONED| + -- ONE_TO_ONE_EXCHANGE |PARTITIONED| + -- EMPTY_TUPLE_SOURCE |PARTITIONED| \ No newline at end of file diff --git a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/util/JoinUtils.java b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/util/JoinUtils.java index d66e6fc..71603ff 100644 --- a/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/util/JoinUtils.java +++ b/hyracks-fullstack/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/util/JoinUtils.java @@ -178,33 +178,49 @@ return null; } AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) e; - IExpressionAnnotation ann = fexp.getAnnotations().get(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY); - if (ann == null) { - return null; + FunctionIdentifier fi = fexp.getFunctionIdentifier(); + if (fi.equals(AlgebricksBuiltinFunctions.AND)) { + BroadcastSide fBcastSide = null; + for (Mutable<ILogicalExpression> a : fexp.getArguments()) { + BroadcastSide aBcastSide = getBroadcastJoinSide(a.getValue(), varsLeft, varsRight); + if (fBcastSide == null) { + fBcastSide = aBcastSide; + } + else if (aBcastSide != null && !aBcastSide.equals(fBcastSide)) { + return null; + } + } + return fBcastSide; } - BroadcastSide side = (BroadcastSide) ann.getObject(); - if (side == null) { - return null; - } - int i; - switch (side) { - case LEFT: - i = 0; - break; - case RIGHT: - i = 1; - break; - default: + else { + IExpressionAnnotation ann = fexp.getAnnotations().get(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY); + if (ann == null) { return null; - } - ArrayList<LogicalVariable> vars = new ArrayList<>(); - fexp.getArguments().get(i).getValue().getUsedVariables(vars); - if (varsLeft.containsAll(vars)) { - return BroadcastSide.LEFT; - } else if (varsRight.containsAll(vars)) { - return BroadcastSide.RIGHT; - } else { - return null; + } + BroadcastSide side = (BroadcastSide) ann.getObject(); + if (side == null) { + return null; + } + int i; + switch (side) { + case LEFT: + i = 0; + break; + case RIGHT: + i = 1; + break; + default: + return null; + } + ArrayList<LogicalVariable> vars = new ArrayList<>(); + fexp.getArguments().get(i).getValue().getUsedVariables(vars); + if (varsLeft.containsAll(vars)) { + return BroadcastSide.LEFT; + } else if (varsRight.containsAll(vars)) { + return BroadcastSide.RIGHT; + } else { + return null; + } } } } -- To view, visit https://asterix-gerrit.ics.uci.edu/2024 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id1475c5e574be2632c92ae619f3a36c56c222514 Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Dmitry Lychagin <dmitry.lycha...@couchbase.com>