You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by tl...@apache.org on 2020/12/01 09:27:34 UTC

[ignite] branch master updated: IGNITE-13765 Incorrect work of predicates (< and >) in where clause with compound primary key (closes #8510)

This is an automated email from the ASF dual-hosted git repository.

tledkov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 006c566  IGNITE-13765 Incorrect work of predicates (< and >) in where clause with compound primary key (closes #8510)
006c566 is described below

commit 006c566d6743d00c63eb816930b9c41f22e1e7a6
Author: korlov42 <ko...@gridgain.com>
AuthorDate: Tue Dec 1 12:26:58 2020 +0300

    IGNITE-13765 Incorrect work of predicates (< and >) in where clause with compound primary key (closes #8510)
---
 .../processors/query/h2/database/H2Tree.java       | 34 ++++++++++++++++++++++
 .../processors/query/h2/database/H2TreeIndex.java  |  3 +-
 .../processors/cache/index/BasicIndexTest.java     | 15 ++++++++++
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
index 99a0add..4fb9a41 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2Tree.java
@@ -626,6 +626,40 @@ public class H2Tree extends BPlusTree<H2Row, H2Row> {
     }
 
     /**
+     * Checks both rows are the same. <p/>
+     * Primarly used to verify both search rows are the same and we can apply
+     * the single row lookup optimization.
+     *
+     * @param r1 The first row.
+     * @param r2 Another row.
+     * @return {@code true} in case both rows are efficiently the same, {@code false} otherwise.
+     */
+    boolean checkRowsTheSame(H2Row r1, H2Row r2) {
+        if (r1 == r2)
+            return true;
+
+        for (int i = 0, len = cols.length; i < len; i++) {
+            IndexColumn idxCol = cols[i];
+
+            int idx = idxCol.column.getColumnId();
+
+            Value v1 = r1.getValue(idx);
+            Value v2 = r2.getValue(idx);
+
+            if (v1 == null && v2 == null)
+                continue;
+
+            if (!(v1 != null && v2 != null))
+                return false;
+
+            if (compareValues(v1, v2) != 0)
+                return false;
+        }
+
+        return true;
+    }
+
+    /**
      * @param io IO.
      * @param pageAddr Page address.
      * @param idx Item index.
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
index 1b7ffe7..4701e8a 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
@@ -26,6 +26,7 @@ import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
+
 import javax.cache.CacheException;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
@@ -423,7 +424,7 @@ public class H2TreeIndex extends H2TreeIndexBase {
     /** */
     private boolean isSingleRowLookup(SearchRow lower, SearchRow upper, H2Tree tree) {
         return !cctx.mvccEnabled() && indexType.isPrimaryKey() && lower != null && upper != null &&
-            tree.compareRows((H2Row)lower, (H2Row)upper) == 0 && hasAllIndexColumns(lower);
+            tree.checkRowsTheSame((H2Row)lower, (H2Row)upper) && hasAllIndexColumns(lower);
     }
 
     /** */
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
index 24a3759..9673af8 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/BasicIndexTest.java
@@ -1373,6 +1373,21 @@ public class BasicIndexTest extends AbstractIndexingCommonTest {
     }
 
     /** */
+    @Test
+    public void testOpenRangePredicateOnCompoundPk() throws Exception {
+        inlineSize = 10;
+
+        startGrid();
+
+        sql("create table test (id1 int, id2 int, val int, constraint pk primary key (id1, id2))");
+
+        for (int i = 1; i <= 5; i++)
+            sql("insert into test (id1, id2, val) values (?, ?, ?)", 0, i, i);
+
+        assertEquals(5, sql("select * from test where id1 = 0 and id2 > 0").getAll().size());
+    }
+
+    /** */
     private void checkAll() {
         IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME);