简体   繁体   English

简单的MySQL查询长16秒

[英]Simple MySQL query 16 seconds long

I am running a 8gb ram, quad-core, SSD cloud server. 我正在运行8GB RAM,四核,SSD云服务器。

Most DB queries are fast, but one query updating only one column for one row is taking up to 16 seconds, according to New Relic. 根据New Relic的说法,大多数数据库查询速度很快,但是一个查询仅更新一行的一列最多需要16秒。

My query is: 我的查询是:

UPDATE user SET ad=$currentAdSet WHERE ckey='$_COOKIE[ckey]'

And I am using the mysql_query("") php function to execute the query. 而且我正在使用mysql_query("") php函数执行查询。

Mu user table has around 43000 rows and a simple structure. Mu user表大约有43000行,结构简单。

Why is this query taking so long? 为什么这个查询要花这么长时间? Any ideas? 有任何想法吗?

Try to add an index on ckey and check the timing again. 尝试在ckey上添加索引,然后再次检查计时。 I would advise some reading on indexes. 我建议您阅读一些索引。

BTW, using directly a cookie value might lead to SQL injection 顺便说一句,直接使用cookie值可能会导致SQL注入

You can try and see what is making it be so slow by using EXPLAIN . 您可以尝试使用EXPLAIN来查看使它如此缓慢的原因。 Then, based on the bottle necks you see, use indexes. 然后,根据您看到的瓶颈,使用索引。

ensure ckey is indexed and, if not needed, ad is NOT indexed. 确保ckey已编入索引,如果不需要,则广告未编入索引。

the first will allow faster selection of records, the second faster update 第一个可以更快地选择记录,第二个可以更快地更新

hope this helps 希望这可以帮助

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

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