Skip to main content
VeloDB Cloud 26.x is based on Apache Doris 4.x. See Version Mapping.

Table Model Overview

Choose a table model when you create a table in a VeloDB Cloud warehouse. The model determines whether writes retain every row, update rows by key, or aggregate values by key. VeloDB Cloud supports three models: Duplicate Key, Unique Key, and Aggregate Key. You cannot change the model after creating the table.

Choose a table model by scenario​

The following table helps you quickly decide which table model to use before creating a table:

Business ScenarioRecommended ModelKey Characteristics
Logs, events, behavior analysis, and other cases that need to retain all raw recordsDuplicate model (Duplicate Key)Key columns may repeat; suitable for ad-hoc queries on any dimension
Real-time dimension tables, orders, user profiles, and other cases that update by primary keyUnique model (Unique Key)Key columns are unique; only the latest data for the same Key is kept
Report rollups, traffic statistics, and other fixed analyses that require pre-aggregationAggregate model (Aggregate Key)Pre-aggregates by Key columns to reduce scan volume and computation

Compare model behavior​

Duplicate Key model​

  • Core mechanism: The specified Key columns are allowed to repeat. The storage layer keeps all written data without deduplication or aggregation.
  • Applicable scenarios: Cases that must retain all raw data records, such as logs, detail events, and behavior streams.
  • Advantages: Free from aggregation constraints, it can fully take advantage of columnar storage. Queries read only the relevant columns and do not need to read all Key columns, which makes it suitable for ad-hoc queries on any dimension.
  • Limitations: Writes do not pre-aggregate data. Use an asynchronous materialized view when the workload needs precomputed aggregates.
  • Details: Duplicate model

Unique Key model​

  • Core mechanism: Each key identifies one logical row. Queries return the latest row for each key. Older physical versions are removed during compaction.
  • Applicable scenarios: Cases that require a unique primary key constraint and where data is continuously updated, such as real-time dimension tables, order status, and user profiles.
  • Advantages: Guarantees primary key uniqueness, supports UPDATE and DELETE statements, and supports both whole-row updates and partial-column updates during ingestion.
  • Limitations: Writes do not pre-aggregate data. Use an asynchronous materialized view when the workload needs precomputed aggregates.
  • Details: Unique model

Aggregate Key model​

  • Core mechanism: Combines Value columns by Key columns during ingestion, compaction, and query execution. Queries return the final aggregated values.
  • Applicable scenarios: Report-style queries with fixed dimensions, such as metric rollups, traffic statistics, and ad click aggregation.
  • Advantages: Pre-aggregation greatly reduces the amount of data scanned and the computation required at query time.
  • Limitations:
    • Requires additional work for count(*) queries because all Key columns must be combined to count logical rows.
    • The aggregation method of Value columns is fixed at table creation time. When running other types of aggregation queries, you must consider semantic correctness.
  • Details: Aggregate model

Tip:

Both the Unique model and the Aggregate model support partial column updates. See Partial column update of the Unique model and Partial column update of the Aggregate model for usage recommendations.

Sort key​

Table data is stored by column. Columns fall into two categories:

  • Key columns: Used for grouping and sorting, explicitly specified at table creation time.
  • Value columns: Hold the remaining fields. Their treatment depends on the table model: retain them, replace them on an upsert, or combine them with a declared aggregation method.

Key columns can consist of one or more fields. Key columns define the storage sort order. In the Unique and Aggregate models, they also identify rows to replace or combine. The meaning of Key columns differs slightly across models:

Table ModelRole of Key Columns
Duplicate model (Duplicate Key)Used only for sorting; uniqueness is not enforced
Unique model (Unique Key)Sorting plus uniqueness constraint; used to deduplicate by primary key
Aggregate model (Aggregate Key)Sorting plus uniqueness constraint; used to pre-aggregate by Key

Benefits of a well-designed sort key​

Key columns affect data access, compression, and row identity:

  1. Accelerates query performance: The sort key helps reduce the amount of data scanned. Range queries or filter queries can locate data directly based on the sort key, and queries that require sorting can also be accelerated by the sort key.
  2. Optimizes data compression: Similar data is clustered together by the sort key, which significantly improves the compression ratio and reduces storage usage.
  3. Defines rows to deduplicate: In the Unique model, Key columns identify the rows to deduplicate.

Sort key design recommendations​

When designing Key columns, follow these principles:

  • Key columns must come before all Value columns.
  • Prefer integer types: Integers are far more efficient than strings for computation and lookup.
  • Use integer lengths only as large as needed: Within the range required by the business, choose the shortest integer type possible.
  • Choose string types to match the data: Use the smallest sufficient declared length for VARCHAR. The STRING type does not take a declared length and is restricted to Value columns.

Compare table-model capabilities​

The following table summarizes the differences across the three table models in deduplication, views, updates, and ingestion:

CapabilityDuplicate ModelUnique ModelAggregate Model
Key column uniqueness constraintNot supported; Key columns may repeatSupportedSupported
Synchronous materialized viewSupportedSupportedSupported
Asynchronous materialized viewSupportedSupportedSupported
UPDATE statementNot supportedSupportedNot supported
DELETE statementSupported with restrictionsSupportedSupported on Key columns, with Rollup restrictions
Whole-row update during ingestionNot supportedSupportedNot supported
Partial column update during ingestionNot supportedSupportedPartially supported

For Aggregate Key tables, delete predicates can reference only Key columns, and those columns must exist in each Rollup. See Delete data with SQL for model-specific and partition restrictions.

Next steps​

After understanding the differences between the models, continue with the detailed documentation for each: