Exploring Column Families in CockroachDB
Column families are a concept that allows you to change how rows are stored in a SQL table, to improve performance and reduce contention. By default, all of the columns of a row are stored in a single database key. With column families, you can ask the database to store the columns in multiple keys!
You might want to do this, for example, if one column is read or written much more frequently than the others: giving it its own column family can reduce the amount of contention on that row, and improve the performance of fetching data from the row.
To create a table with columns in CockroachDB, it’s very easy: add them to the
CREATE TABLE statement. For example, if you had a users table with a seldom-read JSON payload, you could put it in its own column family:
CREATE TABLE users ( id INT PRIMARY KEY name STRING, big_metadata_payload JSON, FAMILY (id, name), FAMILY (big_metadata_payload) )