CREATE DICTIONARY
Public Preview
Creates a dictionary object based on an original object. The dictionary object organizes the key-value mappings from the original object in the form of a hash table and is cached in the memory of all BE nodes. It can be viewed as a cached table.
Advantages
- Richer original objects for dictionary objects: When using
dictionary_get()
to query dictionary objects, the original object can be a table of any type, asynchronous materialized view, or logical view. However, when usingdict_mapping()
to query dictionary tables, the dictionary tables can only be primary key tables. - Fast query speed: Since the dictionary object is a hash table and fully cached in the memory of all BE nodes, querying the dictionary object to get the mapping is realized by looking up the hash table in memory. Therefore, the query speed is very fast.
- Supports multiple value columns: Internally, the dictionary object encodes multiple value columns into a single STRUCT type column. For queries based on a key, multiple values are returned together. Therefore, the dictionary object can serve as a dimension table where each key (usually a unique identifier) corresponds to multiple values (descriptive attributes).
- Ensures consistent snapshot reads: The dictionary snapshot obtained within the same transaction is consistent, ensuring that the query results from the dictionary object do not change during the same query or load process.
Syntax
CREATE DICTIONARY <dictionary_object_name> USING <dictionary_source>
(
column_name KEY, [..., column_name KEY,]
column_name VALUE[, ..., column_name VALUE]
)
[PROPERTIES ("key"="value", ...)];
Parameters
dictionary_object_name
: The name of the dictionary object. The dictionary object is effective globally and does not belong to a specific database.dictionary_source
: The name of the original object on which the dictionary object is based. The original object can be a table of any type, asynchronous materialized view, or logical view.- Definition of columns in the dictionary object: To preserve the key-value mapping maintained in the dictionary table, you need to use the
KEY
andVALUE
keywords in the dictionary object's columns to specify the keys and their mapped values.- The column names
column_name
in the dictionary object must be consistent with those in the dictionary table. - The data types for key and value columns in the dictionary object are limited to boolean, integer, string, and date types.
- The key column in the original object must ensure uniqueness.
- The column names
- Related properties of dictionary objects (
PROPERTIES
):dictionary_warm_up
: The method to cache data into the dictionary object on each BE node. Valid values:TRUE
(default) orFALSE
. If the parameter is set toTRUE
, data is automatically cached into the dictionary object after its creation; if the parameter is set toFALSE
, you need to manually refresh the dictionary object to cache the data.dictionary_memory_limit
: The maximum memory the dictionary object can occupy on each BE node. Unit: bytes. Default value: 2,000,000,000 bytes (2 GB).dictionary_refresh_interval
: The interval for periodically refreshing the dictionary object. Unit: seconds. Default value:0
. A value<=0
means no automatic refresh.dictionary_read_latest
: Whether to only query the latest dictionary object, mainly affecting the dictionary object queried during refresh. Valid values:TRUE
orFALSE
(default). If the parameter is set toTRUE
, the dictionary object cannot be queried during refresh because the latest dictionary object is still being refreshed. If the parameter is set toFALSE
, the previously successfully cached dictionary object can be queried during refresh.dictionary_ignore_failed_refresh
: Whether to automatically roll back to the last successfully cached dictionary object if the refresh fails. Valid values:TRUE
orFALSE
(default). If the parameter is set toTRUE
, it automatically rolls back to the last successfully cached dictionary object when the refresh fails. If the parameter is set toFALSE
, the dictionary object status is set toCANCELLED
when the refresh fails.