If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Multi Join Optimisation/Explain help.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-16-11, 17:12
RGM RGM is offline
Registered User
 
Join Date: Feb 2011
Posts: 29
Multi Join Optimisation/Explain help.

This is for a threaded private message system.

I'm trying to get the latest post per topic, latest first for a given user.

The query works as in it returned what I need. I don't fully appreciate what the explain is telling me.

My test data is very small, 200 posts, 5 topics.

If this query is likely to be a problem how can I optimise it.

If it's easier to read outside of the image..

There are indexes on all the date fields (datetime) and the id fields (author_id, topic_id etc)

Code:
explain extended
SELECT mp.author_id
, mp.msg_date
, mt.subject
, mp.msg_post
, mt.id as topic_id
, CONCAT(a.first_name, " ", a.last_name) as name
, a.profile_image
, amt.has_unread 
FROM (SA_message_topics mt) 
JOIN SA_message_posts mp ON mt.last_post_date = mp.msg_date 
JOIN SA_angels a ON mp.author_id = a.id 
JOIN SA_angels_to_message_topics amt ON amt.topic_id = mt.id AND amt.angel_id = 2 
ORDER BY mt.last_post_date DESC 
LIMIT 10
Attached Thumbnails
Multi Join Optimisation/Explain help.-grab.jpg  
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On