velodb-best-practices

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

VeloDB Best Practices

VeloDB 最佳实践

Problem-first table design intelligence for Apache Doris. 37 rules, 7 use case templates, 4 sizing guides. All details in
references/
directory and compiled
AGENTS.md
.

面向 Apache Doris 的问题导向型表设计指南。 包含37条规则、7个用例模板、4份容量规划指南。 所有详情请查看
references/
目录及编译后的
AGENTS.md
文件。

1 ▸ Problem-First Routing

1 ▸ 问题导向型路由

I need to build…

我需要构建…

ProblemTemplate(s)Key Rules
Real-time log/event analytics
usecase-log-event
DUPLICATE, RANGE partition, dynamic TTL, ZSTD
CDC / MySQL sync to Doris
usecase-cdc-sync
UNIQUE MoW, sequence_col, HASH bucket
Dashboard with pre-aggregated metrics
usecase-dashboard-metrics
AGGREGATE, BITMAP_UNION, sync MV
User-facing API with low-latency point queries
usecase-point-query
UNIQUE MoW, store_row_column, BloomFilter
Star schema with JOIN-heavy analytics
usecase-star-schema-join
Colocation, same bucket key/count
Small dimension / lookup table
usecase-dimension-lookup
DUPLICATE, RANDOM bucket, 3 buckets
Observability (logs + traces + metrics)
usecase-observability
3 tables: DUP logs, DUP traces, AGG metrics
Vehicle/fleet tracking
usecase-log-event
+
usecase-point-query
Time-series + point-query hybrid
E-commerce order analytics
usecase-star-schema-join
+
usecase-dashboard-metrics
Star schema + AGG rollups
Full-text search / content search
schema-index-text-search
Inverted index, MATCH, BM25
User behavior / funnel analysis
schema-types-bitmap-count-distinct
BITMAP_UNION, bitmap_intersect
Semi-structured JSON data
schema-types-variant-json
VARIANT type, schema_template
业务场景模板核心规则
实时日志/事件分析
usecase-log-event
DUPLICATE、RANGE 分区、动态TTL、ZSTD
CDC / MySQL 同步至 Doris
usecase-cdc-sync
UNIQUE MoW、sequence_col、HASH 分桶
含预聚合指标的仪表板
usecase-dashboard-metrics
AGGREGATE、BITMAP_UNION、同步MV
低延迟点查询的用户API
usecase-point-query
UNIQUE MoW、store_row_column、BloomFilter
多JOIN分析的星型 schema
usecase-star-schema-join
Colocation、相同分桶键/数量
小维度/ lookup表
usecase-dimension-lookup
DUPLICATE、RANDOM 分桶、3个分桶
可观测性(日志+链路追踪+指标)
usecase-observability
3张表:DUP日志表、DUP链路追踪表、AGG指标表
车辆/车队追踪
usecase-log-event
+
usecase-point-query
时序数据+点查询混合模式
电商订单分析
usecase-star-schema-join
+
usecase-dashboard-metrics
星型schema+AGG预聚合
全文检索/内容搜索
schema-index-text-search
倒排索引、MATCH、BM25
用户行为/漏斗分析
schema-types-bitmap-count-distinct
BITMAP_UNION、bitmap_intersect
半结构化JSON数据
schema-types-variant-json
VARIANT类型、schema_template

My query is slow after evidence shows…

证据显示我的查询变慢…

For live slow-query or runtime diagnosis, do not use this table as the first response. First read
references/cli-investigation.md
and collect or attempt evidence (
profile get
,
profile list
,
profile history
,
tablet
,
EXPLAIN
, or
auth status
). Use this table only after evidence points to the symptom.
SymptomCheck These RulesQuick Fix
Full table scan on WHERE clause
schema-keys-selectivity-first
Move filtered column to sort key position 1
JOINs are slow / shuffle
usecase-star-schema-join
Small dims (<1GB): broadcast + runtime filter. Large: colocation
COUNT DISTINCT is slow
schema-types-bitmap-count-distinct
Switch to BITMAP_UNION aggregation
LIKE '%keyword%' is slow
schema-index-ngram-for-like
Add NGram BloomFilter index
Point query latency too high
usecase-point-query
Enable store_row_column + Prepared Statement
Storage growing too fast
schema-partition-auto-on-demand
+
schema-props-compression
AUTO PARTITION + ZSTD compression + scheduled DROP PARTITION
Sync MV not being used
schema-mv-sync-rollup
Use raw columns (not date_trunc) in MV GROUP BY; unique aliases
Async MV rewrite fails
schema-mv-async-join
+
schema-mv-async-limits
Check State/RefreshState; query MV directly if predicate fails
Data skew / hot tablets
schema-bucket-composite-for-skew
Composite bucket key or RANDOM
Import fails / data version error
schema-mv-async-limits
Check concurrent MV refresh limit (max 3)
VARCHAR in key kills perf
schema-keys-fixed-length-types
Move VARCHAR after fixed-length types
Writes slow on UNIQUE table
schema-model-prefer-mow
Ensure MoW is enabled (not MoR)

