Skip to main content

Dictionary layout types

There are a variety of ways to store dictionaries in memory, each with CPU and RAM-usage trade-offs.
Recommended layoutsflat, hashed, and complex_key_hashed provide the best query performance. Caching layouts are not recommended due to potentially poor performance and difficulty tuning parameters — see cache for details.
Cache-based layouts are unsuitable for reliable insert-time enrichment because their warmed entries are local to each server and are lost when a server restarts or is replaced. ClickHouse Cloud autoscaling and managed node replacement make this condition more likely. Use a fully loaded layout instead; see Cache dictionaries in ingestion paths.

Specify dictionary layout

Use CREATE DICTIONARY to create dictionaries.When creating a dictionary that reads from a ClickHouse table, include a dedicated user’s username and password in the SOURCE clause. That user needs SELECT permission on the source table. See the ClickHouse dictionary source example.Verify the list of supported dictionary sources in the Cloud Compatibility guide.
You can configure a dictionary layout with the LAYOUT clause (for DDL) or the layout setting for configuration file definitions.

See also CREATE DICTIONARY for the full DDL syntax. Dictionaries without word complex-key* in a layout have a key with UInt64 type, complex-key* dictionaries have a composite key (complex, with arbitrary types). Numeric key example (column key_column has UInt64 type):

Composite key example (key has one element with String type):

Improve dictionary performance

There are several ways to improve dictionary performance:
  • Call the function for working with the dictionary after GROUP BY.
  • Mark attributes to extract as injective. An attribute is called injective if different keys correspond to different attribute values. So when GROUP BY uses a function that fetches an attribute value by the key, this function is automatically taken out of GROUP BY.
ClickHouse generates an exception for errors with dictionaries. Examples of errors can be:
  • The dictionary being accessed could not be loaded.
  • Error querying a cached dictionary.
You can view the list of dictionaries and their statuses in the system.dictionaries table.