You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "jackwener (via GitHub)" <gi...@apache.org> on 2023/04/06 07:47:03 UTC

[GitHub] [doris] jackwener opened a new pull request, #18428: [feature](Nereids): deduplicate InPredicate.

jackwener opened a new pull request, #18428:
URL: https://github.com/apache/doris/pull/18428

   # Proposed changes
   
   Issue Number: close #xxx
   
   ## Problem summary
   deduplicate InPredicate.
   
   tpcds-q27 
   
   ```sql
   (s_state IN (
        'TN'
      , 'TN'
      , 'TN'
      , 'TN'
      , 'TN'
      , 'TN')
   ```
   
   ## Checklist(Required)
   
   * [x] Does it affect the original behavior
   * [x] Has unit tests been added
   * [ ] Has document been added or modified
   * [ ] Does it need to update dependencies
   * [x] Is this PR support rollback (If NO, please explain WHY)
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] englefly commented on a diff in pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "englefly (via GitHub)" <gi...@apache.org>.
englefly commented on code in PR #18428:
URL: https://github.com/apache/doris/pull/18428#discussion_r1160353362


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/rules/InPredicateDedup.java:
##########
@@ -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.
+
+package org.apache.doris.nereids.rules.expression.rewrite.rules;
+
+import org.apache.doris.nereids.rules.expression.rewrite.AbstractExpressionRewriteRule;
+import org.apache.doris.nereids.rules.expression.rewrite.ExpressionRewriteContext;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.InPredicate;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Deduplicate InPredicate, For example:
+ * where A in (x, x) ==> where A in (x)
+ */
+public class InPredicateDedup extends AbstractExpressionRewriteRule {
+
+    public static InPredicateDedup INSTANCE = new InPredicateDedup();
+
+    @Override
+    public Expression visitInPredicate(InPredicate inPredicate, ExpressionRewriteContext context) {
+        Set<Expression> dedupExpr = new HashSet<>();
+        List<Expression> newOptions = new ArrayList<>();
+        for (Expression option : inPredicate.getOptions()) {
+            if (dedupExpr.contains(option)) {
+                continue;
+            }
+            dedupExpr.add(option);
+            newOptions.add(option);
+        }
+        return new InPredicate(inPredicate.getCompareExpr(), newOptions);

Review Comment:
   if there is only one option, it would be better to convert to equalTo



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] englefly commented on pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "englefly (via GitHub)" <gi...@apache.org>.
englefly commented on PR #18428:
URL: https://github.com/apache/doris/pull/18428#issuecomment-1499914980

   run buildall


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #18428:
URL: https://github.com/apache/doris/pull/18428#issuecomment-1500062220

   PR approved by anyone and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] jackwener commented on pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on PR #18428:
URL: https://github.com/apache/doris/pull/18428#issuecomment-1498636324

   run buildall


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] github-actions[bot] commented on pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #18428:
URL: https://github.com/apache/doris/pull/18428#issuecomment-1500062184

   PR approved by at least one committer and no changes requested.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] englefly commented on a diff in pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "englefly (via GitHub)" <gi...@apache.org>.
englefly commented on code in PR #18428:
URL: https://github.com/apache/doris/pull/18428#discussion_r1160355477


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/rules/InPredicateDedup.java:
##########
@@ -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.
+
+package org.apache.doris.nereids.rules.expression.rewrite.rules;
+
+import org.apache.doris.nereids.rules.expression.rewrite.AbstractExpressionRewriteRule;
+import org.apache.doris.nereids.rules.expression.rewrite.ExpressionRewriteContext;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.InPredicate;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Deduplicate InPredicate, For example:
+ * where A in (x, x) ==> where A in (x)
+ */
+public class InPredicateDedup extends AbstractExpressionRewriteRule {
+
+    public static InPredicateDedup INSTANCE = new InPredicateDedup();
+
+    @Override
+    public Expression visitInPredicate(InPredicate inPredicate, ExpressionRewriteContext context) {
+        Set<Expression> dedupExpr = new HashSet<>();

Review Comment:
   In many BI scenarios, the sql is auto-generated, and hence there may be thousands of  options. It takes a long time to apply this rule. It is better to deduplicate in BE side.
   How about set a threshold for the max number of options for this rule.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] jackwener commented on a diff in pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on code in PR #18428:
URL: https://github.com/apache/doris/pull/18428#discussion_r1160415167


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/rules/InPredicateDedup.java:
##########
@@ -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.
+
+package org.apache.doris.nereids.rules.expression.rewrite.rules;
+
+import org.apache.doris.nereids.rules.expression.rewrite.AbstractExpressionRewriteRule;
+import org.apache.doris.nereids.rules.expression.rewrite.ExpressionRewriteContext;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.InPredicate;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Deduplicate InPredicate, For example:
+ * where A in (x, x) ==> where A in (x)
+ */
+public class InPredicateDedup extends AbstractExpressionRewriteRule {
+
+    public static InPredicateDedup INSTANCE = new InPredicateDedup();
+
+    @Override
+    public Expression visitInPredicate(InPredicate inPredicate, ExpressionRewriteContext context) {
+        Set<Expression> dedupExpr = new HashSet<>();
+        List<Expression> newOptions = new ArrayList<>();
+        for (Expression option : inPredicate.getOptions()) {
+            if (dedupExpr.contains(option)) {
+                continue;
+            }
+            dedupExpr.add(option);
+            newOptions.add(option);
+        }
+        return new InPredicate(inPredicate.getCompareExpr(), newOptions);

Review Comment:
   InPredicateToEqualToRule will do it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] jackwener merged pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener merged PR #18428:
URL: https://github.com/apache/doris/pull/18428


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] jackwener commented on pull request #18428: [feature](Nereids): deduplicate InPredicate.

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on PR #18428:
URL: https://github.com/apache/doris/pull/18428#issuecomment-1498716550

   run buildall


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org