Answer the question
In order to leave comments, you need to log in
When you need a lot of indexes, what to do?
I have the following table structure
CREATE TABLE `tb_visitors` (
`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='Запись визитов';
--
-- Индексы сохранённых таблиц
--
ALTER TABLE `tb_visitors`
ADD PRIMARY KEY (`id`),
ADD KEY `status` (`status`),
ADD KEY `idad` (`idad`),
ADD KEY `idus` (`idus`),
ADD KEY `ip` (`ip`);
DELETE FROM `tb_visitors` WHERE `status` = '1' AND `date` < '".time()."'
Answer the question
In order to leave comments, you need to log in
Build only those indexes that are needed. Every insert/modify/delete operation is an index rebuild. The more indexes, the longer these operations take. As long as the fetch rate is sufficient without the use of indexes, there is no need to build them.
With a mass change, you can first disable indexes, after the change, enable them again.
LOCK TABLES `table` WRITE;
ALTER TABLE `table` DISABLE KEYS;
INSERT/UPDATE/DELETE ...
ALTER TABLE `table` ENABLE KEYS;
UNLOCK TABLES;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question