Mnesia 中 set 和ordered_set 之间的区别?
set类型的表和ordered_set类型的表有什么区别? 我对读/写性能的差异、排序的依据、跨分布式节点的影响等感兴趣。
What are the differences between a table of type set, and a table of type ordered_set? I'm interested in the differences in read/write performance, what the ordering is based on, the effects across distributed nodes, and such.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
排序基于主键,这意味着ordered_set表在使用复杂主键进行匹配/选择迭代时要快得多。 例如,如果您的记录类似于
{{Key, Val1}, Val2}
,您可以匹配或选择Key
来快速获取Val1
和Val2
表示每次出现Key
。 除此之外,我不知道读/写速度有显着差异。对ordered_set表进行碎片化也是可能的,尽管这意味着迭代将是部分排序的,但不是完全排序的。 对单个片段的迭代是有序的,但片段之间的顺序是未定义的。
The ordering is based on the primary key, which means ordered_set tables are much faster at doing match/select iteration using complex primary keys. For example, if your record looks like
{{Key, Val1}, Val2}
, you can match or select onKey
to very quickly getVal1
andVal2
for every occurance ofKey
. Other than that, I'm not aware of a significant difference in read/write speed.Fragmenting ordered_set tables is also possible, though it means the iteration will be partially ordered, but not fully ordered. Iterating over a single fragment is ordered, but the order from fragment to fragment is undefined.
就排序的来源而言:
所以排序看起来像一个直的 < 或> 元素上的比较。
除了顺序之外,它与套装完全相同。 因此,我大胆猜测,对于较低“值”的元素,查找平均会比集合更快。 但除此之外我不确定。
由于 Erlang 与进程无关并且不允许变量修改,因此分布式节点之间的效果应该与本地节点相同。
警告:
我还没有对这两种类型进行任何基准测试,因此这是我对性能的猜测。
as far as the ordering goes from the source:
So the ordering looks like a straight < or > comparison on the element.
Other than the ordering the it's exactly the same as the set. So I'd hazard a guess that for elements of lower "value" look ups would be faster on average than the set. But other than that I'm not sure.
Since Erlang is process agnostic and doesn't allow variable modification the effects across distributed nodes should be identical to local nodes.
Caveat:
I haven't run any benchmarking on the two types so this is speculation on my part regarding performance.