Mnesia 中 set 和ordered_set 之间的区别?

发布于 2024-07-23 06:57:20 字数 69 浏览 8 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叫思念不要吵 2024-07-30 06:57:20

排序基于主键,这意味着ordered_set表在使用复杂主键进行匹配/选择迭代时要快得多。 例如,如果您的记录类似于 {{Key, Val1}, Val2},您可以匹配或选择 Key 来快速获取 Val1Val2 表示每次出现 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 on Key to very quickly get Val1 and Val2 for every occurance of Key. 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.

失眠症患者 2024-07-30 06:57:20

就排序的来源而言:

add_element(E, [H|Es]) when E > H -> [H|add_element(E, Es)];
add_element(E, [H|_]=Set) when E < H -> [E|Set];
add_element(_E, [_H|_]=Set) -> Set;     %E == H
add_element(E, []) ->[E].

所以排序看起来像一个直的 < 或> 元素上的比较。

除了顺序之外,它与套装完全相同。 因此,我大胆猜测,对于较低“值”的元素,查找平均会比集合更快。 但除此之外我不确定。

由于 Erlang 与进程无关并且不允许变量修改,因此分布式节点之间的效果应该与本地节点相同。

警告:

我还没有对这两种类型进行任何基准测试,因此这是我对性能的猜测。

as far as the ordering goes from the source:

add_element(E, [H|Es]) when E > H -> [H|add_element(E, Es)];
add_element(E, [H|_]=Set) when E < H -> [E|Set];
add_element(_E, [_H|_]=Set) -> Set;     %E == H
add_element(E, []) ->[E].

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文