I am a real newbie with sql and the indexes.
I'd like to know if it's better to use indexes on mutliple columns or multiple index on each columns.
Most of my queries have this structure :
SELECT
c.app_id,
c.app_version_id,
count(DISTINCT dqaid) AS user_open
FROM crashes c
JOIN reasons r ON c.reason = r.id
WHERE status = 0
AND datecreated >= (NOW() - INTERVAL 7 DAY)
GROUP BY c.app_id, c.app_version_id
should I put indexes like that :
* @Table(name="crashes", indexes={
* @Index(name="datecreated_idx", columns={"datecreated"}),
* @Index(name="app_id_idx", columns={"app_id"}),
* @Index(name="app_version_id_idx", columns={"app_version_id"}),
* @Index(name="dqaid_idx", columns={"dqaid"}),
* })
Or more like that :
* @Index(name="app_v_id_idx", columns={"app_version_id", "app_id", "datecreated"}),
I understand what an index is for, but I don't really undestand how they work. Do they work on the select ? On the where ? On the group by ?