我是sql和索引的新手。
我想知道在mutliple列上使用索引或在每列上使用多个索引是否更好。
我的大多数查询都有这种结构:
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
我应该把这样的索引放在:
* @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"}),
* })
或更像是:
* @Index(name="app_v_id_idx", columns={"app_version_id", "app_id", "datecreated"}),
我理解索引的用途,但我并不真正理解它们是如何工作的。他们在选择上工作吗?在哪里?在小组上?