查询优化如何减少postgresql中的计划时间和执行时间。 SQL查询:-
select s.id,state_name state, d.id no_districts,b.id no_blocks,v.id no_villages,district_name district,block_tehsil_name block,village_name village ,corr_vs,non_corr_vs,corr_gw,non_corr_gw,corr_sw,non_corr_sw
from ref_state s left join ref_district d on d.ref_state_id=s.id
left join ref_block_tehsil b on d.id=b.ref_district_id
left join ref_village v on v.ref_block_tehsil_id=b.id
left join (select ref_village_id ,coalesce(sum(tot_vs),0)-coalesce(sum(non_corr_vs),0) corr_vs,sum(non_corr_vs)non_corr_vs
from (select ref_village_id,count(vs.id)tot_vs,(select count(id) from mi_census_village_schedule_validation vsv where vsv.ref_village_id=vs.ref_village_id)non_corr_vs from mi_census_village_schedule vs group by ref_village_id )vs1 group by ref_village_id ) vs on vs.ref_village_id=v.id
left join(select ref_village_id ,coalesce(sum(tot_gw),0)- coalesce(sum(non_corr_gw),0) corr_gw,sum(non_corr_gw)non_corr_gw from (select ref_village_id,count(gws.id)tot_gw,(select count(id) from mi_census_ground_water_scheme_validation gwsv where gwsv.ref_village_id=gws.ref_village_id)non_corr_gw from mi_census_ground_water_scheme gws group by ref_village_id )gws1 group by ref_village_id ) gws on gws.ref_village_id=v.id
left join (select ref_village_id,coalesce(sum(tot_sw),0)- coalesce(sum(non_corr_sw),0) corr_sw,sum(non_corr_sw)non_corr_sw from(select ref_village_id,count(sws.id)tot_sw,(select count(id) from mi_census_surface_water_scheme_validation swsv where swsv.ref_village_id=sws.ref_village_id)non_corr_sw from mi_census_surface_water_scheme sws group by ref_village_id )sws1 group by ref_village_id ) sws on sws.ref_village_id=v.id
where s.id=30and d.id=21 and b.id=127 and v.id=632
答案 0 :(得分:0)
有几种技术可以帮助提高工作空间下SQL查询的性能。遵循SQL最佳做法以确保查询优化,例如