views:

13

answers:

0

Hi, i was trying to optimize some queries on my MySql Db when i found myself in a doubt.

The problem: two similar queries produce almost the same result but the one I tought would be more expensive it isn´t,

Having this table:

CREATE TABLE `da_video_votes` ( 
 `video_id` int(10) NOT NULL, 
 `user_id` int(10) NOT NULL, 
 `type` enum('l','d') default NULL COMMENT 'like or dont', 
 `c_date` date default NULL,
 `c_time` time default NULL, 
 UNIQUE KEY `unique_vote_by_id` (`video_id`,`user_id`,`c_date`), 
 KEY `type` (`type`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8
  • explain select video_id,type,count(*) from da_video_votes v GROUP BY video_id,type

  • explain select video_id,GROUP_CONCAT(DISTINCT video_id ORDER BY type DESC SEPARATOR '|') FROM da_video_votes v;

Exaplain command on the first query tells me that is using a filesort an a temporary table while the second one who is using GROUP_CONCAT doesnt tell me nothing on the extra column.

Well, that´s my doubt :S why ? What is mysql doing internally on this particular case.