📜  @PrimaryKeyColumn(ordinal = 3,type = PrimaryKeyType.CLUSTERED) (1)

📅  最后修改于: 2023-12-03 15:29:14.399000             🧑  作者: Mango

@PrimaryKeyColumn in Cassandra

@PrimaryKeyColumn is an annotation that is used in Cassandra to indicate the primary key of a table. The primary key is used to uniquely identify a row in a table.

Syntax

The @PrimaryKeyColumn annotation has the following syntax:

@PrimaryKeyColumn(ordinal = 3, type = PrimaryKeyType.CLUSTERED)
  • ordinal: The position of the column in the primary key. Starts at 0 for the first column and increments for each subsequent column.
  • type: The type of the primary key column. Possible values are PARTITIONED and CLUSTERED.
Explanation

In the example above, ordinal is set to 3, indicating that this column is the fourth column in the table's primary key. type is set to CLUSTERED, indicating that this is a clustered primary key.

A clustered primary key is used to group related rows together on disk. Rows with the same partition key are placed on the same node, and rows with different partition keys are spread out across the cluster. Within a partition, rows are sorted by the clustering columns.

Conclusion

@PrimaryKeyColumn is a useful annotation in Cassandra that is used to define the primary key of a table. It helps to uniquely identify a row in a table and can be used to group related rows together on disk.