对于实时慢查询或运行时诊断,请勿直接使用下表作为第一响应。请先阅读
references/cli-investigation.md
并收集或尝试获取证据(
profile get
profile list
profile history
tablet
EXPLAIN
auth status
)。仅当证据指向对应症状时,再使用下表。
症状检查对应规则快速修复方案
WHERE子句触发全表扫描
schema-keys-selectivity-first
将过滤列移至排序键第1位
JOIN操作缓慢/数据 shuffle
usecase-star-schema-join
小维度表(<1GB):广播+运行时过滤;大表:Colocation
COUNT DISTINCT 缓慢
schema-types-bitmap-count-distinct
切换为 BITMAP_UNION 聚合
LIKE '%keyword%' 缓慢
schema-index-ngram-for-like
添加NGram BloomFilter索引
点查询延迟过高
usecase-point-query
启用 store_row_column + Prepared Statement
存储增长过快
schema-partition-auto-on-demand
+
schema-props-compression
AUTO分区 + ZSTD压缩 + 定期删除分区
同步MV未被使用
schema-mv-sync-rollup
MV的GROUP BY使用原始列(而非date_trunc);使用唯一别名
异步MV重写失败
schema-mv-async-join
+
schema-mv-async-limits
检查State/RefreshState;若谓词失败,直接查询MV
数据倾斜/热点Tablet
schema-bucket-composite-for-skew
复合分桶键或RANDOM分桶
导入失败/数据版本错误
schema-mv-async-limits
检查并发MV刷新限制(最多3个)
键中包含VARCHAR导致性能下降
schema-keys-fixed-length-types
将VARCHAR列移至定长类型之后
UNIQUE表写入缓慢
schema-model-prefer-mow
确保启用MoW(而非MoR)

2 ▸ Pre-Flight Checklist (Before Any CREATE TABLE)

2 ▸ 预检查清单(创建任何表之前)

