我有一个运行缓慢的更新查询,想看看我是否可以提高性能
这是查询
update appmaster a
INNER JOIN appid b ON a.activity = b.activity
SET a.activity_id = b.activity_id
WHERE a.activity_id IS null
appmaster包含大约9百万条记录,但不到100万条记录的activity_id为空
appid包含171,000条记录
我尝试为这两个表设置活动索引,但似乎没有帮助。 我会在appmaster activity_id上设置一个索引,因为这是我的where条件,但这是值im设置。
有什么想法吗?
appmaster table
CREATE TABLE appfiltration.appmaster (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(75) DEFAULT NULL,
activity varchar(150) NOT NULL,
class varchar(150) NOT NULL,
device varchar(60) NOT NULL,
version varchar(60) DEFAULT NULL,
theme varchar(50) DEFAULT NULL,
upload_date date DEFAULT NULL,
activity_id int(11) DEFAULT NULL,
PRIMARY KEY (id),
INDEX idx_activity (activity)
)
ENGINE = INNODB
AUTO_INCREMENT = 9457807
AVG_ROW_LENGTH = 136
CHARACTER SET utf8
COLLATE utf8_unicode_ci;
appid table
CREATE TABLE appfiltration.appid (
activity_id int(11) NOT NULL AUTO_INCREMENT,
activity varchar(200) NOT NULL,
name varchar(50) DEFAULT NULL,
result int(11) NOT NULL DEFAULT 0,
change1 float DEFAULT NULL,
result_last int(11) NOT NULL DEFAULT 0,
change2 float DEFAULT NULL,
result_last2 int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (activity_id, activity)
)
ENGINE = INNODB
AUTO_INCREMENT = 251064
AVG_ROW_LENGTH = 63
CHARACTER SET utf8
COLLATE utf8_unicode_ci;
结果来自
EXPLAIN SELECT a.activity_id, b.activity_id
FROM appmaster a
JOIN appid b ON a.activity = b.activity
WHERE a.activity_id IS NULL