cql - Difference between partition key, composite key and clustering key in Cassandra? -


I am reading articles around the net to understand the difference between the following key types But I find it hard to understand that the examples will certainly help in better understanding.

  primary key, partition key, composite key clustering key    

There is so much confusion around it, I will try to make it as simple as possible.

The primary key is a general concept to point to one or more columns used to retrieve data from a table.

Make the primary key simple

  table stack overflow (main text, primary key, data text);   

This means that it is done by a single column.

But the primary key aggregate (aka premises ), generated from more columns

  table stackoverflow (key_part_one text, key_part_two integer, to create data text, primary key (Key_part_one, key_part_two)); In the case of the primary key, the "first part" of the key is called   PARTITION key   

(this example has a key_part_one partition key) and the second part of the key is the clustering key please

Please note that both the split and clustering keys can be created by more columns

  table stackoverflow (k_part_one text, K_part_two integer, k_clust_one text, k_clust_two full Create a static, k_clust_three UUID, data text, primary key ((k_part_one, k_part_two), k_clust_one, k_clust_two, k_clust_three);   

Behind these names ...

  • Partition key is responsible for distributing data in your nodes.
  • is responsible for sorting the data within the clustering key partition.
  • Primary key Partition key in a single field-key table.
  • Composite / Compound Key is only a multiple column key

    Further usage information:


    Due to more requests - small usage and content example
    Simple Key: Stack overflow (key, data) values Put in ('yes', 'singles'); * Select from Stackoverflow where the key = 'yes';

    Table content

      key | Data ---- + ------ Yes | Single   

    Composite / Complex key can get inserted into "wide rows"

      stackoverflow (Key_part_one, key_part_two, data) value ('Ronaldo', 9, 'football player'); Insert Stack Overflow (Key_Party_On, Key_Party_Too, Data) Value ('Ronaldo', 10, 'Former Football Player'); * Select * from Stackoverflow where key_part_one = 'ronaldo';   

    Table content

      key_part_one | Key_part_two | Data -------------- + -------------- + ------------------- - Ronaldo. 9 | Football player Ronaldo | 10 | Former football player   

    But you can query with all the leading ...

     Select  from stackoverflow where key_part_one = 'Ronaldo' and Key_part_two = 10;   

    query output

      key_part_one | Key_part_two | Data -------------- + -------------- + ------------------- - Ronaldo. 10 | Former football player   

    Important Note: Partition key requires a minimum-specifier where a query is executed using the clause. For example: Primary key (col1, col2, col2, col4, col4))

    For example:

    If you have an entire partition key, You can only execute the query to be passed on both col1 and col2, it is 2 columns that define the partition key "normal" rule to create the query You must at least give all the keyboard key columns Then, you can add each key in that sequence.

    Therefore valid questions are ( secondary indexed )

    • col1 and col2
    • col1 and col2 and col10 < / Li>
    • col1 and col2 and col10 and col 4
    • Hope it helps.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -