以下两条语句,一条查询的,一条是把想把查询的东西update到对应行中,但update的语句效率很慢,
两条语句条件的写法上大致一样,究竟oracle的update是怎样的原理,导致效率这么慢,求助一下各位--更新的语句(速度很慢,基本不动)
update t_join_situation a
set (a.special_clinic_compen_money,a.special_clinic_compen_count)=
(
select a.special_clinic_compen_money+compensation_sum as a1,a.special_clinic_compen_count+compensation_count as a2 from
(
select sum(this_year_compensation_cost) as compensation_sum,count(1) as compensation_count,people_number from t_compensate_proof where
type='3' and state='0' and year='2010' and city_number='P00000'
group by people_number
) b
where a.city_number='P00000' and a.year='2010' and a.people_number=b.people_number
)
where exists (select 1 from t_compensate_proof b where
a.people_number=b.people_number and a.city_number='P00000' and a.city_number=b.city_number
)--查询速度很快
select a.people_number from t_join_situation a,
(
select sum(this_year_compensation_cost) as compensation_sum,count(1) as compensation_count,people_number from t_compensate_proof where
type='2' and state='0' and year='2010' and city_number='U00000'
group by people_number
) b
where a.city_number='U00000' and a.year='2010' and a.people_number=b.people_number
两条语句条件的写法上大致一样,究竟oracle的update是怎样的原理,导致效率这么慢,求助一下各位--更新的语句(速度很慢,基本不动)
update t_join_situation a
set (a.special_clinic_compen_money,a.special_clinic_compen_count)=
(
select a.special_clinic_compen_money+compensation_sum as a1,a.special_clinic_compen_count+compensation_count as a2 from
(
select sum(this_year_compensation_cost) as compensation_sum,count(1) as compensation_count,people_number from t_compensate_proof where
type='3' and state='0' and year='2010' and city_number='P00000'
group by people_number
) b
where a.city_number='P00000' and a.year='2010' and a.people_number=b.people_number
)
where exists (select 1 from t_compensate_proof b where
a.people_number=b.people_number and a.city_number='P00000' and a.city_number=b.city_number
)--查询速度很快
select a.people_number from t_join_situation a,
(
select sum(this_year_compensation_cost) as compensation_sum,count(1) as compensation_count,people_number from t_compensate_proof where
type='2' and state='0' and year='2010' and city_number='U00000'
group by people_number
) b
where a.city_number='U00000' and a.year='2010' and a.people_number=b.people_number
from t_join_situation a,
(select sum(this_year_compensation_cost) as compensation_sum,count(1) as compensation_count,people_number,city_number
from t_compensate_proof where type='3' and state='0' and year='2010' and city_number='P00000'
group by city_number,people_number) b
where a.people_number=b.people_number and a.city_number=b.city_number)
set t1=compensation_sum,t2=compensation_count
但我更新的字段不是索引字段