Run through this checklist in order. Each step references the relevant rule:
  • Data model — UNIQUE (updates?) vs DUPLICATE (append?) vs AGGREGATE (pre-agg only?) →
    schema-model-choose-for-workload
  • Partition strategy — Time-series? AUTO PARTITION preferred. Small table? Skip. Do NOT combine AUTO with dynamic_partition. →
    schema-partition-*
  • Bucket key + count — HASH on JOIN key. Calculate explicit count:
    daily_GB / target_tablet_GB
    . Use explicit fallback counts when volume is unknown: 3 for small dimensions, 8 for medium tables, 16-32 for large daily fact tables. →
    schema-bucket-*
  • Sort key order — High-selectivity first, fixed-length before VARCHAR →
    schema-keys-*
  • Data types — Native types, not STRING. DECIMAL not FLOAT. →
    schema-types-*
  • Indexes — BloomFilter for equality, Inverted for text, NGram for LIKE →
    schema-index-*
  • Properties — MoW enabled? Compression? Cloud mode replication_num=1? →
    schema-props-*
  • DDL hard constraints (VeloDB rejects DDL if any violated):
    • UNIQUE KEY + PARTITION BY RANGE → partition column MUST be in the UNIQUE KEY:
      UNIQUE KEY(id, dt) PARTITION BY RANGE(dt)
    • Key columns must be the FIRST N columns in schema, same order — put key cols first, non-key after. Example:
      UNIQUE KEY(account_id, symbol)
      means schema must start with
      account_id, symbol, ...
      — never place non-key columns between key columns
    • store_row_column = "true"
      only works on UNIQUE MoW — NOT on AGGREGATE or DUPLICATE
    • AUTO PARTITION requires
      date_trunc()
      AND empty parens:
      AUTO PARTITION BY RANGE(date_trunc(col, 'day')) ()
      — bare column name fails, missing
      ()
      fails
    • Dynamic partition requires explicit
      PARTITION BY RANGE(col) ()
      clause in DDL — properties alone are not enough
    • Do not set
      dynamic_partition.buckets
      ; put the numeric count only in
      DISTRIBUTED BY HASH(col) BUCKETS N
    • compaction_policy = "time_series"
      only for DUPLICATE tables — fails on UNIQUE
    • Async MV refresh: use
      REFRESH AUTO ON SCHEDULE EVERY 10 MINUTE
      or
      REFRESH COMPLETE ON SCHEDULE EVERY 10 MINUTE
      — NOT
      REFRESH SCHEDULE EVERY
      , NOT
      REFRESH ASYNC EVERY(INTERVAL ...)
      . Minimum interval: 1 MINUTE
    • MV using
      NOW()
      /
      CURDATE()
      : add
      PROPERTIES ("enable_nondeterministic_function" = "true")
    • BOOLEAN defaults must be quoted:
      DEFAULT "true"
      not
      DEFAULT TRUE
    • BloomFilter index: use
      PROPERTIES ("bloom_filter_columns" = "col1,col2")
      — NOT inline
      INDEX ... USING BLOOM FILTER
    • AGGREGATE column syntax: aggregation function BEFORE default:
      col BIGINT SUM DEFAULT "0"
      — NOT
      col BIGINT DEFAULT "0" SUM
    • AGGREGATE
      DEFAULT "null"
      only works for VARCHAR — fails on INT, DATE, DECIMAL, BIGINT. Omit DEFAULT entirely for REPLACE_IF_NOT_NULL on non-string types:
      vip_level INT REPLACE_IF_NOT_NULL
      (not
      DEFAULT "null"
      )
    • enable_unique_key_partial_update
      is a session variable, NOT a table property
    • Full details:
      schema-ddl-gotchas

