level 1
gac0540
楼主
hz_ent_electric表里有32w数据,每天大约400多条。这个表上有关于ent_name和data_time的复合索引,normal, btree。另一个表ln_enterprise_name_tg_cap里,大约7百条数据。
每天用ln_enterprise_name_tg_cap表里的数据更新一下hz_ent_electric里符合条件的数据的一些字段。如果用select的话,基本就是秒查,
select * from hz_ent_electric a,ln_enterprise_name_tg_cap b where a.data_time >= "2022-12-21" and a.ent_name = b.ent_name and (a.MIN_CONSUM is null or a.MIN_CONSUM = 0)
但如果update的话,需要好几百秒,update hz_ent_electric a,ln_enterprise_name_tg_cap bset a.min_consum=b.tg_cap*0.2*24*0.8, a.max_consum=b.tg_cap*24*0.8where a.ent_name=b.ent_name and a.data_time >= "2022-12-21"and (a.MIN_CONSUM is null or a.MIN_CONSUM = 0);
请问这种是为什么呢?
2022年12月22日 09点12分
1
每天用ln_enterprise_name_tg_cap表里的数据更新一下hz_ent_electric里符合条件的数据的一些字段。如果用select的话,基本就是秒查,
select * from hz_ent_electric a,ln_enterprise_name_tg_cap b where a.data_time >= "2022-12-21" and a.ent_name = b.ent_name and (a.MIN_CONSUM is null or a.MIN_CONSUM = 0)
但如果update的话,需要好几百秒,update hz_ent_electric a,ln_enterprise_name_tg_cap bset a.min_consum=b.tg_cap*0.2*24*0.8, a.max_consum=b.tg_cap*24*0.8where a.ent_name=b.ent_name and a.data_time >= "2022-12-21"and (a.MIN_CONSUM is null or a.MIN_CONSUM = 0);
请问这种是为什么呢?