...">

Rails - an index for a query on three columns of a table

I have a query that I often use:

Site.where("mobile_visible = true AND (created_at > :date OR updated_at > :date)", :date => "12-04-30")

It creates this sql

SELECT `sites`.* FROM `sites` WHERE (mobile_visible = true AND (created_at > '12-04-30' OR updated_at > '12-04-30'))

I want to add an index or indexes to make this query more efficient. Should I add 3 indexes for 3 columns separately or 1 index indexing all three columns separately?

+3
source share
1 answer

The best approach is to create an index that strikes all the elements from you, where the proposal is not only one.

. , , , . , .

:

add_index :sites, [:mobile_visible, :created_at, :updated_at]
+2

All Articles