Skip to content

Commit

Permalink
[Enhancement] use cloud native persistent index by default (StarRocks…
Browse files Browse the repository at this point in the history
…#52209)

Signed-off-by: luohaha <[email protected]>
  • Loading branch information
luohaha committed Oct 28, 2024
1 parent bf04f84 commit 23e567b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class TableProperty implements Writable, GsonPostProcessable {
public static final String BINLOG_PROPERTY_PREFIX = "binlog";
public static final String BINLOG_PARTITION = "binlog_partition_";

public static final String CLOUD_NATIVE_INDEX_TYPE = "CLOUD_NATIVE";
public static final String LOCAL_INDEX_TYPE = "LOCAL";

public enum QueryRewriteConsistencyMode {
DISABLE, // 0: disable query rewrite
LOOSE, // 1: enable query rewrite, and skip the partition version check, still need to check mv partition exist
Expand Down Expand Up @@ -695,10 +698,11 @@ public TableProperty buildPrimaryIndexCacheExpireSec() {
}

public TableProperty buildPersistentIndexType() {
String type = properties.getOrDefault(PropertyAnalyzer.PROPERTIES_PERSISTENT_INDEX_TYPE, "LOCAL");
if (type.equals("LOCAL")) {
String defaultType = Config.enable_cloud_native_persistent_index_by_default ? CLOUD_NATIVE_INDEX_TYPE : LOCAL_INDEX_TYPE;
String type = properties.getOrDefault(PropertyAnalyzer.PROPERTIES_PERSISTENT_INDEX_TYPE, defaultType);
if (type.equals(LOCAL_INDEX_TYPE)) {
persistentIndexType = TPersistentIndexType.LOCAL;
} else if (type.equals("CLOUD_NATIVE")) {
} else if (type.equals(CLOUD_NATIVE_INDEX_TYPE)) {
persistentIndexType = TPersistentIndexType.CLOUD_NATIVE;
}
return this;
Expand All @@ -707,9 +711,9 @@ public TableProperty buildPersistentIndexType() {
public static String persistentIndexTypeToString(TPersistentIndexType type) {
switch (type) {
case LOCAL:
return "LOCAL";
return LOCAL_INDEX_TYPE;
case CLOUD_NATIVE:
return "CLOUD_NATIVE";
return CLOUD_NATIVE_INDEX_TYPE;
default:
// shouldn't happen
// for it has been checked outside
Expand Down
6 changes: 6 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2958,6 +2958,12 @@ public class Config extends ConfigBase {
@ConfField(mutable = true)
public static boolean enable_persistent_index_by_default = true;

/*
* Using cloud native persistent index in primary key table by default when creating table.
*/
@ConfField(mutable = true)
public static boolean enable_cloud_native_persistent_index_by_default = true;

/**
* timeout for external table commit
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1326,15 +1326,16 @@ public static TPersistentIndexType analyzePersistentIndexType(Map<String, String
if (properties != null && properties.containsKey(PROPERTIES_PERSISTENT_INDEX_TYPE)) {
String type = properties.get(PROPERTIES_PERSISTENT_INDEX_TYPE);
properties.remove(PROPERTIES_PERSISTENT_INDEX_TYPE);
if (type.equalsIgnoreCase("LOCAL")) {
if (type.equalsIgnoreCase(TableProperty.LOCAL_INDEX_TYPE)) {
return TPersistentIndexType.LOCAL;
} else if (type.equalsIgnoreCase("CLOUD_NATIVE")) {
} else if (type.equalsIgnoreCase(TableProperty.CLOUD_NATIVE_INDEX_TYPE)) {
return TPersistentIndexType.CLOUD_NATIVE;
} else {
throw new AnalysisException("Invalid persistent index type: " + type);
}
}
return TPersistentIndexType.LOCAL;
return Config.enable_cloud_native_persistent_index_by_default ? TPersistentIndexType.CLOUD_NATIVE
: TPersistentIndexType.LOCAL;
}

public static PeriodDuration analyzeStorageCoolDownTTL(Map<String, String> properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4044,7 +4044,7 @@ public void modifyTableEnablePersistentIndexMeta(Database db, OlapTable table, M
tableProperty.buildEnablePersistentIndex();

if (table.isCloudNativeTable()) {
// now default to LOCAL
// now default to CLOUD_NATIVE
tableProperty.buildPersistentIndexType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void testDefaultTableCompression() throws AnalysisException {
public void testPersistentIndexType() throws AnalysisException {
// empty property
Map<String, String> property = new HashMap<>();
Assert.assertEquals(TPersistentIndexType.LOCAL, PropertyAnalyzer.analyzePersistentIndexType(property));
Assert.assertEquals(TPersistentIndexType.CLOUD_NATIVE, PropertyAnalyzer.analyzePersistentIndexType(property));

Map<String, String> property2 = new HashMap<>();
property2.put(PropertyAnalyzer.PROPERTIES_PERSISTENT_INDEX_TYPE, "LOCAL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void testCreateLakeTableEnablePersistentIndex() throws Exception {
Assert.assertTrue(enablePersistentIndex);
// check table persistentIndexType
String indexType = lakeTable.getPersistentIndexTypeString();
Assert.assertEquals(indexType, "LOCAL");
Assert.assertEquals(indexType, "CLOUD_NATIVE");

String sql = "show create table lake_test.table_with_persistent_index";
ShowCreateTableStmt showCreateTableStmt =
Expand All @@ -245,7 +245,7 @@ public void testCreateLakeTableEnablePersistentIndex() throws Exception {
"(c0 int, c1 string, c2 int, c3 bigint)\n" +
"PRIMARY KEY(c0)\n" +
"distributed by hash(c0) buckets 2\n" +
"properties('enable_persistent_index' = 'true');"));
"properties('enable_persistent_index' = 'true', 'persistent_index_type' = 'LOCAL');"));

ExceptionChecker.expectThrowsNoException(() -> createTable(
"create table lake_test.table_in_be_and_cn\n" +
Expand All @@ -256,7 +256,7 @@ public void testCreateLakeTableEnablePersistentIndex() throws Exception {
LakeTable lakeTable = getLakeTable("lake_test", "table_in_be_and_cn");
// check table persistentIndex
boolean enablePersistentIndex = lakeTable.enablePersistentIndex();
Assert.assertFalse(enablePersistentIndex);
Assert.assertTrue(enablePersistentIndex);

String sql = "show create table lake_test.table_in_be_and_cn";
ShowCreateTableStmt showCreateTableStmt =
Expand Down

0 comments on commit 23e567b

Please sign in to comment.