AMashenkov commented on code in PR #1179: URL: https://github.com/apache/ignite-3/pull/1179#discussion_r991080570
########## modules/storage-api/src/main/java/org/apache/ignite/internal/storage/index/InlineUtils.java: ########## @@ -0,0 +1,106 @@ +/* + * 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.index; + +import static org.apache.ignite.internal.util.Constants.KiB; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.List; +import org.apache.ignite.internal.binarytuple.BinaryTupleCommon; +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.ColumnDescriptor; + +/** + * Helper class for index inlining. + */ +public class InlineUtils { + /** Inline size of an undefined (not set by the user) variable length column in bytes. */ + static final int UNDEFINED_VARLEN_INLINE_SIZE = 10; + + /** Inline size for large numbers ({@link BigDecimal} and {@link BigInteger}) in bytes. */ + static final int BIG_NUMBER_INLINE_SIZE = 4; + + /** Maximum inline size for a {@link BinaryTuple}, in bytes. */ + static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB; + + /** {@link BinaryTuple} size class in bytes. */ + static final int BINARY_TUPLE_SIZE_CLASS = 2; + + /** + * Calculates inline size for column. + * + * @param nativeType Column type. + * @return Inline size in bytes. + */ + static int inlineSize(NativeType nativeType) { + NativeTypeSpec spec = nativeType.spec(); + + if (spec.fixedLength()) { + return nativeType.sizeInBytes(); + } + + // Variable length columns. + + switch (spec) { + case STRING: { + int length = ((VarlenNativeType) nativeType).length(); + + return length == Integer.MAX_VALUE ? UNDEFINED_VARLEN_INLINE_SIZE : length * 2; Review Comment: ok, also I'd limit default value for var-length types (e.g. with 64-256 bytes). Usually, the upper limit for var-length columns is usually calculated with some reserve. So, the actual values size is less the limit (often noticeably). Also, large inline-size means less data will fit to the index page and may have negative impact on performance. In case of relatively large values with similar prefixes user always can increase inline-size manually, but imho, in most of cases, this limit will reduce index size with no performance penalty. -- 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-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org