Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL update performance VERY bad

I'm having VERY bad performance with UPDATE on MySQL, my update statement is quite basic like:

UPDATE `tbl_name` 
   SET `field1` = 'value1', `field2` = 'value2' .. `fieldN` = 'valueN' 
WHERE `tbl_name`.`id` = 123;

values are few (15), all TEXT kind and WHERE condition is just one using id. values are JSON strings (but this should not bother to MySQL, it should see them as just plain text).

In "tbl_name" I have few records (around 4k).

The problem is that executing this UPDATE statement I got 8 seconds of execution time (taken from MySQL slow query log).

I'm running MySQL alone on an EC2 High CPU Medium istance and I think it's pretty impossible that these performances are "normal", I would expect much more performance.

Do you have any idea to investigate the problem?

** UPDATE ** Thank you for your fast answers, table is InnoDB and id is a PRIMARY, UNIQUE. Values are TEXT (not varchar)

** UPDATE bis ** No, id is an integer, all other fields are TEXT

like image 924
Simone D. Avatar asked Mar 25 '26 13:03

Simone D.


1 Answers

Since MySQL do not support EXPLAIN UPDATE statements before version 5.6.3, we're quite blind about this query. Try USE INDEX statement...

I've launched the same on my server. All was ok with 15 TEXT fields and 4096 rows of quite arbitrary text. It was ok with both USE INDEX(PRIMARY) and IGNORE INDEX(PRIMARY) statements.

So, I suppose, you have problems with your SQL server, installation package, or whatever, not query...

like image 89
RDB Avatar answered Mar 28 '26 03:03

RDB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!