Bug #31903 Wrong works with lower_case_table_names = 0 and wrong tablename cases
Submitted: 29 Oct 2007 9:26 Modified: 13 Nov 2007 14:31
Reporter: Ivan Kurnosov Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.46, 5.1.22 OS:Windows (Any)
Assigned to: Alexander Nozdrin CPU Architecture:Any
Tags: case sensitivity, table names

[29 Oct 2007 9:26] Ivan Kurnosov
Description:
lower_case_table_names = 0 works strange with windows OS.
After trying of update table with incorrect tablename we get missing af records, that follows the updated
the server restart (and repairing of table) is "fixed" that trouble

How to repeat:
DROP TABLE IF EXISTS `menu_menuitem`;

CREATE TABLE `menu_menuitem` (
  `id` int(11) NOT NULL auto_increment,
  `parent_id` int(10) unsigned default '0',
  `type_id` int(10) unsigned default NULL,
  `menu_id` int(10) unsigned default NULL,
  `title` varchar(255) NOT NULL default '',
  `order` int(10) unsigned default '0',
  `obj_id` int(10) unsigned default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=cp1251 PACK_KEYS=0;

#
# Data for the `menu_menuitem` table  (LIMIT 0,500)
#

INSERT INTO `menu_menuitem` (`id`, `parent_id`, `type_id`, `menu_id`, `title`, `order`, `obj_id`) VALUES 
  (1,0,2,5,'Новости',1,661),
  (2,0,2,5,'Страницы',2,662),
  (3,0,2,5,'Каталог',3,663),
  (4,0,2,5,'Галерея',4,664),
  (5,0,2,5,'Пользователи',5,665),
  (6,0,2,5,'Панель управления',7,666),
  (7,0,2,5,'Сообщения',8,815),
  (8,0,2,5,'Форум',9,888);

COMMIT;

mysql> select * from menu_menuitem;
+----+-----------+---------+---------+-------------------+-------+--------+
| id | parent_id | type_id | menu_id | title             | order | obj_id |
+----+-----------+---------+---------+-------------------+-------+--------+
|  1 |         0 |       2 |       5 | Новости           |     1 |    661 |
|  2 |         0 |       2 |       5 | Страницы          |     2 |    662 |
|  3 |         0 |       2 |       5 | Каталог           |     3 |    663 |
|  4 |         0 |       2 |       5 | Галерея           |     4 |    664 |
|  5 |         0 |       2 |       5 | Пользователи      |     5 |    665 |
|  6 |         0 |       2 |       5 | Панель управления |     7 |    666 |
|  7 |         0 |       2 |       5 | Сообщения         |     8 |    815 |
|  8 |         0 |       2 |       5 | Форум             |     9 |    888 |
+----+-----------+---------+---------+-------------------+-------+--------+
8 rows in set (0.00 sec)

mysql> UPDATE  `menu_menuItem` SET `order` = 1, `parent_id` = '6' WHERE `id` = '
8';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from menu_menuitem;
+----+-----------+---------+---------+-------------------+-------+--------+
| id | parent_id | type_id | menu_id | title             | order | obj_id |
+----+-----------+---------+---------+-------------------+-------+--------+
|  1 |         0 |       2 |       5 | Новости           |     1 |    661 |
|  2 |         0 |       2 |       5 | Страницы          |     2 |    662 |
|  3 |         0 |       2 |       5 | Каталог           |     3 |    663 |
|  4 |         0 |       2 |       5 | Галерея           |     4 |    664 |
|  5 |         0 |       2 |       5 | Пользователи      |     5 |    665 |
|  6 |         0 |       2 |       5 | Панель управления |     7 |    666 |
|  7 |         0 |       2 |       5 | Сообщения         |     8 |    815 |
+----+-----------+---------+---------+-------------------+-------+--------+
7 rows in set (0.00 sec)

# Here we restart server deamon

mysql> set names cp866;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql>
mysql> set names cp866;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1
Current database: mzz

Query OK, 0 rows affected (0.20 sec)

mysql> select * from menu_menuitem;
+----+-----------+---------+---------+-------------------+-------+--------+
| id | parent_id | type_id | menu_id | title             | order | obj_id |
+----+-----------+---------+---------+-------------------+-------+--------+
|  1 |         0 |       2 |       5 | Новости           |     1 |    661 |
|  2 |         0 |       2 |       5 | Страницы          |     2 |    662 |
|  3 |         0 |       2 |       5 | Каталог           |     3 |    663 |
|  4 |         0 |       2 |       5 | Галерея           |     4 |    664 |
|  5 |         0 |       2 |       5 | Пользователи      |     5 |    665 |
|  6 |         0 |       2 |       5 | Панель управления |     7 |    666 |
|  7 |         0 |       2 |       5 | Сообщения         |     8 |    815 |
|  8 |         6 |       2 |       5 | Форум             |     1 |    888 |
+----+-----------+---------+---------+-------------------+-------+--------+
8 rows in set (0.00 sec)

# ps: cache turned off

Suggested fix:
it would be nice that mysql throws error about non-exists table, when tablename is in incorrect case
[29 Oct 2007 12:13] Sveta Smirnova
Thank you for the report.

Verified as described.

This is Windows specific issue. Bug is not repeatable on Mac OS X.
[13 Nov 2007 14:14] Alexander Nozdrin
The Manual says
(http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html):

[quote]
Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive. Note that if you force this variable to 0 with --lower-case-table-names=0 on a case-insensitive filesystem and access MyISAM tablenames using different lettercases, index corruption may result.
[/quote]

This is the case. Index is corrupted, thus wrong data are received.
[13 Nov 2007 14:31] Ivan Kurnosov
Alexander Nozdrin
I've read that chapter before i post the bug, but:

1. why corruption in index influences on the query that don't uses any indexes? (I mean qries like SELECT * FROM `table`)
2. why mysql daemon restart "fixes" that corruption? (or repairing is doing automatically before/during/after server starts)