0

I am researching the possibility of using secondary index feature in Cassandra using Aquiles. I know for the primary index (key), a I must be using OrderPreservingPartitioner in order to query. At first, I thought that with secondary indexes, there is no such limitation, but I noticed that start key is part of GetIndexedSlicesCommand. Does that imply that under RandomPartitioner, this command is unusable?

galets
  • 17,802
  • 19
  • 72
  • 101

1 Answers1

2

You don't need OrderPreservingPartitioner to query by row key, it's only needed if you want to get a meaningful range of rows by their key, like 'all rows with a key between 5 and 9'. (Note that can and should almost always use RandomPartitioner instead.)

The start key for get_indexed_slices behaves the same way that it does for get_range_slices. That is, it's not very meaningful for examining a range of rows between two keys when using RandomPartitioner, but it is useful for paging through a lot of rows. There's even a FAQ entry on the topic. Basically, if you're going to get a ton of results from a call to get_indexed_slices, you don't want to fetch them all at once, you want to get a chunk (of 10, 100, or 1000, depending on size) at a time, and then set the start_key to the last key you saw in the previous chunk to get the next chunk.

Tyler Hobbs
  • 6,872
  • 24
  • 31
  • Are you saying it is possible to get a range of rows with a key between 5 and 9 using RandomPartitioner? Because according to what I am reading, it is not only not recommended, but quite impossible too – galets Apr 21 '11 at 15:18
  • No, an OrderPreservingPartitioner is needed for that. – Tyler Hobbs Apr 21 '11 at 17:26
  • so when I have RP, how do I need to call get_indexed_slices, which start key to supply on the 1st call? My understanding was that behind the scenes, it will get converted to MD5, so will that skip all the keys who have MD5 below that of the start key? – galets Apr 22 '11 at 00:13
  • Use an empty string for the start key for the first page -- it has the special property of being 'less' than everything else. Every page after the first will use the last key of the previous page for its start key; note that you'll also want to ignore the first row on all pages after the first, as it's a row you've already seen before. – Tyler Hobbs Apr 22 '11 at 15:24