Skip to content

Commit 54f62df

Browse files
seokyun-ha-tossEsoragotoSpirit
authored andcommitted
[Enhancement] Skip predicate column vacuuming when TTL is negative or usage is empty (StarRocks#71290)
Signed-off-by: seokyun.ha <seokyun.ha@toss.im> Signed-off-by: 絵空事スピリット <richard.wang@celerdata.com> Co-authored-by: 絵空事スピリット <richard.wang@celerdata.com>
1 parent dbadad5 commit 54f62df

6 files changed

Lines changed: 29 additions & 11 deletions

File tree

docs/en/using_starrocks/Cost_based_optimizer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ The following table describes the default settings. If you need to modify them,
212212
| statistic_auto_collect_max_predicate_column_size_on_sample_strategy | INT | 16 | When the Auto Full Collection task hits the sampled collection policy, if the table has an unusually large number of Predicate Columns and exceeds this configuration item, the task will not switch to full collection of the Predicate Columns, but maintains to be the sampled collection of all columns. This configuration item controls the maximum value of Predicate Column for this behavior. |
213213
| statistic_auto_collect_predicate_columns_threshold | INT | 32 | If the number of columns in the table exceeds this configuration during automatic collection, only the column statistics for the Predicate Column will be collected. |
214214
| statistic_predicate_columns_persist_interval_sec | LONG | 60 | The interval at which FE synchronize and persists statistics of Predicate Column. |
215-
| statistic_predicate_columns_ttl_hours | LONG | 24 | The elimination time of the Predicate Column statistics cached in FE. |
215+
| statistic_predicate_columns_ttl_hours | LONG | 24 | The TTL in hours for Predicate Column entries in FE; vacuum removes older data. A negative value disables vacuum. |
216216
| enable_predicate_columns_collection | BOOLEAN | TRUE | Whether to enable predicate columns collection. If disabled, predicate columns will not be recorded during query optimization. |
217217
| enable_manual_collect_array_ndv | BOOLEAN | FALSE | Whether to enable manual collection for the NDV information of the ARRAY type. |
218218
| enable_auto_collect_array_ndv | BOOLEAN | FALSE | Whether to enable automatic collection for the NDV information of the ARRAY type. |
@@ -250,7 +250,7 @@ Parameter description:
250250
- `PREDICATE COLUMNS`: Collect statistics from only Predicate Columns. Supported since v3.5.0.
251251
- `MULTIPLE COLUMNS`: Collects joint statistics from the specified multiple columns. Currently, only manual synchronous collection of multiple columns is supported. The number of columns for manual statistics collection cannot exceed `statistics_max_multi_column_combined_num`, the default value is `10`. Supported since v3.5.0.
252252

253-
- [WITH SYNC | ASYNC MODE]: whether to run the manual collection task in synchronous or asynchronous mode. Synchronous collection is used by default if you do not specify this parameter.
253+
- `WITH SYNC | ASYNC MODE`: whether to run the manual collection task in synchronous or asynchronous mode. Synchronous collection is used by default if you do not specify this parameter.
254254

255255
- `PROPERTIES`: custom parameters. If `PROPERTIES` is not specified, the default settings in the `fe.conf` file are used. The properties that are actually used can be viewed via the `Properties` column in the output of SHOW ANALYZE STATUS.
256256

@@ -318,7 +318,7 @@ Parameter description:
318318

319319
- `col_name`: columns from which to collect statistics. Separate multiple columns with commas (`,`). If this parameter is not specified, the entire table is collected. This parameter is required for histograms.
320320

321-
- [WITH SYNC | ASYNC MODE]: whether to run the manual collection task in synchronous or asynchronous mode. Synchronous collection is used by default if you not specify this parameter.
321+
- `WITH SYNC | ASYNC MODE`: whether to run the manual collection task in synchronous or asynchronous mode. Synchronous collection is used by default if you not specify this parameter.
322322

323323
- `WITH N BUCKETS`: `N` is the number of buckets for histogram collection. If not specified, the default value in `fe.conf` is used.
324324

docs/ja/using_starrocks/Cost_based_optimizer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ v3.5.0 以降、StarRocks は自動収集中に、テーブルのデータが前
214214
| statistic_auto_collect_max_predicate_column_size_on_sample_strategy | INT | 16 | 自動フル収集タスクがサンプル収集ポリシーに当たったとき、テーブルに異常に多くのPredicate Columnがあり、この設定項目を超えた場合、タスクはPredicate Columnのフル収集に切り替わらず、すべての列のサンプル収集に維持されます。この設定項目は、この動作のためのPredicate Columnの最大値を制御します。 |
215215
| statistic_auto_collect_predicate_columns_threshold | INT | 32 | 自動収集中にテーブルの列数がこの設定を超えた場合、Predicate Columnの列統計のみが収集されます。 |
216216
| statistic_predicate_columns_persist_interval_sec | LONG | 60 | FE が Predicate Column の統計情報を同期し、永続化する間隔。 |
217-
| statistic_predicate_columns_ttl_hours | LONG | 24 | FE にキャッシュされた Predicate Column 統計の消去時間|
217+
| statistic_predicate_columns_ttl_hours | LONG | 24 | FE にキャッシュされた Predicate Column の TTL(時間)。vacuum が古いデータを削除。負の値で vacuum を無効化|
218218
| enable_predicate_columns_collection | BOOLEAN | TRUE | Predicate Column の収集を有効にするかどうか。無効にすると、クエリ最適化中に Predicate Column が記録されません。 |
219219
| enable_manual_collect_array_ndv | BOOLEAN | FALSE | ARRAY タイプの NDV 情報の手動収集を有効にするかどうか。 |
220220
| enable_auto_collect_array_ndv | BOOLEAN | FALSE | ARRAY タイプの NDV 情報の自動収集を有効にするかどうか。 |
@@ -252,7 +252,7 @@ ANALYZE [FULL|SAMPLE] TABLE tbl_name
252252
- `PREDICATE COLUMNS`:Predicate Column のみから統計情報を収集する。v3.5.0 からサポート。
253253
- `MULTIPLE COLUMNS`:指定した複数の列から共同の統計情報を収集する。現在のところ、複数列の手動同期収集のみがサポートされている。手動で統計情報を収集する列の数は `statistics_max_multi_column_combined_num` を超えることはできず、デフォルト値は `10` である。v3.5.0 からサポートされている。
254254

255-
- [WITH SYNC | ASYNC MODE]: 手動収集タスクを同期モードまたは非同期モードで実行するかどうか。指定しない場合、デフォルトで同期収集が使用されます。
255+
- `WITH SYNC | ASYNC MODE`: 手動収集タスクを同期モードまたは非同期モードで実行するかどうか。指定しない場合、デフォルトで同期収集が使用されます。
256256

257257
- `PROPERTIES`: カスタムパラメータ。`PROPERTIES` が指定されていない場合、`fe.conf` ファイルのデフォルト設定が使用されます。実際に使用されるプロパティは、SHOW ANALYZE STATUS の出力の `Properties` 列で確認できます。
258258

@@ -320,7 +320,7 @@ ANALYZE TABLE tbl_name UPDATE HISTOGRAM ON col_name [, col_name]
320320

321321
- `col_name`: 統計を収集する列。複数の列をカンマ(`,`)で区切ります。このパラメータが指定されていない場合、テーブル全体が収集されます。ヒストグラムにはこのパラメータが必要です。
322322

323-
- [WITH SYNC | ASYNC MODE]: 手動収集タスクを同期モードまたは非同期モードで実行するかどうか。指定しない場合、デフォルトで同期収集が使用されます。
323+
- `WITH SYNC | ASYNC MODE`: 手動収集タスクを同期モードまたは非同期モードで実行するかどうか。指定しない場合、デフォルトで同期収集が使用されます。
324324

325325
- `WITH N BUCKETS`: ヒストグラム収集のためのバケット数 `N`。指定しない場合、`fe.conf` のデフォルト値が使用されます。
326326

docs/zh/using_starrocks/Cost_based_optimizer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ StarRocks 提供灵活的信息采集方式,您可以根据业务场景选择
209209
| statistic_auto_collect_max_predicate_column_size_on_sample_strategy | INT | 16 | 自动全量采集任务命中 Sample 策略时,如果表中 Predicate Column 特别多并且超过配置项,则不会转为对 Predicate Column 的全量采集,保持对所有列的抽样采集。当前配置项控制该行为中 Predicate Column 的最大值。 |
210210
| statistic_auto_collect_predicate_columns_threshold | INT | 32 | 自动采集时若发现表中的列数超过配置项,则仅会采集 Predicate Column 的列统计信息。 |
211211
| statistic_predicate_columns_persist_interval_sec | LONG | 60 | FE 对 Predicate Column 的同步和持久化间隔周期。 |
212-
| statistic_predicate_columns_ttl_hours | LONG | 24 | Predicate Column 信息在 FE 中缓存淘汰时间|
212+
| statistic_predicate_columns_ttl_hours | LONG | 24 | Predicate Column FE 中的 TTL(小时),vacuum 会清理更旧的数据;为负数时关闭 vacuum|
213213
| enable_predicate_columns_collection | BOOLEAN | TRUE | 是否启用 Predicate Column 采集。如果禁用,在查询优化期间将不会记录 Predicate Column。 |
214214
| enable_manual_collect_array_ndv | BOOLEAN | FALSE | 是否允许手动采集 ARRAY 类型列的 NDV 信息。 |
215215
| enable_auto_collect_array_ndv | BOOLEAN | FALSE | 是否允许自动采集 ARRAY 类型列的 NDV 信息。 |

fe/fe-core/src/main/java/com/starrocks/common/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,8 +2359,8 @@ public class Config extends ConfigBase {
23592359
@ConfField(mutable = true, comment = "The interval to persist predicate columns state")
23602360
public static long statistic_predicate_columns_persist_interval_sec = 60L;
23612361

2362-
@ConfField(mutable = true, comment = "The TTL of predicate columns, it would not be considered as predicate " +
2363-
"columns after this period")
2362+
@ConfField(mutable = true, comment = "The TTL of predicate columns in hours; entries older than this are " +
2363+
"removed by vacuum. A negative value (e.g. -1) disables predicate column vacuum.")
23642364
public static long statistic_predicate_columns_ttl_hours = 24;
23652365

23662366
@ConfField(mutable = true, comment = "Enable predicate columns collection. If disabled, predicate columns " +

fe/fe-core/src/main/java/com/starrocks/statistic/columns/PredicateColumnsMgr.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,14 @@ public void persist() {
174174

175175
public void vacuum() {
176176
long ttlHour = Config.statistic_predicate_columns_ttl_hours;
177+
if (ttlHour < 0) {
178+
return;
179+
}
177180
LocalDateTime ttlTime = TimeUtils.getSystemNow().minusHours(ttlHour);
178181
Predicate<ColumnUsage> outdated = x -> x.getLastUsed().isBefore(ttlTime);
179182

180183
long before = id2columnUsage.size();
181-
if (id2columnUsage.values().removeIf(outdated)) {
184+
if (before > 0 && id2columnUsage.values().removeIf(outdated)) {
182185
long after = id2columnUsage.size();
183186
LOG.info("removed {} objects from predicate columns because of ttl {}", before - after,
184187
Config.statistic_predicate_columns_ttl_hours);

fe/fe-core/src/test/java/com/starrocks/statistic/columns/ColumnUsageTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,19 @@ public void testColumnUsagePersist() throws MetaNotFoundException {
287287
Assertions.assertEquals(usage, restored);
288288
}
289289
}
290-
}
290+
291+
@Test
292+
public void testPredicateColumnsVacuumSkipsWhenTtlDisabled() throws Exception {
293+
starRocksAssert.query("select * from t0 where v1 > 1").explainQuery();
294+
PredicateColumnsMgr mgr = PredicateColumnsMgr.getInstance();
295+
TableName t0 = new TableName(connectContext.getDatabase(), "t0");
296+
Assertions.assertEquals(1, mgr.queryPredicateColumns(t0).size());
297+
298+
long beforeValue = Config.statistic_predicate_columns_ttl_hours;
299+
Config.statistic_predicate_columns_ttl_hours = -1;
300+
mgr.vacuum();
301+
Assertions.assertEquals(1, mgr.queryPredicateColumns(t0).size());
302+
303+
Config.statistic_predicate_columns_ttl_hours = beforeValue;
304+
}
305+
}

0 commit comments

Comments
 (0)