Lets say I have a decent sized MySQL table (that we'll call departments) with a bunch of columns that cluster together like so:
Departments Table:
| id | ds_settings | ds_reports | sales_settings | sales_reports | eng_settings | eng_reports | ops_settings | ops_reports | queryable_id | queryable_type |
|----|-------------|------------|----------------|---------------|--------------|-------------|--------------|-------------|--------------|----------------|
So as far as columns are concerned, we have "settings" and we have "reports". When this table is queried, it will typically be looking for just the all the settings or reports for a given "queryable" id and type.
So MOST queries to this table will end up looking something like this:
SELECT ds_settings, sales_settings, eng_settings, ops_settings
FROM departments
where queryable_id = 1
AND queryable_type = "User"
Why question is, what's a the correct way to index this table? Does it make design sense to include an index that encompasses all of "settings" AND all of "reports", e.g.:
UNIQUE KEY `index_on_settings` (`queryable_id`,`queryable_type`,
`ds_settings`,`sales_settings`,`eng_settings`)
...or is this misunderstanding how compound indexes are supposed to work?
KEY `indxqry` ( `queryable_id` , `queryable_type` )