您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

update优化一条

2026/6/13 12:28:03发布26次查看
原语句 update haha a set (td03_flag) = (select td03_flag from z_temp1 b where a.user_id = b.user_id and lx = pz) plan hash value: 1855602026 sql_id 62h7a9s7yyr18, child number 0------------------------------------- update haha a set (td03_
原语句
update haha a set (td03_flag) = (select td03_flag
from z_temp1 b where a.user_id = b.user_id and lx = 'pz')
plan hash value: 1855602026sql_id 62h7a9s7yyr18, child number 0------------------------------------- update haha a set (td03_flag) = (select td03_flagfrom z_temp1 b where a.user_id = b.user_id and lx = 'pz')plan hash value: 1855602026-------------------------------------------------------------------------------------------------------------| id | operation | name | rows | bytes | cost (%cpu)| time |-------------------------------------------------------------------------------------------------------------| 0 | update statement | | | | 8720m(100)| || 1 | update | haha | | | | || 2 | table access full | haha | 2094k| 51m| 5404 (3)| 00:01:05 || 3 | table access by index rowid | z_temp1 | 24383 | 714k| 4163 (2)| 00:00:50 || 4 | bitmap conversion to rowids | | | | | || 5 | bitmap and | | | | | || 6 | bitmap conversion from rowids| | | | | ||* 7 | index range scan | z_temp1_u | 2438k| | 3 (0)| 00:00:01 || 8 | bitmap conversion from rowids| | | | | ||* 9 | index range scan | z_temp1_l | 2438k| | 4108 (2)| 00:00:50 |-------------------------------------------------------------------------------------------------------------predicate information (identified by operation id):--------------------------------------------------- 7 - access(b.user_id=:b1) 9 - access(lx='pz')我们可以看第7步的谓词7 - access(b.user_id=:b1) 这种:b1 是一个变量,变量就有输入源,这里的变量的输入源就是第2步中的每一行
我们就可以简单理解为,就是第2步有多少条语句,第三步就要执行多少次(7是第三步的子步骤,从这一步开始,一直执行完整个 第3步) 这种行为即是nested loop。
虽然这里有索引,但这里的整个过程,是 两个位图索引 bitmap and,并且会回表,都是单块读,其中回表的单块读在这里占大头(每次都有24383个单块读)的。 我们从统计信息看到 步骤2 有2094k 行 我们可以简单认为, 第三步 这个整个步骤(bitmap and +回表) 被整个执行了 2094k即200多万次。 不慢才怪 优化后语句
explain plan for merge into haha a
using (select td03_flag, user_id
from z_temp1 b
where user_id in (select user_id
from haha where lx='pz')
) h
on (a.user_id = h.user_id)
when matched then
update set a.td03_flag = h.td03_flag;
这里需要创建两个索引
create index haha_idx on haha(lx,user_id) ;
create index z_temp1_ind_uidtd03 on z_temp1(userid,td03_flag) ;
优化前sql2个小时还没跑完
之后虽然执行时间对方没有反馈,但对方也没有再喊叫 看来满足需求了:)
优化虽易,乙方不易,且行且珍惜
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product