EmbeddedRocksDB Engine

This engine allows integrating ClickHouse with rocksdb.

Creating a Table

  1. CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
  2. (
  3. name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1],
  4. name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2],
  5. ...
  6. ) ENGINE = EmbeddedRocksDB PRIMARY KEY(primary_key_name)

Required parameters:

  • primary_key_name – any column name in the column list.
  • primary key must be specified, it supports only one column in the primary key. The primary key will be serialized in binary as a rocksdb key.
  • columns other than the primary key will be serialized in binary as rocksdb value in corresponding order.
  • queries with key equals or in filtering will be optimized to multi keys lookup from rocksdb.

Example:

  1. CREATE TABLE test
  2. (
  3. `key` String,
  4. `v1` UInt32,
  5. `v2` String,
  6. `v3` Float32,
  7. )
  8. ENGINE = EmbeddedRocksDB
  9. PRIMARY KEY key

Metrics

There is also system.rocksdb table, that expose rocksdb statistics:

  1. SELECT
  2. name,
  3. value
  4. FROM system.rocksdb
  5. ┌─name──────────────────────┬─value─┐
  6. no.file.opens 1
  7. number.block.decompressed 1
  8. └───────────────────────────┴───────┘

Configuration

You can also change any rocksdb options using config:

  1. <rocksdb>
  2. <options>
  3. <max_background_jobs>8</max_background_jobs>
  4. </options>
  5. <column_family_options>
  6. <num_levels>2</num_levels>
  7. </column_family_options>
  8. <tables>
  9. <table>
  10. <name>TABLE</name>
  11. <options>
  12. <max_background_jobs>8</max_background_jobs>
  13. </options>
  14. <column_family_options>
  15. <num_levels>2</num_levels>
  16. </column_family_options>
  17. </table>
  18. </tables>
  19. </rocksdb>