Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple But Slow Query

I have this simple query that runs in 0.55s.

SELECT tr.*

FROM Tournament_Result tr, Game g, Tournament t
LEFT JOIN Tournament_Type tt ON t.intType = tt.intTournamentType

WHERE tr.intTournamentId = t.intTournamentId
AND t.intGameId = g.intGameId
AND t.strStatus = 'live'

ORDER BY dtmCreated DESC

All joins are keys, either primary or index keys. If I removed the left join "LEFT JOIN Tournament_Type tt ON t.intType = tt.intTournamentType", the query runs instantly.

So I figure it must be the "t.intType = tt.intTournamentType" join, but I checked and both keys are indecies. Not sure what to do here. I even tried direct join and its always the Tournament_Type table that slows it down. I even ran the "OPTIMIZE" command on it.

Any ideas?

Thanks in advance!

Armin

like image 560
Armin Avatar asked Apr 01 '26 12:04

Armin


1 Answers

There is something missing in the query.Tournament_Type table is LEFT JOINED and

also none of the fields from Tournament_Type table used in any other join or in the SELECT

If you are adding one column from Tournament_Type table to be shown in the result

SELECT Tournament_Result.*,
(select <<Col1>> from Tournament_Type where Tournament_Type.intTournamentType=t.intType)

FROM  Game 
inner join Tournament on Tournament.intGameId = Game.intGameId
inner join Tournament_Result on Tournament_Result.intTournamentId = Tournament.intTournamentId
WHERE Tournament.strStatus = 'live'
ORDER BY dtmCreated DESC
like image 82
Sankara Avatar answered Apr 03 '26 10:04

Sankara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!