我应该在Ruby on Rails 3.0中的counter-cache列上添加索引

环境:Rails 3.0.4,MySQL,Ruby 1.8.7 我有下表:
  create_table "countries", :force => true do |t|
    t.string  "iso",            :limit => 2,                 :null => false
    t.string  "name",           :limit => 80,                :null => false
    t.string  "printable_name", :limit => 80,                :null => false
    t.string  "iso3",           :limit => 3
    t.integer "numcode",        :limit => 2
    t.integer "users_count",    :default => 0
    t.integer "rank"
  end
我经常搜索超过n个用户的国家/地区。向计数器缓存'users_count'添加索引是否有意义? 我意识到它会为每个添加的用户增加一点点开销,但我想确保在计数器缓存的机制中没有其他的东西,     
已邀请:
正如您所说,添加索引会为每个数据库写入
countries
表增加一点开销,以换取加速使用该列的查询。 根据经验,除非您有大量的写入,否则如果您在查询的
where
子句中执行任何大量引用
users_count
列的查询,则可能值得添加索引。 当创建国家/地区的用户时,Rails计数器缓存功能只会增加
users_count
值,并在用户被销毁时减少。     

要回复问题请先登录注册