While there is no such command as
UPDATE DELAYED, you can create this mechanism in a rather strange way. Please follow my rather crazy train of thought...
SCENARIO : Let's say you have just a single DB Server called M1
- You want to fire UPDATEs at a single table called
- You don't want UPDATEs to log jam the table
SOLUTION : Serialize UPDATEs
MECHANISM : Would you believe MySQL Replication ?
That's right, I said MySQL Replication.
You are probably saying right now
How in the world would having a Slave create UPDATE DELAYED ?
Here is how you do it:
STEP 01 : Using another DB Server (call it M2), create a MySQL Instance with binary logging enabled.
STEP 02 : mysqldump all user databases with no data, just structures (called it MySQLSchema.sql)
STEP 03 : Edit MySQLSchema.sql, change all
STEP 04 : Edit MySQLSchema.sql, change all
STEP 05 : Run
source MySQLSchema.sql on M2.
STEP 06 : Run
RESET MASTER; on M2
STEP 07 : Add
/etc/my.cnf on M1
STEP 08 :
service mysql restart on M1
STEP 09 : Setup replication from M2 to M1
STEP 10 : In your application, fire your code
UPDATE `mydb.timing` SET
`max` = greatest(`max`,@value),
`average` = `average` + ((@value - `average`) / (`count` + 1)),
`count` = `count` + 1
WHERE `name` = @name
only at M2
That's it. No locking can ever happen on M2 since
mydb.timing on M2 uses the BLACKHOLE Storage Engine (a.k.a /dev/null Storage Engine). Having MySQL Replication from M2 to M1 forms a queue that serializes UPDATEs. The delay appears in the form of MySQL Replication's asynchronous operation. Replication lag (in this instance only) is totally acceptable since you are looking for
Give it a Try !!!
This turns MySQL Replication upside down because the production server becomes a Slave to a BlackHole Server. With this strange topology, you can also implement
Make sure you include this option
on M2. Otherwise, lots of UPDATEs makes for lots of binlogs