我正在根据其他表的状态从一个表中删除记录,并从服务器生成长响应时间。
基本上,如果name
status = 'p1'
delete
次查询shold log_player_login
记录了另一个表格。问题是我认为WHERE timestamp > '$timeHuman' AND status = 'p1'
有DELETE FROM pstone_cuboids
WHERE owner NOT IN (
SELECT DISTINCT(name)
AS name
FROM log_player_login
WHERE timestamp > '2013-01-01 00:00:00' AND status = 'p1'
);
我做错了什么?
{{1}}
自:
答案 0 :(得分:1)
在最新版本的MySQL之前,带有子查询的not in
效率很低。我建议将其替换为not exists
并添加索引:
DELETE FROM pstone_cuboids
WHERE not exists (SELECT 1
FROM log_player_login lpl
WHERE lpl.timestamp > '2013-01-01 00:00:00' AND lpl.status = 'p1' and
lpl.name = pston_cuboids.owner
);
create index log_player_login_owner_status_timestamp on log_player_login(name, status, timestamp);
索引应包含所有三个字段,最后一个字段必须为timestamp
。