Skip to main content
added [query-performance] to 2412 questions - Shog9 (Id=1924)
Link
edited title
Link
Arash Mousavi
  • 663
  • 2
  • 12
  • 21

strange using where"using where" in simple query

Source Link
Arash Mousavi
  • 663
  • 2
  • 12
  • 21

strange using where in simple query

I have a table with this structure:

mysql> describe user_groups;

+----------+----------------------+------+-----+---------+----------------+
| Field    | Type                 | Null | Key | Default | Extra          |
+----------+----------------------+------+-----+---------+----------------+
| id       | int(11) unsigned     | NO   | MUL | NULL    | auto_increment |
| user_id  | int(11) unsigned     | NO   | PRI | NULL    |                |
| group_id | smallint(5) unsigned | NO   | PRI | NULL    |                |
+----------+----------------------+------+-----+---------+----------------+

primary key of this table is : PRIMARY(user_id, group_id) I have simple query:

mysql> EXPLAIN SELECT `UserGroup`.`user_id` , `UserGroup`.`group_id` FROM `user_groups` AS `UserGroup` WHERE `UserGroup`.`user_id` IN ( 1, 2 );
+----+-------------+-----------+-------+---------------+---------+---------+------+------+--------------------------+
| id | select_type | table     | type  | possible_keys | key     | key_len | ref  | rows | Extra                    |
+----+-------------+-----------+-------+---------------+---------+---------+------+------+--------------------------+
|  1 | SIMPLE      | UserGroup | range | PRIMARY       | PRIMARY | 4       | NULL |    4 | Using where; Using index |
+----+-------------+-----------+-------+---------------+---------+---------+------+------+--------------------------+

it has using where; , according it has additional disk seek,I know using where; concept, and Also I know it is not terrible , but conceptually I want to know why this query has using where;, although the condition is on primary key directly and it doesn't have order or anything that causes using where;. How can I fix this using where;?