This the Query I want to optimize, it seems to take 30 seconds or so to run on a database around 1.7GB with about 1.5million Rows in the PepTargetEntity and the TargetMatchEntity and only thousands in the Customer Table and SearchEntity Table. I expect such a simple statement to take milliseconds to complete.
There are indexes on :
- Customer(SearchId)
- PepTargetEntity(CustomerId)
- TargetMatchEntity(CustomerId)
If anyone has any ideas it would be much appreciated, Thanks in advance.
SELECT CustomerId, Rank, PepId, TargetId, FalsePositive
FROM (SELECT T.CustomerId, T.Rank, T.Id AS PepId, NULL AS TargetId, T.FalsePositive, C.Surname, C.Firstname FROM PepTargetEntity T
INNER JOIN Customer C ON T.CustomerId= C.Id
WHERE c.SearchId = 3265 OR 3270 = 0
UNION
SELECT T.CustomerId, T.Rank, Null AS PepId, T.Id AS TargetId, T.FalsePositive, C.Surname, C.Firstname
FROM TargetmATCHEntity T
INNER JOIN Customer C ON T.CustomerId= C.Id
WHERE c.SearchId = 3265 OR 3270 = 0)
ORDER BY Surname ASC,FirstName ASC,Rank DESC
LIMIT 50
OFFSET 0
Aucun commentaire:
Enregistrer un commentaire