Php MySQL/Percona在联接表中使用min或max时更新性能

Php MySQL/Percona在联接表中使用min或max时更新性能,php,mysql,join,Php,Mysql,Join,以下查询在5s内运行: UPDATE table1 li inner JOIN (SELECT min(c.id_table1 ) as id FROM table2 l JOIN table3 c ON c.id_table2 = l.id AND c.date = '2016-01-01' JOIN bloc_table b ON b.id = l.id_bloc_table and b.reference =

以下查询在5s内运行:

UPDATE table1 li inner JOIN (SELECT min(c.id_table1 ) as id
        FROM table2 l
                JOIN table3 c ON c.id_table2 = l.id AND c.date = '2016-01-01'
                JOIN bloc_table b ON b.id = l.id_bloc_table and b.reference = '2568548'
                JOIN code_client a ON a.id_code_client = c.id_code_client AND ( a.label = 'C' OR a.label LIKE 'C %')
        WHERE c.hour IS NULL) t1
        ON li.id_ligne_c = t1.id
        SET li.hour = '11:18'
以下是解释:

id选择\u类型表分区类型可能\u键\u列参考行过滤额外
1更新常量表中的空无匹配行
2派生l空索引主、唯一表2、fk\U表2\U块表fk\U表2\U块表4空2719403 100.00使用索引
使用where
2派生的b NULL eq_ref PRIMARY、unique_bloc_table、key_bloc_table、fk_bloc_table_client_file PRIMARY 4 mydb.l.id_bloc_table 1 5.00使用where
2使用where
2个派生的r NULL eq_ref PRIMARY、唯一的客户机项目PRIMARY 2 mydb.b.id_客户机文件1 100.00使用where

而以下各项以0.00001秒的速度运行:

UPDATE table1 li inner JOIN (SELECT c.id_table1 as id
        FROM table2 l
                JOIN table3 c ON c.id_table2 = l.id AND c.date = '2016-01-01'
                JOIN bloc_table b ON b.id = l.id_bloc_table and b.reference = '2568548'
                JOIN code_client a ON a.id_code_client = c.id_code_client AND ( a.label = 'C' OR a.label LIKE 'C %')
        WHERE c.hour IS NULL) t1
        ON li.id_ligne_c = t1.id
        SET li.hour = '11:18'
以下是解释:

id选择\u类型表分区类型可能\u键\u列参考行过滤额外
1个简单b NULL ref主、唯一\u bloc\u表、键\u bloc\u表、fk\u bloc\u表\u客户端\u文件键\u bloc\u表4常量1 100.00 NULL
1个简单的r NULL eq\u ref PRIMARY,唯一的\u client\u item PRIMARY 2个mydb.b.id\u client\u file 1 100.00,使用where
1简单空范围主、唯一\u代码\u客户端\u libelle唯一\u代码\u客户端\u libelle 14空1 100.00使用where;使用索引
1简单l空参考主表,唯一表2,fk表2集团表唯一表2 4 mydb.b.id集团表6 100.00使用索引
使用where
1更新li NULL相等参考主4 mydb.c.id对齐c 1 100.00 NULL

唯一的区别是使用“MIN”作为一种一次仅更新一行的方式,以防同一客户机多次出现,以相同的顺序放置不同的项目

我正在使用percona DB v5.7.17-11

如何通过一次只选择一行来实现相同的性能(0.00001 Vs 5)

联接或where子句中使用的所有字段都已编制索引


感谢您为此查询添加解释计划
explain%query%
@MaxP,我添加了它,但它看起来不太可读。