I have this query that runs quite quickly without a join, just on the one table. Now I added in a left join to try to get a bit more information but it is now taking like 20 seconds to run this 1 query which is nuts. Here is my query:
SELECT
`rt`.*,
`um`.`id` AS `usermap_id`
FROM
`rb_raketracking` AS `rt`
LEFT JOIN
`rb_usermap` AS `um`
ON
rt.room_username = um.room_username
AND
rt.fk_room_id = um.fk_room_id
WHERE
(rt.fk_room_id = '4')
AND (rt.data_date LIKE "2008-01%")
now if I remove the left join it runs in seconds. The table rb_usermap does not have a lot of info in there so I don't see why this is crushing the query so drastically. Any help is much appreciated.
after reading up on the situation it seams that indexs can very easily speed up this query. i wont have a chance to try this out until monday but i dont see why all columns are not index to begin with? why not eh?
Holy freaking crap. My 20 second script / query turned into 1 second by adding indexes. Freaking crazy faster. I never heard of indexes before this thread but wow, anyone who has not head of them or used them please try it out.
after talking to a friend over a few beers, my next way to make my queries faster is to look at them through the "explain" command. I never knew SQL had so much to offer.