id
stringlengths
29
30
content
stringlengths
152
2.6k
codereview_new_java_data_14781
public TiDAGRequest buildTiDAGReq( TiKVScanPlan plan = buildIndexScan(columnList, conditions, index, table, tableStatistics, false); if (plan.getCost() < minIndexCost) { - minIndexPlan = plan; minIndexCost = plan.getCost(); } } ```suggestion if (minCostIndexPlan != null && (minIndexCost < minCostPlan.getCost() || useIndexScanFirst)) { ``` public TiDAGRequest buildTiDAGReq( TiKVScanPlan plan = buildIndexScan(columnList, conditions, index, table, tableStatistics, false); if (plan.getCost() < minIndexCost) { + minCostIndexPlan = plan; minIndexCost = plan.getCost(); } }
codereview_new_java_data_14782
public TiDAGRequest buildTiDAGReq( && dagRequest.getEncodeType() == EncodeType.TypeCHBlock) { dagRequest.setEncodeType(EncodeType.TypeChunk); } - // Set DAG Request's store type as minPlan's store type. dagRequest.setStoreType(minPlanStoreType); dagRequest.addRanges(minCostPlan.getKeyRanges(), minCostPlan.getRangeFilters()); ```suggestion dagRequest.setStoreType(minCostPlanStoreType); ``` public TiDAGRequest buildTiDAGReq( && dagRequest.getEncodeType() == EncodeType.TypeCHBlock) { dagRequest.setEncodeType(EncodeType.TypeChunk); } + // Set DAG Request's store type as minCostPlan's store type. dagRequest.setStoreType(minPlanStoreType); dagRequest.addRanges(minCostPlan.getKeyRanges(), minCostPlan.getRangeFilters());
codereview_new_java_data_14783
// TODO: more refactoring on the way public class ClusterIndexScanKeyRangeBuilder extends KeyRangeBuilder { - private final long id; - public ClusterIndexScanKeyRangeBuilder(long id, IndexRange ir) { super(ir); - this.id = id; } private KeyRange toPairKey() { Key lbsKey = Key.toRawKey(lPointKey.append(lKey).getBytes()); Key ubsKey = Key.toRawKey(uPointKey.append(uKey).getBytes()); return makeCoprocRange( - ByteString.copyFrom(RowKey.encode(id, lbsKey.getBytes())), - ByteString.copyFrom(RowKey.encode(id, ubsKey.getBytes()))); } public KeyRange compute() { Just call it tableID, id is ambiguous. // TODO: more refactoring on the way public class ClusterIndexScanKeyRangeBuilder extends KeyRangeBuilder { + private final long tableId; + public ClusterIndexScanKeyRangeBuilder(long tableId, IndexRange ir) { super(ir); + this.tableId = tableId; } private KeyRange toPairKey() { Key lbsKey = Key.toRawKey(lPointKey.append(lKey).getBytes()); Key ubsKey = Key.toRawKey(uPointKey.append(uKey).getBytes()); return makeCoprocRange( + ByteString.copyFrom(RowKey.encode(tableId, lbsKey.getBytes())), + ByteString.copyFrom(RowKey.encode(tableId, ubsKey.getBytes()))); } public KeyRange compute() {
codereview_new_java_data_14784
public static RowKey decode(byte[] value) { } public static byte[] encode(long tableId, Handle handle) { - CodecDataOutput cdo = new CodecDataOutput(); - encodePrefix(cdo, tableId); - cdo.write(handle.encoded()); - return cdo.toBytes(); } public static byte[] encode(long tableId, byte[] key) { Call encode(tableId,handle.encoded()) may better public static RowKey decode(byte[] value) { } public static byte[] encode(long tableId, Handle handle) { + return encode(tableId, handle.encoded()); } public static byte[] encode(long tableId, byte[] key) {
codereview_new_java_data_14785
public List<TiIndexColumn> convertIndexColToPrefixCols(TiIndexInfo indexInfo) { for (TiIndexColumn tiIndexColumn : tiIndexColumns) { /** * We need to consider the prefix index. For example: when we have 'a varchar(50), index - * idx(a(10))' So we will get 'columnInfo.getLength() = 50' and - * 'columnInfo.getType().getLength() = 10'. {@link TiIndexColumn#isPrefixIndex()} will use - * columnLength == DataType.UnspecifiedLength to check check whether we have prefix index. * https://github.com/pingcap/tidb/issues/29805 */ TiColumnInfo columnInfo = getColumn(tiIndexColumn.getName()); if (tiIndexColumn.getLength() != DataType.UNSPECIFIED_LEN - && tiIndexColumn.getLength() == columnInfo.getType().getLength()) { result.add(columnInfo.toUnSpecifiedLenIndexColumn()); } else { result.add(tiIndexColumn); ```suggestion * columnLength == DataType.UnspecifiedLength to check whether we have prefix index. ``` public List<TiIndexColumn> convertIndexColToPrefixCols(TiIndexInfo indexInfo) { for (TiIndexColumn tiIndexColumn : tiIndexColumns) { /** * We need to consider the prefix index. For example: when we have 'a varchar(50), index + * idx(a(10))' So we will get 'columnInfo.getLength() = 50' and 'tiIndexColumn.getLength() = + * 10'. {@link TiIndexColumn#isPrefixIndex()} will use columnLength == + * DataType.UnspecifiedLength to check whether we have prefix index. * https://github.com/pingcap/tidb/issues/29805 */ TiColumnInfo columnInfo = getColumn(tiIndexColumn.getName()); if (tiIndexColumn.getLength() != DataType.UNSPECIFIED_LEN + && tiIndexColumn.getLength() == columnInfo.getLength()) { result.add(columnInfo.toUnSpecifiedLenIndexColumn()); } else { result.add(tiIndexColumn);
codereview_new_java_data_14786
public TiIndexInfo( this.isInvisible = isInvisible; } public static TiIndexInfo genClusterIndex(TiTableInfo table) { if (table.isPkHandle() || table.isCommonHandle()) { ImmutableList<TiIndexColumn> columns; if (table.isPkHandle()) { TiColumnInfo pkColumn = table.getPKIsHandleColumn(); - // The integer handle is no prefix when store in to Tikv. columns = ImmutableList.of(pkColumn.toUnSpecifiedLenIndexColumn()); } else { - // make cols which not has no prefix len to UNSPECIFIED_LEN. columns = ImmutableList.copyOf(table.convertIndexColToPrefixCols(table.getPrimaryKey())); } return new TiIndexInfo( ```suggestion // The integer handle has no prefix when store in to Tikv. ``` public TiIndexInfo( this.isInvisible = isInvisible; } + // To reuse the logic of buildIndexScan, we wrap the primary key as an index here. public static TiIndexInfo genClusterIndex(TiTableInfo table) { if (table.isPkHandle() || table.isCommonHandle()) { ImmutableList<TiIndexColumn> columns; if (table.isPkHandle()) { TiColumnInfo pkColumn = table.getPKIsHandleColumn(); + // The integer handle has no prefix when store in to Tikv. columns = ImmutableList.of(pkColumn.toUnSpecifiedLenIndexColumn()); } else { + // make the len of cols which don't have prefix to UNSPECIFIED_LEN. columns = ImmutableList.copyOf(table.convertIndexColToPrefixCols(table.getPrimaryKey())); } return new TiIndexInfo(
codereview_new_java_data_14787
public TiIndexInfo( this.isInvisible = isInvisible; } public static TiIndexInfo genClusterIndex(TiTableInfo table) { if (table.isPkHandle() || table.isCommonHandle()) { ImmutableList<TiIndexColumn> columns; if (table.isPkHandle()) { TiColumnInfo pkColumn = table.getPKIsHandleColumn(); - // The integer handle is no prefix when store in to Tikv. columns = ImmutableList.of(pkColumn.toUnSpecifiedLenIndexColumn()); } else { - // make cols which not has no prefix len to UNSPECIFIED_LEN. columns = ImmutableList.copyOf(table.convertIndexColToPrefixCols(table.getPrimaryKey())); } return new TiIndexInfo( ```suggestion // make the len of cols which don't have prefix to UNSPECIFIED_LEN. ``` public TiIndexInfo( this.isInvisible = isInvisible; } + // To reuse the logic of buildIndexScan, we wrap the primary key as an index here. public static TiIndexInfo genClusterIndex(TiTableInfo table) { if (table.isPkHandle() || table.isCommonHandle()) { ImmutableList<TiIndexColumn> columns; if (table.isPkHandle()) { TiColumnInfo pkColumn = table.getPKIsHandleColumn(); + // The integer handle has no prefix when store in to Tikv. columns = ImmutableList.of(pkColumn.toUnSpecifiedLenIndexColumn()); } else { + // make the len of cols which don't have prefix to UNSPECIFIED_LEN. columns = ImmutableList.copyOf(table.convertIndexColToPrefixCols(table.getPrimaryKey())); } return new TiIndexInfo(
codereview_new_java_data_14788
public TiIndexInfo( this.isInvisible = isInvisible; } public static TiIndexInfo genClusterIndex(TiTableInfo table) { if (table.isPkHandle() || table.isCommonHandle()) { ImmutableList<TiIndexColumn> columns; if (table.isPkHandle()) { TiColumnInfo pkColumn = table.getPKIsHandleColumn(); - // The integer handle is no prefix when store in to Tikv. columns = ImmutableList.of(pkColumn.toUnSpecifiedLenIndexColumn()); } else { - // make cols which not has no prefix len to UNSPECIFIED_LEN. columns = ImmutableList.copyOf(table.convertIndexColToPrefixCols(table.getPrimaryKey())); } return new TiIndexInfo( introudce why we need genClusterIndex in comment. I think it is for reuse of indexscan? public TiIndexInfo( this.isInvisible = isInvisible; } + // To reuse the logic of buildIndexScan, we wrap the primary key as an index here. public static TiIndexInfo genClusterIndex(TiTableInfo table) { if (table.isPkHandle() || table.isCommonHandle()) { ImmutableList<TiIndexColumn> columns; if (table.isPkHandle()) { TiColumnInfo pkColumn = table.getPKIsHandleColumn(); + // The integer handle has no prefix when store in to Tikv. columns = ImmutableList.of(pkColumn.toUnSpecifiedLenIndexColumn()); } else { + // make the len of cols which don't have prefix to UNSPECIFIED_LEN. columns = ImmutableList.copyOf(table.convertIndexColToPrefixCols(table.getPrimaryKey())); } return new TiIndexInfo(
codereview_new_java_data_14789
public static TiSession getInstance(TiConfiguration conf) { } // if NewCollationEnabled is not set in configuration file, - // we will set it to true when TiDB version is greater than or equal to v6.0.0. // Otherwise, we will set it to false private void refreshNewCollationEnabled() { if (!conf.getNewCollationEnable().isPresent()) { ```suggestion // we will set it to true when TiDB version is greater than or equal to v6.0.0. ``` public static TiSession getInstance(TiConfiguration conf) { } // if NewCollationEnabled is not set in configuration file, + // we will set it to true when TiDB version is greater than or equal to v6.0.0. // Otherwise, we will set it to false private void refreshNewCollationEnabled() { if (!conf.getNewCollationEnable().isPresent()) {