gpt4 book ai didi

cassandra - 了解 cassandra 的内部数据存储

转载 作者:行者123 更新时间:2023-12-02 22:53:46 25 4
gpt4 key购买 nike

我有这张 table

create table comment_by_post
(
postId uuid,
userId uuid,
cmntId timeuuid,
cmntTxt text,
cmntBy text,
time bigint,
primary key ((postId, userId),cmntId)
)

这是该表中的内部数据

RowKey: 4978f728-0f96-11e5-a6c0-1697f925ec7b:4978f728-0f96-12e5-a6c0-1697f92e537a
=> (name=d3f02a30-126f-11e5-879b-e700f669bcfc:, value=, timestamp=1434270721107000)
=> (name=d3f02a30-126f-11e5-879b-e700f669bcfc:cmnttxt, value=636d6e743434, timestamp=1434270721107000)
-------------------
RowKey: 4978f728-0f96-11e5-a6c0-1697f925ec7b:4978f728-0f96-12e5-a6c0-1697f92eec7a
=> (name=465fee30-126f-11e5-879b-e700f669bcfc:, value=, timestamp=1434270483603000)
=> (name=465fee30-126f-11e5-879b-e700f669bcfc:cmnttxt, value=636d6e7432, timestamp=1434270483603000)
=> (name=4ba89f40-126f-11e5-879b-e700f669bcfc:, value=, timestamp=1434270492468000)
=> (name=4ba89f40-126f-11e5-879b-e700f669bcfc:cmnttxt, value=636d6e7431, timestamp=1434270492468000)
=> (name=504a61f0-126f-11e5-879b-e700f669bcfc:, value=, timestamp=1434270500239000)
=> (name=504a61f0-126f-11e5-879b-e700f669bcfc:cmnttxt, value=636d6e7433, timestamp=1434270500239000)
-------------------
RowKey: 4978f728-0f96-11e5-a6c0-1697f925ec7b:4978f728-0f96-12e5-a6c0-1697f92e237a
=> (name=cd1e8f30-126f-11e5-879b-e700f669bcfc:, value=, timestamp=1434270709667000)
=> (name=cd1e8f30-126f-11e5-879b-e700f669bcfc:cmnttxt, value=636d6e7433, timestamp=1434270709667000)

如果我做主键(postId,userId,cmntId)那么它就像:

RowKey: 4978f728-0f96-11e5-a6c0-1697f925ec7b
=> (name=4978f728-0f96-12e5-a6c0-1697f92eec7a:971da150-1260-11e5-879b-e700f669bcfc:, value=, timestamp=1434264176613000)

=> (name=4978f728-0f96-12e5-a6c0-1697f92eec7a:971da150-1260-11e5-879b-e700f669bcfc:cmnttxt, value=636d6e7431, timestamp=1434264176613000)

=> (name=4978f728-0f96-12e5-a6c0-1697f92eec7a:a0d4a900-1260-11e5-879b-e700f669bcfc:, value=, timestamp=1434264192912000)

=> (name=4978f728-0f96-12e5-a6c0-1697f92eec7a:a0d4a900-1260-11e5-879b-e700f669bcfc:cmnttxt, value=636d6e7432, timestamp=1434264192912000)

=> (name=4978f728-0f96-12e5-a6c0-1697f92eec7a:a5d94c30-1260-11e5-879b-e700f669bcfc:, value=, timestamp=1434264201331000)

为什么会这样?两者有什么好处?

最佳答案

Christopher 已经解释了如何将分区键连接在一起以生成用于存储的行键,因此我不会重新散列(没有双关语)。但我会解释这两种方法的优缺点。

PRIMARY KEY (postId, userId,cmntId)

使用此主键,您的数据将按 postId 进行分区,并按 userId 聚类和cmntId 。这意味着,对帖子发表的所有评论都将通过 postId 一起存储在磁盘上。 ,然后按 userId 排序和cmntId (分别)。

这里的优点是查询灵 active 。您可以查询某个帖子的所有评论,或特定用户对某个帖子的所有评论。

缺点是,与其他解决方案相比,您有更高的机会实现无限制的行增长。如果您的总列数为 postId如果超过 20 亿,您将最大化每个 postId 可以存储的数据量。 。但是您为每个帖子存储这么多评论数据的可能性很低,所以应该没问题。

PRIMARY KEY ((postId, userId),cmntId)

此解决方案通过 postId 的串联行键将注释数据存储在一起,有助于消除无限制行增长的可能性。和userId (按 cmntId 排序。这是相对于其他解决方案的优势。

缺点是失去查询灵 active ,因为现在您需要提供 postIduserId每个查询。此 PRIMARY KEY 定义根本不支持仅使用 postId 进行注释的查询。 ,因为 Cassandra CQL 要求您提供查询的完整分区键。

关于cassandra - 了解 cassandra 的内部数据存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30827411/

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