All pastes #559036 Raw Edit

Stuff

public text v1 · immutable
·published 2007-06-11 16:33 UTC
rendered paste body
CREATE TABLE `grupos_genteya_usuarios` (
  `id_grupo` int(6) unsigned NOT NULL,
  `id_usuario` int(8) unsigned NOT NULL,
  `fecha_aceptacion` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id_grupo`,`id_usuario`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

mysql> explain SELECT * FROM `grupos_genteya_usuarios` WHERE `id_grupo`='19' ORDER BY RAND() LIMIT 0,10;
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+---------------------------------+
| id | select_type | table                   | type | possible_keys | key     | key_len | ref   | rows | Extra                           |
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+---------------------------------+
|  1 | SIMPLE      | grupos_genteya_usuarios | ref  | PRIMARY       | PRIMARY | 4       | const |    1 | Using temporary; Using filesort |
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+---------------------------------+
1 row in set (0.00 sec)

mysql> explain SELECT * FROM `grupos_genteya_usuarios` WHERE `id_grupo`='19' ORDER BY `fecha_aceptacion` DESC LIMIT 0,10;
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+-----------------------------+
| id | select_type | table                   | type | possible_keys | key     | key_len | ref   | rows | Extra                       |
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+-----------------------------+
|  1 | SIMPLE      | grupos_genteya_usuarios | ref  | PRIMARY       | PRIMARY | 4       | const |    1 | Using where; Using filesort |
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+-----------------------------+
1 row in set (0.00 sec)

mysql> explain SELECT * FROM `grupos_genteya_usuarios` WHERE `id_grupo`='19'  LIMIT 0,10;
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+-------+
| id | select_type | table                   | type | possible_keys | key     | key_len | ref   | rows | Extra |
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+-------+
|  1 | SIMPLE      | grupos_genteya_usuarios | ref  | PRIMARY       | PRIMARY | 4       | const |    1 |       |
+----+-------------+-------------------------+------+---------------+---------+---------+-------+------+-------+


How can i avoid the order by forcing the "Using temporary; Using filesort" ?