sql - What is a multiple key index? -
sql - What is a multiple key index? -
add_index :microposts, [:user_id, :created_at]
i going through michael hartl's railstutorial , noticed he's using called multiple key index. know means active record uses both keys @ same time, i'm not sure advantages , disadvantages of using multiple key indexes are.
if can give reply appreciate it.
any index can give benefit allowing query narrow downwards set of rows examine.
a multi-column index can help when query includes conditions on multiple columns.
for example:
select * mytable user_id = 123 , created_at > '2013-02-01'
the multi-column index narrows downwards subset of rows associated user_id 123, within subset, farther narrows downwards selection recent created_at value.
without sec column in index, rdbms have load all rows user_id 123 memory before determine if pass criteria.
for more information, see presentation how design indexes, really.
sql ruby-on-rails
Comments
Post a Comment