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 2022/06/09 09:05:47 UTC

[GitHub] [ignite] alex-plekhanov opened a new pull request, #10080: IGNITE-17046 Move H2RowComparator logic to the core module

alex-plekhanov opened a new pull request, #10080:
URL: https://github.com/apache/ignite/pull/10080

   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-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] 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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r913466968


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/types/BooleanInlineIndexKeyType.java:
##########
@@ -46,10 +48,15 @@ public BooleanInlineIndexKeyType() {
     }
 
     /** {@inheritDoc} */
-    @Override public int compare0(long pageAddr, int off, BooleanIndexKey key) {
+    @Override public boolean isComparableTo(IndexKey key) {
+        return key instanceof NumericIndexKey;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int compare0(long pageAddr, int off, IndexKey key) {
         boolean bool1 = PageUtils.getByte(pageAddr, off + 1) != 0;
 
-        return Integer.signum(Boolean.compare(bool1, (boolean)key.key()));
+        return -((NumericIndexKey)key).compareTo(bool1);

Review Comment:
   But `ObjectHashInlineIndexKeyType` is not a `NumericIndexKey`. All `NumericIndexKey`'s return -1, 0 or 1, so `Integer.signum()` is not required



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r913473469


##########
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java:
##########
@@ -265,7 +265,7 @@ private H2PkHashIndexCursor(Iterator<GridCursor<? extends CacheDataRow>> iter) {
         /** {@inheritDoc} */
         @Override public Row get() {
             try {
-                return desc.createRow(curr.get());
+                return new H2CacheRow(desc, curr.get());
             }
             catch (IgniteCheckedException e) {

Review Comment:
   `curr.get()` can throw `IgniteCheckedException`



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] timoninmaxim commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r915736684


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -98,68 +108,45 @@ public List<IndexColumn> getH2IdxColumns() {
 
     /** */
     private Object getKey(int idx, CacheDataRow row) {
-        int cacheIdx = h2IdxColumns.get(idx).column.getColumnId();

Review Comment:
   Why not? By `rowDesc.getFieldValue(row, idx)` I mean new non-existent method we can add to descriptor.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r915977421


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -98,68 +108,45 @@ public List<IndexColumn> getH2IdxColumns() {
 
     /** */
     private Object getKey(int idx, CacheDataRow row) {
-        int cacheIdx = h2IdxColumns.get(idx).column.getColumnId();
+        int colId = keyColumns.get(idx);
 
-        if (cacheDesc.isKeyColumn(cacheIdx))
-            return key(row);
+        if (rowDescriptor.isKeyColumn(colId))
+            return unwrap(row.key());
 
-        else if (cacheDesc.isValueColumn(cacheIdx))
-            return value(row);
+        else if (rowDescriptor.isValueColumn(colId))
+            return unwrap(row.value());
 
-        // columnValue ignores default columns (_KEY, _VAL), so make this shift.
-        return cacheDesc.columnValue(row.key(), row.value(), cacheIdx - QueryUtils.DEFAULT_COLUMNS_COUNT);
+        // getFieldValue ignores default columns (_KEY, _VAL), so make this shift.
+        return rowDescriptor.getFieldValue(row.key(), row.value(), colId - QueryUtils.DEFAULT_COLUMNS_COUNT);
     }
 
     /** {@inheritDoc} */
     @Override public int partition(CacheDataRow row) {
-        Object key = key(row);
+        Object key = unwrap(row.key());
 
-        return cacheDesc.context().affinity().partition(key);
+        return rowDescriptor.context().affinity().partition(key);

Review Comment:
   I'm not sure KeyCacheObject always has precalculated partition here. I can try to change it and run TC, if there will be no failures we can leave this change, but it still risky.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] timoninmaxim commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r915540208


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/DateTimeIndexKey.java:
##########
@@ -0,0 +1,31 @@
+/*
+ * 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.cache.query.index.sorted.keys;
+
+/**
+ * Class that represnts a numeric index key.

Review Comment:
   Not numeric, but date/time.



##########
modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryAllTypesTest.java:
##########
@@ -286,20 +290,79 @@ public void testBoolField() {
         check(cache.query(qry), 0, CNT / 2 + 1, valGen, persGen);
     }
 
+    /** */
+    @Test
+    public void testRangeCrossTypeConvertion() {
+        int cnt = 100;

Review Comment:
   Let's add also a test for cases that is out of default range. As we discussed (byteKey vs (int)1000) and similar. 



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexDefinition.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.cache.query.index.sorted;
+
+import java.util.LinkedHashMap;
+import org.apache.ignite.internal.cache.query.index.IndexName;
+import org.apache.ignite.internal.processors.query.GridQueryRowDescriptor;
+
+/**
+ * Define query index.
+ */
+public class QueryIndexDefinition implements SortedIndexDefinition {
+    /** Wrapped key definitions. */
+    private final LinkedHashMap<String, IndexKeyDefinition> keyDefs;
+
+    /** Table row descriptor. */
+    private final GridQueryRowDescriptor rowDescriptor;
+
+    /** Index name. */
+    private final IndexName idxName;
+
+    /** Index tree name. */
+    private final String treeName;
+
+    /** Configured inline size. */
+    private final int inlineSize;
+
+    /** Segments. */
+    private final int segments;
+
+    /** Whether this index is primary key (unique) or not. */
+    private final boolean isPrimary;
+
+    /** Whether this index is affinity key index or not. */
+    private final boolean isAffinity;
+
+    /** Index row comparator. */
+    private final IndexRowComparator rowComparator;

Review Comment:
   Do we actually need interface `IndexRowComparator`? Now there is a single implementation of it within the same module.



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyType.java:
##########
@@ -90,6 +91,13 @@ public interface InlineIndexKeyType {
      */
     public int compare(long pageAddr, int off, int maxSize, IndexKey v);
 
+    /**
+     * @return {@code True} if inlined value can be compared to index key .

Review Comment:
   whitespace before the dot.



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -98,68 +108,45 @@ public List<IndexColumn> getH2IdxColumns() {
 
     /** */
     private Object getKey(int idx, CacheDataRow row) {
-        int cacheIdx = h2IdxColumns.get(idx).column.getColumnId();

Review Comment:
   Can we replace it with `rowDesc.getFieldValue(row, idx)`? Looks like this method just invokes different methods of descriptor multiple times.



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -15,70 +15,80 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.internal.processors.query.h2.index;
+package org.apache.ignite.internal.cache.query.index.sorted;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import org.apache.ignite.internal.binary.BinaryObjectImpl;
-import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition;
-import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings;
-import org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler;
 import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType;
 import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
 import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKeyFactory;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
+import org.apache.ignite.internal.processors.query.GridQueryRowDescriptor;
 import org.apache.ignite.internal.processors.query.QueryUtils;
-import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor;
-import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
-import org.h2.table.IndexColumn;
 
-/** Maps CacheDataRow to IndexRow using H2 columns references. */
+/** Maps CacheDataRow to IndexRow using columns references. */
 public class QueryIndexRowHandler implements InlineIndexRowHandler {
     /** Cache descriptor. */
-    private final GridH2RowDescriptor cacheDesc;
+    private final GridQueryRowDescriptor rowDescriptor;
 
-    /** H2 index columns. */
-    private final List<IndexColumn> h2IdxColumns;
+    /** Index to columns references. */
+    private volatile List<Integer> keyColumns;

Review Comment:
   Do we have already another level of sync here? I suppose in case of altering columns all query threads should be locked before updating Index and unlocked after invoking `onMetadataUpdated()`? Otherwise it may not be thread-safe and then throw `ArraysOutOfBoundException` in `GridQueryRowDescriptorImpl#getFieldValue`. Then we don't need additional sync here. Am I missing something?
   
   



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r914084628


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryRowDescriptor.java:
##########
@@ -56,13 +48,13 @@ public class GridH2RowDescriptor {
     private volatile String[] fields;
 
     /** */
-    private volatile int[] fieldTypes;
+    private volatile IndexKeyType[] fieldTypes;

Review Comment:
   New wrapper H2 row descriptor created instead 



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r913470344


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowCompartorImpl.java:
##########
@@ -81,15 +81,22 @@ private boolean sameType(IndexKey key, int idxType) {
     }
 
     /** */
-    private int compare(IndexKey lkey, IndexKey rkey) {
-        if (lkey == NullIndexKey.INSTANCE)
-            return lkey.compare(rkey);
-        else if (rkey == NullIndexKey.INSTANCE)
-            return 1;
-
-        if (lkey.type() == rkey.type())
-            return lkey.compare(rkey);
+    private int compare(IndexKey lkey, IndexKey rkey) throws IgniteCheckedException {
+        try {
+            if (lkey == NullIndexKey.INSTANCE)
+                return lkey.compare(rkey);
+            else if (rkey == NullIndexKey.INSTANCE)
+                return 1;
+
+            if (lkey.isComparableTo(rkey))
+                return lkey.compare(rkey);
+            else if (rkey.isComparableTo(lkey))
+                return -rkey.compare(lkey);
+        }
+        catch (RuntimeException e) {

Review Comment:
   There is exception handling logic up in the stack, where runtime exceptions trigger failure handler, so checked exception required here.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] timoninmaxim commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r913545731


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowCompartorImpl.java:
##########
@@ -81,15 +81,22 @@ private boolean sameType(IndexKey key, int idxType) {
     }
 
     /** */
-    private int compare(IndexKey lkey, IndexKey rkey) {
-        if (lkey == NullIndexKey.INSTANCE)
-            return lkey.compare(rkey);
-        else if (rkey == NullIndexKey.INSTANCE)
-            return 1;
-
-        if (lkey.type() == rkey.type())
-            return lkey.compare(rkey);
+    private int compare(IndexKey lkey, IndexKey rkey) throws IgniteCheckedException {
+        try {
+            if (lkey == NullIndexKey.INSTANCE)
+                return lkey.compare(rkey);
+            else if (rkey == NullIndexKey.INSTANCE)
+                return 1;
+
+            if (lkey.isComparableTo(rkey))
+                return lkey.compare(rkey);
+            else if (rkey.isComparableTo(lkey))
+                return -rkey.compare(lkey);
+        }
+        catch (RuntimeException e) {

Review Comment:
   Is the reason for it is that `H2ValueIndexKey#compare` wraps `IgniteCheckedException` to `RuntimeException`, and in this point you wraps it again to checked exception. Looks weird, should we just add `IgniteCheckedException` to `compare` signature instead?
   



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] timoninmaxim commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r915958357


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -98,68 +108,45 @@ public List<IndexColumn> getH2IdxColumns() {
 
     /** */
     private Object getKey(int idx, CacheDataRow row) {
-        int cacheIdx = h2IdxColumns.get(idx).column.getColumnId();
+        int colId = keyColumns.get(idx);
 
-        if (cacheDesc.isKeyColumn(cacheIdx))
-            return key(row);
+        if (rowDescriptor.isKeyColumn(colId))
+            return unwrap(row.key());
 
-        else if (cacheDesc.isValueColumn(cacheIdx))
-            return value(row);
+        else if (rowDescriptor.isValueColumn(colId))
+            return unwrap(row.value());
 
-        // columnValue ignores default columns (_KEY, _VAL), so make this shift.
-        return cacheDesc.columnValue(row.key(), row.value(), cacheIdx - QueryUtils.DEFAULT_COLUMNS_COUNT);
+        // getFieldValue ignores default columns (_KEY, _VAL), so make this shift.
+        return rowDescriptor.getFieldValue(row.key(), row.value(), colId - QueryUtils.DEFAULT_COLUMNS_COUNT);
     }
 
     /** {@inheritDoc} */
     @Override public int partition(CacheDataRow row) {
-        Object key = key(row);
+        Object key = unwrap(row.key());
 
-        return cacheDesc.context().affinity().partition(key);
+        return rowDescriptor.context().affinity().partition(key);

Review Comment:
   We can use `KeyCacheObject` as parameter for the `partition(key)`? It is not necessary to unwrap object here.



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -98,68 +108,45 @@ public List<IndexColumn> getH2IdxColumns() {
 
     /** */
     private Object getKey(int idx, CacheDataRow row) {

Review Comment:
   There is a single usage, let's inline this method.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r915628534


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexDefinition.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.cache.query.index.sorted;
+
+import java.util.LinkedHashMap;
+import org.apache.ignite.internal.cache.query.index.IndexName;
+import org.apache.ignite.internal.processors.query.GridQueryRowDescriptor;
+
+/**
+ * Define query index.
+ */
+public class QueryIndexDefinition implements SortedIndexDefinition {
+    /** Wrapped key definitions. */
+    private final LinkedHashMap<String, IndexKeyDefinition> keyDefs;
+
+    /** Table row descriptor. */
+    private final GridQueryRowDescriptor rowDescriptor;
+
+    /** Index name. */
+    private final IndexName idxName;
+
+    /** Index tree name. */
+    private final String treeName;
+
+    /** Configured inline size. */
+    private final int inlineSize;
+
+    /** Segments. */
+    private final int segments;
+
+    /** Whether this index is primary key (unique) or not. */
+    private final boolean isPrimary;
+
+    /** Whether this index is affinity key index or not. */
+    private final boolean isAffinity;
+
+    /** Index row comparator. */
+    private final IndexRowComparator rowComparator;

Review Comment:
   We don't need it, but from OOP point of view I think it's better to have interface even for single implementation.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r914489670


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowCompartorImpl.java:
##########
@@ -81,15 +81,22 @@ private boolean sameType(IndexKey key, int idxType) {
     }
 
     /** */
-    private int compare(IndexKey lkey, IndexKey rkey) {
-        if (lkey == NullIndexKey.INSTANCE)
-            return lkey.compare(rkey);
-        else if (rkey == NullIndexKey.INSTANCE)
-            return 1;
-
-        if (lkey.type() == rkey.type())
-            return lkey.compare(rkey);
+    private int compare(IndexKey lkey, IndexKey rkey) throws IgniteCheckedException {
+        try {
+            if (lkey == NullIndexKey.INSTANCE)
+                return lkey.compare(rkey);
+            else if (rkey == NullIndexKey.INSTANCE)
+                return 1;
+
+            if (lkey.isComparableTo(rkey))
+                return lkey.compare(rkey);
+            else if (rkey.isComparableTo(lkey))
+                return -rkey.compare(lkey);
+        }
+        catch (RuntimeException e) {

Review Comment:
   Yes, but there still can be some runtime exceptions (for example NumberFormatException) in compare method and wrapping of RuntimeExceptions to IgniteCheckedExceptions is still required.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r915634265


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -98,68 +108,45 @@ public List<IndexColumn> getH2IdxColumns() {
 
     /** */
     private Object getKey(int idx, CacheDataRow row) {
-        int cacheIdx = h2IdxColumns.get(idx).column.getColumnId();

Review Comment:
   `columnsCnt = fieldsCnt + 2`, first two columns are mapped to _KEY and _VAL fields, which can't be retrieved by `getFieldValue`. 



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] timoninmaxim commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r913498431


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/types/BooleanInlineIndexKeyType.java:
##########
@@ -46,10 +48,15 @@ public BooleanInlineIndexKeyType() {
     }
 
     /** {@inheritDoc} */
-    @Override public int compare0(long pageAddr, int off, BooleanIndexKey key) {
+    @Override public boolean isComparableTo(IndexKey key) {
+        return key instanceof NumericIndexKey;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int compare0(long pageAddr, int off, IndexKey key) {
         boolean bool1 = PageUtils.getByte(pageAddr, off + 1) != 0;
 
-        return Integer.signum(Boolean.compare(bool1, (boolean)key.key()));
+        return -((NumericIndexKey)key).compareTo(bool1);

Review Comment:
   > All NumericIndexKey's return -1, 0 or 1
   
   As I can see it's not guaranteed. `BooleanIndexKey#compareTo(boolean)` leads to `Boolean.compare` that has docs:
   
   > Returns: the value 0 if x == y; a value less than 0 if !x && y; and a value greater than 0 if x && !y
   
   AFAIU, it means it may return different value for different implementations of java. It is not guaranteed that it will be "-1" or "1" everywhere - just negative or positive.
   
   But our docs for `NullableInlineIndexKeyType#compare0` strictly describes possible return values.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] alex-plekhanov commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r915933508


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -15,70 +15,80 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.internal.processors.query.h2.index;
+package org.apache.ignite.internal.cache.query.index.sorted;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import org.apache.ignite.internal.binary.BinaryObjectImpl;
-import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition;
-import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings;
-import org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandler;
 import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType;
 import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
 import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKeyFactory;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
+import org.apache.ignite.internal.processors.query.GridQueryRowDescriptor;
 import org.apache.ignite.internal.processors.query.QueryUtils;
-import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor;
-import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
-import org.h2.table.IndexColumn;
 
-/** Maps CacheDataRow to IndexRow using H2 columns references. */
+/** Maps CacheDataRow to IndexRow using columns references. */
 public class QueryIndexRowHandler implements InlineIndexRowHandler {
     /** Cache descriptor. */
-    private final GridH2RowDescriptor cacheDesc;
+    private final GridQueryRowDescriptor rowDescriptor;
 
-    /** H2 index columns. */
-    private final List<IndexColumn> h2IdxColumns;
+    /** Index to columns references. */
+    private volatile List<Integer> keyColumns;

Review Comment:
   Here is the same sync as it was before change (lock on GridH2Table, but I'm not sure it protects from problems during index scan).
   Now I've added direct mapping to properties, it's safer in concurrent environment. 



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] timoninmaxim commented on a diff in pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
timoninmaxim commented on code in PR #10080:
URL: https://github.com/apache/ignite/pull/10080#discussion_r912962497


##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowCompartorImpl.java:
##########
@@ -81,15 +81,22 @@ private boolean sameType(IndexKey key, int idxType) {
     }
 
     /** */
-    private int compare(IndexKey lkey, IndexKey rkey) {
-        if (lkey == NullIndexKey.INSTANCE)
-            return lkey.compare(rkey);
-        else if (rkey == NullIndexKey.INSTANCE)
-            return 1;
-
-        if (lkey.type() == rkey.type())
-            return lkey.compare(rkey);
+    private int compare(IndexKey lkey, IndexKey rkey) throws IgniteCheckedException {
+        try {
+            if (lkey == NullIndexKey.INSTANCE)
+                return lkey.compare(rkey);
+            else if (rkey == NullIndexKey.INSTANCE)
+                return 1;
+
+            if (lkey.isComparableTo(rkey))
+                return lkey.compare(rkey);
+            else if (rkey.isComparableTo(lkey))
+                return -rkey.compare(lkey);
+        }
+        catch (RuntimeException e) {

Review Comment:
   Why do we need handle runtime exceptions here?



##########
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2PkHashIndex.java:
##########
@@ -265,7 +265,7 @@ private H2PkHashIndexCursor(Iterator<GridCursor<? extends CacheDataRow>> iter) {
         /** {@inheritDoc} */
         @Override public Row get() {
             try {
-                return desc.createRow(curr.get());
+                return new H2CacheRow(desc, curr.get());
             }
             catch (IgniteCheckedException e) {

Review Comment:
   No exceptions now



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryRowDescriptor.java:
##########
@@ -56,13 +48,13 @@ public class GridH2RowDescriptor {
     private volatile String[] fields;
 
     /** */
-    private volatile int[] fieldTypes;
+    private volatile IndexKeyType[] fieldTypes;

Review Comment:
   Let's rename IndexKeyType to FieldType or smth similar. This collection isn't about index fields.



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/QueryIndexRowHandler.java:
##########
@@ -54,31 +49,44 @@ public class QueryIndexRowHandler implements InlineIndexRowHandler {
     /** Index key type settings. */
     private final IndexKeyTypeSettings keyTypeSettings;
 
-    /** H2 Table. */
-    private final GridH2Table h2Table;
-
     /** */
-    public QueryIndexRowHandler(GridH2Table h2table, List<IndexColumn> h2IdxColumns,
-        LinkedHashMap<String, IndexKeyDefinition> keyDefs, List<InlineIndexKeyType> keyTypes, IndexKeyTypeSettings keyTypeSettings) {
-        this.h2IdxColumns = h2IdxColumns;
-        this.keyTypes = keyTypes;
+    public QueryIndexRowHandler(
+        GridQueryRowDescriptor rowDescriptor,
+        LinkedHashMap<String, IndexKeyDefinition> keyDefs,
+        List<InlineIndexKeyType> keyTypes,
+        IndexKeyTypeSettings keyTypeSettings
+    ) {
+        this.keyTypes = Collections.unmodifiableList(keyTypes);
         this.keyDefs = Collections.unmodifiableList(new ArrayList<>(keyDefs.values()));
-        this.h2Table = h2table;
-        cacheDesc = h2table.rowDescriptor();
+        this.rowDescriptor = rowDescriptor;
         this.keyTypeSettings = keyTypeSettings;
+
+        List<Integer> keyColumns = new ArrayList<>(keyDefs.size());
+        List<String> fields = new ArrayList<>(rowDescriptor.type().fields().keySet());
+
+        for (String fieldName : keyDefs.keySet()) {
+            if (QueryUtils.KEY_FIELD_NAME.equals(fieldName))

Review Comment:
   Let's move this logic inside `GridQueryRowDescriptor`, it already have similar methods. Also let's move logic of `QueryIndexRowHandler#getKey` to the descriptor too.



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/IndexProcessor.java:
##########
@@ -527,14 +529,35 @@ public void destroyOrphanIndex(
         tree.destroy();
     }
 
+    /**
+     * @return {@code true} In case of use an unwrapped PK for the index.
+     */
+    public boolean useUnwrappedPk(GridCacheContext<?, ?> cctx, String treeName) {
+        IgniteCacheDatabaseSharedManager db = cctx.shared().database();
+        db.checkpointReadLock();
+
+        try {
+            RootPage page = cctx.offheap().findRootPageForIndex(cctx.cacheId(), treeName, 0);
+
+            return page == null || metaPageInfo(page, cctx.groupId(), cctx.dataRegion().pageMemory()).useUnwrappedPk();
+        }
+        catch (IgniteCheckedException ignore) {
+            return true;
+        }
+        finally {
+            db.checkpointReadUnlock();
+        }
+
+    }
+
     /**
      * @param page Root page.
      * @param grpId Cache group id.
      * @param pageMemory Page memory.
-     * @return Inline size.
+     * @return Meta page info.
      * @throws IgniteCheckedException If something went wrong.
      */
-    private int inlineSize(RootPage page, int grpId, PageMemory pageMemory) throws IgniteCheckedException {
+    private MetaPageInfo metaPageInfo(RootPage page, int grpId, PageMemory pageMemory) throws IgniteCheckedException {

Review Comment:
   Currently we have 2 similar methods for getting MetaPageInfo. One is here `IndexProcessor#metaPageInfo`, and another one is in `InlineIndexTree#metaInfo`. Let's use single one instead.



##########
modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2ValueIndexKey.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.h2.database;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType;
+import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
+import org.apache.ignite.internal.processors.cache.CacheObjectValueContext;
+import org.apache.ignite.internal.processors.query.h2.H2Utils;
+import org.h2.table.Table;
+import org.h2.value.Value;
+
+/**
+ * Index key wrapped over H2 Value.
+ */
+public class H2ValueIndexKey implements IndexKey {
+    /** */
+    private final CacheObjectValueContext coCtx;
+
+    /** */
+    private final Table table;
+
+    /** */
+    private final Value val;
+
+    /** */
+    public H2ValueIndexKey(CacheObjectValueContext coCtx, Table table, Value val) {
+        this.coCtx = coCtx;
+        this.table = table;
+        this.val = val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object key() {
+        return val.getObject();
+    }
+
+    /** {@inheritDoc} */
+    @Override public IndexKeyType type() {
+        return IndexKeyType.forCode(val.getType());
+    }
+
+    /** {@inheritDoc} */
+    @Override public int compare(IndexKey o) {
+        try {
+            return compareValues(val, H2Utils.wrap(coCtx, o.key(), o.type().code()));
+        }
+        catch (IgniteCheckedException e) {
+            throw new IgniteException(e);
+        }
+    }
+
+    /**
+     * @param v1 First value.
+     * @param v2 Second value.
+     * @return Comparison result.
+     */
+    public int compareValues(Value v1, Value v2) {

Review Comment:
   private



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/keys/IndexKey.java:
##########
@@ -29,12 +29,19 @@ public interface IndexKey {
     public Object key();
 
     /**
-     * @return Index key type {@link IndexKeyTypes}.
+     * @return Index key type {@link IndexKeyType}.
      */
-    public int type();
+    public IndexKeyType type();
 
     /**
      * @return Comparison result with other IndexKey the same type.

Review Comment:
   Now `the same type` isn't true. Let's fix the docs



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/types/BooleanInlineIndexKeyType.java:
##########
@@ -46,10 +48,15 @@ public BooleanInlineIndexKeyType() {
     }
 
     /** {@inheritDoc} */
-    @Override public int compare0(long pageAddr, int off, BooleanIndexKey key) {
+    @Override public boolean isComparableTo(IndexKey key) {
+        return key instanceof NumericIndexKey;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int compare0(long pageAddr, int off, IndexKey key) {
         boolean bool1 = PageUtils.getByte(pageAddr, off + 1) != 0;
 
-        return Integer.signum(Boolean.compare(bool1, (boolean)key.key()));
+        return -((NumericIndexKey)key).compareTo(bool1);

Review Comment:
   It's required here to return `Integer.signum()`. `Comparable#compareTo` doesn't specify return values, it just describe them as "positive" and "negative". But we have different logic in inline comparison for values "-1" and "-2". 



##########
modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/types/BooleanInlineIndexKeyType.java:
##########
@@ -46,10 +48,15 @@ public BooleanInlineIndexKeyType() {
     }
 
     /** {@inheritDoc} */
-    @Override public int compare0(long pageAddr, int off, BooleanIndexKey key) {
+    @Override public boolean isComparableTo(IndexKey key) {
+        return key instanceof NumericIndexKey;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int compare0(long pageAddr, int off, IndexKey key) {
         boolean bool1 = PageUtils.getByte(pageAddr, off + 1) != 0;
 
-        return Integer.signum(Boolean.compare(bool1, (boolean)key.key()));
+        return -((NumericIndexKey)key).compareTo(bool1);

Review Comment:
   see `ObjectHashInlineIndexKeyType#compare0`.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite] asfgit closed pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #10080: IGNITE-17046 Move H2RowComparator logic to the core module
URL: https://github.com/apache/ignite/pull/10080


-- 
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: notifications-unsubscribe@ignite.apache.org

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