Skip to content
10.1 Overview and Use Criteria

10.1 Overview and Use Criteria

VOLATILE tables store temporary data in memory. Data is lost when the server restarts, so use them for current state that can be rebuilt, temporary aggregates, and caches shared across sessions.

VOLATILE Table Characteristics

Create a VOLATILE table with CREATE VOLATILE TABLE.

CREATE VOLATILE TABLE ch10_overview (
    sensor_id  VARCHAR(64) PRIMARY KEY,
    value      DOUBLE,
    updated_at DATETIME
);

VOLATILE tables have the following characteristics.

ItemDescription
Main usesCurrent-state caches, temporary aggregates, and intermediate results
StorageMemory
Data after restartLost
Sharing scopeServer-wide
KeyOptional PRIMARY KEY
Main featuresUPDATE, DELETE, ON DUPLICATE KEY UPDATE, and red-black tree indexes
BackupNot supported

Use Criteria

Use a VOLATILE table when:

  • Data may be lost after a server restart.
  • Data can be recalculated or rebuilt from its source at any time.
  • Current state, recent aggregates, or temporary results require fast queries.
  • Multiple sessions need to share the same temporary state.
  • In-memory response time is more important than disk persistence.

The following example maintains the latest sensor state.

INSERT INTO ch10_overview VALUES ('TEMP-01', 23.5, NOW)
ON DUPLICATE KEY UPDATE SET value = 23.5, updated_at = NOW;

SELECT *
FROM ch10_overview
WHERE sensor_id = 'TEMP-01';

-- Clean up because the next section reuses this name.
DROP TABLE ch10_overview;

Usage Patterns

PatternKeySource for rebuildingRecommended expiration method
Latest device stateDevice IDTAG or LOGUpdate the same key
Short-interval aggregatesTarget and time bucketTAG or LOGReplace or rebuild the bucket
Job progressJob IDJob systemDelete the key after completion
Temporary query cacheRequest or object IDPersistent tableRebuild the entire cache

For current-state updates, see Data Ingestion and Modification. For temporary aggregates, see Queries and Analysis.

When to Consider Other Tables

Use another table type for the following requirements.

RequirementRecommended table
Source data that must survive a restartTAG or LOG
Persistent reference data, such as code lists or device master dataLOOKUP
Business data requiring transactions and relational updatesTRANSACTION
Time-series data for long-term analysisTAG

Data stored only in a VOLATILE table cannot be recovered after server shutdown. Store important data in a suitable persistent table: TAG, LOG, LOOKUP, or TRANSACTION. Use VOLATILE tables for caches or intermediate results.

Design Sequence

Make the following decisions when designing a VOLATILE table.

  1. Confirm that the data can be rebuilt.
  2. Decide whether a PRIMARY KEY is required.
  3. Estimate the row count and memory usage.
  4. Prepare an initial load procedure for use after restart.
  5. Save results that must be retained to persistent tables through explicit application writes. There is no dedicated flush command that persists a VOLATILE table.

For schema and primary key design, see Table Structure and Schema. For restart handling, see Restart and Data Loss.

Last updated on