Mongoid order_by 和 find_by 查询需要哪个索引?
Which index is needed for a Mongoid order_by and find_by query?
查找最近创建的名为 "Jeff"、
的用户
User.order_by(created_at: :desc)
.find_by(name: "Jeff")
应该为此查询创建哪些索引?会是 created_at
和 name
上的 2 个索引吗?
或者两者的复合索引?
在这种情况下,您必须对两者都使用复合索引才能覆盖查询。
有时可以Index Intersection使用多个索引来完成查询,但是限制之一是
Index intersection does not apply when the sort() operation requires an index completely separate from the query predicate.
这个查询就是这种情况。
查找最近创建的名为 "Jeff"、
的用户User.order_by(created_at: :desc)
.find_by(name: "Jeff")
应该为此查询创建哪些索引?会是 created_at
和 name
上的 2 个索引吗?
或者两者的复合索引?
在这种情况下,您必须对两者都使用复合索引才能覆盖查询。
有时可以Index Intersection使用多个索引来完成查询,但是限制之一是
Index intersection does not apply when the sort() operation requires an index completely separate from the query predicate.
这个查询就是这种情况。