1

随机访问我并不是指选择随机记录,
随机访问是在相同的时间内获取所有记录的能力,
与从数组中获取值的方式相同。
来自维基百科:http ://en.wikipedia.org/wiki/Random_access

我的意图是存储一个非常大的字符串数组,一个对于内存来说太大了。
但仍然有好处或随机访问数组。

我通常使用 MySQL,但它似乎只有 B-Tree 和 Hash 索引类型。

我看不出为什么不可能实现这样的事情的原因。
索引将像数组一样,从零开始并以 1 递增。

我想简单地通过它的索引获取一个字符串,而不是根据字符串获取索引。目标是提高性能。我也无法控制访问字符串的顺序,它将是一个远程数据库服务器,它将不断接收来自客户端的索引并返回该索引的字符串。

有解决方案吗?

ps 我不认为这是不适合内存的随机访问容器的副本?
因为在那个问题中,除了随机访问之外,他还有其他要求

4

2 回答 2

3

Given your definition, if you just use an SSD for storing your data, it will allow for what you call random access (i.e. uniform access speed across the data set). The fact that sequential access is less expensive than random one comes from the fact that sequential access to disk is much faster than random one (and any database tries it's best to make up for this, btw).

That said, even RAM access is not uniform as sequential access is faster due to caching and NUMA. So uniform access is an illusion anyway, which begs the question, why you are so insisting of having it in the first place. I.e. what you think will go wrong when having slow random access - it might be still fast enough for your use case.

于 2011-08-22T16:08:01.813 回答
1

您在谈论恒定时间,但您提到了一个唯一的递增主键。

除非这样的键是无间隙的,否则您不能将其用作偏移量,因此您仍然需要某种结构来查找实际偏移量。

通过偏移量查找记录通常不是特别有用,因为您通常希望通过一些更友好的方法来查找它,这总是涉及到一个索引。搜索 B-Tree 索引是最坏的情况 O(log n),这非常好。

假设您只有一个字符串数组 - 将其存储在固定长度记录的磁盘文件中,并使用文件系统寻找您想要的偏移量。

然后针对数据库查找进行基准测试。

于 2011-08-22T16:33:00.637 回答