I have a MySQL table mes_mes
that contains ~12 000 000 rows. This is the structure:
CREATE TABLE `mes_mes` (
`id` bigint(20) NOT NULL,
`sent_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`to_id` int(11) NOT NULL,
`from_id` int(11) NOT NULL,
`msg_txt` text CHARACTER SET latin1 NOT NULL,
`read_t` varchar(20) NOT NULL DEFAULT '0',
`img_id` varchar(11) CHARACTER SET latin1 NOT NULL,
`em_id` tinyint(1) NOT NULL,
`is_received` tinyint(1) NOT NULL DEFAULT '1',
`is_copy` bigint(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
DELIMITER $$
CREATE TRIGGER `instant_messages_d` BEFORE DELETE ON `mes_mes` FOR EACH ROW BEGIN
UPDATE users_table SET inbox_msg_total=inbox_msg_total-1 WHERE id=OLD.to_id;
UPDATE mes_fol set msg_total=msg_total-1 where sender=OLD.from_id and receiver=OLD.to_id;
END
$$
DELIMITER ;
ALTER TABLE `mes_mes`
ADD PRIMARY KEY (`id`) USING BTREE,
ADD KEY `to_id` (`to_id`,`is_received`,`id`),
ADD KEY `to_id_2` (`to_id`,`from_id`,`id`),
ADD KEY `from_id` (`from_id`,`id`),
ADD KEY `is_copy` (`is_copy`);
ALTER TABLE `mes_mes`
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;
Problem:
The number of rows is growing and now I am not able to update the table because the request hangs for 1-2 minutes and then the server just crashes. I don't understand where is the problem because the where
clause is primary key.
MySQL query:
"UPDATE mes_mes set msg_txt='Spam', img_id='', em_id='10' WHERE id IN (". implode(', ', $_POST['msg_id']).")"
$_POST['msg_id']
does not contain more than 20 values.
P.S. The problem occurs on production server. I ran into this twice and unfortunately didn't look in the logs. I don't want to repeat anymore because the server becomes unavailable. I suspect the server runs out of memory. As long as there were fewer records in the database, there was no problem. Just wonder how such a simple query can cause problems.