I didn’t know you could actually do this before addressing this problem in a benchmark using 5.0.36.
MySQL allows you to update two tables with a single UPDATE statement. I knew you could reference two tables in an UPDATE statement but not update both. However when working with a client after benchmarking I observed a large number of Created_tmp_disk_tables via SHOW GLOBAL STATUS and found that this query was the offending query only for certain circumstances. Understanding took a little longer.
schema.sql
DROP TABLE IF EXISTS a; CREATE TABLE a( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, i INT UNSIGNED NOT NULL, c CHAR(1) NOT NULL) ENGINE=INNODB; DROP TABLE IF EXISTS b; CREATE TABLE b( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, i INT UNSIGNED NOT NULL, c CHAR(1) NOT NULL, t TEXT NOT NULL) ENGINE=INNODB;
data.sql
INSERT INTO a VALUES(1,1,'a'); INSERT INTO a …[Read more]