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/10/10 14:49:06 UTC

[GitHub] [ignite-3] ibessonov commented on a diff in pull request #1179: IGNITE-17855 Implement inline size calculation for B+tree

ibessonov commented on code in PR #1179:
URL: https://github.com/apache/ignite-3/pull/1179#discussion_r991347714


##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.

Review Comment:
   And by this. I don't get it



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.

Review Comment:
   What do you mean by this comment?



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {

Review Comment:
   Why is `maxVarlenInlineSize` a parameter?



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.

Review Comment:
   What is "class" here? Looks more like offset size



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.
+        int sizeClass = 2;
+
+        if (columns.stream().allMatch(c -> c.type().spec().fixedLength())) {
+            int totalFixedColumnSize = columns.stream().mapToInt(c -> c.type().sizeInBytes()).sum();
+
+            sizeClass = Math.min(sizeClass, BinaryTupleCommon.flagsToEntrySize(BinaryTupleCommon.valueSizeToFlags(totalFixedColumnSize)));
+        }
+
+        int inlineSize = BinaryTupleCommon.HEADER_SIZE
+                + (hasNullColumns ? BinaryTupleCommon.nullMapSize(columns.size()) : 0)
+                + columns.size() * sizeClass;
+
+        for (int i = 0; i < columns.size() && inlineSize < MAX_BINARY_TUPLE_INLINE_SIZE; i++) {
+            inlineSize += inlineSize(columns.get(i).type(), maxVarlenInlineSize);
+        }
+
+        return Math.min(inlineSize, MAX_BINARY_TUPLE_INLINE_SIZE);
+    }
+
+    /**
+     * Calculates the inline size for the {@link BinaryTuple} that will be stored in the index {@link BplusInnerIo} and {@link BplusLeafIo}.
+     * Minimum number of items in a {@link BplusInnerIo} is {@code 2}, so that there is no significant performance drop.
+     *
+     * @param pageSize Page size in bytes.
+     * @param indexBplusIoHeaderSize Index {@link BplusInnerIo} and {@link BplusLeafIo} header size in bytes.
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    public static int binaryTupleBplusIoInlineSize(
+            int pageSize,
+            int indexBplusIoHeaderSize,
+            IndexDescriptor indexDescriptor,
+            int maxVarlenInlineSize
+    ) {
+        int innerNodePayloadSize = pageSize - BplusInnerIo.HEADER_SIZE - PARTITIONLESS_LINK_SIZE_BYTES;

Review Comment:
   I think we should introduce a constant like `CHILD_LINK_SIZE` in BplusInnerIo, what do you think? Having explicit mentions of partitionless links is too mouthful



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.
+        int sizeClass = 2;
+
+        if (columns.stream().allMatch(c -> c.type().spec().fixedLength())) {
+            int totalFixedColumnSize = columns.stream().mapToInt(c -> c.type().sizeInBytes()).sum();
+
+            sizeClass = Math.min(sizeClass, BinaryTupleCommon.flagsToEntrySize(BinaryTupleCommon.valueSizeToFlags(totalFixedColumnSize)));

Review Comment:
   This line is so messy. We can use static imports or extract some variables, what do you think?



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.
+        int sizeClass = 2;
+
+        if (columns.stream().allMatch(c -> c.type().spec().fixedLength())) {
+            int totalFixedColumnSize = columns.stream().mapToInt(c -> c.type().sizeInBytes()).sum();
+
+            sizeClass = Math.min(sizeClass, BinaryTupleCommon.flagsToEntrySize(BinaryTupleCommon.valueSizeToFlags(totalFixedColumnSize)));
+        }
+
+        int inlineSize = BinaryTupleCommon.HEADER_SIZE
+                + (hasNullColumns ? BinaryTupleCommon.nullMapSize(columns.size()) : 0)
+                + columns.size() * sizeClass;
+
+        for (int i = 0; i < columns.size() && inlineSize < MAX_BINARY_TUPLE_INLINE_SIZE; i++) {
+            inlineSize += inlineSize(columns.get(i).type(), maxVarlenInlineSize);
+        }
+
+        return Math.min(inlineSize, MAX_BINARY_TUPLE_INLINE_SIZE);
+    }
+
+    /**
+     * Calculates the inline size for the {@link BinaryTuple} that will be stored in the index {@link BplusInnerIo} and {@link BplusLeafIo}.
+     * Minimum number of items in a {@link BplusInnerIo} is {@code 2}, so that there is no significant performance drop.
+     *
+     * @param pageSize Page size in bytes.
+     * @param indexBplusIoHeaderSize Index {@link BplusInnerIo} and {@link BplusLeafIo} header size in bytes.
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    public static int binaryTupleBplusIoInlineSize(
+            int pageSize,
+            int indexBplusIoHeaderSize,
+            IndexDescriptor indexDescriptor,
+            int maxVarlenInlineSize
+    ) {
+        int innerNodePayloadSize = pageSize - BplusInnerIo.HEADER_SIZE - PARTITIONLESS_LINK_SIZE_BYTES;
+        int leafNodePayloadSize = pageSize - BplusLeafIo.HEADER_SIZE;
+
+        // So that at least 2 items fit on the BplusInnerIo.
+        int maxInnerNodeItemSize = (innerNodePayloadSize / 2) - PARTITIONLESS_LINK_SIZE_BYTES;
+
+        int itemSize = Math.min(maxInnerNodeItemSize, binaryTupleInlineSize(indexDescriptor, maxVarlenInlineSize) + indexBplusIoHeaderSize);
+
+        // If there is a variable length column.
+        if (indexDescriptor.columns().stream().anyMatch(not(c -> c.type().spec().fixedLength()))) {

Review Comment:
   Or you could write `!foo.allMatch(c -> c...fixedLength())`, would be easier to understand



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.
+        int sizeClass = 2;
+
+        if (columns.stream().allMatch(c -> c.type().spec().fixedLength())) {
+            int totalFixedColumnSize = columns.stream().mapToInt(c -> c.type().sizeInBytes()).sum();
+
+            sizeClass = Math.min(sizeClass, BinaryTupleCommon.flagsToEntrySize(BinaryTupleCommon.valueSizeToFlags(totalFixedColumnSize)));
+        }
+
+        int inlineSize = BinaryTupleCommon.HEADER_SIZE
+                + (hasNullColumns ? BinaryTupleCommon.nullMapSize(columns.size()) : 0)
+                + columns.size() * sizeClass;
+
+        for (int i = 0; i < columns.size() && inlineSize < MAX_BINARY_TUPLE_INLINE_SIZE; i++) {
+            inlineSize += inlineSize(columns.get(i).type(), maxVarlenInlineSize);
+        }
+
+        return Math.min(inlineSize, MAX_BINARY_TUPLE_INLINE_SIZE);
+    }
+
+    /**
+     * Calculates the inline size for the {@link BinaryTuple} that will be stored in the index {@link BplusInnerIo} and {@link BplusLeafIo}.
+     * Minimum number of items in a {@link BplusInnerIo} is {@code 2}, so that there is no significant performance drop.
+     *
+     * @param pageSize Page size in bytes.
+     * @param indexBplusIoHeaderSize Index {@link BplusInnerIo} and {@link BplusLeafIo} header size in bytes.

Review Comment:
   Looking at this comment, I don't understand what it means. I think the word "header" might be misleading. Please expand the comment and maybe remove the parameter.



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.
+        int sizeClass = 2;
+
+        if (columns.stream().allMatch(c -> c.type().spec().fixedLength())) {
+            int totalFixedColumnSize = columns.stream().mapToInt(c -> c.type().sizeInBytes()).sum();
+
+            sizeClass = Math.min(sizeClass, BinaryTupleCommon.flagsToEntrySize(BinaryTupleCommon.valueSizeToFlags(totalFixedColumnSize)));
+        }
+
+        int inlineSize = BinaryTupleCommon.HEADER_SIZE
+                + (hasNullColumns ? BinaryTupleCommon.nullMapSize(columns.size()) : 0)
+                + columns.size() * sizeClass;
+
+        for (int i = 0; i < columns.size() && inlineSize < MAX_BINARY_TUPLE_INLINE_SIZE; i++) {
+            inlineSize += inlineSize(columns.get(i).type(), maxVarlenInlineSize);
+        }
+
+        return Math.min(inlineSize, MAX_BINARY_TUPLE_INLINE_SIZE);
+    }
+
+    /**
+     * Calculates the inline size for the {@link BinaryTuple} that will be stored in the index {@link BplusInnerIo} and {@link BplusLeafIo}.
+     * Minimum number of items in a {@link BplusInnerIo} is {@code 2}, so that there is no significant performance drop.
+     *
+     * @param pageSize Page size in bytes.
+     * @param indexBplusIoHeaderSize Index {@link BplusInnerIo} and {@link BplusLeafIo} header size in bytes.
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    public static int binaryTupleBplusIoInlineSize(
+            int pageSize,
+            int indexBplusIoHeaderSize,
+            IndexDescriptor indexDescriptor,
+            int maxVarlenInlineSize
+    ) {
+        int innerNodePayloadSize = pageSize - BplusInnerIo.HEADER_SIZE - PARTITIONLESS_LINK_SIZE_BYTES;
+        int leafNodePayloadSize = pageSize - BplusLeafIo.HEADER_SIZE;
+
+        // So that at least 2 items fit on the BplusInnerIo.
+        int maxInnerNodeItemSize = (innerNodePayloadSize / 2) - PARTITIONLESS_LINK_SIZE_BYTES;
+
+        int itemSize = Math.min(maxInnerNodeItemSize, binaryTupleInlineSize(indexDescriptor, maxVarlenInlineSize) + indexBplusIoHeaderSize);
+
+        // If there is a variable length column.
+        if (indexDescriptor.columns().stream().anyMatch(not(c -> c.type().spec().fixedLength()))) {
+            // Let's try to increase itemSize for BplusInnerIo.
+            int additionalInnerNodeItemSize = (innerNodePayloadSize % (itemSize + PARTITIONLESS_LINK_SIZE_BYTES))

Review Comment:
   This code is really hard to read without comments. I understand why these calculations are here, but othe people may have struggles



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.
+        int sizeClass = 2;
+
+        if (columns.stream().allMatch(c -> c.type().spec().fixedLength())) {
+            int totalFixedColumnSize = columns.stream().mapToInt(c -> c.type().sizeInBytes()).sum();
+
+            sizeClass = Math.min(sizeClass, BinaryTupleCommon.flagsToEntrySize(BinaryTupleCommon.valueSizeToFlags(totalFixedColumnSize)));
+        }
+
+        int inlineSize = BinaryTupleCommon.HEADER_SIZE
+                + (hasNullColumns ? BinaryTupleCommon.nullMapSize(columns.size()) : 0)
+                + columns.size() * sizeClass;
+
+        for (int i = 0; i < columns.size() && inlineSize < MAX_BINARY_TUPLE_INLINE_SIZE; i++) {
+            inlineSize += inlineSize(columns.get(i).type(), maxVarlenInlineSize);
+        }
+
+        return Math.min(inlineSize, MAX_BINARY_TUPLE_INLINE_SIZE);
+    }
+
+    /**
+     * Calculates the inline size for the {@link BinaryTuple} that will be stored in the index {@link BplusInnerIo} and {@link BplusLeafIo}.
+     * Minimum number of items in a {@link BplusInnerIo} is {@code 2}, so that there is no significant performance drop.
+     *
+     * @param pageSize Page size in bytes.
+     * @param indexBplusIoHeaderSize Index {@link BplusInnerIo} and {@link BplusLeafIo} header size in bytes.
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    public static int binaryTupleBplusIoInlineSize(
+            int pageSize,
+            int indexBplusIoHeaderSize,
+            IndexDescriptor indexDescriptor,
+            int maxVarlenInlineSize
+    ) {
+        int innerNodePayloadSize = pageSize - BplusInnerIo.HEADER_SIZE - PARTITIONLESS_LINK_SIZE_BYTES;
+        int leafNodePayloadSize = pageSize - BplusLeafIo.HEADER_SIZE;
+
+        // So that at least 2 items fit on the BplusInnerIo.
+        int maxInnerNodeItemSize = (innerNodePayloadSize / 2) - PARTITIONLESS_LINK_SIZE_BYTES;
+
+        int itemSize = Math.min(maxInnerNodeItemSize, binaryTupleInlineSize(indexDescriptor, maxVarlenInlineSize) + indexBplusIoHeaderSize);
+
+        // If there is a variable length column.
+        if (indexDescriptor.columns().stream().anyMatch(not(c -> c.type().spec().fixedLength()))) {
+            // Let's try to increase itemSize for BplusInnerIo.
+            int additionalInnerNodeItemSize = (innerNodePayloadSize % (itemSize + PARTITIONLESS_LINK_SIZE_BYTES))
+                    / (innerNodePayloadSize / (itemSize + PARTITIONLESS_LINK_SIZE_BYTES));
+
+            // Let's check if we can increase itemSize for BplusInnerIo so that the number of items for BplusLeafIo does not decrease.
+            if (additionalInnerNodeItemSize > 0

Review Comment:
   This doesn't match what we discussed. I proposed choosing minimal value from two calculated deltas. But you either use a delta from inner page or a 0. Please fix it. Please also try to simplify this code by introducing some variables, like "innerPageMaxItems" or whatever.
   By the way, why do you call them nodes here? Usually we refer to them as pages



##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length column in bytes.
+     * @return Inline size in bytes, not more than the {@link #MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.
+        int sizeClass = 2;
+
+        if (columns.stream().allMatch(c -> c.type().spec().fixedLength())) {
+            int totalFixedColumnSize = columns.stream().mapToInt(c -> c.type().sizeInBytes()).sum();
+
+            sizeClass = Math.min(sizeClass, BinaryTupleCommon.flagsToEntrySize(BinaryTupleCommon.valueSizeToFlags(totalFixedColumnSize)));

Review Comment:
   Also, it's a double conversion, not very intuitive. Can we have "valueSizeToEntrySize"?
   BTW, entry size if better than "class"



-- 
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