我在使用mysql上的大型表时遇到问题。大型表上的Mysql性能问题
我有超过2.5百万的数据表。这是我的问题。
select count(*) from location
where tagCode=24345
and xLocation >=81 and xLocation <=264
and yLocation >=356 and yLocation <=484
and locationDate >= '2017-03-08 00:00:01' and locationDate <= '2017-03-08 11:54:01';
我想获得该查询计数的数量。但它的行数超过1秒。这导致了问题。
我在表中添加了索引。
ALTER TABLE位置ADD INDEX(tagCode,xLocation,yLocation, locationDate);
如何提高性能?
'EXPLAIN'对此查询有何说法?使用'BETWEEN'是否有帮助? – tadman
您的查询和索引对我来说看起来是最优的。如果其他列(例如locationDate)上的一个具有较低的基数然后标记代码,则可以相应地重新排列索引。 – Strawberry
单独在数据库上执行时行为是否一致? – chris85