Cassandra UUID vs TimeUUID的优点和缺点 [英] Cassandra UUID vs TimeUUID benefits and disadvantages
问题描述
由于TimeUUID可以轻松地允许您在CQL中使用 now()
,是否有任何原因,您不会只是继续使用TimeUUID而不是普通的旧UUID ?
UUID
和 TIMEUUID
以相同的方式存储在Cassandra中,它们只表示两种不同的排序实现。
TIMEUUID
列按照其时间组件先排序,然后按其原始字节排序,而 UUID
列首先按其版本排序,如果两者都是版本1组件,最后由它们的原始字节。 Curioly时间组件排序实现在Cassandra代码中的 UUIDType
和 TimeUUIDType
之间重复,除了不同的格式。 p>
我想到 UUID
与 TIMEUUID
问题主要是文档:如果你选择 TIMEUUID
你说的是按时间顺序存储事物,这些事情可能发生在同一时间,所以一个简单的时间戳是'足够了。使用 UUID
说,你不在乎顺序(即使在实践中列将按时间排序,如果你放置版本1 UUID),你只是想
即使使用 NOW()
生成 UUID
值是很方便的,它也是非常惊讶的其他人阅读你的代码。
它可能在事情的宏伟计划无关紧要,但排序非版本1的UUID比版本1快一点,所以如果你有一个 UUID
列并自己生成UUID,去另一个版本。
Given that TimeUUID handily allows you to use now()
in CQL, are there any reasons you wouldn't just go ahead and always use TimeUUID instead of plain old UUID?
UUID
and TIMEUUID
are stored the same way in Cassandra, and they only really represent two different sorting implementations.
TIMEUUID
columns are sorted by their time components first, and then by their raw bytes, whereas UUID
columns are sorted by their version first, then if both are version 1 by their time component, and finally by their raw bytes. Curiosly the time component sorting implementations are duplicated between UUIDType
and TimeUUIDType
in the Cassandra code, except for different formatting.
I think of the UUID
vs. TIMEUUID
question primarily as documentation: if you choose TIMEUUID
you're saying that you're storing things in chronological order, and that these things can occur at the same time, so a simple timestamp isn't enough. Using UUID
says that you don't care about order (even if in practice the columns will be ordered by time if you put version 1 UUIDs in them), you just want to make sure that things have unique IDs.
Even if using NOW()
to generate UUID
values is convenient, it's also very surprising to other people reading your code.
It probably does not matter much in the grand scheme of things, but sorting non-version 1 UUIDs is a bit faster than version 1, so if you have a UUID
column and generate the UUIDs yourself, go for another version.
这篇关于Cassandra UUID vs TimeUUID的优点和缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!