简体   繁体   English

如何优化这个简单的SQL查询?

[英]How do I optimize this simple SQL query?

I have a very simple and straightforward SQL query that is taking over 100 seconds to complete. 我有一个非常简单明了的SQL查询,耗时超过100秒。 There are about 10,000 rows of data in the table being searched. 所搜索的表中大约有10,000行数据。 What can I do to speed up this query? 我该如何加快查询速度?

The table structure that the query is searching is.. 查询正在搜索的表结构是..

id (int 10)
forumId (varchar 255)
username (varchar 255)
email (varchar 255)
timestamp (int 10)

For example the query is.. 例如查询是..

SELECT * FROM users WHERE forumId = 'minecraft' AND username = 'test'

It is taking over 100 seconds 耗时超过100秒

add compound index, 添加复合索引,

ALTER TABLE ADD INDEX(forumId, username)

also lower your string length to about 75 :) 还可以将您的字符串长度降低到约75 :)

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

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