I don't understand how this is doing a filesort, etc. Could someone please enlighten me??
Apologies for the wrapping, but I figured it would be more readable then..
#
# Table structure for table 'quotesland_quotes'
#
CREATE TABLE quotesland_quotes (
id mediumint(16) NOT NULL auto_increment,
author_id int(16) default NULL,
category_id int(16) default NULL,
quote mediumtext,
submitted_by varchar(75) default NULL,
lastviewed datetime NOT NULL default '0000-00-00 00:00:00',
viewed bigint(20) default NULL,
pending char(1) default NULL,
PRIMARY KEY (id),
KEY index_author_id (author_id),
KEY index_category_id (category_id),
KEY index_pending (pending),
KEY index_quote (quote(250)),
KEY index_viewed (viewed)
) TYPE=MyISAM;
#
# Table structure for table 'quotesland_authors'
#
CREATE TABLE quotesland_authors (
id int(16) NOT NULL auto_increment,
author varchar(75) default NULL,
first varchar(30) default NULL,
last varchar(30) default NULL,
PRIMARY KEY (id),
UNIQUE KEY index_artist (author),
KEY index_lastfirst (last,first)
) TYPE=MyISAM;
#
# Table structure for table 'quotesland_categories'
#
CREATE TABLE quotesland_categories (
id int(16) NOT NULL default '0',
category varchar(75) default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
And here is the explain:
[size=1]
explain SELECT a.id,a.author_id,a.category_id,a.quote,b.author,c.category
FROM quotesland_quotes as a, quotesland_authors as b, quotesland_categories as c
where a.author_id = b.id and a.category_id = c.id
order by viewed desc limit 5
(apologies for the wrap)
+-------+--------+-----------------------------------+-----------------+---------+---------------+------+---------------------------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+-------+--------+-----------------------------------+-----------------+---------+---------------+------+---------------------------------+
| b | ALL | PRIMARY | NULL | NULL | NULL | 5337 | Using temporary; Using filesort |
| a | ref | index_author_id,index_category_id | index_author_id | 5 | b.id | 2 | |
| c | eq_ref | PRIMARY | PRIMARY | 4 | a.category_id | 1 | |
+-------+--------+-----------------------------------+-----------------+---------+---------------+------+---------------------------------+
[/size]