You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ti...@apache.org on 2021/12/14 14:23:13 UTC

[ignite] branch master updated: IGNITE-14945 IndexQuery uses inline IO for index rows filtering (#9631)

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

timoninmaxim 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 d4c702c  IGNITE-14945 IndexQuery uses inline IO for index rows filtering (#9631)
d4c702c is described below

commit d4c702cde9dae780c861b8c038c1c9f1281083d5
Author: Maksim Timonin <ti...@gmail.com>
AuthorDate: Tue Dec 14 17:21:09 2021 +0300

    IGNITE-14945 IndexQuery uses inline IO for index rows filtering (#9631)
---
 .../cache/query/index/IndexQueryProcessor.java     | 260 ++++++++++++++-------
 .../query/index/sorted/IndexKeyDefinition.java     |  12 -
 .../query/index/sorted/IndexRowComparator.java     |   9 +-
 .../query/index/sorted/IndexRowCompartorImpl.java  |  32 ++-
 .../index/sorted/inline/IndexQueryContext.java     |  33 ++-
 .../query/index/sorted/inline/InlineIndexImpl.java |   6 +-
 .../index/sorted/inline/InlineIndexKeyType.java    |   8 +-
 .../query/index/sorted/inline/InlineIndexTree.java |  40 +---
 .../sorted/inline/InlineTreeFilterClosure.java     |  39 +++-
 .../cache/persistence/tree/BPlusTree.java          |   3 +-
 .../cache/query/reducer/IndexQueryReducer.java     |   2 +-
 .../processors/query/GridQueryProcessor.java       |  14 +-
 .../processors/query/h2/database/H2TreeIndex.java  |   2 +-
 .../processors/query/h2/index/H2RowComparator.java |  16 +-
 .../cache/query/IndexQueryInlineSizesTest.java     | 206 ++++++++++++++++
 .../ignite/cache/query/IndexQueryTestSuite.java    |   1 +
 16 files changed, 505 insertions(+), 178 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/IndexQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/IndexQueryProcessor.java
index b812cf6..89dbe4b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/IndexQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/IndexQueryProcessor.java
@@ -23,6 +23,7 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.PriorityQueue;
@@ -43,12 +44,16 @@ import org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition
 import org.apache.ignite.internal.cache.query.index.sorted.SortedSegmentedIndex;
 import org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext;
 import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexImpl;
+import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType;
+import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree;
 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.CacheObjectUtils;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree;
+import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO;
 import org.apache.ignite.internal.processors.cache.query.IndexQueryDesc;
 import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.util.GridCloseableIteratorAdapter;
@@ -57,9 +62,12 @@ import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.lang.IgniteBiPredicate;
 import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.spi.indexing.IndexingQueryFilter;
 import org.jetbrains.annotations.Nullable;
 
 import static org.apache.ignite.internal.cache.query.index.SortOrder.DESC;
+import static org.apache.ignite.internal.cache.query.index.sorted.inline.types.NullableInlineIndexKeyType.CANT_BE_COMPARE;
+import static org.apache.ignite.internal.cache.query.index.sorted.inline.types.NullableInlineIndexKeyType.COMPARE_UNSUPPORTED;
 
 /**
  * Processor of {@link IndexQuery}.
@@ -82,14 +90,14 @@ public class IndexQueryProcessor {
         GridCacheContext<K, V> cctx,
         IndexQueryDesc idxQryDesc,
         @Nullable IgniteBiPredicate<K, V> filter,
-        IndexQueryContext qryCtx,
+        IndexingQueryFilter cacheFilter,
         boolean keepBinary
     ) throws IgniteCheckedException {
         SortedSegmentedIndex idx = findSortedIndex(cctx, idxQryDesc);
 
         IndexRangeQuery qry = prepareQuery(idx, idxQryDesc);
 
-        GridCursor<IndexRow> cursor = querySortedIndex(cctx, idx, qryCtx, qry);
+        GridCursor<IndexRow> cursor = querySortedIndex(cctx, idx, cacheFilter, qry);
 
         SortedIndexDefinition def = (SortedIndexDefinition)idxProc.indexDefinition(idx.id());
 
@@ -477,11 +485,24 @@ public class IndexQueryProcessor {
     private GridCursor<IndexRow> querySortedIndex(
         GridCacheContext<?, ?> cctx,
         SortedSegmentedIndex idx,
-        IndexQueryContext qryCtx,
+        IndexingQueryFilter cacheFilter,
         IndexRangeQuery qry
     ) throws IgniteCheckedException {
         int segmentsCnt = cctx.isPartitioned() ? cctx.config().getQueryParallelism() : 1;
 
+        BPlusTree.TreeRowClosure<IndexRow, IndexRow> treeFilter = null;
+
+        // No need in the additional filter step for queries with 0 or 1 criteria.
+        // Also skips filtering if the current search is unbounded (both boundaries equal to null).
+        if (qry.criteria.length > 1 && !(qry.lower == null && qry.upper == null)) {
+            LinkedHashMap<String, IndexKeyDefinition> idxDef = idxProc.indexDefinition(idx.id()).indexKeyDefinitions();
+
+            treeFilter = new IndexQueryCriteriaClosure(
+                qry, idxDef, ((SortedIndexDefinition)idxProc.indexDefinition(idx.id())).rowComparator());
+        }
+
+        IndexQueryContext qryCtx = new IndexQueryContext(cacheFilter, treeFilter, null);
+
         if (segmentsCnt == 1)
             return treeIndexRange(idx, 0, qry, qryCtx);
 
@@ -507,83 +528,10 @@ public class IndexQueryProcessor {
     private GridCursor<IndexRow> treeIndexRange(SortedSegmentedIndex idx, int segment, IndexRangeQuery qry, IndexQueryContext qryCtx)
         throws IgniteCheckedException {
 
-        LinkedHashMap<String, IndexKeyDefinition> idxDef = idxProc.indexDefinition(idx.id()).indexKeyDefinitions();
-
         boolean lowIncl = inclBoundary(qry, true);
         boolean upIncl = inclBoundary(qry, false);
 
-        // Step 1. Traverse index and find index boundaries.
-        GridCursor<IndexRow> findRes = idx.find(qry.lower, qry.upper, lowIncl, upIncl, segment, qryCtx);
-
-        // No need in the additional filter step for queries with 0 or 1 criteria.
-        if (qry.criteria.length <= 1)
-            return findRes;
-
-        // Step 2. Filter range if the criteria apply to multiple fields.
-        return new GridCursor<IndexRow>() {
-            /** */
-            private final IndexRowComparator rowCmp = ((SortedIndexDefinition)idxProc.indexDefinition(idx.id())).rowComparator();
-
-            /** {@inheritDoc} */
-            @Override public boolean next() throws IgniteCheckedException {
-                if (!findRes.next())
-                    return false;
-
-                while (rowIsOutOfRange(get(), qry.lower, qry.upper)) {
-                    if (!findRes.next())
-                        return false;
-                }
-
-                return true;
-            }
-
-            /** {@inheritDoc} */
-            @Override public IndexRow get() throws IgniteCheckedException {
-                return findRes.get();
-            }
-
-            /**
-             * Checks that {@code row} belongs to the range specified with {@code lower} and {@code upper}.
-             *
-             * @return {@code true} if the row doesn't belong the range, otherwise {@code false}.
-             */
-            private boolean rowIsOutOfRange(IndexRow row, IndexRow low, IndexRow high) throws IgniteCheckedException {
-                if (low == null && high == null)
-                    return false;  // Unbounded search, include all.
-
-                int criteriaKeysCnt = qry.criteria.length;
-
-                for (int i = 0; i < criteriaKeysCnt; i++) {
-                    RangeIndexQueryCriterion c = qry.criteria[i];
-
-                    boolean descOrder = idxDef.get(c.field()).order().sortOrder() == DESC;
-
-                    if (low != null && low.key(i) != null) {
-                        int cmp = rowCmp.compareRow(row, low, i);
-
-                        if (cmp == 0) {
-                            if (!c.lowerIncl())
-                                return true;  // Exclude if field equals boundary field and criteria is excluding.
-                        }
-                        else if ((cmp < 0) ^ descOrder)
-                            return true;  // Out of bound. Either below 'low' margin or column with desc order.
-                    }
-
-                    if (high != null && high.key(i) != null) {
-                        int cmp = rowCmp.compareRow(row, high, i);
-
-                        if (cmp == 0) {
-                            if (!c.upperIncl())
-                                return true;  // Exclude if field equals boundary field and criteria is excluding.
-                        }
-                        else if ((cmp > 0) ^ descOrder)
-                            return true;  // Out of bound. Either above 'high' margin or column with desc order.
-                    }
-                }
-
-                return false;
-            }
-        };
+        return idx.find(qry.lower, qry.upper, lowIncl, upIncl, segment, qryCtx);
     }
 
     /**
@@ -650,7 +598,6 @@ public class IndexQueryProcessor {
                         }
 
                         return 0;
-
                     } catch (IgniteCheckedException e) {
                         throw new IgniteException("Failed to sort remote index rows", e);
                     }
@@ -674,7 +621,7 @@ public class IndexQueryProcessor {
 
             head = c.get();
 
-            if (c != null && c.next())
+            if (c.next())
                 cursors.add(c);
 
             return true;
@@ -687,6 +634,108 @@ public class IndexQueryProcessor {
     }
 
     /**
+     * Checks index rows for matching to specified index criteria.
+     */
+    private static class IndexQueryCriteriaClosure implements BPlusTree.TreeRowClosure<IndexRow, IndexRow> {
+        /** */
+        private final IndexRangeQuery qry;
+
+        /** */
+        private final IndexRowComparator rowCmp;
+
+        /** */
+        private final boolean[] descOrderCache;
+
+        /** */
+        IndexQueryCriteriaClosure(
+            IndexRangeQuery qry,
+            LinkedHashMap<String, IndexKeyDefinition> idxDef,
+            IndexRowComparator rowCmp
+        ) {
+            this.qry = qry;
+            this.rowCmp = rowCmp;
+            descOrderCache = new boolean[qry.criteria.length];
+
+            for (int i = 0; i < qry.criteria.length; i++) {
+                RangeIndexQueryCriterion c = qry.criteria[i];
+
+                descOrderCache[i] = idxDef.get(c.field()).order().sortOrder() == DESC;
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean apply(
+            BPlusTree<IndexRow, IndexRow> tree,
+            BPlusIO<IndexRow> io,
+            long pageAddr,
+            int idx
+        ) throws IgniteCheckedException {
+            return !rowIsOutOfRange((InlineIndexTree)tree, io, pageAddr, idx, qry.lower, qry.upper);
+        }
+
+        /**
+         * Checks that {@code row} belongs to the range specified with {@code low} and {@code high}.
+         *
+         * @return {@code true} if the row doesn't belong the range, otherwise {@code false}.
+         */
+        private boolean rowIsOutOfRange(
+            InlineIndexTree tree,
+            BPlusIO<IndexRow> io,
+            long pageAddr,
+            int idx,
+            IndexRow low,
+            IndexRow high
+        ) throws IgniteCheckedException {
+            int criteriaKeysCnt = qry.criteria.length;
+
+            int off = io.offset(idx);
+
+            int fieldOff = 0;
+
+            InlineIndexRow currRow = new InlineIndexRow(tree, io, pageAddr, idx);
+
+            List<InlineIndexKeyType> keyTypes = tree.rowHandler().inlineIndexKeyTypes();
+
+            for (int keyIdx = 0; keyIdx < criteriaKeysCnt; keyIdx++) {
+                RangeIndexQueryCriterion c = qry.criteria[keyIdx];
+
+                InlineIndexKeyType keyType = keyIdx < keyTypes.size() ? keyTypes.get(keyIdx) : null;
+
+                boolean descOrder = descOrderCache[keyIdx];
+
+                int maxSize = tree.inlineSize() - fieldOff;
+
+                if (low != null && low.key(keyIdx) != null) {
+                    int cmp = currRow.compare(rowCmp, low, keyIdx, off + fieldOff, maxSize, keyType);
+
+                    if (cmp == 0) {
+                        if (!c.lowerIncl())
+                            return true;  // Exclude if field equals boundary field and criteria is excluding.
+                    }
+                    else if ((cmp < 0) ^ descOrder)
+                        return true;  // Out of bound. Either below 'low' margin or column with desc order.
+                }
+
+                if (high != null && high.key(keyIdx) != null) {
+                    int cmp = currRow.compare(rowCmp, high, keyIdx, off + fieldOff, maxSize, keyType);
+
+                    if (cmp == 0) {
+                        if (!c.upperIncl())
+                            return true;  // Exclude if field equals boundary field and criteria is excluding.
+                    }
+                    else if ((cmp > 0) ^ descOrder)
+                        return true;  // Out of bound. Either above 'high' margin or column with desc order.
+                }
+
+                if (keyType != null)
+                    fieldOff += keyType.inlineSize(pageAddr, off + fieldOff);
+            }
+
+            return false;
+        }
+    }
+
+    /**
      * @return Modified description for criterion in case of error.
      */
     private static String rangeDesc(RangeIndexQueryCriterion c, String fldName, Object lower, Object upper) {
@@ -719,4 +768,57 @@ public class IndexQueryProcessor {
         /** */
         private IndexRow upper;
     }
+
+    /**
+     * Wrapper class over index row. It is suitable for comparison. It tries to check inlined keys first, and fetches a
+     * cache entry only if the inlined information is not full enough for comparison.
+     */
+    private static class InlineIndexRow {
+        /** */
+        private final long pageAddr;
+
+        /** */
+        private final int idx;
+
+        /** */
+        private final InlineIndexTree tree;
+
+        /** */
+        private final BPlusIO<IndexRow> io;
+
+        /** Set it for accessing keys from underlying cache entry. */
+        private IndexRow currRow;
+
+        /** */
+        private InlineIndexRow(InlineIndexTree tree, BPlusIO<IndexRow> io, long addr, int idx) {
+            pageAddr = addr;
+            this.idx = idx;
+            this.tree = tree;
+            this.io = io;
+        }
+
+        /** Compare using inline. {@code keyType} is {@code null} for non-inlined keys. */
+        private int compare(
+            IndexRowComparator rowCmp,
+            IndexRow o,
+            int keyIdx,
+            int off,
+            int maxSize,
+            @Nullable InlineIndexKeyType keyType
+        ) throws IgniteCheckedException {
+            if (currRow == null) {
+                int cmp = COMPARE_UNSUPPORTED;
+
+                if (keyType != null)
+                    cmp = rowCmp.compareKey(pageAddr, off, maxSize, o.key(keyIdx), keyType);
+
+                if (cmp == COMPARE_UNSUPPORTED || cmp == CANT_BE_COMPARE)
+                    currRow = tree.getRow(io, pageAddr, idx);
+                else
+                    return cmp;
+            }
+
+            return rowCmp.compareRow(currRow, o, keyIdx);
+        }
+    }
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexKeyDefinition.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexKeyDefinition.java
index e1699de..39a4230 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexKeyDefinition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexKeyDefinition.java
@@ -23,8 +23,6 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import org.apache.ignite.internal.cache.query.index.Order;
 import org.apache.ignite.internal.cache.query.index.SortOrder;
-import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
-import org.apache.ignite.internal.cache.query.index.sorted.keys.NullIndexKey;
 import org.apache.ignite.internal.util.typedef.internal.U;
 
 /**
@@ -75,16 +73,6 @@ public class IndexKeyDefinition implements Externalizable {
         return precision;
     }
 
-    /**
-     * @return {@code true} if specified key's type matches to the current type, otherwise {@code false}.
-     */
-    public boolean validate(IndexKey key) {
-        if (key == NullIndexKey.INSTANCE)
-            return true;
-
-        return idxType == key.type();
-    }
-
     /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
         // Send only required info for using in MergeSort algorithm.
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowComparator.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowComparator.java
index 25258a0..76c7ffa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowComparator.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowComparator.java
@@ -18,6 +18,8 @@
 package org.apache.ignite.internal.cache.query.index.sorted;
 
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType;
+import org.apache.ignite.internal.cache.query.index.sorted.inline.types.NullableInlineIndexKeyType;
 import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
 
 /**
@@ -25,15 +27,16 @@ import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
  */
 public interface IndexRowComparator {
     /**
-     * Compare index keys.
+     * Compare inlined index key with specified key. If it is impossible to compare inlined key, it returns special vals:
+     * {@code COMPARE_UNSUPPORTED} and {@code CANT_BE_COMPARE}, see {@link NullableInlineIndexKeyType}.
      *
      * @param pageAddr address of an index row.
      * @param off offset of an index key.
      * @param maxSize max size to read.
      * @param key key to compare with.
-     * @param curType type of index key.
+     * @param type inline type of index key.
      */
-    public int compareKey(long pageAddr, int off, int maxSize, IndexKey key, int curType) throws IgniteCheckedException;
+    public int compareKey(long pageAddr, int off, int maxSize, IndexKey key, InlineIndexKeyType type) throws IgniteCheckedException;
 
     /**
      * Compare index keys.
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowCompartorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowCompartorImpl.java
index f42a9ce..fa01dd5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowCompartorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/IndexRowCompartorImpl.java
@@ -19,6 +19,7 @@
 package org.apache.ignite.internal.cache.query.index.sorted;
 
 import org.apache.ignite.IgniteCheckedException;
+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.NullIndexKey;
 
@@ -33,18 +34,39 @@ import static org.apache.ignite.internal.cache.query.index.sorted.inline.types.N
  * 2. Comparison of different types is not supported.
  */
 public class IndexRowCompartorImpl implements IndexRowComparator {
+    /** Key type settings for this index. */
+    protected final IndexKeyTypeSettings keyTypeSettings;
+
+    /** */
+    public IndexRowCompartorImpl(IndexKeyTypeSettings settings) {
+        keyTypeSettings = settings;
+    }
+
     /** {@inheritDoc} */
-    @Override public int compareKey(long pageAddr, int off, int maxSize, IndexKey key, int curType) {
-        if (curType == IndexKeyTypes.UNKNOWN)
+    @Override public int compareKey(long pageAddr, int off, int maxSize, IndexKey key, InlineIndexKeyType type) {
+        if (type.type() == IndexKeyTypes.UNKNOWN)
             return CANT_BE_COMPARE;
 
-        if (key == NullIndexKey.INSTANCE)
-            return 1;
+        // Value can be set up by user in query with different data type. Don't compare different types in this comparator.
+        if (sameType(key, type.type())) {
+            // If inlining of POJO is not supported then don't compare it here.
+            if (type.type() != IndexKeyTypes.JAVA_OBJECT || keyTypeSettings.inlineObjSupported())
+                return type.compare(pageAddr, off, maxSize, key);
+            else
+                return CANT_BE_COMPARE;
+        }
 
-        // Check that types are different before that.
         return COMPARE_UNSUPPORTED;
     }
 
+    /** */
+    private boolean sameType(IndexKey key, int idxType) {
+        if (key == NullIndexKey.INSTANCE)
+            return true;
+
+        return idxType == key.type();
+    }
+
     /** {@inheritDoc} */
     @Override public int compareRow(IndexRow left, IndexRow right, int idx) throws IgniteCheckedException {
         return compare(left.key(idx), right.key(idx));
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/IndexQueryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/IndexQueryContext.java
index 99c6b81..2e27c70 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/IndexQueryContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/IndexQueryContext.java
@@ -17,21 +17,31 @@
 
 package org.apache.ignite.internal.cache.query.index.sorted.inline;
 
+import org.apache.ignite.internal.cache.query.index.sorted.IndexRow;
 import org.apache.ignite.internal.processors.cache.mvcc.MvccSnapshot;
+import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree;
 import org.apache.ignite.spi.indexing.IndexingQueryFilter;
 
 /** */
 public class IndexQueryContext {
-    /** Cache entry filter. */
-    private final IndexingQueryFilter filter;
+    /** Cache filter. */
+    private final IndexingQueryFilter cacheFilter;
+
+    /** Index rows filter. */
+    private final BPlusTree.TreeRowClosure<IndexRow, IndexRow> rowFilter;
 
     /** */
     private final MvccSnapshot mvccSnapshot;
 
     /** */
-    public IndexQueryContext(IndexingQueryFilter filter, MvccSnapshot snapshot) {
-        this.filter = filter;
-        this.mvccSnapshot = snapshot;
+    public IndexQueryContext(
+        IndexingQueryFilter cacheFilter,
+        BPlusTree.TreeRowClosure<IndexRow, IndexRow> rowFilter,
+        MvccSnapshot mvccSnapshot
+    ) {
+        this.cacheFilter = cacheFilter;
+        this.rowFilter = rowFilter;
+        this.mvccSnapshot = mvccSnapshot;
     }
 
     /**
@@ -42,9 +52,16 @@ public class IndexQueryContext {
     }
 
     /**
-     * @return Filter.
+     * @return Cache filter.
+     */
+    public IndexingQueryFilter cacheFilter() {
+        return cacheFilter;
+    }
+
+    /**
+     * @return Index row filter.
      */
-    public IndexingQueryFilter filter() {
-        return filter;
+    public BPlusTree.TreeRowClosure<IndexRow, IndexRow> rowFilter() {
+        return rowFilter;
     }
 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexImpl.java
index e320670..b93b3d0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexImpl.java
@@ -364,8 +364,8 @@ public class InlineIndexImpl extends AbstractIndex implements InlineIndex {
         if (qryCtx == null)
             return null;
 
-        IndexingQueryCacheFilter cacheFilter = qryCtx.filter() == null ? null
-            : qryCtx.filter().forCache(cctx.cache().name());
+        IndexingQueryCacheFilter cacheFilter = qryCtx.cacheFilter() == null ? null
+            : qryCtx.cacheFilter().forCache(cctx.cache().name());
 
         MvccSnapshot v = qryCtx.mvccSnapshot();
 
@@ -375,7 +375,7 @@ public class InlineIndexImpl extends AbstractIndex implements InlineIndex {
             return null;
 
         return new InlineTreeFilterClosure(
-            cacheFilter, v, cctx, cctx.kernalContext().config().getGridLogger());
+            cacheFilter, qryCtx.rowFilter(), v, cctx, cctx.kernalContext().config().getGridLogger());
     }
 
     /** {@inheritDoc} */
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyType.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyType.java
index b61b8a6..d6f90d1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyType.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexKeyType.java
@@ -64,12 +64,17 @@ public interface InlineIndexKeyType {
      * @param off Offset.
      * @param key Index key.
      * @param maxSize Max size.
-     *
      * @return Amount of bytes actually stored.
      */
     public int put(long pageAddr, int off, IndexKey key, int maxSize);
 
     /**
+     * Gets index key from inline index tree.
+     *
+     * @param pageAddr Page address.
+     * @param off Offset.
+     * @param maxSize Max size.
+     * @return Index key extracted from index tree.
      */
     @Nullable public IndexKey get(long pageAddr, int off, int maxSize);
 
@@ -80,7 +85,6 @@ public interface InlineIndexKeyType {
      * @param off Offset.
      * @param maxSize Max size.
      * @param v Value that should be compare.
-     *
      * @return -1, 0 or 1 if inlined value less, equal or greater
      * than given respectively, or -2 if inlined part is not enough to compare.
      */
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexTree.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexTree.java
index b87332d..fb99fb4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexTree.java
@@ -27,7 +27,6 @@ import org.apache.ignite.internal.cache.query.index.IndexName;
 import org.apache.ignite.internal.cache.query.index.SortOrder;
 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.IndexKeyTypes;
 import org.apache.ignite.internal.cache.query.index.sorted.IndexRow;
 import org.apache.ignite.internal.cache.query.index.sorted.IndexRowCache;
 import org.apache.ignite.internal.cache.query.index.sorted.IndexRowImpl;
@@ -78,9 +77,6 @@ public class InlineIndexTree extends BPlusTree<IndexRow, IndexRow> {
     /** Amount of bytes to store inlined index keys. */
     private final int inlineSize;
 
-    /** Index key type settings for this tree. */
-    private final IndexKeyTypeSettings keyTypeSettings;
-
     /** Recommends change inline size if needed. */
     private final InlineRecommender recommender;
 
@@ -192,8 +188,6 @@ public class InlineIndexTree extends BPlusTree<IndexRow, IndexRow> {
             setIos(inlineSize, mvccEnabled);
         }
 
-        this.keyTypeSettings = keyTypeSettings;
-
         initTree(initNew, inlineSize);
 
         this.recommender = recommender;
@@ -292,38 +286,18 @@ public class InlineIndexTree extends BPlusTree<IndexRow, IndexRow> {
 
                 InlineIndexKeyType keyType = keyTypes.get(keyIdx);
 
-                IndexKeyDefinition keyDef = keyDefs.get(keyIdx);
-
-                int cmp = COMPARE_UNSUPPORTED;
-
-                // Value can be set up by user in query with different data type.
-                // By default do not compare different types.
-                if (keyDef.validate(row.key(keyIdx))) {
-                    if (keyType.type() != IndexKeyTypes.JAVA_OBJECT || keyTypeSettings.inlineObjSupported()) {
-                        cmp = keyType.compare(pageAddr, off + fieldOff, maxSize, row.key(keyIdx));
-
-                        fieldOff += keyType.inlineSize(pageAddr, off + fieldOff);
-                    }
-                    // If inlining of POJO is not supported then fallback to previous logic.
-                    else
-                        break;
-                }
-
-                // Can't compare as inlined bytes are not enough for comparation.
-                if (cmp == CANT_BE_COMPARE)
-                    break;
-
-                // Try compare stored values for inlined keys with different approach?
-                if (cmp == COMPARE_UNSUPPORTED)
-                    cmp = def.rowComparator().compareKey(
-                        pageAddr, off + fieldOff, maxSize, row.key(keyIdx), keyType.type());
+                int cmp = def.rowComparator().compareKey(pageAddr, off + fieldOff, maxSize, row.key(keyIdx), keyType);
 
                 if (cmp == CANT_BE_COMPARE || cmp == COMPARE_UNSUPPORTED)
                     break;
+                else
+                    fieldOff += keyType.inlineSize(pageAddr, off + fieldOff);
 
-                if (cmp != 0)
-                    return applySortOrder(cmp, keyDef.order().sortOrder());
+                if (cmp != 0) {
+                    IndexKeyDefinition keyDef = keyDefs.get(keyIdx);
 
+                    return applySortOrder(cmp, keyDef.order().sortOrder());
+                }
             } catch (Exception e) {
                 throw new IgniteException("Failed to store new index row.", e);
             }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineTreeFilterClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineTreeFilterClosure.java
index a57395f..70618a0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineTreeFilterClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineTreeFilterClosure.java
@@ -45,20 +45,29 @@ public class InlineTreeFilterClosure implements BPlusTree.TreeRowClosure<IndexRo
     private final MvccSnapshot mvccSnapshot;
 
     /** */
-    private final IndexingQueryCacheFilter filter;
+    private final IndexingQueryCacheFilter cacheFilter;
 
     /** */
-    private final GridCacheContext cctx;
+    private final BPlusTree.TreeRowClosure<IndexRow, IndexRow> rowFilter;
+
+    /** */
+    private final GridCacheContext<?, ?> cctx;
 
     /** */
     private final IgniteLogger log;
 
     /** Constructor. */
-    public InlineTreeFilterClosure(IndexingQueryCacheFilter filter, MvccSnapshot mvccSnapshot,
-        GridCacheContext<?, ?> cctx, IgniteLogger log) {
-        assert (filter != null || mvccSnapshot != null) && cctx != null;
-
-        this.filter = filter;
+    public InlineTreeFilterClosure(
+        IndexingQueryCacheFilter cacheFilter,
+        BPlusTree.TreeRowClosure<IndexRow, IndexRow> rowFilter,
+        MvccSnapshot mvccSnapshot,
+        GridCacheContext<?, ?> cctx,
+        IgniteLogger log
+    ) {
+        assert (cacheFilter != null || mvccSnapshot != null) && cctx != null;
+
+        this.cacheFilter = cacheFilter;
+        this.rowFilter = rowFilter;
         this.mvccSnapshot = mvccSnapshot;
         this.cctx = cctx;
         this.log = log;
@@ -68,10 +77,16 @@ public class InlineTreeFilterClosure implements BPlusTree.TreeRowClosure<IndexRo
     @Override public boolean apply(BPlusTree<IndexRow, IndexRow> tree, BPlusIO<IndexRow> io,
         long pageAddr, int idx) throws IgniteCheckedException {
 
-        boolean val = filter == null || applyFilter((InlineIO)io, pageAddr, idx);
+        boolean val = cacheFilter == null || applyFilter((InlineIO)io, pageAddr, idx);
+
+        if (!val)
+            return false;
+
+        if (rowFilter != null)
+            val = rowFilter.apply(tree, io, pageAddr, idx);
 
-        if (mvccSnapshot != null)
-            return val && applyMvcc((InlineIO)io, pageAddr, idx);
+        if (!val && mvccSnapshot != null)
+            return applyMvcc((InlineIO)io, pageAddr, idx);
 
         return val;
     }
@@ -83,9 +98,9 @@ public class InlineTreeFilterClosure implements BPlusTree.TreeRowClosure<IndexRo
      * @return {@code True} if row passes the filter.
      */
     private boolean applyFilter(InlineIO io, long pageAddr, int idx) {
-        assert filter != null;
+        assert cacheFilter != null;
 
-        return filter.applyPartition(PageIdUtils.partId(pageId(io.link(pageAddr, idx))));
+        return cacheFilter.applyPartition(PageIdUtils.partId(pageId(io.link(pageAddr, idx))));
     }
 
     /**
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
index 4d769a0..6997ff5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java
@@ -1126,7 +1126,8 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure implements
         L upper,
         boolean lowIncl,
         boolean upIncl,
-        TreeRowClosure<L, T> c, Object x
+        TreeRowClosure<L, T> c,
+        Object x
     ) throws IgniteCheckedException {
         checkDestroyed();
 
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/IndexQueryReducer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/IndexQueryReducer.java
index 75ac0c4..c5956b2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/IndexQueryReducer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/reducer/IndexQueryReducer.java
@@ -96,7 +96,7 @@ public class IndexQueryReducer<R> extends MergeSortCacheQueryReducer<R> {
         private final IndexQueryResultMeta meta;
 
         /** Every node will return the same key types for the same index, then it's possible to use simple comparator. */
-        private final IndexRowComparator idxRowComp = new IndexRowCompartorImpl();
+        private final IndexRowComparator idxRowComp = new IndexRowCompartorImpl(null);
 
         /** */
         IndexedNodePageComparator(
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 461a559..392a8c2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -64,7 +64,6 @@ import org.apache.ignite.internal.binary.BinaryMetadata;
 import org.apache.ignite.internal.cache.query.index.IndexProcessor;
 import org.apache.ignite.internal.cache.query.index.IndexQueryProcessor;
 import org.apache.ignite.internal.cache.query.index.IndexQueryResult;
-import org.apache.ignite.internal.cache.query.index.sorted.inline.IndexQueryContext;
 import org.apache.ignite.internal.managers.communication.GridMessageListener;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
@@ -3369,8 +3368,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param cacheName Cache name.
      * @param valCls Cache value class.
      * @param idxQryDesc Index query description.
-     * @param filter Optional user defined cache entries filter.
-     * @param filters Ignite specific cache entries filters.
+     * @param entryFilter Optional user defined cache entries filter.
+     * @param cacheFilter Ignite specific cache entries filters.
      * @param keepBinary Keep binary flag.
      * @return Key/value rows.
      * @throws IgniteCheckedException If failed.
@@ -3379,8 +3378,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         String cacheName,
         String valCls,
         final IndexQueryDesc idxQryDesc,
-        @Nullable IgniteBiPredicate<K, V> filter,
-        final IndexingQueryFilter filters,
+        @Nullable IgniteBiPredicate<K, V> entryFilter,
+        final IndexingQueryFilter cacheFilter,
         boolean keepBinary
     ) throws IgniteCheckedException {
         if (!busyLock.enterBusy())
@@ -3392,10 +3391,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             return executeQuery(GridCacheQueryType.INDEX, valCls, cctx,
                 new IgniteOutClosureX<IndexQueryResult<K, V>>() {
                     @Override public IndexQueryResult<K, V> applyx() throws IgniteCheckedException {
-                        IndexQueryContext qryCtx = new IndexQueryContext(filters, null);
-
-                        return idxQryPrc.queryLocal(cctx, idxQryDesc, filter, qryCtx, keepBinary);
-
+                        return idxQryPrc.queryLocal(cctx, idxQryDesc, entryFilter, cacheFilter, keepBinary);
                     }
                 }, true);
         }
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 ed1f366..74a1a83 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
@@ -222,7 +222,7 @@ public class H2TreeIndex extends H2TreeIndexBase {
         if (qctx == null)
             return null;
 
-        return new IndexQueryContext(qctx.filter(), qctx.mvccSnapshot());
+        return new IndexQueryContext(qctx.filter(), null, qctx.mvccSnapshot());
     }
 
     /** */
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/index/H2RowComparator.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/index/H2RowComparator.java
index e9bb762..d0906e5 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/index/H2RowComparator.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/index/H2RowComparator.java
@@ -50,31 +50,29 @@ public class H2RowComparator extends IndexRowCompartorImpl {
     /** Ignite H2 session. */
     private final SessionInterface ses;
 
-    /** Key type settings for this index. */
-    private final IndexKeyTypeSettings keyTypeSettings;
-
     /** */
     public H2RowComparator(GridH2Table table, IndexKeyTypeSettings keyTypeSettings) {
+        super(keyTypeSettings);
+
         this.table = table;
-        this.keyTypeSettings = keyTypeSettings;
 
         coctx = table.rowDescriptor().context().cacheObjectContext();
         ses = table.rowDescriptor().indexing().connections().jdbcConnection().getSession();
     }
 
     /** {@inheritDoc} */
-    @Override public int compareKey(long pageAddr, int off, int maxSize, IndexKey key, int curType) {
-        int cmp = super.compareKey(pageAddr, off, maxSize, key, curType);
+    @Override public int compareKey(long pageAddr, int off, int maxSize, IndexKey key, InlineIndexKeyType type) {
+        int cmp = super.compareKey(pageAddr, off, maxSize, key, type);
 
         if (cmp != COMPARE_UNSUPPORTED)
             return cmp;
 
-        int objType = key == NullIndexKey.INSTANCE ? curType : key.type();
+        int objType = key == NullIndexKey.INSTANCE ? type.type() : key.type();
 
-        int highOrder = Value.getHigherOrder(curType, objType);
+        int highOrder = Value.getHigherOrder(type.type(), objType);
 
         // H2 supports comparison between different types after casting them to single type.
-        if (highOrder != objType && highOrder == curType) {
+        if (highOrder != objType && highOrder == type.type()) {
             Value va = DataType.convertToValue(ses, key.key(), highOrder);
             va = va.convertTo(highOrder);
 
diff --git a/modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryInlineSizesTest.java b/modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryInlineSizesTest.java
new file mode 100644
index 0000000..16cbef1
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryInlineSizesTest.java
@@ -0,0 +1,206 @@
+/*
+ * 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.cache.query;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Random;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
+import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.gt;
+import static org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.lt;
+
+/** */
+@RunWith(Parameterized.class)
+public class IndexQueryInlineSizesTest extends GridCommonAbstractTest {
+    /** */
+    private static final String CACHE = "TEST_CACHE";
+
+    /** */
+    private static final String TABLE_CACHE = "TEST_CACHE_TABLE";
+
+    /** */
+    private static final String VALUE_TYPE = "TEST_VALUE_TYPE";
+
+    /** */
+    private static final String TABLE = "TEST_TABLE";
+
+    /** */
+    private static final int CNT = 10_000;
+
+    /** */
+    private static IgniteEx crd;
+
+    /** */
+    @Parameterized.Parameter
+    public int inlineSize;
+
+    /** */
+    @Parameterized.Parameters(name = "inlineSize={0}")
+    public static Iterable<Integer> parameters() {
+        return IntStream.range(0, 20).boxed().collect(Collectors.toList());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        crd = startGrid(2);
+
+        prepareTable(crd);
+    }
+
+    /** */
+    @Test
+    public void testFixedInlineKeys() throws Exception {
+        try (Index idx = new Index(inlineSize, "fld1, fld2")) {
+            check((low, high) -> new IndexQuery<Integer, BinaryObject>(VALUE_TYPE, idx.idxName)
+                .setCriteria(gt("fld1", low), lt("fld2", high)));
+        }
+    }
+
+    /** */
+    @Test
+    public void testVarInlineKeys() throws Exception {
+        try (Index idx = new Index(inlineSize, "fld1, fld3")) {
+            check((low, high) -> new IndexQuery<Integer, BinaryObject>(VALUE_TYPE, idx.idxName)
+                .setCriteria(gt("fld1", low), lt("fld3", strFieldVal(high))));
+        }
+    }
+
+    /** */
+    @Test
+    public void testVarInlineKeysFirst() throws Exception {
+        try (Index idx = new Index(inlineSize, "fld3, fld1")) {
+            check((low, high) -> new IndexQuery<Integer, BinaryObject>(VALUE_TYPE, idx.idxName)
+                .setCriteria(gt("fld1", low), lt("fld3", strFieldVal(high))));
+        }
+    }
+
+    /** */
+    @Test
+    public void testNonInlinedKeys() throws Exception {
+        try (Index idx = new Index(inlineSize, "fld1, fld4")) {
+            check((low, high) -> new IndexQuery<Integer, BinaryObject>(VALUE_TYPE, idx.idxName)
+                .setCriteria(gt("fld1", low), lt("fld4", new BigDecimal(high))));
+        }
+    }
+
+    /** */
+    @Test
+    public void testNonInlinedKeysFirst() throws Exception {
+        try (Index idx = new Index(inlineSize, "fld4, fld1", 0)) {
+            check((low, high) -> new IndexQuery<Integer, BinaryObject>(VALUE_TYPE, idx.idxName)
+                .setCriteria(gt("fld1", low), lt("fld4", new BigDecimal(high))));
+        }
+    }
+
+    /** */
+    @Test
+    public void testVarlenAndNonInlined() throws Exception {
+        try (Index idx = new Index(inlineSize, "fld3, fld4")) {
+            check((low, high) -> new IndexQuery<Integer, BinaryObject>(VALUE_TYPE, idx.idxName)
+                .setCriteria(gt("fld3", strFieldVal(low)), lt("fld4", new BigDecimal(high))));
+        }
+    }
+
+    /** */
+    private void check(BiFunction<Integer, Integer, IndexQuery<Integer, BinaryObject>> qryBld) {
+        Random r = new Random();
+
+        int low = r.nextInt(CNT / 2);
+        int high = low + r.nextInt(CNT / 2);
+
+        IndexQuery<Integer, BinaryObject> qry = qryBld.apply(low, high);
+
+        List<?> result = crd.cache(TABLE_CACHE).withKeepBinary().query(qry).getAll();
+
+        assertEquals(high - low - 1, result.size());
+    }
+
+    /** */
+    private void prepareTable(Ignite crd) {
+        SqlFieldsQuery tblQry = new SqlFieldsQuery("create table " + TABLE +
+            "(id int PRIMARY KEY, fld1 int, fld2 int, fld3 varchar, fld4 decimal)" +
+            " with \"CACHE_NAME=" + TABLE_CACHE + ",VALUE_TYPE=" + VALUE_TYPE + "\";");
+
+        crd.getOrCreateCache(CACHE).query(tblQry);
+
+        try (IgniteDataStreamer<Integer, BinaryObject> s = crd.dataStreamer(TABLE_CACHE)) {
+            IntStream.range(0, CNT).forEach((v) -> {
+                BinaryObject bo = crd.binary().builder(VALUE_TYPE)
+                    .setField("fld1", v)
+                    .setField("fld2", v)
+                    .setField("fld3", strFieldVal(v))
+                    .setField("fld4", new BigDecimal(v))
+                    .build();
+
+                s.addData(v, bo);
+            });
+        }
+    }
+
+    /** */
+    private static String strFieldVal(int val) {
+        return String.format("%10s", val).replace(" ", "0");
+    }
+
+    /** */
+    private static class Index implements AutoCloseable {
+        /** */
+        private final String idxName;
+
+        /** */
+        private Index(int inlineSize, String flds) {
+            this(inlineSize, flds, inlineSize);
+        }
+
+        /** */
+        private Index(int inlineSize, String flds, int expInlineSize) {
+            idxName = "IDX_" + inlineSize;
+
+            SqlFieldsQuery idxQry = new SqlFieldsQuery(
+                "create index " + idxName + " on " + TABLE + "(" + flds + ") INLINE_SIZE " + inlineSize);
+
+            crd.cache(CACHE).query(idxQry).getAll();
+
+            GridH2Table tbl = ((IgniteH2Indexing)crd.context().query().getIndexing()).schemaManager()
+                .dataTable("PUBLIC", TABLE);
+
+            assertEquals(expInlineSize, ((H2TreeIndexBase)tbl.getIndex(idxName)).inlineSize());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void close() throws Exception {
+            SqlFieldsQuery idxQry = new SqlFieldsQuery("drop index " + idxName);
+
+            crd.cache(CACHE).query(idxQry).getAll();
+        }
+    }
+}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryTestSuite.java
index e141e27..7c399aa 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryTestSuite.java
@@ -28,6 +28,7 @@ import org.junit.runners.Suite;
     IndexQueryAllTypesTest.class,
     IndexQueryFailoverTest.class,
     IndexQueryFilterTest.class,
+    IndexQueryInlineSizesTest.class,
     IndexQueryKeepBinaryTest.class,
     IndexQueryLocalTest.class,
     IndexQueryQueryEntityTest.class,