这个SQL有没优化的余地呢解决思路

这个SQL有没优化的余地呢

select distinct(t.tid) from mcuhome_post t where t.uid = ‘1’ and isthread = 0 

CREATE TABLE `mcuhome_post` (

  `pid` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `tagid` mediumint(8) unsigned NOT NULL DEFAULT ‘0’,

  `tid` mediumint(8) unsigned NOT NULL DEFAULT ‘0’,

  `uid` mediumint(8) unsigned NOT NULL DEFAULT ‘0’,

  `username` varchar(15) NOT NULL DEFAULT ”,

  `ip` varchar(20) NOT NULL DEFAULT ”,

  `dateline` int(10) unsigned NOT NULL DEFAULT ‘0’,

  `message` text NOT NULL,

  `pic` varchar(255) NOT NULL DEFAULT ”,

  `isthread` tinyint(1) NOT NULL DEFAULT ‘0’,

  `hotuser` text NOT NULL,

  PRIMARY KEY (`pid`),

  KEY `tid` (`tid`,`dateline`)

) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

tid是帖子的ID

我们这个post表是帖子的评论表,uid是参与评论的会员的id ,我们要检索出某个会员,参与过评论的帖子的所有tid 当然,同一篇帖子可以被同一个uid评论N次。现在要检索出某个uid的会员,所有评论过的帖子tid的集合。



试试

alter table mcuhome_post add index idx_th(uid,isthread,tid)



create index xx on mcuhome_post(uid,isthread,tid)

这个SQL有没优化的余地呢解决思路

相关文章:

你感兴趣的文章:

标签云: