通过主键搜索,RethinkDB 查询并没有变得更快。有什么陷阱吗?

RethinkDB query is not getting any faster by searching by the primary key. Is there any gotcha?

我的 contacts table 填充了 50k 条记录,因此我可以对性能进行基准测试。

引起我注意的是这些查询几乎同时完成:

查询 1:

r.db('rethinkdb_faker').table('contacts').filter({"id":3453}).limit(1)

查询 2:

r.db('rethinkdb_faker').table('contacts').filter({"name":"contact3453"}).limit(1)

他们大约需要 160ms 在 I5 1.7ghz Ubuntu 服务器上完成。

我绝对期待 查询 1 到 运行 更快,因为我读过自动考虑主索引。我还读到 id 会自动作为主键。此外,我没有找到任何配置主键的选项。

我是不是做错了什么或者这是预料之中的?

编辑

感谢@mlucy 的回答,我现在可以在 13ms 中给出相同配置的结果。

您可以使用 getgetAll 访问主索引。因此,如果您将第一个查询重写为 r.db('rethinkdb_faker').table('contacts').get(3453),它应该会快得多。