Search code examples
cassandracassandra-2.0cassandra-cli

How to design the cassandra table for one query with a ordering and limit?


Now I created a table:

CREATE TABLE posts_by_user(
  user_id    bigint,
  post_id    uuid,
  post_at    timestamp,
  PRIMARY KEY (user_id,post_id)
);

I want to select last 10 rows with operator IN for user_id and ordering by post_at field.

Also I read a good article: http://planetcassandra.org/blog/the-in-operator-in-cassandra-cql/

I can nit use query: WHERE post_at = time AND user_id IN (1,2) because I need all notes, not for a concrete date.

How i can change my design schema? Thank you.

I change on:

CREATE TABLE posts_by_user (
  user_id    bigint,
  post_id    uuid,
  post_at    timestamp,
  PRIMARY KEY (user_id, post_at)
) WITH CLUSTERING ORDER BY (post_at DESC);

Think it is a good...


Solution

  • How about using this approach: http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use-slice-partition.html