我只是想知道MySQL实际上是如何执行“IN”查询的。
例如, 我有一个查询,其中我在IN数组中使用100个参数,如:
SELECT productName, price FROM tbl_product WHERE id IN (1,2,3,4,5,6,7,8,9,10,11,......,100) AND status = 'y';
现在,SQL引擎如何执行此查询?
是否会启动任何循环,如
SELECT productName, price FROM tbl_product WHERE id = '1' AND status = 'y';
SELECT productName, price FROM tbl_product WHERE id = '2' AND status = 'y';
SELECT productName, price FROM tbl_product WHERE id = '3' AND status = 'y';
SELECT productName, price FROM tbl_product WHERE id = '4' AND status = 'y';
.........
........
......
SELECT productName, price FROM tbl_product WHERE id = '98' AND status = 'y';
SELECT productName, price FROM tbl_product WHERE id = '99' AND status = 'y';
SELECT productName, price FROM tbl_product WHERE id = '100' AND status = 'y';
OR
只需从
等1个查询中获取SELECT productName, price FROM tbl_product WHERE (id = '1' OR id = '2' OR id = '3' OR id = '4' OR id = '5' .......... OR id = '99' OR id = '100') AND status = 'y';