ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tled...@apache.org
Subject [ignite] branch ignite-2.9.1 updated: IGNITE-13765 Incorrect work of predicates (< and >) in where clause with compound primary key (closes #8510)
Date Tue, 01 Dec 2020 09:32:04 GMT
This is an automated email from the ASF dual-hosted git repository.

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


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

commit fc22988eb02fe6a7da6aebdb999bf62dc8d59642
Author: korlov42 <korlov@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)
    
    (cherry picked from commit 006c566d6743d00c63eb816930b9c41f22e1e7a6)
---
 .../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 080c1b1..7950f67 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
@@ -577,6 +577,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 b2d770e..6f5ffe4 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
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.UUID;
 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;
@@ -384,7 +385,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 7944e74..fe01d90 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
@@ -1183,6 +1183,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);
 


Mime
View raw message