Module Review: CQL
You’ve mastered the query language that powers the world’s most scalable databases. It looks like SQL, but requires a completely different mindset.
1. Key Takeaways
- Schema is Deployment: A Keyspace defines replication strategies (NetworkTopologyStrategy vs SimpleStrategy). A Table defines data distribution (Partition Key).
- Primary Key Anatomy:
PRIMARY KEY ((Partition Key), Clustering Key). - Partition Key: Determines WHERE data lives (which node).
- Clustering Key: Determines ORDER of data on disk.
- The Golden Rule: Always provide the Partition Key in your
WHEREclause. - ALLOW FILTERING: The keyword of death. It causes a full cluster scan. Never use in production.
- Writes are Cheap: INSERT/UPDATE/DELETE are all appended to the Commit Log and MemTable. No read-before-write.
- Collections: Use
Set,List,Mapfor nested data. Usefrozen<>for performance or Primary Key usage.
2. Interactive Flashcards
Test your recall.
Loading...
Answer
1 / 5
3. Cheat Sheet
| Concept | Command / Syntax | Notes |
|---|---|---|
| Create Keyspace | CREATE KEYSPACE k WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 3}; |
Always use NTS in prod. |
| Create Table | CREATE TABLE t (id uuid, val text, PRIMARY KEY(id)); |
Simple PK. |
| Composite PK | PRIMARY KEY ((part_key), clust_key) |
Groups by part_key, sorts by clust_key. |
| Insert / Update | INSERT INTO t (id, val) VALUES (...) |
Same as Update (Upsert). |
| TTL | USING TTL 86400 |
Expires data after N seconds. |
| Select | SELECT * FROM t WHERE id = ? |
Must allow coordinator to find the node. |
| Frozen UDT | frozen<my_type> |
Serialized as one blob. Required for PKs. |
| Batch | BEGIN BATCH ... APPLY BATCH |
Use for atomicity across tables, NOT performance. |
4. Next Steps
Now that you can model and query data, it’s time to understand Consistency Levels.