从 Mnesia 获取大量数据 - 最快的方法
我有一个记录:
-record(bigdata, {mykey,some1,some2}).
做一个
mnesia:match_object({bigdata, mykey, some1,'_'})
最快的方式获取超过5000行?
澄清: 创建“自定义”键是一种选择(这样我就可以进行读取),但是在一个键上进行 5000 次读取比 match_object 更快吗?
I have a record:
-record(bigdata, {mykey,some1,some2}).
Is doing a
mnesia:match_object({bigdata, mykey, some1,'_'})
the fastest way fetching more than 5000 rows?
Clarification:
Creating "custom" keys is an option (so I can do a read) but is doing 5000 reads fastest than match_object on one single key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我很好奇你正在解决的问题,表中有多少行等等,如果没有这些信息,这可能不是一个相关的答案,但是......
如果你有一个包,那么最好对键使用 read/2,然后遍历返回的记录列表。如果可能的话,最好对数据进行结构化以避免选择和匹配。
一般来说,select/2 优于 match_object,因为它可以更好地避免全表扫描。另外,假设您不需要事务支持,则 dirty_select 将比 select/2 更快。而且,如果您可以忍受这些限制,Mensa 允许您直接对照基础 ets 表,这非常快,但请查看文档,因为它仅适用于非常罕见的情况。
I'm curious as to the problem you are solving, how many rows are in the table, etc., without that information this might not be a relevant answer, but...
If you have a bag, then it might be better to use read/2 on the key and then traverse the list of records being returned. It would be best, if possible, to structure your data to avoid selects and match.
In general select/2 is preferred to match_object as it tends to better avoid full table scans. Also, dirty_select is going to be faster then select/2 assuming you do not need transactional support. And, if you can live with the constraints, Mensa allows you to go against the underlying ets table directly which is very fast, but look at the documentation as it is appropriate only in very rarified situations.
Mnesia 更多的是一个键值存储系统,它会遍历所有记录来获取匹配。
为了快速获取,应该设计存储结构来直接支持查询。将
some1
作为键或索引。然后通过read
或index_read
获取它们。Mnesia is more a key-value storage system, and it will traverse all its records for getting match.
To fetch in a fast way, you should design the storage structure to directly support the query. To Make
some1
as key or index. Then fetch them byread
orindex_read
.返回超过 5000 行
的语句最快方式
取决于所讨论的问题。数据库结构是什么?我们想要什么?记录结构是什么?之后,就归结为如何编写读取函数。如果我们确定主键,那么我们使用mnesia:read/1 或 mnesia:read/2
如果没有,使用 查询列表理解。搜索嵌套记录和复杂条件查询更加灵活。请参阅下面的用法:所以我认为如果您想要最快的方法,我们需要更多的说明和问题细节。亲爱的,速度取决于很多因素!
The statement
Fastest Way
toreturn more than 5000 rows
depends on the problem in question. What is the database structure ? What do we want ? what is the record structure ? After those, then, it boils down to how you write your read functions. If we are sure about the primary key, then we usemnesia:read/1 or mnesia:read/2
if not, its better and more beautiful to use Query List comprehensions. Its more flexible to search nested records and with complex conditional queries. see usage below:So i think if you want fastest way, we need more clarification and problem detail. Speed depends on many factors my dear !