ATM I am trying to learn how to efficiently use database inidices and would appreciate to get some expert input. I do not have any performance issues currently. I would just like to know, how you would handle your indices with this query:
SELECT B.event,
COALESCE(B.system, C.surname || ' ' || C.forename) AS name,
C.label,
B.timestamp
FROM A
INNER JOIN B ON A.event=B.event
INNER JOIN C ON B.state=C.id
LEFT OUTER JOIN D ON B.hur=D.id
WHERE A.id IN(12,13,14,15,...)
ORDER BY B.event, B.timestamp
A.id, C.id and D.id are already primary keys
UPDATE
normally i would put INDEX(A.event) and INDEX(B.event, B.timestamp). Is this correct?
And what about B.event, B.state and B.hur ?
Rewrite your query as this:
, and create a composite index on
B (event, timestamp)