gpt4 book ai didi

Cassandra:选择分区键

转载 作者:行者123 更新时间:2023-12-03 11:07:50 24 4
gpt4 key购买 nike

我不确定使用非常常见的共享列值(如 Country )作为复合主键的分区键还是使用相当独特的列值(如 Last_Name )在性能方面更好。

看着 Cassandra 1.2's documentation about indexes我明白了:

"When to use an index: Cassandra's built-in indexes are best on a table having many rows that contain the indexed value. The more unique values that exist in a particular column, the more overhead you will have, on average, to query and maintain the index. For example, suppose you had a user table with a billion users and wanted to look up users by the state they lived in. 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."

"When not to use an index: 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. 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. 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."



Looking at the examples from CQL's SELECT为了

“查询复合主键和排序结果”,我看到类似 UUID 的东西被用作分区键... 这表明最好使用一些相当独特的东西 ?

enter image description here

最佳答案

您编写的文档中的索引是指二级索引。在 cassandra 中有一个 difference between the primary and secondary indexes .对于二级索引来说,拥有非常独特的值确实很糟糕,但是对于主键中的组件,这取决于我们关注的组件。在主键中,我们有这些组件:

PRIMARY KEY(partitioning key, clustering key_1 ... clustering key_n)



分区键用于在不同节点之间分配数据,如果您希望您的节点是平衡的(即在每个节点上分布良好的数据),那么您希望您的分区键尽可能随机。这就是您的示例使用 UUID 的原因。

集群键用于排序,以便使用特定的集群键查询列可以更有效。这就是您希望您的值不唯一的地方,如果唯一的行频繁出现,则会影响性能。

cql docs对正在发生的事情有一个很好的解释。

关于Cassandra:选择分区键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18168379/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com