9.1 Overview and Use Criteria
LOOKUP tables store relatively small, frequently referenced datasets such as code lists, device master data, thresholds, and settings. Data is persistent, but all rows used by SQL queries reside in memory. This makes them suitable for repeated key-based lookups and updates.
LOOKUP Table Characteristics
Create a LOOKUP table with CREATE LOOKUP TABLE. A PRIMARY KEY is required.
CREATE LOOKUP TABLE ch9_overview (
sensor_id VARCHAR(64) PRIMARY KEY,
site VARCHAR(32),
unit VARCHAR(16),
status VARCHAR(16)
);LOOKUP tables have the following characteristics.
| Item | Description |
|---|---|
| Main uses | Code tables, device master data, thresholds, and reference data |
| Requirement | PRIMARY KEY required |
| Storage | Persistent storage; all rows loaded into memory at server startup |
| Query patterns | Optimized for primary key lookups; supports general predicates and JOIN with other tables |
| Modification patterns | INSERT, UPDATE, DELETE |
| Additional features | SEQUENCE columns and Append duplicate-key policy |
Use Criteria
Use a LOOKUP table when:
- The dataset is relatively small and frequently referenced as a whole.
- All rows and required secondary indexes fit in server memory.
- You manage reference information such as codes, names, locations, units, or states.
- Descriptive information must be joined to source data in TAG or LOG tables.
- Reference values, such as thresholds or settings, can change during operation.
- A
PRIMARY KEYclearly identifies each row.
For a JOIN that adds descriptions such as location and unit to TAG or LOG data, see Queries and Analysis.
When to Consider Other Tables
Consider other table types for the following requirements.
| Requirement | Recommended table |
|---|---|
| Large volumes of time-series measurements | TAG |
| Append-oriented source events | LOG |
| Large relational datasets that cannot all fit in memory | TRANSACTION |
| Transactions and relational business processing | TRANSACTION |
| Current-state cache kept only in server memory | VOLATILE |
LOOKUP is suitable for reference data. Persistence does not make it a disk-oriented large-volume table. Store source data in LOG or TAG, and use LOOKUP for memory-resident reference data queried repeatedly. Use TRANSACTION when relational data exceeds available memory or requires complex business processing.
Clean up the example table as follows.
DROP TABLE ch9_overview;Design Sequence
Make the following decisions when designing a LOOKUP table.
- Choose the
PRIMARY KEYthat identifies each row. - Choose a natural key or a surrogate key based on SEQUENCE or AUTO_INCREMENT.
- Add indexes to columns frequently queried or joined.
- Validate memory requirements for expected row sizes, row counts, and secondary indexes.
- Distinguish columns updated during operation from immutable columns.
- Prepare a query that checks the target scope before bulk changes.
For schema and key design, see Table Structure and Schema and PRIMARY KEY Policy.