I need to run the following type of query:
SELECT * FROM outbox
ORDER BY timestamp ASC
LIMIT 10
DDL:
CREATE TABLE IF NOT EXISTS stories_views.outbox (
key_id uuid,
message text,
created_at timestamp,
PRIMARY KEY ((key_id), created_at))
WITH CLUSTERING ORDER BY (created_at asc)
AND compaction = { 'class' : 'SizeTieredCompactionStrategy' };
Please tell me how to design a table so that there is no search across the entire Cassandra cluster.
You have it the correct way if your query is always going to be what you had described above. Cassandra® being a distributed NoSQL database is going to do a full cluster scan if your query is badly designed. If you're leveraging point queries i.e. leveraging the full primary keys, it won't do a scan. With versions
5.x
and above, we now have an efficient Storaged-Attached Index (SAI) that will help giving you the flexibility to query by a non-primary key column on your table.For more data modeling understanding, you could leverage this free-browser-based handy tutorial where you could understand the nuances of data modeling. Cheers!