gpt4 book ai didi

ruby-on-rails - 确定 ActiveRecord 在查找过程中是否使用了索引?

转载 作者:行者123 更新时间:2023-12-04 01:48:50 25 4
gpt4 key购买 nike

有什么办法吗,using the console确定数据库查找是否使用索引?

例如:User.where(name: 'Bob', state: 'Delaware').first
有没有办法确定是否使用索引来快速找到它?

我添加了索引,但想验证它们是否用于某些查找。

谢谢

最佳答案

你可以用这个检查:

User.where(name: 'Bob', state: 'Delaware').explain

请记住,索引并不总是使查询更快,在某些情况下,索引可能会使查询运行得更慢,而某些数据库试图识别这一点,甚至可能也不使用此索引。

检查索引的基数:

https://www.lullabot.com/articles/slow-queries-check-the-cardinality-of-your-mysql-indexes

小心!

http://edgeguides.rubyonrails.org/active_record_querying.html#running-explain

关于ruby-on-rails - 确定 ActiveRecord 在查找过程中是否使用了索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41878648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com