所以我有一张拥有5600万行的表,插入数据并查询它的时间非常非常长。我很好奇任何人的建议。
我的服务器有32GB内存(大多数未使用),2X RAID SSD和E3-1270,所以它应该很快。
然而一些选择查询花费了40秒以上。我基本上存储了游戏世界中物体的位置。下面是结构:
CREATE TABLE IF NOT EXISTS `object_positions2` (
`entry` mediumint(9) NOT NULL,
`type` tinyint(4) NOT NULL,
`x_int` int(11) NOT NULL,
`y_int` int(11) NOT NULL,
`z_int` int(11) NOT NULL,
`x` float NOT NULL,
`y` float NOT NULL,
`z` float NOT NULL,
`continent` smallint(6) NOT NULL,
`zone` smallint(6) NOT NULL,
`build` float NOT NULL,
PRIMARY KEY (`entry`,`type`,`x_int`,`y_int`,`z_int`),
KEY `entry` (`entry`,`type`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
我的查询基于条目和类型(这就是为什么有一个索引那里),并予圆浮子X,Y,Z为int上插入(作为更高效如果它已经存在,则不插入,因为浮点数比较昂贵)。
有没有人有任何想法,为什么它花了这么长时间来做插入甚至查询? MySQL不支持这么多行吗?
这里是例如插入语句:
REPLACE INTO `object_positions2` (`entry` ,`type` , `x_int` , `y_int` , `z_int`, `x` ,`y` ,`z` ,`continent` ,`zone` ,`build`) VALUES ('$entry', '$type', '" . round($x) . "', '" . round($y) . "', '" . round($z) . "', '$x', '$y', '$z', '$continent', '$zone', '$ZeBuild');
提前感谢! 〜乔希
2012-12-13
Geesu
+0
基本经验法则:**在任何**连接,'where或'order by'子句中使用的字段都应该有一个索引。这意味着你需要一个关于npc_flags的索引,但是你也在该字段的DERIVED值上做了什么,这意味着索引不能被使用。同上sqrt/pow的东西。 –
+0
whatch的3d/2d索引的mysql 解决在http://stackoverflow.com/questions/4974299/increasing-performance-on-a-select-query-with-large-3d-point-data-set –