我正在运行一个Rails应用程序并使用mongoid。我已经在rails应用程序中创建了帐户作为Mongoid::Document
账户文档中有大量记录,我添加了复合索引来快速查询。但是应用程序的性能较差
我试图对查询进行解释,但indexOnly
属性显示为false
值。
有人能告诉我什么是创建复合索引的最佳方法吗
如何检查我编写的查询是否正确使用了索引?
这是我的查询
first_record = Account.where(column_1: 5, column_2: "xxxx", column_3: "xxxxxx", column_4: "xxxxxxxxxxx", column_5: "xxxxxxxxx")
first_record.explain()
=> {"cursor"=>"BtreeCursor provider_5_params_idx", "isMultiKey"=>false, "n"=>10320, "nscannedObjects"=>10320, "nscanned"=>10320, "nscannedObjectsAllPlans"=>10320, "nscannedAllPlans"=>10320, "scanAndOrder"=>false, "indexOnly"=>false, "nYields"=>317, "nChunkSkips"=>0, "millis"=>222464, "indexBounds"=>{"column_1"=>[[5, 5]], "column_2"=>[["xxxx", "xxxx"]], "column_3"=>[["xxxxx", "xxxxx"]], "column_4"=>[["pxxxx", "xxxxxxx"]], "column_5"=>[["xxxxxx", "xxxxxx"]]}, "allPlans"=>[{"cursor"=>"BtreeCursor provider_5_params_idx", "n"=>10320, "nscannedObjects"=>10320, "nscanned"=>10320, "indexBounds"=>{"column_1"=>[[5, 5]], "column_2"=>[["xxxx", "xxxx"]], "column_3"=>[["xxxx", "xxxx"]], "column_4"=>[["xxxx", "xxxxx"]], "column_5"=>[["xxxxx", "xxxxx"]]}}], "oldPlan"=>{"cursor"=>"BtreeCursor provider_5_params_idx", "indexBounds"=>{"column_1"=>[[5, 5]], "column_2"=>[["xxxx", "xxxx"]], "column_3"=>[["xxxxx", "xxxxx"]], "column_4"=>[["xxxx", "xxxxx"]], "column_5"=>[["xxxxx", "xxxxx"]]}}, "server"=>"xxxxxxxxx"}
此外,我用以下方式创建了索引db.account.ensureIndex({column_1:1,column_2:1,column_3:1,column_4:1,column_5:1}, {name:"provider_5_params_idx",background:true});
为column_1索引两次是打字错误吗?
与计划类似,扫描了10320个对象,这是因为索引不起作用。