Bug #5533 keys (#) return no matches
Submitted: 13 Sep 2004 0:58 Modified: 4 Oct 2004 21:10
Reporter: Kevin Landreth Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.3 OS:Linux (RH Enterprise ES3 TaroonUpdate2)
Assigned to: Matthew Lord CPU Architecture:Any

[13 Sep 2004 0:58] Kevin Landreth
Description:
Both delete and update do not work on this varchar(32) column.  You have to use like instead of =  to match records.  Evidence below ( for the update comand) .  However, on a different table, same database, it works.  Now, I've deleted the tables and re-created them many times already and the problem persists.  

mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
7 rows in set (0.00 sec)
version                         4.1.3-beta-log             
version_comment                 yes                        
version_compile_machine      i686                       
version_compile_os              pc-linux                   

mysql> select * from drupal_sessions where uid = 1;
+-----+----------------------------------+-----------------+------------+-----------------+
| uid | sid                              | hostname        | timestamp  | session         |
+-----+----------------------------------+-----------------+------------+-----------------+
|   1 | 08cb660b2140bf4cedcd2fd032bdbbf8 | xxx.xxx.xxx.xxx | 1095034879 | messages|a:0:{} |
+-----+----------------------------------+-----------------+------------+-----------------+
1 row in set (0.00 sec)

mysql> update drupal_sessions SET uid=0 WHERE sid='08cb660b2140bf4cedcd2fd032bdbbf8';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql> update drupal_sessions SET uid=0 WHERE sid like '08cb660b2140bf4cedcd2fd032bdbbf8';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from drupal_sessions where sid='08cb660b2140bf4cedcd2fd032bdbbf8';
+-----+----------------------------------+-----------------+------------+-----------------+
| uid | sid                              | hostname        | timestamp  | session         |
+-----+----------------------------------+-----------------+------------+-----------------+
|   1 | 08cb660b2140bf4cedcd2fd032bdbbf8 | xxx.xxx.xxx.xxx | 1095035122 | messages|a:0:{} |
+-----+----------------------------------+-----------------+------------+-----------------+
1 row in set (0.00 sec)

mysql> show table status like 'drupal_sessions';
+-----------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| Name            | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation       | Checksum | Create_options | Comment |
+-----------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| drupal_sessions | MyISAM |       9 | Dynamic    |    1 |             92 |         216 |      4294967295 |         4096 |       124 |           NULL | 2004-09-12 15:58:59 | 2004-09-12 19:25:22 | NULL       | utf8_general_ci |     NULL |                |         |
+-----------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
1 row in set (0.00 sec)

mysql> show table status like 'drupal_users';
+--------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| Name         | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation       | Checksum | Create_options | Comment |
+--------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| drupal_users | MyISAM |       9 | Dynamic    |    2 |             84 |         168 |      4294967295 |         4096 |         0 |           NULL | 2004-09-12 15:58:59 | 2004-09-12 19:49:51 | NULL       | utf8_general_ci |     NULL |                |         |
+--------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
1 row in set (0.01 sec)

mysql> update drupal_users set changed=UNIX_TIMESTAMP() where name='admin';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update drupal_users set changed=UNIX_TIMESTAMP() where name like 'admin';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

I tried this with the password field as well (since it uses similar jargon) and it worked in the user table. (didn't want to paste the pw hash in here).

This problem does not exists on slackware-current (post slackware-10 | pre slackware 11)

If you need additional information I will be more than happy to accomidate you.

How to repeat:
Compeletly removed mysql-* from the rpms. 
Download 4.1.3 and compile it
create a user and import the tables into the server.

Populate the database and do selects.

Suggested fix:
none
[13 Sep 2004 1:00] Kevin Landreth
CREATE TABLE drupal_sessions (
  uid int(10) unsigned NOT NULL,
  sid varchar(32) NOT NULL default '',
  hostname varchar(128) NOT NULL default '',
  timestamp int(11) NOT NULL default '0',
  session longtext,
  KEY uid (uid),
  KEY sid (sid(4)),
  KEY timestamp (timestamp)
) TYPE=MyISAM;

I think the problem might be with the Key....but I don't know if its a mysql error or an oversite.
[13 Sep 2004 1:35] Kevin Landreth
Turns out it was the Keys in sid (sid(4)) would find to matches.

When creating a full text key or standard key = began to work and like was no longer required.
[4 Oct 2004 21:10] Matthew Lord
Hi Kevin,

I see, it looks like some of the statements were using the one index and some the other.

I'll close this one now.

Thanks for your bug report!

Best Regards