Hi
first name,
The most successful ClickHouse Cloud users tend to:
Pick the right primary keys
Unlike traditional databases, ClickHouse primary keys are not for enforcing uniqueness, but for optimizing query performance. They determine how data is sorted on disk and create a sparse index for efficient data retrieval. Pick your primary keys based on:
- Use fields that are used to filter in most queries.
- Choose columns with lower cardinality first.
- Consider a time-based component in your primary key, as filtering by time on a timestamp dataset is pretty common.
Use bulk or async inserts
ClickHouse performs best when inserts are batched (for example, for rows of 1000) as opposed to many rows individually, especially for large datasets. If you prefer not to batch inserts, we recommend using the async insert option. When using async inserts, ClickHouse will batch inserts for you.
Limit usage of mutations
Mutations are commands that alter data, such as UPDATE or DELETE. While we recently released the lightweight update and delete operations, we still recommend limiting mutations for the best performance. It is best to design your schema and query access patterns in such a way that you edit data in ClickHouse only when necessary.
Avoid nullable columns
Columns that can be null take extra space and will require additional memory for queries. Instead of making columns nullable, we recommend setting a default value for columns, such as 0 for Int columns and an empty string for String columns.
To read more about best practices in ClickHouse, please visit our docs. If you have any questions about best practices, join our Slack to ask the community, email us any time at support@clickhouse.com, or get free live and on-demand training here.
-- Rich Raposa Learning Team at ClickHouse
ClickHouse Inc., 650 Castro St. Ste. 120 Unit 92426, Mountain View, CA 94041, USA. If you'd like to no longer receive emails like these, you can unsubscribe here.