Ошибка в индексах и очень медленная во всех запросах

у этой таблицы есть все проблемы на свете 🙁
медленный поиск с полями name_ar, name_en с Query LIKE,
медленно с SELECT запросом с полями cid, uid, sid, ssid, product_id, havproduct
очень медленный в INSERT Query
я думаю, что ошибка в индексах в этой таблице

создание таблицы

CREATE TABLE `eng_subjects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cid` int(11) NOT NULL,
`did` int(11) NOT NULL,
`sid` int(11) NOT NULL,
`ssid` int(11) NOT NULL DEFAULT '0',
`product_id` int(11) NOT NULL DEFAULT '0',
`havproduct` int(11) NOT NULL DEFAULT '0',
`shortcut` int(11) DEFAULT '0',
`uid` int(11) NOT NULL,
`ar_name` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
`en_name` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL,
`ar_desc` longtext COLLATE utf8_unicode_ci NOT NULL,
`en_desc` longtext COLLATE utf8_unicode_ci NOT NULL,
`ar_pic` varchar(500) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
`en_pic` varchar(500) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
`video` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
`piclinknews` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
`active_links` int(11) NOT NULL,
`stop_smile` int(11) NOT NULL,
`subscribe` int(11) NOT NULL,
`subscribe_type` int(11) NOT NULL,
`close` int(11) NOT NULL DEFAULT '0',
`active` int(11) NOT NULL DEFAULT '1',
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`orderBy` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`viewnum` int(11) NOT NULL DEFAULT '1',
`updated` int(11) NOT NULL DEFAULT '0',
`pin_from` int(11) NOT NULL DEFAULT '0',
`pin_to` int(11) NOT NULL DEFAULT '0',
`up_to` int(11) NOT NULL DEFAULT '0',
`deleted` int(11) NOT NULL DEFAULT '0',
`deleted_reason` varchar(250) CHARACTER SET utf8 NOT NULL DEFAULT 'not Deleted',
`average_price` float NOT NULL DEFAULT '0',
`last_update` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0000-00-00 00:00:00',
`country_id` int(11) NOT NULL,
`discomment` int(11) NOT NULL,
`user_active` tinyint(4) NOT NULL DEFAULT '1',
`dep_active` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
KEY `subject_idx_did` (`did`),
KEY `idx_uid` (`uid`),
KEY `idx_cid` (`cid`),
KEY `idx_pin2` (`sid`,`deleted`,`pin_to`,`close`),
KEY `engine4_subject_date` (`date`),
KEY `idx_cid2` (`cid`,`deleted`,`close`),
KEY `engine4_subject1` (`product_id`,`deleted`),
KEY `idx_prodid1` (`product_id`,`deleted`)
) ENGINE=InnoDB AUTO_INCREMENT=22383826 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

Вставить запрос

INSERT INTO eng_subjects (`ar_name`,`en_name`,`video`,`piclinknews`,`ar_desc`,`en_desc`,`country_id`,`active_links`,`stop_smile`,`subscribe`,`subscribe_type`,`shortcut`,`cid`,`did`,`sid`,`ssid`,`orderBy`,`discomment`,`uid`)
VALUES ('test title','test title','','','testing content','testing content','62','','','','','','24','26','437','0','2014-07-26 11:08:40','0','1165262')

вставка результата
http://i.stack.imgur.com/MEyPB.png

Выбор запроса

select * from `eng_subjects` WHERE `cid` = 24 and active = 1 and `deleted` = 0 order by id desc LIMIT 30

объяснять

id  select_type table       type    possible_keys       key     key_len ref     rows    Extra
1   SIMPLE      eng_subjects ref    idx_cid,idx_cid2    idx_cid 4       const   205438  Using where

эта таблица имеет обновление в полях views каждый визит на эту тему
я думаю, что скопировать структуру и создать новую таблицу с тем же именем
и переместить все данные в новую таблицу и удалить все индексы в старой таблице
но каков наилучший способ добавить индексы в этой таблице.


Я думаю, что проблема аддитивной и очень медленной из-за большого количества плохих индексов .. как насчет удаления всех индексов?

Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
eng_subjects 0 PRIMARY 1 id A 196089 NULL NULL BTREE
eng_subjects 1 subject_idx_did 1 did A 3 NULL NULL BTREE
eng_subjects 1 idx_uid 1 uid A 49022 NULL NULL BTREE
eng_subjects 1 idx_pin2 1 sid A 139 NULL NULL BTREE
eng_subjects 1 idx_pin2 2 deleted A 338 NULL NULL BTREE
eng_subjects 1 idx_pin2 3 pin_to A 1203 NULL NULL BTREE
eng_subjects 1 idx_pin2 4 close A 1474 NULL NULL BTREE
eng_subjects 1 engine4_subject_date 1 date A 196089 NULL NULL BTREE
eng_subjects 1 engine4_subject1 1 product_id A 4 NULL NULL BTREE
eng_subjects 1 engine4_subject1 2 deleted A 4 NULL NULL BTREE
eng_subjects 1 idx_prodid1 1 product_id A 4 NULL NULL BTREE
eng_subjects 1 idx_prodid1 2 deleted A 4 NULL NULL BTREE
eng_subjects 1 idx_for_qry 1 cid A 100 NULL NULL BTREE
eng_subjects 1 idx_for_qry 2 active A 100 NULL NULL BTREE
eng_subjects 1 idx_for_qry 3 deleted A 100 NULL NULL BTREE

0

Решение

Может быть, попробуйте с этим ключом:

KEY `idx_for_qry` (`cid`,`active `,`deleted`)

И удалите «idx_cid» потому что если у вас есть составной ключ, первое поле ключа просто индексируется

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector