1. 程式人生 > >今天我發現了MySQL的一個Bug

今天我發現了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啦。
。。。。。。

如果你覺得這個事情很有意思或很沒意思,請移步到下面的地址看個究竟: