我编写了以下查询,该查询在我的本地服务器上运行大约40秒,但在托管的mysql服务器上继续运行。 有人可以帮忙并确定如何改进它吗?
Set @rownum = 0;
Set @rownum1 = 0;
explain select * from
(select *, @rownum1:=@rownum1+1 as ida from xvp_tenant_683.activity_archive_90) tbl1
where tbl1.ida >
(select id from
(select *, @rownum:=@rownum+1 as id from xvp_tenant_683.activity_archive_90) tbl
where ctype = 'WRAPUP' and dtStart = '2015-10-01 17:08:59' and uid='30774' and
cprofiletype = 'inbound' and pid = '53');
表结构是:
CREATE TABLE `activity_archive_90` (
`cType` varchar(20) NOT NULL DEFAULT '',
`dtStart` datetime NOT NULL DEFAULT '1900-01-01 00:00:00',
`dtEnd` datetime NOT NULL DEFAULT '1900-01-01 00:00:00',
`iDuration` int(11) NOT NULL DEFAULT '0',
`dRevenue` decimal(10,2) NOT NULL DEFAULT '0.00',
`uId` int(11) NOT NULL DEFAULT '0',
`cUserName` varchar(100) NOT NULL DEFAULT '',
`cProfileType` varchar(10) NOT NULL DEFAULT '',
`pId` int(11) NOT NULL DEFAULT '0',
`ccId` int(11) NOT NULL DEFAULT '0',
`ibProfiles` text,
`obProfiles` text,
PRIMARY KEY (`cType`,`dtStart`,`uId`,`cProfileType`,`pId`),
KEY `cType` (`cType`),
KEY `dtStart` (`dtStart`),
KEY `dtEnd` (`dtEnd`),
KEY `uId` (`uId`),
KEY `pId` (`pId`),
KEY `ccId` (`ccId`),
KEY `cProfileType` (`cProfileType`),
KEY `cUserName` (`cUserName`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
在托管服务器上解释声明结果是:
# id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
1, PRIMARY, <derived2>, ALL, , , , , 333708, Using where
3, UNCACHEABLE SUBQUERY, <derived4>, ALL, , , , , 333708, Using where
4, DERIVED, activity_archive_90, ALL, , , , , 333708,
2, DERIVED, activity_archive_90, ALL, , , , , 333708,
在我的本地服务器上解释语句结果是:
# id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
1, PRIMARY, <derived2>, ALL, , , , , 333525, Using where
3, UNCACHEABLE SUBQUERY, <derived4>, ref, <auto_key0>, <auto_key0>, 47, const,const,const,const,const, 10, Using index condition
4, DERIVED, zzz_activity_archive_90, ALL, , , , , 333525,
2, DERIVED, zzz_activity_archive_90, ALL, , , , , 333525,
我注意到第二个结果使用了一个键,这可能是我本地服务器上更快结果的原因?如何在托管服务器上包含此密钥(我无权访问托管服务器上的alter table)