You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/06/09 15:46:53 UTC

[GitHub] [ignite] AMashenkov opened a new pull request #7909: IGNITE-13021: Calcite integration. Avoid full scans for disjunctive queries.

AMashenkov opened a new pull request #7909:
URL: https://github.com/apache/ignite/pull/7909


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-12407: Add Cluster API support to Java thin client`
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.


----------------------------------------------------------------
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.

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



[GitHub] [ignite] AMashenkov merged pull request #7909: IGNITE-13021: Calcite integration. Avoid full scans for disjunctive queries.

Posted by GitBox <gi...@apache.org>.
AMashenkov merged pull request #7909:
URL: https://github.com/apache/ignite/pull/7909


   


----------------------------------------------------------------
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.

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



[GitHub] [ignite] rkondakov commented on a change in pull request #7909: IGNITE-13021: Calcite integration. Avoid full scans for disjunctive queries.

Posted by GitBox <gi...@apache.org>.
rkondakov commented on a change in pull request #7909:
URL: https://github.com/apache/ignite/pull/7909#discussion_r437289158



##########
File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rule/logical/LogicalOrToUnionRule.java
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.rule.logical;
+
+import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.tools.RelBuilder;
+
+/**
+ * Converts OR to UNION ALL.
+ */
+public class LogicalOrToUnionRule extends RelOptRule {
+    /** Instance. */
+    public static final RelOptRule INSTANCE = new LogicalOrToUnionRule(LogicalFilter.class, "LogicalOrToUnionRule");
+
+    /**
+     * Constructor.
+     *
+     * @param clazz Class of relational expression to match.
+     * @param desc  Description, or null to guess description
+     */
+    private LogicalOrToUnionRule(Class<LogicalFilter> clazz, String desc) {
+        super(
+            operand(clazz, any()),
+            RelFactories.LOGICAL_BUILDER, desc);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onMatch(RelOptRuleCall call) {
+        final LogicalFilter rel = call.rel(0);
+        final RelOptCluster cluster = rel.getCluster();
+
+        RexNode dnf = RexUtil.toDnf(cluster.getRexBuilder(), rel.getCondition());
+
+        if (!dnf.isA(SqlKind.OR))
+            return;
+
+        List<RexNode> operands = RelOptUtil.disjunctions(dnf);
+
+        if (operands.size() != 2)
+            return;
+
+        RelNode input = rel.getInput(0);
+
+        call.transformTo(rel, ImmutableMap.of(
+            createUnionAll(cluster, input, operands.get(0), operands.get(1)), rel,
+            createUnionAll(cluster, input, operands.get(1), operands.get(0)), rel
+        ));
+    }
+
+    /**
+     * Creates 'UnionAll' for conditions.
+     *
+     * @param cluster The cluster UnionAll expression will belongs to.
+     * @param input Input.
+     * @param op1 First filter condition.
+     * @param op2 Second filter condition.
+     * @return UnionAll expression.
+     */
+    private RelNode createUnionAll(RelOptCluster cluster, RelNode input, RexNode op1, RexNode op2) {
+        RelBuilder builder = relBuilderFactory.create(cluster, null);
+
+        builder.push(input).filter(op1);
+        builder.push(input).filter(RexUtil.andNot(cluster.getRexBuilder(), op2, op1));

Review comment:
       How `RexUtil.andNot` handles `NULL` value? In the ticket's example
   ```
   SELECT * FROM emps WHERE name='A' 
   UNION ALL
   SELECT * FROM emps WHERE surname='B'  AND LNNVL(name='A')
   ```
   we need to make sure that row `name=NULL, surname=B` will be returned by the rewritten plan. Can we verify it by writing a test?




----------------------------------------------------------------
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.

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