DEV Community

Cover image for Exploring Column Families in CockroachDB
Jordan Lewis
Jordan Lewis

Posted on • Edited on • Originally published at jordanlewis.org

Exploring Column Families in CockroachDB

In this video, I break down what Column Families are in CockroachDB, why you'd want to use them, and how you can explore them in more detail for yourself.

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)
)

Let me know what you think of the video, and what other database content you'd like to see!


đź‘‹Hello, I'm Jordan Lewis, an engineer and manager at Cockroach Labs. I'm passionate about programming and databases, and the intersection of the two, and I like to create content that teaches you how databases work under the covers.

🙏While you're here, would you consider following me on Twitch, where I produce educational livestreams about database programming?


✨Twitch | YouTube | GitHub | Twitter

Top comments (0)