Originally posted by MattR
That's interesting -- however without knowing what data is in your table, indexes and such I wouldn't bet the bank on a single example.
Code:
+---------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------------------+------+-----+---------+----------------+
| cityid | smallint(5) unsigned | | PRI | NULL | auto_increment |
| city | varchar(36) | | MUL | | |
| lat | float(6,3) | | MUL | 0.000 | |
| lon | float(6,3) | | MUL | 0.000 | |
| stateid | tinyint(3) unsigned | | | 0 | |
+---------+----------------------+------+-----+---------+----------------+
~100 rows (just a table i had handy
)
For example, if the query plans are identical (all else held constant) but the initial optimization is faster then you'll see only a .0003s difference as the size of the table increases.
However, if there is something neat with IN then the query times would increase as the size of the rows do..
yeah, i get what you're saying. i would think you're probably right about it just being the initial parsing of the query -- that's why i was saying about ORs making the query longer. i imagine both are optimized the same once it starts searching the table, though. the output from explain is the same w/ ORs or IN(), except if you do this
Code:
mysql> EXPLAIN SELECT * FROM cities WHERE cityid=1 OR cityid=1;
+--------+-------+---------------+---------+---------+-------+------+-------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------+-------+---------------+---------+---------+-------+------+-------+
| cities | const | PRIMARY | PRIMARY | 2 | const | 1 | |
+--------+-------+---------------+---------+---------+-------+------+-------+
1 row in set (0.00 sec)
mysql> EXPLAIN SELECT * FROM cities WHERE cityid IN(1, 1);
+--------+-------+---------------+---------+---------+------+------+------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------+-------+---------------+---------+---------+------+------+------------+
| cities | range | PRIMARY | PRIMARY | 2 | NULL | 1 | where used |
+--------+-------+---------------+---------+---------+------+------+------------+
1 row in set (0.00 sec)
in that case, IN() doesn't notice that the values are the same.
Bookmarks