위처럼 테스트 해보면 실행계획같이 동일 합니다.
꼭 상수때문에 발생하는 문제는 아닌것 같습니다.
mysql> desc city
-> ;
+-------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| Name | char(35) | NO | | | |
| CountryCode | char(3) | NO | MUL | | |
| District | char(20) | NO | | | |
| Population | int(11) | NO | | 0 | |
+-------------+----------+------+-----+---------+----------------+
5 rows in set (0.09 sec)
mysql> explain select * from city where id=1 ;
+----+-------------+-------+------------+-------+---------------+---------+-----
----+-------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_
len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+-------+---------------+---------+-----
----+-------+------+----------+-------+
| 1 | SIMPLE | city | NULL | const | PRIMARY | PRIMARY | 4
| const | 1 | 100.00 | NULL |
+----+-------------+-------+------------+-------+---------------+---------+-----
----+-------+------+----------+-------+
1 row in set, 1 warning (0.09 sec)
mysql> set @A:=1 ;
Query OK, 0 rows affected (0.08 sec)
mysql> explain select * from city where id =@A ;
+----+-------------+-------+------------+-------+---------------+---------+-----
----+-------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_
len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+-------+---------------+---------+-----
----+-------+------+----------+-------+
| 1 | SIMPLE | city | NULL | const | PRIMARY | PRIMARY | 4
| const | 1 | 100.00 | NULL |
+----+-------------+-------+------------+-------+---------------+---------+-----
----+-------+------+----------+-------+
1 row in set, 1 warning (0.00 sec)