首页 文章

加快此查询(加入mediumtext字段)

提问于
浏览
0

我有这个问题

SELECT t.name,t.userid,t.date,t.cat_id,t.forum_id,t.reply,t.hidden,t.moderated,t.sticky,t.statut,t.poll,t.helpful,t.del, t_data.message, user.name AS author_name,user.level AS author_level,user.is_globalMod AS author_global,user.award, user.statut AS author_statut,user.posts AS user_posts,user.point AS user_points,user.title AS user_title, user.image AS user_avatar,user.sex AS user_sex,user.other_level,user.hid_posts FROM frm_thread AS t LEFT JOIN frm_thread_data AS t_data ON t_data.thread_id = t.id LEFT JOIN frm_member AS user ON user.id =t.userid WHERE t.id = 248925

frm_thread是

CREATE TABLE IF NOT EXISTS frm_thread ( id mediumint(7) unsigned NOT NULL auto_increment, last_userid int(10) unsigned NOT NULL, last_date int(10) unsigned default NULL, forum_id tinyint(5) unsigned NOT NULL, cat_id tinyint(3) unsigned NOT NULL, name varchar(250) collate utf8_unicode_ci NOT NULL, userid int(10) unsigned NOT NULL, date int(10) unsigned default NULL, view mediumint(5) unsigned NOT NULL, reply smallint(4) NOT NULL, sticky tinyint(1) unsigned NOT NULL, linked tinyint(1) unsigned NOT NULL, linked_order tinyint(2) unsigned NOT NULL, spam tinyint(1) unsigned NOT NULL, statut tinyint(1) unsigned NOT NULL, moderated tinyint(1) unsigned NOT NULL, hidden tinyint(1) unsigned NOT NULL, poll smallint(5) unsigned NOT NULL, del tinyint(1) unsigned NOT NULL, t_icon smallint(10) unsigned NOT NULL, helpful int(10) unsigned NOT NULL PRIMARY KEY (id), KEY forum_id (forum_id), KEY last_date (last_date,date,sticky), KEY linked (linked), KEY date (date), KEY userid (userid), KEY last_userid (last_userid) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=249014 ;

frm_thread_data

CREATE TABLE IF NOT EXISTS frm_thread_data ( thread_id int(10) unsigned NOT NULL, message mediumtext collate utf8_unicode_ci NOT NULL, PRIMARY KEY (thread_id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

正如你所看到的,消息内容在一个单独的表中,现在这个查询正常在0.0005中完成,由codeigniter分析显示

有些时候它需要25.0050秒

我有一个帖子表,但文本字段不在一个单独的表中,它总是给出一个接近0.0020的数字

请问有什么方法可以解决这个问题吗?

EXPLAIN SHOW's

id select_type表类型possible_keys键key_len ref rows Extra
1 SIMPLE t const PRIMARY PRIMARY 3 const 1
1 SIMPLE t_data const PRIMARY PRIMARY 4 const 1
1 SIMPLE用户const PRIMARY PRIMARY 4 const 1

1 回答

相关问题