我有一个这样的查询...
SELECT SQL_CACHE area3, area, area2, COUNT( area ) AS total
FROM wpthillsdatabase
GROUP BY area
ORDER BY area3 ASC , area ASC
它的解释说它正在使用文件排序,没有索引和临时表......
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE wpthillsdatabaseV12 ALL NULL NULL NULL NULL 9334 Using temporary; Using filesort
是否可以进一步优化它以删除带有索引的文件排序或临时表,或者这是否尽可能好?
仅供参考,表格的结构是这样的......
CREATE TABLE `wpthillsdatabase` (
`hillnumber` varchar(6) NOT NULL default '',
`wikipedia` varchar(100) NOT NULL default '',
`hillname` varchar(100) NOT NULL default '',
`meters` char(6) NOT NULL default '',
`GridZN` char(2) NOT NULL default '',
`GridEast` char(5) NOT NULL default '',
`GridNorth` char(5) NOT NULL default '',
`numeast` char(7) NOT NULL default '',
`numnorth` char(7) NOT NULL default '',
`areadecimal` decimal(5,2) NOT NULL default '0.00',
`area` varchar(3) NOT NULL default '',
`area2` varchar(100) NOT NULL default '',
`maps` varchar(100) NOT NULL default '',
`waypointname` char(6) character set latin1 collate latin1_bin NOT NULL default '',
`latitude` decimal(10,8) NOT NULL default '0.00000000',
`longitude` decimal(10,7) NOT NULL default '0.0000000',
`area3` smallint(2) NOT NULL default '0',
`dip` decimal(5,1) NOT NULL default '0.0' COMMENT 'col height (m)',
`climbedbytotal` smallint(6) NOT NULL default '0',
`trigID` varchar(6) NOT NULL default '',
`trigEast` varchar(7) NOT NULL default '',
`trigNorth` varchar(7) NOT NULL default '',
`trigLat` varchar(10) NOT NULL default '',
`trigLon` varchar(10) NOT NULL default '',
`SummitInfo` varchar(290) NOT NULL default '',
PRIMARY KEY (`hillnumber`,`area3`),
UNIQUE KEY `meters` (`meters`,`hillnumber`),
UNIQUE KEY `SortIndex1` (`hillnumber`,`hillname`,`meters`),
UNIQUE KEY `NearByHills` (`numeast`,`numnorth`,`hillnumber`),
UNIQUE KEY `hillnumber_only` (`hillnumber`),
UNIQUE KEY `Area3_Sort` (`area3`,`hillnumber`,`hillname`,`meters`),
UNIQUE KEY `GirdZN_sort` (`GridZN`,`hillnumber`,`hillname`,`meters`),
UNIQUE KEY `hil_lat_lon` (`hillnumber`,`latitude`,`longitude`),
KEY `trigID` (`trigID`,`hillname`,`meters`),
KEY `climbedbytotal` (`climbedbytotal`),
KEY `hillname` (`hillname`,`meters`),
KEY `area3` (`area3`,`hillnumber`),
KEY `hillname_only` (`hillname`),
KEY `area3_trigID` (`area3`,`trigID`),
KEY `Area_text` (`area`,`area3`),
KEY `dip_area3` (`dip`,`area3`),
KEY `lat_lon` (`latitude`,`longitude`,`meters`),
KEY `trigID_area3` (`trigID`,`area3`),
KEY `numeast_north` (`numeast`,`numnorth`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
Ta
菲尔