按顺序完成以下检查,每一步对应相关规则:
  • 数据模型 — UNIQUE(需要更新?)vs DUPLICATE(仅追加?)vs AGGREGATE(仅预聚合?)→
    schema-model-choose-for-workload
  • 分区策略 — 时序数据?优先使用AUTO分区。小表?跳过分区。请勿同时使用AUTO和dynamic_partition。→
    schema-partition-*
  • 分桶键+数量 — 基于JOIN键进行HASH分桶。明确计算数量:
    每日数据量GB / 目标Tablet大小GB
    。若数据量未知,使用默认值:小维度表3个,中等表8个,大型日事实表16-32个。→
    schema-bucket-*
  • 排序键顺序 — 高选择性列优先,定长类型列在VARCHAR之前 →
    schema-keys-*
  • 数据类型 — 使用原生类型,而非STRING。使用DECIMAL而非FLOAT。→
    schema-types-*
  • 索引 — 等值查询用BloomFilter,文本查询用倒排索引,LIKE查询用NGram →
    schema-index-*
  • 表属性 — 是否启用MoW?压缩配置?云模式下replication_num=1?→
    schema-props-*
  • DDL硬约束(违反则VeloDB会拒绝DDL):
    • UNIQUE KEY + PARTITION BY RANGE → 分区列必须包含在UNIQUE KEY中:
      UNIQUE KEY(id, dt) PARTITION BY RANGE(dt)
    • 键列必须是schema中的前N列,顺序一致——键列在前,非键列在后。示例:
      UNIQUE KEY(account_id, symbol)
      意味着schema必须以
      account_id, symbol, ...
      开头——切勿在键列之间插入非键列
    • store_row_column = "true"
      仅适用于UNIQUE MoW表——不适用于AGGREGATE或DUPLICATE表
    • AUTO分区需要
      date_trunc()
      及空括号:
      AUTO PARTITION BY RANGE(date_trunc(col, 'day')) ()
      ——仅列名或缺少
      ()
      都会失败
    • 动态分区需要在DDL中显式声明
      PARTITION BY RANGE(col) ()
      子句——仅靠属性配置无效
    • 请勿设置
      dynamic_partition.buckets
      ;分桶数量仅需在
      DISTRIBUTED BY HASH(col) BUCKETS N
      中指定
    • compaction_policy = "time_series"
      仅适用于DUPLICATE表——在UNIQUE表上会失败
    • 异步MV刷新:使用
      REFRESH AUTO ON SCHEDULE EVERY 10 MINUTE
      REFRESH COMPLETE ON SCHEDULE EVERY 10 MINUTE
      ——请勿使用
      REFRESH SCHEDULE EVERY
      REFRESH ASYNC EVERY(INTERVAL ...)
      。最小间隔为1分钟
    • MV使用
      NOW()
      /
      CURDATE()
      :添加
      PROPERTIES ("enable_nondeterministic_function" = "true")
    • BOOLEAN类型默认值必须加引号:
      DEFAULT "true"
      而非
      DEFAULT TRUE
    • BloomFilter索引:使用
      PROPERTIES ("bloom_filter_columns" = "col1,col2")
      ——请勿使用内联
      INDEX ... USING BLOOM FILTER
    • AGGREGATE列语法:聚合函数在默认值之前:
      col BIGINT SUM DEFAULT "0"
      ——而非
      col BIGINT DEFAULT "0" SUM
    • AGGREGATE表的
      DEFAULT "null"
      仅适用于VARCHAR类型——在INT、DATE、DECIMAL、BIGINT类型上会失败。非字符串类型使用REPLACE_IF_NOT_NULL时请省略DEFAULT:
      vip_level INT REPLACE_IF_NOT_NULL
      (而非
      DEFAULT "null"
    • enable_unique_key_partial_update
      是会话变量,而非表属性
    • 详细信息:
      schema-ddl-gotchas

2b ▸ DDL Templates (copy the closest match, customize columns)

2b ▸ DDL模板(复制最匹配的模板,自定义列)

For each CREATE TABLE, select the closest template below. Customize column names, types, bucket count, and partition settings. Do NOT write DDL from scratch.
创建表时,请选择以下最匹配的模板,自定义列名、类型、分桶数量和分区设置。请勿从零开始编写DDL。

T1: Append-only events/logs (DUPLICATE)

T1: 仅追加的事件/日志表(DUPLICATE)

sql
CREATE TABLE events (
    entity_id    VARCHAR(64)  NOT NULL,
    event_time   DATETIME     NOT NULL,
    event_type   VARCHAR(50)  NOT NULL,
    payload      VARIANT
) DUPLICATE KEY(entity_id, event_time, event_type)
PARTITION BY RANGE(event_time) ()
DISTRIBUTED BY HASH(entity_id) BUCKETS 10
PROPERTIES (
    "dynamic_partition.enable" = "true",
    "dynamic_partition.time_unit" = "DAY",
    "dynamic_partition.start" = "-90",
    "dynamic_partition.end" = "3",
    "dynamic_partition.prefix" = "p",
    "compression" = "zstd",
    "compaction_policy" = "time_series",
    "replication_num" = "1"
);
sql
CREATE TABLE events (
    entity_id    VARCHAR(64)  NOT NULL,
    event_time   DATETIME     NOT NULL,
    event_type   VARCHAR(50)  NOT NULL,
    payload      VARIANT
) DUPLICATE KEY(entity_id, event_time, event_type)
PARTITION BY RANGE(event_time) ()
DISTRIBUTED BY HASH(entity_id) BUCKETS 10
PROPERTIES (
    "dynamic_partition.enable" = "true",
    "dynamic_partition.time_unit" = "DAY",
    "dynamic_partition.start" = "-90",
    "dynamic_partition.end" = "3",
    "dynamic_partition.prefix" = "p",
    "compression" = "zstd",
    "compaction_policy" = "time_series",
    "replication_num" = "1"
);

T2: Updatable with partition (UNIQUE MoW + CDC)

T2: 可更新带分区表(UNIQUE MoW + CDC)

sql
CREATE TABLE orders (
    order_id     BIGINT       NOT NULL,
    order_time   DATETIME     NOT NULL,
    update_time  DATETIME     NOT NULL,
    status       VARCHAR(20),
    amount       DECIMAL(18,2)
) UNIQUE KEY(order_id, order_time)
PARTITION BY RANGE(order_time) ()
DISTRIBUTED BY HASH(order_id) BUCKETS 5
PROPERTIES (
    "enable_unique_key_merge_on_write" = "true",
    "function_column.sequence_col" = "update_time",
    "dynamic_partition.enable" = "true",
    "dynamic_partition.time_unit" = "DAY",
    "dynamic_partition.start" = "-365",
    "dynamic_partition.end" = "3",
    "dynamic_partition.prefix" = "p",
    "replication_num" = "1"
);
sql
CREATE TABLE orders (
    order_id     BIGINT       NOT NULL,
    order_time   DATETIME     NOT NULL,
    update_time  DATETIME     NOT NULL,
    status       VARCHAR(20),
    amount       DECIMAL(18,2)
) UNIQUE KEY(order_id, order_time)
PARTITION BY RANGE(order_time) ()
DISTRIBUTED BY HASH(order_id) BUCKETS 5
PROPERTIES (
    "enable_unique_key_merge_on_write" = "true",
    "function_column.sequence_col" = "update_time",
    "dynamic_partition.enable" = "true",
    "dynamic_partition.time_unit" = "DAY",
    "dynamic_partition.start" = "-365",
    "dynamic_partition.end" = "3",
    "dynamic_partition.prefix" = "p",
    "replication_num" = "1"
);

T3: Small dimension / lookup (UNIQUE, no partition)

T3: 小维度/ lookup表(UNIQUE,无分区)

sql
CREATE TABLE dim_product (
    product_id   INT          NOT NULL,
    name         VARCHAR(200),
    category     VARCHAR(50)
) UNIQUE KEY(product_id)
DISTRIBUTED BY HASH(product_id) BUCKETS 3
PROPERTIES (
    "enable_unique_key_merge_on_write" = "true",
    "replication_num" = "1"
);
sql
CREATE TABLE dim_product (
    product_id   INT          NOT NULL,
    name         VARCHAR(200),
    category     VARCHAR(50)
) UNIQUE KEY(product_id)
DISTRIBUTED BY HASH(product_id) BUCKETS 3
PROPERTIES (
    "enable_unique_key_merge_on_write" = "true",
    "replication_num" = "1"
);

T4: Pre-aggregated KPIs (AGGREGATE)

T4: 预聚合KPI表(AGGREGATE)

sql
CREATE TABLE daily_kpi (
    stat_date    DATE         NOT NULL,
    dimension    VARCHAR(50)  NOT NULL,
    metric_sum   BIGINT       SUM DEFAULT "0",
    metric_max   DOUBLE       MAX DEFAULT "0",
    unique_users BITMAP       BITMAP_UNION
) AGGREGATE KEY(stat_date, dimension)
PARTITION BY RANGE(stat_date) ()
DISTRIBUTED BY HASH(dimension) BUCKETS 3
PROPERTIES (
    "dynamic_partition.enable" = "true",
    "dynamic_partition.time_unit" = "MONTH",
    "dynamic_partition.start" = "-12",
    "dynamic_partition.end" = "1",
    "dynamic_partition.prefix" = "p",
    "replication_num" = "1"
);
sql
CREATE TABLE daily_kpi (
    stat_date    DATE         NOT NULL,
    dimension    VARCHAR(50)  NOT NULL,
    metric_sum   BIGINT       SUM DEFAULT "0",
    metric_max   DOUBLE       MAX DEFAULT "0",
    unique_users BITMAP       BITMAP_UNION
) AGGREGATE KEY(stat_date, dimension)
PARTITION BY RANGE(stat_date) ()
DISTRIBUTED BY HASH(dimension) BUCKETS 3
PROPERTIES (
    "dynamic_partition.enable" = "true",
    "dynamic_partition.time_unit" = "MONTH",
    "dynamic_partition.start" = "-12",
    "dynamic_partition.end" = "1",
    "dynamic_partition.prefix" = "p",
    "replication_num" = "1"
);

T5: Point query / API serving (UNIQUE MoW + row store)

T5: 点查询/API服务表(UNIQUE MoW + 行存储)

sql
CREATE TABLE user_profiles (
    user_id      BIGINT       NOT NULL,
    update_time  DATETIME     NOT NULL,
    name         VARCHAR(100),
    data         VARIANT
) UNIQUE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 5
PROPERTIES (
    "enable_unique_key_merge_on_write" = "true",
    "function_column.sequence_col" = "update_time",
    "store_row_column" = "true",
    "light_schema_change" = "true",
    "replication_num" = "1"
);

sql
CREATE TABLE user_profiles (
    user_id      BIGINT       NOT NULL,
    update_time  DATETIME     NOT NULL,
    name         VARCHAR(100),
    data         VARIANT
) UNIQUE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 5
PROPERTIES (
    "enable_unique_key_merge_on_write" = "true",
    "function_column.sequence_col" = "update_time",
    "store_row_column" = "true",
    "light_schema_change" = "true",
    "replication_num" = "1"
);

3 ▸ Connection & VeloCLI

3 ▸ 连接与VeloCLI

Detect VeloCLI

检测VeloCLI

Before running any queries, detect the CLI binary:
  1. Check
    VELOCLI_PATH
    env var — if set, use that binary path
  2. command -v velocli
    — use from PATH
  3. command -v sdbcli
    — only for explicit SelectDB environments
  4. If none available: fall back to
    mysql
    client (see
    references/start-*.md
    )
运行任何查询前,请先检测CLI二进制文件:
  1. 检查环境变量
    VELOCLI_PATH
    ——若已设置,使用该路径
  2. command -v velocli
    ——使用PATH中的可执行文件
  3. command -v sdbcli
    ——仅适用于明确的SelectDB环境
  4. 若以上均不可用: fallback至
    mysql
    客户端(详见
    references/start-*.md

When VeloCLI is available, prefer it for all operations:

若VeloCLI可用,优先使用它执行所有操作:

TaskVeloCLI Command
Run SQL
velocli sql "SELECT ..."
DDL inspection
velocli sql "SHOW CREATE TABLE db.t"
Table/tablet health
velocli tablet db.t
(overview) or
velocli tablet db.t --detail
Profile a slow query
velocli sql "SELECT ..." --profile
→ captures query_id
Get query profile
velocli profile get <qid>
or
--full
for complete diagnosis
Compare fast vs slow
velocli profile diff <slow_qid> <fast_qid>
Performance trend
velocli profile history <sql_pattern> --days 7
Test connection
velocli auth status
Switch environment
velocli use <name>
任务VeloCLI命令
执行SQL
velocli sql "SELECT ..."
DDL检查
velocli sql "SHOW CREATE TABLE db.t"
表/Tablet健康状态
velocli tablet db.t
(概览)或
velocli tablet db.t --detail
(详情)
慢查询性能分析
velocli sql "SELECT ..." --profile
→ 捕获query_id
获取查询性能分析报告
velocli profile get <qid>
或添加
--full
获取完整诊断信息
对比快慢查询
velocli profile diff <slow_qid> <fast_qid>
性能趋势
velocli profile history <sql_pattern> --days 7
测试连接
velocli auth status
切换环境
velocli use <name>

Runtime Query Investigation

运行时查询排查

For slow queries or runtime performance issues, read
references/cli-investigation.md
.
  • Evidence first is mandatory: collect or attempt profile, tablet, DDL, stats, EXPLAIN, history, active-query, or connection evidence before forming hypotheses. If evidence cannot be collected locally, state that and provide the exact commands to run
  • Prefer existing profiles: use
    profile get <query_id>
    ,
    profile list
    , or
    profile history
    before re-executing SQL
  • Proactive discovery: for vague slow-query reports, start with
    auth status
    ,
    profile list --active
    , and recent
    profile list
    before asking the user for more context
  • Safety gate: before running user SQL with
    --profile
    , check whether it is safe (no DDL, no mutation, no unbounded scan). For unknown, peak-hour, or expensive SQL, run
    velocli sql "EXPLAIN <query>" --format json
    first and ask confirmation or request an existing query_id
  • Hypotheses, not verdicts: diagnostic mappings are heuristics. Present evidence, likely cause, what to check next, and when the conclusion may be wrong
  • If velocli is unavailable, fall back to SQL commands listed in the reference
  • Always use
    --format json
    for structured agent-readable output
对于慢查询或运行时性能问题,请阅读
references/cli-investigation.md
  • 必须优先收集证据:在形成假设前,先收集或尝试获取性能分析报告、Tablet信息、DDL、统计数据、EXPLAIN结果、历史记录、活跃查询或连接证据。若无法本地收集证据,请说明情况并提供具体执行命令
  • 优先使用已有性能分析报告:在重新执行SQL前,先使用
    profile get <query_id>
    profile list
    profile history
  • 主动排查:对于模糊的慢查询报告,先执行
    auth status
    profile list --active
    和近期的
    profile list
    ,再向用户询问更多上下文
  • 安全校验:使用
    --profile
    运行用户提供的SQL前,检查是否安全(无DDL、无数据变更、无无界扫描)。对于未知、高峰时段或高成本SQL,先执行
    velocli sql "EXPLAIN <query>" --format json
    ,并请求确认或获取已有的query_id
  • 提出假设而非定论:诊断映射为启发式规则。请呈现证据、可能原因、下一步检查项及结论可能错误的场景
  • 若velocli不可用,fallback至参考文档中的SQL命令
  • 始终使用
    --format json
    获取结构化、可被Agent读取的输出

Quick-start guides

快速入门指南

  • references/start-cloud.md
    — VeloDB Cloud
  • references/start-self-hosted.md
    — Self-hosted / BYOC / on-prem

  • references/start-cloud.md
    ——VeloDB云服务
  • references/start-self-hosted.md
    ——自建/BYOC/本地部署

4 ▸ Cluster Sizing

4 ▸ 集群容量规划

Sizing guides are in:
  • references/sizing-fe.md
    — FE node sizing
  • references/sizing-be-integrated.md
    — BE sizing (integrated storage)
  • references/sizing-be-cloud.md
    — BE sizing (cloud / storage-compute)
  • references/sizing-storage-formula.md
    — Storage calculation formula

容量规划指南位于:
  • references/sizing-fe.md
    ——FE节点容量规划
  • references/sizing-be-integrated.md
    ——BE节点容量规划(集成存储)
  • references/sizing-be-cloud.md
    ——BE节点容量规划(云/存算分离)
  • references/sizing-storage-formula.md
    ——存储计算公式

5 ▸ Rule Index by Category

5 ▸ 按类别划分的规则索引

Data Model — CRITICAL (4 rules)

数据模型 — 关键(4条规则)

  • schema-model-choose-for-workload
    — DUP vs UNIQUE vs AGG decision tree
  • schema-model-prefer-mow
    — Always MoW for UNIQUE tables
  • schema-model-avoid-agg-for-updates
    — AGG cannot UPDATE/DELETE
  • schema-model-sequence-col-for-cdc
    — Sequence column for out-of-order CDC
  • schema-model-choose-for-workload
    — DUP、UNIQUE、AGG选型决策树
  • schema-model-prefer-mow
    — UNIQUE表始终使用MoW
  • schema-model-avoid-agg-for-updates
    — AGG表无法执行UPDATE/DELETE
  • schema-model-sequence-col-for-cdc
    — 为乱序CDC数据设置sequence列

Partition Strategy — CRITICAL (4 rules)

分区策略 — 关键(4条规则)

  • schema-partition-range-for-timeseries
    — RANGE for time-series
  • schema-partition-dynamic-ttl
    — Dynamic partition for automated TTL
  • schema-partition-auto-on-demand
    — AUTO for sporadic data
  • schema-partition-skip-for-small
    — Skip partitioning under 1 GB
  • schema-partition-range-for-timeseries
    — 时序数据使用RANGE分区
  • schema-partition-dynamic-ttl
    — 动态分区实现自动TTL
  • schema-partition-auto-on-demand
    — 零散数据使用AUTO分区
  • schema-partition-skip-for-small
    — 数据量小于1GB时跳过分区

Bucket Strategy — CRITICAL (5 rules)

分桶策略 — 关键(5条规则)

  • schema-bucket-hash-vs-random
    — HASH for pruning, RANDOM for DUP only
  • schema-bucket-high-cardinality-key
    — Choose high-cardinality column
  • schema-bucket-composite-for-skew
    — Composite key to fix data skew
  • schema-bucket-target-size
    — Target 1-10 GB per tablet
  • schema-bucket-cloud-mandatory-hash
    — Cloud MoW requires HASH
  • schema-bucket-hash-vs-random
    — 哈希分桶用于数据裁剪,随机分桶仅适用于DUP表
  • schema-bucket-high-cardinality-key
    — 选择高基数列作为分桶键
  • schema-bucket-composite-for-skew
    — 复合分桶键解决数据倾斜
  • schema-bucket-target-size
    — 每个Tablet目标大小为1-10GB
  • schema-bucket-cloud-mandatory-hash
    — 云MoW表必须使用哈希分桶

Sort Key — CRITICAL (5 rules)

排序键 — 关键(5条规则)

  • schema-keys-selectivity-first
    — High selectivity first
  • schema-keys-fixed-length-types
    — Fixed-length before VARCHAR
  • schema-keys-prefix-index-limits
    — 36 bytes max, VARCHAR terminates it
  • schema-keys-cluster-key-for-mow
    — Cluster key for UNIQUE tables
  • schema-keys-avoid-float
    — No FLOAT/DOUBLE in sort key
  • schema-keys-selectivity-first
    — 高选择性列优先
  • schema-keys-fixed-length-types
    — 定长类型列在VARCHAR之前
  • schema-keys-prefix-index-limits
    — 前缀索引最大36字节,VARCHAR会终止前缀索引
  • schema-keys-cluster-key-for-mow
    — UNIQUE表使用集群键
  • schema-keys-avoid-float
    — 排序键中避免使用FLOAT/DOUBLE

Data Types — HIGH (5 rules)

数据类型 — 重要(5条规则)

  • schema-types-native-vs-string
    — Native types, not STRING
  • schema-types-zonemap-limitations
    — JSON/ARRAY disable ZoneMap
  • schema-types-variant-json
    — VARIANT for semi-structured JSON
  • schema-types-bitmap-count-distinct
    — BITMAP_UNION for exact count-distinct
  • schema-types-doris-specifics
    — DATETIME precision, VARCHAR vs STRING
  • schema-types-native-vs-string
    — 使用原生类型,而非STRING
  • schema-types-zonemap-limitations
    — JSON/ARRAY类型会禁用ZoneMap
  • schema-types-variant-json
    — 半结构化JSON使用VARIANT类型
  • schema-types-bitmap-count-distinct
    — BITMAP_UNION实现精确去重计数
  • schema-types-doris-specifics
    — DATETIME精度、VARCHAR vs STRING

Indexes — HIGH (7 rules)

索引 — 重要(7条规则)

  • schema-index-bloomfilter
    — BloomFilter for equality
  • schema-index-inverted
    — Inverted for text/range
  • schema-index-ngram-for-like
    — NGram for LIKE %pattern%
  • schema-index-bitmap
    — Bitmap for medium cardinality
  • schema-index-vector
    — HNSW/IVF for ANN search
  • schema-index-text-search
    — Full-text MATCH + BM25
  • schema-index-bloomfilter
    — 等值查询使用BloomFilter
  • schema-index-inverted
    — 文本/范围查询使用倒排索引
  • schema-index-ngram-for-like
    — LIKE %pattern%查询使用NGram
  • schema-index-bitmap
    — 中等基数列使用Bitmap索引
  • schema-index-vector
    — 近似最近邻搜索使用HNSW/IVF
  • schema-index-text-search
    — 全文检索使用MATCH + BM25

Query Acceleration — HIGH (3 rules)

查询加速 — 重要(3条规则)

  • schema-mv-sync-rollup
    — Sync MV for single-table aggregation
  • schema-mv-async-join
    — Async MV for multi-table JOIN
  • schema-mv-async-limits
    — Operational limits (50M rows, 3 concurrent)
  • schema-mv-sync-rollup
    — 单表聚合使用同步MV
  • schema-mv-async-join
    — 多表JOIN使用异步MV
  • schema-mv-async-limits
    — 操作限制(5000万行、3个并发)

Table Properties — HIGH/MEDIUM (2 rules)

表属性 — 重要/中等(2条规则)

  • schema-props-cloud-forced
    — Cloud mode forced properties
  • schema-props-compression
    — LZ4 vs ZSTD compression
  • schema-props-cloud-forced
    — 云模式强制属性
  • schema-props-compression
    — LZ4 vs ZSTD压缩

Caching — MEDIUM (2 rules)

缓存 — 中等(2条规则)

  • schema-cache-file-cache
    — File cache for cloud mode
  • schema-cache-query-partition
    — Query and partition cache
  • schema-cache-file-cache
    — 云模式下的文件缓存
  • schema-cache-query-partition
    — 查询与分区缓存