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 Scenario | Recommended Model | Key Characteristics |
|---|---|---|
| Logs, events, behavior analysis, and other cases that need to retain all raw records | Duplicate 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 key | Unique 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-aggregation | Aggregate 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
UPDATEandDELETEstatements, 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.
- Requires additional work for
- 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 Model | Role 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:
- 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.
- Optimizes data compression: Similar data is clustered together by the sort key, which significantly improves the compression ratio and reduces storage usage.
- 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. TheSTRINGtype 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:
| Capability | Duplicate Model | Unique Model | Aggregate Model |
|---|---|---|---|
| Key column uniqueness constraint | Not supported; Key columns may repeat | Supported | Supported |
| Synchronous materialized view | Supported | Supported | Supported |
| Asynchronous materialized view | Supported | Supported | Supported |
UPDATE statement | Not supported | Supported | Not supported |
DELETE statement | Supported with restrictions | Supported | Supported on Key columns, with Rollup restrictions |
| Whole-row update during ingestion | Not supported | Supported | Not supported |
| Partial column update during ingestion | Not supported | Supported | Partially 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:
Duplicate Model
Duplicate Key model in detail: table creation syntax and write behavior. Suitable for scenarios that need to retain raw records, such as logs and events.
Unique Model
Unique Key model in detail: primary key deduplication, UPDATE/DELETE, and partial column updates. Suitable for real-time update scenarios.
Aggregate Model
Aggregate Key model in detail: the pre-aggregation mechanism and the choice of aggregation functions. Suitable for report and metric rollup analysis.
Best Practices
Table model selection recommendations, limitations of the Aggregate model, and best practices for Key columns and data types at table creation time.