basic information:
Thedatasheet has almost 10 million pieces of data, using the mycat sublibrary.
the indexes in the data table are
- PRIMARY id
- AppName (AppName, custidStatus, channel)
the table creation statement is as follows
CREATE TABLE `eis_email_history` (
`id` bigint(20) NOT NULL DEFAULT "0",
`AppName` int(11) NOT NULL DEFAULT "0",
`emailto` varchar(256) COLLATE utf8_unicode_ci NOT NULL DEFAULT "" COMMENT "email",
`emailfrom` varchar(256) COLLATE utf8_unicode_ci NOT NULL DEFAULT "" COMMENT "email",
`subject` varchar(256) COLLATE utf8_unicode_ci NOT NULL DEFAULT "" COMMENT "",
`content` text COLLATE utf8_unicode_ci NOT NULL COMMENT "",
`sendtime` int(11) NOT NULL DEFAULT "0" COMMENT "unixtime",
`sendstatus` tinyint(4) NOT NULL DEFAULT "0" COMMENT "0:1:2:3:",
`channel` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT "" COMMENT "",
`AmazonOrderId` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT "" COMMENT "???",
`ASIN` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT "" COMMENT "asin",
`attachment` text COLLATE utf8_unicode_ci COMMENT "2"tab" +"/" +"tab" ",
`templateId` bigint(20) NOT NULL DEFAULT "0" COMMENT "Id",
`custidStatus` int(20) NOT NULL DEFAULT "0" COMMENT "Id",
PRIMARY KEY (`id`),
KEY `emailto` (`emailto`(255)),
KEY `sendtime` (`sendtime`),
KEY `sendstatus` (`sendstatus`),
KEY `emailfrom` (`emailfrom`(255)),
KEY `asin` (`ASIN`),
KEY `orderid` (`AmazonOrderId`),
KEY `AppName` (`AppName`,`custidStatus`,`channel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
first of all, there is no order by
SELECT
`id`,
`emailto`,
`channel`,
`AppName`,
`AmazonOrderId`
FROM
`eis_email_history`
WHERE `AppName` = 21
AND `custidStatus` IN (0, 1, 2)
AND `channel` = "***"
LIMIT 50
this query is basically a second query, and then the result of explain is
order by id desc,
1explain
.depending on the situation, the index of the where condition is not used due to the addition of order by, but the primary key scan is used