W
W
WiNNeR_tig2017-10-12 15:35:01
MySQL
WiNNeR_tig, 2017-10-12 15:35:01

Fighting locks in memory tables using Redis, is it worth it?

There is such a table, about 1 ml of records accumulate in it by the evening, the table works actively for reading, writing and updating, and deletions are still made during the day where there are locks up to 0.2 seconds per 1 deletion ...
First, I deleted it with a regular DELETE query indicating the key status and date , then I tried it through a loop, since there is no index on date, since this field is used only when deleting.

Время загрузки: 0.26188206672668 - Скорость: 0.262 мс. 
DELETE FROM `tb_visits` WHERE `id` = '605242' LIMIT 1

I'm thinking of moving everything to Redis and sorting by key, as SELECTs can be like this
SELECT * FROM `tb_visits` WHERE `idad` = '338236' AND `status` = '0' LIMIT 127
SELECT `id` FROM `tb_visits` WHERE `idad` = '416' AND (`idus` = '1481066' OR `ip` = INET_ATON('185.124.154.186')) LIMIT 1

Is it worth it or is there another way to solve the problem?
And yet, according to the same principle, there are a dozen more such tables on the site, but they do not accumulate more than 100 tons of records per day.
CREATE TABLE `tb_visits` (
  `id` int(11) UNSIGNED NOT NULL,
  `idad` int(11) UNSIGNED NOT NULL,
  `idus` int(11) UNSIGNED NOT NULL,
  `ip` int(10) UNSIGNED NOT NULL,
  `date` int(10) UNSIGNED NOT NULL,
  `status` enum('0','1') NOT NULL DEFAULT '0'
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COMMENT='Запись визитов';

INSERT INTO `tb_visits` (`id`, `idad`, `idus`, `ip`, `date`, `status`) VALUES (1016695, 336347, 1488770, 630656028, 1507867665, '1');

ALTER TABLE `tb_visits`
  ADD PRIMARY KEY (`id`),
  ADD KEY `status` (`status`),
  ADD KEY `idad` (`idad`),
  ADD KEY `idus` (`idus`),
  ADD KEY `ip` (`ip`);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question