Skip to content

Commit a6a9f99

Browse files
branch-3.0: [Opt](mow) Forbid time_series compaction policy on unique table #49905 (#50128)
Cherry-picked from #49905 Co-authored-by: bobhan1 <baohan@selectdb.com>
1 parent f7153b7 commit a6a9f99

File tree

6 files changed

+97
-3
lines changed

6 files changed

+97
-3
lines changed

fe/fe-core/src/main/java/org/apache/doris/alter/SchemaChangeHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,11 @@ public void updateTableProperties(Database db, String tableName, Map<String, Str
23742374
+ " or " + PropertyAnalyzer.SIZE_BASED_COMPACTION_POLICY);
23752375
}
23762376

2377+
if (compactionPolicy != null && compactionPolicy.equals(PropertyAnalyzer.TIME_SERIES_COMPACTION_POLICY)
2378+
&& olapTable.getKeysType() == KeysType.UNIQUE_KEYS) {
2379+
throw new UserException("Time series compaction policy is not supported for unique key table");
2380+
}
2381+
23772382
Map<String, Long> timeSeriesCompactionConfig = new HashMap<>();
23782383
if (properties.containsKey(PropertyAnalyzer.PROPERTIES_TIME_SERIES_COMPACTION_GOAL_SIZE_MBYTES)) {
23792384
timeSeriesCompactionConfig

fe/fe-core/src/main/java/org/apache/doris/cloud/alter/CloudSchemaChangeHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.doris.alter.SchemaChangeHandler;
2121
import org.apache.doris.catalog.Database;
2222
import org.apache.doris.catalog.Env;
23+
import org.apache.doris.catalog.KeysType;
2324
import org.apache.doris.catalog.MaterializedIndex;
2425
import org.apache.doris.catalog.MaterializedIndex.IndexExtState;
2526
import org.apache.doris.catalog.OlapTable;
@@ -179,6 +180,10 @@ public void updateTableProperties(Database db, String tableName, Map<String, Str
179180
+ PropertyAnalyzer.TIME_SERIES_COMPACTION_POLICY
180181
+ " or " + PropertyAnalyzer.SIZE_BASED_COMPACTION_POLICY);
181182
}
183+
if (compactionPolicy != null && compactionPolicy.equals(PropertyAnalyzer.TIME_SERIES_COMPACTION_POLICY)
184+
&& olapTable.getKeysType() == KeysType.UNIQUE_KEYS) {
185+
throw new UserException("Time series compaction policy is not supported for unique key table");
186+
}
182187
olapTable.readLock();
183188
try {
184189
if (compactionPolicy == olapTable.getCompactionPolicy()) {

fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,8 @@ public static Boolean analyzeSkipWriteIndexOnLoad(Map<String, String> properties
898898
+ " must be `true` or `false`");
899899
}
900900

901-
public static String analyzeCompactionPolicy(Map<String, String> properties) throws AnalysisException {
901+
public static String analyzeCompactionPolicy(Map<String, String> properties, KeysType keysType)
902+
throws AnalysisException {
902903
if (properties == null || properties.isEmpty()) {
903904
return SIZE_BASED_COMPACTION_POLICY;
904905
}
@@ -913,6 +914,9 @@ public static String analyzeCompactionPolicy(Map<String, String> properties) thr
913914
}
914915
}
915916

917+
if (keysType == KeysType.UNIQUE_KEYS && compactionPolicy.equals(TIME_SERIES_COMPACTION_POLICY)) {
918+
throw new AnalysisException("Time series compaction policy is not supported for unique key table");
919+
}
916920
return compactionPolicy;
917921
}
918922

fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ private boolean createOlapTable(Database db, CreateTableStmt stmt) throws UserEx
25652565
// set compaction policy
25662566
String compactionPolicy = PropertyAnalyzer.SIZE_BASED_COMPACTION_POLICY;
25672567
try {
2568-
compactionPolicy = PropertyAnalyzer.analyzeCompactionPolicy(properties);
2568+
compactionPolicy = PropertyAnalyzer.analyzeCompactionPolicy(properties, olapTable.getKeysType());
25692569
} catch (AnalysisException e) {
25702570
throw new DdlException(e.getMessage());
25712571
}

regression-test/suites/datatype_p0/decimalv3/test_decimalv3_overflow.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ suite("test_decimalv3_overflow") {
643643
DISTRIBUTED BY HASH(`id`) BUCKETS 10
644644
PROPERTIES(
645645
"replication_num"="1",
646-
"compaction_policy" = "time_series",
647646
"enable_unique_key_merge_on_write" = "true"
648647
); """
649648
sql """ insert into test4 values(1, 62324, 0.00273) """
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("test_mow_time_series_compaction") {
19+
def tableName = "test_mow_time_series_compaction"
20+
sql """ DROP TABLE IF EXISTS ${tableName} """
21+
test {
22+
sql """ CREATE TABLE ${tableName}
23+
(k int, v1 int, v2 int )
24+
UNIQUE KEY(k)
25+
DISTRIBUTED BY HASH (k)
26+
BUCKETS 1 PROPERTIES(
27+
"replication_num" = "1",
28+
"enable_unique_key_merge_on_write"="true",
29+
"compaction_policy" = "time_series");
30+
"""
31+
exception "Time series compaction policy is not supported for unique key table"
32+
}
33+
34+
tableName = "test_mor_time_series_compaction"
35+
sql """ DROP TABLE IF EXISTS ${tableName} """
36+
test {
37+
sql """ CREATE TABLE ${tableName}
38+
(k int, v1 int, v2 int )
39+
UNIQUE KEY(k)
40+
DISTRIBUTED BY HASH (k)
41+
BUCKETS 1 PROPERTIES(
42+
"replication_num" = "1",
43+
"enable_unique_key_merge_on_write"="false",
44+
"compaction_policy" = "time_series");
45+
"""
46+
exception "Time series compaction policy is not supported for unique key table"
47+
}
48+
49+
tableName = "test_mow_time_series_compaction_2"
50+
sql """ DROP TABLE IF EXISTS ${tableName} """
51+
sql """ CREATE TABLE ${tableName}
52+
(k int, v1 int, v2 int )
53+
UNIQUE KEY(k)
54+
DISTRIBUTED BY HASH (k)
55+
BUCKETS 1 PROPERTIES(
56+
"replication_num" = "1",
57+
"enable_unique_key_merge_on_write"="true");
58+
"""
59+
sql "insert into ${tableName} values (1, 1, 1),(2,2,2),(3,3,3);"
60+
test {
61+
sql "alter table ${tableName} set (\"compaction_policy\" = \"time_series\");"
62+
exception "Time series compaction policy is not supported for unique key table"
63+
}
64+
65+
tableName = "test_mor_time_series_compaction_2"
66+
sql """ DROP TABLE IF EXISTS ${tableName} """
67+
sql """ CREATE TABLE ${tableName}
68+
(k int, v1 int, v2 int )
69+
UNIQUE KEY(k)
70+
DISTRIBUTED BY HASH (k)
71+
BUCKETS 1 PROPERTIES(
72+
"replication_num" = "1",
73+
"enable_unique_key_merge_on_write"="false");
74+
"""
75+
sql "insert into ${tableName} values (1, 1, 1),(2,2,2),(3,3,3);"
76+
test {
77+
sql "alter table ${tableName} set (\"compaction_policy\" = \"time_series\");"
78+
exception "Time series compaction policy is not supported for unique key table"
79+
}
80+
81+
}

0 commit comments

Comments
 (0)