So, I have these 2 tables. One contains, lets call them, bugs, and another contains solutions. One bug may have more than one solution (or state, if you may), and I’d like to get the last one.
Right now, I’m doing it like this:
Select b.*, ap.approveMistakeId
from bugs_table as b
LEFT JOIN (select approveId, approveCause, approveDate, approveInfo,
approveUsername, mistakeId as approveMistakeId
from approve_table
order by approveDate desc) AS ap
ON m.mistakeId = ap.approveMistakeId
GROUP BY b.bugId
This is not a complete query, it is just to show the how I’m approaching it. The real query joins more than 10 tables.
The problem with this is, that with this subselect, the query runs for about 3.3s and returns ~2.4K records. Without this query, it runs for 0.4s, which is more acceptable. I have created and index on approveDate, but that didn’t seem to solve the problem.
Could the solution be a view, that was created from this query, and then joined to this query? Or is there a way to do this in some other manner?
Thanks!
The problem was the sub-select. The solution – de-normalization. Yes, I know, that isn’t the best solution, but definitely the fastest.
Tried aggregate self-sorting, but that only added time. Same with joining with a view.