The AWDwR book has the following:
add_index :categories_products, [:product_id, :category_id]
add_index :categories_products, :category_id
The first, composite index actually serves two purposes: it creates an
index which can be searched
on both foreign key columns, and with most databases it also creates an
index that enables fast lookup by the product id. The second index then
completes the picture, allowing fast lookup on category id.
My question is if the composite index creates an index for both foreign
key columns then why do we
need the second add index for category_id? TIA.