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

前端 未结 8 1355
無奈伤痛
無奈伤痛 2020-11-22 12:18

I have been reading articles around the net to understand the differences between the following key types. But it just seems hard for me to grasp. Examples will

8条回答
  •  借酒劲吻你
    2020-11-22 13:18

    In database design, a compound key is a set of superkeys that is not minimal.

    A composite key is a set that contains a compound key and at least one attribute that is not a superkey

    Given table: EMPLOYEES {employee_id, firstname, surname}

    Possible superkeys are:

    {employee_id}
    {employee_id, firstname}
    {employee_id, firstname, surname}
    

    {employee_id} is the only minimal superkey, which also makes it the only candidate key--given that {firstname} and {surname} do not guarantee uniqueness. Since a primary key is defined as a chosen candidate key, and only one candidate key exists in this example, {employee_id} is the minimal superkey, the only candidate key, and the only possible primary key.

    The exhaustive list of compound keys is:

    {employee_id, firstname}
    {employee_id, surname}
    {employee_id, firstname, surname}
    

    The only composite key is {employee_id, firstname, surname} since that key contains a compound key ({employee_id,firstname}) and an attribute that is not a superkey ({surname}).

提交回复
热议问题