简体   繁体   中英

Improve performance of query with indexing

I have a MySQL database with over 10k rows. When I execute the query to get all rows within 24 hours, it takes very long to get the results:

$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列表)中使用的字段的索引。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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