简体   繁体   English

使用索引提高查询性能

[英]Improve performance of query with indexing

I have a MySQL database with over 10k rows. 我有一个超过10k行的MySQL数据库。 When I execute the query to get all rows within 24 hours, it takes very long to get the results: 当我执行查询以在24小时内获取所有行时,获取结果需要很长时间:

$sql = 'SELECT *, DATE_FORMAT(m.time, "%d.%m.%Y %H:%i:%s") AS date 
  FROM markers m,pid p 
  WHERE m.time >=DATE_SUB(NOW(), INTERVAL 24 HOUR) 
  AND m.pidID=p.id';

I have read about indexing of tables, but could not adapt it to my query. 我已阅读有关表的索引,但无法使其适应我的查询。 Can anyone please explain how to change the above query with indexing so the query does not a full table scan? 任何人都可以解释如何使用索引更改上述查询,以便查询不进行全表扫描?

查询通常受益于WHEREJOIN...ON条件(以及ORDER|GROUP BY列表)中使用的字段的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM