ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: IGNITE-8468: SQL: optimized inlined UUID comparison. This closes #3977.
Date Tue, 05 Jun 2018 08:30:55 GMT
Repository: ignite
Updated Branches:
  refs/heads/master bc35ce0cd -> c50b3c24a


IGNITE-8468: SQL: optimized inlined UUID comparison. This closes #3977.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c50b3c24
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c50b3c24
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c50b3c24

Branch: refs/heads/master
Commit: c50b3c24ae1cf23e97b6ed4911fab25eff338222
Parents: bc35ce0
Author: AMRepo <andrey.mashenkov@gmail.com>
Authored: Tue Jun 5 11:28:43 2018 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Tue Jun 5 11:28:43 2018 +0300

----------------------------------------------------------------------
 .../query/h2/database/InlineIndexHelper.java    | 37 ++++++++++++++++++--
 .../h2/database/InlineIndexHelperTest.java      | 22 +++++++-----
 2 files changed, 49 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c50b3c24/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelper.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelper.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelper.java
index 3419127..05d5c46 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelper.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelper.java
@@ -413,6 +413,9 @@ public class InlineIndexHelper {
 
                 break;
 
+            case Value.UUID:
+                return compareAsUUID(pageAddr, off, v, type);
+
             case Value.BYTES:
                 return compareAsBytes(pageAddr, off, v);
         }
@@ -425,7 +428,37 @@ public class InlineIndexHelper {
      * @param off Offset.
      * @param v Value to compare.
      * @param type Highest value type.
-     * @return Compare result ({@code -2} means we can't compare).
+     * @return Compare result ({@code Integer.MIN_VALUE} means unsupported operation.
+     */
+    private int compareAsUUID(long pageAddr, int off, Value v, int type) {
+        // only compatible types are supported now.
+        if(PageUtils.getByte(pageAddr, off) == type) {
+            assert type == Value.UUID;
+
+            ValueUuid uuid = (ValueUuid)v.convertTo(Value.UUID);
+            long long1 = PageUtils.getLong(pageAddr, off + 1);
+
+            int c = Long.compare(long1, uuid.getHigh());
+
+            if(c != 0)
+                return fixSort(c, sortType());
+
+            long1 = PageUtils.getLong(pageAddr, off + 9);
+
+            c = Long.compare(long1, uuid.getLow());
+
+            return fixSort(c, sortType());
+        }
+
+        return Integer.MIN_VALUE;
+    }
+
+    /**
+     * @param pageAddr Page address.
+     * @param off Offset.
+     * @param v Value to compare.
+     * @param type Highest value type.
+     * @return Compare result ({@code Integer.MIN_VALUE} means unsupported operation.
      */
     private int compareAsDateTime(long pageAddr, int off, Value v, int type) {
         // only compatible types are supported now.
@@ -470,7 +503,7 @@ public class InlineIndexHelper {
      * @param off Offset.
      * @param v Value to compare.
      * @param type Highest value type.
-     * @return Compare result ({@code -2} means we can't compare).
+     * @return Compare result ({@code Integer.MIN_VALUE} means unsupported operation.
      */
     private int compareAsPrimitive(long pageAddr, int off, Value v, int type) {
         // only compatible types are supported now.

http://git-wip-us.apache.org/repos/asf/ignite/blob/c50b3c24/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
index 41dd4f1..ea23483 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/database/InlineIndexHelperTest.java
@@ -64,7 +64,7 @@ public class InlineIndexHelperTest extends GridCommonAbstractTest {
     private static final long MB = 1024;
 
     /** */
-    private static final int CPUS = Runtime.getRuntime().availableProcessors();
+    private static final Comparator ALWAYS_FAILS_COMPARATOR = new AlwaysFailsComparator();
 
     /** Test utf-8 string cutting. */
     public void testConvert() {
@@ -209,13 +209,7 @@ public class InlineIndexHelperTest extends GridCommonAbstractTest {
 
             ih.put(pageAddr, off, v1 == null ? ValueNull.INSTANCE : ValueString.get(v1),
maxSize);
 
-            Comparator<Value> comp = new Comparator<Value>() {
-                @Override public int compare(Value o1, Value o2) {
-                    throw new AssertionError("Optimized algorithm should be used.");
-                }
-            };
-
-            return ih.compare(pageAddr, off, maxSize,  v2 == null ? ValueNull.INSTANCE :
ValueString.get(v2), comp);
+            return ih.compare(pageAddr, off, maxSize,  v2 == null ? ValueNull.INSTANCE :
ValueString.get(v2), ALWAYS_FAILS_COMPARATOR);
         }
         finally {
             if (page != 0L)
@@ -485,6 +479,8 @@ public class InlineIndexHelperTest extends GridCommonAbstractTest {
 
             assertEquals(v1.getObject(), v11.getObject());
             assertEquals(v2.getObject(), v22.getObject());
+
+            assertEquals(0, ih.compare(pageAddr, 0, max, v1, ALWAYS_FAILS_COMPARATOR));
         }
         finally {
             if (page != 0L)
@@ -560,4 +556,14 @@ public class InlineIndexHelperTest extends GridCommonAbstractTest {
 
         return new String(buffer);
     }
+
+    /**
+     *
+     */
+    private static class AlwaysFailsComparator implements Comparator<Value> {
+        /** {@inheritDoc} */
+        @Override public int compare(Value o1, Value o2) {
+            throw new AssertionError("Optimized algorithm should be used.");
+        }
+    }
 }


Mime
View raw message