今天我发现了MySQL的一个Bug

今天有个测试人员报告说导入通讯录的程序有点问题,无法导入或者只能部分导入,但不会报错。

导入通讯录时会检查联系人姓名是否会在待导入的群组中,如果不在才导入,否则忽略。

我从日志中找出了一个SQL语句,如下:

SELECT contact_id, contact_name, contact_title, gender, birthday, specday, idno, profession,
 company, dept, region,
address, postcode, mobile, phone, fax, email, qq, home_phone, home_address, other, remarks, 
tenant_id, created_by, create_time, modified_by, modify_time FROM mab_contact_info 
WHERE contact_name = '陈志林' 
AND contact_id IN (SELECT contact_id FROM mab_contact_group WHERE contact_group_id = 36);
我一看,就觉得子查询有点问题,因为mab_contact_group表中根本就没有contact_id字段啊。
mysql> desc mab_contact_group;
+--------------------+--------------+------+-----+---------+----------------+
| Field              | Type         | Null | Key | Default | Extra          |
+--------------------+--------------+------+-----+---------+----------------+
| contact_group_id   | int(11)      | NO   | PRI | NULL    | auto_increment |
| contact_group_name | varchar(32)  | NO   |     | NULL    |                |
| super_group_id     | int(11)      | YES  | MUL | NULL    |                |
| tenant_id          | int(11)      | NO   | MUL | NULL    |                |
| contact_group_path | varchar(256) | YES  |     | NULL    |                |
| created_by         | int(11)      | YES  | MUL | NULL    |                |
| create_time        | datetime     | NO   |     | NULL    |                |
| modified_by        | int(11)      | YES  | MUL | NULL    |                |
| modify_time        | datetime     | YES  |     | NULL    |                |
+--------------------+--------------+------+-----+---------+----------------+
9 rows in set (0.00 sec)
但是程序没有报错。于是我把它贴到MySQL中执行,确实不报错,而且找到了数据:
mysql> SELECT contact_id, contact_name, contact_title, gender, birthday, specday, 
idno, profession, company, dept, region,
    -> address, postcode, mobile, phone, fax, email, qq, home_phone, 
home_address, other, remarks, tenant_id, created_by, create_time, modified_by, modify_time 
FROM mab_contact_info 
    -> WHERE contact_name = '陈志林' 
AND contact_id IN (SELECT contact_id FROM mab_contact_group WHERE contact_group_id = 36);
+------------+--------------+---------------+--------+----------+---------+------+------------+---------+------+--------+---------+----------+-------------+-------+------+-------+------+------------+--------------+-------+-----------------------------------------------------------------+-----------+------------+---------------------+-------------+-------------+
| contact_id | contact_name | contact_title | gender | birthday | specday | idno | profession | company | dept | region | address | postcode | mobile      | phone | fax  | email | qq   | home_phone | home_address | other | remarks                                                         | tenant_id | created_by | create_time         | modified_by | modify_time |
+------------+--------------+---------------+--------+----------+---------+------+------------+---------+------+--------+---------+----------+-------------+-------+------+-------+------+------------+--------------+-------+-----------------------------------------------------------------+-----------+------------+---------------------+-------------+-------------+
|        138 | 陈志林       | NULL          | NULL   | NULL     | NULL    | NULL | NULL       | NULL    | NULL | NULL   | NULL    | NULL     | 13975188486 | NULL  | NULL | NULL  | NULL | NULL       | NULL         | NULL  | 导入自《20121128115430956106_contact班主任及管理人员.xls》第2行 |      3000 |       9024 | 2012-11-28 11:54:32 |        NULL | NULL        |
+------------+--------------+---------------+--------+----------+---------+------+------------+---------+------+--------+---------+----------+-------------+-------+------+-------+------+------------+--------------+-------+-----------------------------------------------------------------+-----------+------------+---------------------+-------------+-------------+
1 row in set (0.00 sec)

但是把其中的子查询单独执行,会有问题。

mysql> SELECT contact_id FROM mab_contact_group WHERE contact_group_id = 36;
ERROR 1054 (42S22): Unknown column 'contact_id' in 'field list'
mysql> 
我的第一反应是,我发现MySQL的一个Bug啦。
。。。。。。

如果你觉得这个事情很有意思或很没意思,请移步到下面的地址看个究竟:

http://www.vktone.com/articles/find-bug-of-mysql-oh.html

猜你喜欢

转载自coding1688.iteye.com/blog/1736577