I have a really strange problem, and I have no idea what can cause it. Any suggestion will be gratefully appreciated. Here is the table structures and the queries:
CREATE TABLE `big_test` (
`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT,
`application_id` int(11) unsigned NOT NULL DEFAULT '0',
`account_id` int(11) unsigned NOT NULL DEFAULT '0',
`dev_id` char(128) NOT NULL DEFAULT '',
`gid` char(255) NOT NULL DEFAULT '',
`name` char(20) NOT NULL DEFAULT '',
`age` int(11) unsigned NOT NULL DEFAULT '0',
`image` longblob NOT NULL,
`updatedon` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`eik` bigint(11) unsigned NOT NULL DEFAULT '1',
`me` int(2) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `gid` (`gid`,`application_id`,`account_id`),
KEY `dev_id` (`dev_id`),
KEY `account_id` (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=35796304 DEFAULT CHARSET=utf8
mysql> SELECT gid, application_id, account_id FROM big_test WHERE account_id=14811 AND gid='TEST773475616236';
+-------------------------------------------------------------+----------------+------------+
| gid | application_id | account_id |
+-------------------------------------------------------------+----------------+------------+
| TEST773475616236 | 1655 | 14811 |
| TEST773475616236 | 1655 | 14811 |
+-------------------------------------------------------------+----------------+------------+
2 rows in set (0.00 sec)
mysql> SELECT gid, application_id, account_id FROM big_test WHERE account_id=14811 AND gid='TEST773475616236' AND application_id=1655;
+-------------------------------------------------------------+----------------+------------+
| gid | application_id | account_id |
+-------------------------------------------------------------+----------------+------------+
| TEST773475616236 | 1655 | 14811 |
+-------------------------------------------------------------+----------------+------------+
1 row in set (0.00 sec)
mysql> SELECT gid, application_id, account_id FROM big_test WHERE account_id=14811 AND gid='TEST773475616236' AND application_id<>1655;
Empty set (0.00 sec)
mysql>
All the queries which are used for insert/update operations is "REPLACE". For example:
mysql> REPLACE INTO big_test SET gid='TEST773475616236', application_id=1655, account_id=14811, name='Charlie';
How is that possible, that UNIQUE KEY is not working?
As always, the problem is not in the database it self, but in the programing code. There was a SQL statements executed in transaction, where there was a set for stop checking unique keys. Really stupid but answer the question, and solved the problem :)