title: Cassandra: choosing a Partition Key
body: <p>I'm undecided whether it's better, performance-wise, to use a very commonly shared column value (like <code>Country</code>) as partition key for a compound primary key or a rather unique column value (like <code>Last_Name</code>).  </p>
  
  <p>Looking at <a href="http://www.datastax.com/documentation/cassandra/1.2/webhelp/cassandra/ddl/ddl_primary_index_c.html" rel="noreferrer">Cassandra 1.2's documentation about indexes</a> I get this:</p>
  
  <blockquote>
    <p>"<strong>When to use an index</strong>: 
    Cassandra's built-in indexes are best on a table
    having many rows that contain the indexed value. <strong>The more unique
    values that exist in a particular column, the more overhead you will
    have, on average, to query and maintain the index.</strong> For example,
    suppose you had a user table with a billion users and wanted to look
    up users by the state they lived in. <strong>Many users will share the same
    column value for state (such as CA, NY, TX, etc.). This would be a
    good candidate for an index.</strong>"</p>
    
    <p>"<strong>When not to use an index</strong>: 
    Do not use an index to query a huge volume of records for a small
    number of results. For example, if you create an index on a column
    that has many distinct values, a query between the fields will incur
    many seeks for very few results. <strong>In the table with a billion users,
    looking up users by their email address (a value that is typically
    unique for each user) instead of by their state, is likely to be very
    inefficient.</strong> It would probably be more efficient to manually maintain
    the table as a form of an index instead of using the Cassandra
    built-in index. For columns containing unique data, it is sometimes
    fine performance-wise to use an index for convenience, as long as the
    query volume to the table having an indexed column is moderate and not
    under constant load."</p>
  </blockquote>
  
  <p><a href="http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html?pagename=docs&amp;version=1.2&amp;file=ddl/table#cassandra/cql_reference/select_r.html" rel="noreferrer">Looking at the examples from CQL's SELECT</a> for </p>
  
  <p>"<em>Querying compound primary keys and sorting results</em>", I see something like a UUID being used as partition key... <strong>which would indicate that it's preferable to use something rather unique</strong>?</p>
  
  <p><img src="https://i.stack.imgur.com/vZXhL.png" alt="enter image description here"></p>