Home > database >  SQL statements are optimized using postgresql
SQL statements are optimized using postgresql

Time:10-06

Below a SQL query efficiency is extremely low, hope to have a great god guide;
Select
The sum (case da cpt_ind='1' and the when (b.S YSTEM_CD is null or b.S YSTEM_CD='A') and (, dc uss_ind=1 or d.W ebCKI_ind=1) and m. lt_seg_day_id is not null then 1
The when c.s. YSTEM_CD is not null and da cpt_ind='1' and a.a irln_cd in (' MF ', 'CZ,' OQ ') and, dc uss_ind=0 and d.W ebCKI_ind=0 and Arthur c. ki_typ in (' C ', 'W') and m. lt_seg_day_id is not null then 1
The else 0 end) as airpt_sec_bc,
The sum (case da cpt_ind='1' and the when (b.S YSTEM_CD is null or b.S YSTEM_CD='A') and (, dc uss_ind=1 or d.W ebCKI_ind=1) and m. lt_seg_day_id is not null then 1
The when c.s. YSTEM_CD is not null and da cpt_ind='1' and a.a irln_cd in (' MF ', 'CZ,' OQ ') and, dc uss_ind=0 and d.W ebCKI_ind=0 and Arthur c. ki_typ in (' C ', 'W') and m. lt_seg_day_id is not null then 1
The else 0 end) as airpt_sec_bag
The from dss_pbidt. Dcs_flt a
Inner join
(select flt_seg_day_id pax_hist_id, acpt_ind chkin_pid_nbr, cuss_ind, webcki_ind from dss_pdata. Enr_check_in_event
Union all
The select flt_seg_day_id pax_hist_id, acpt_ind chkin_pid_nbr, cuss_ind, webcki_ind from dss_phist. Enr_check_in_event_h2015
Union all
The select flt_seg_day_id pax_hist_id, acpt_ind chkin_pid_nbr, cuss_ind, webcki_ind from dss_phist. Enr_check_in_event_h2014) d
On (a.f lt_seg_day_id=d.f lt_seg_day_id
And
Da cpt_ind=1
)
The left outer join (select distinct trim (both from PID_NBR) as PID_NBR, SYSTEM_CD from dss_pdata. PRT_CUSS_PID where cz_ind=0) b
On (trim (both the from, dc hkin_pid_nbr)=p. ID_NBR)
The left outer join (select distinct trim (both from PID_NBR) as PID_NBR, SYSTEM_CD, cki_typ from dss_pdata. PRT_CUSS_PID where cz_ind=1) c
On (trim (both the from, dc hkin_pid_nbr)=c.P ID_NBR)
The left outer join
(select distinct s. lt_seg_day_id as flt_seg_day_id, supachai panitchpakdi ax_hist_id as pax_hist_id from
(select opr_dt flt_seg_day_id, pax_hist_id hist_actn_cd, opr_pid_nbr from dss_pdata. Enr_pax_cki_history
Union all
The select opr_dt flt_seg_day_id, pax_hist_id hist_actn_cd, opr_pid_nbr from dss_phist. Enr_pax_cki_history_h2015
Union all
The select opr_dt flt_seg_day_id, pax_hist_id hist_actn_cd, opr_pid_nbr from dss_phist. Enr_pax_cki_history_h2014) s
Where s.o pr_dt & gt;='2015-01-01' and s.o pr_dt & lt; '2015-02-01' and ((Sheldon horowitz ist_actn_cd='BC' and s.o pr_pid_nbr in (select distinct (pid_nbr) from
Dss_pdata. Prt_cuss_pid where system_cd in (' P ', 'H') and cz_ind='0')) or Sheldon horowitz ist_actn_cd=' ' ')
) m
On
(
D.f lt_seg_day_id=m. lt_seg_day_id
And
D.p ax_hist_id=m.p ax_hist_id
)
Where a. cl_dep_date between '20150101' and '20150201'

CodePudding user response:

Put your table (including index) explain bai, in addition to stick the execution plan

CodePudding user response:

Table:
(1) dss_pbidt. Dcs_flt
(2) dss_pdata. Enr_check_in_event
The CREATE INDEX enr_check_in_event_index4
ON dss_pdata. Enr_check_in_event
USING btree
(flt_seg_day_id);
(3) dss_pdata. Enr_pax_cki_history (no index)
(4) dss_pdata. PRT_CUSS_PID (no index)

CodePudding user response:

The execution plan: as shown in figure



CodePudding user response:

The execution plan;

  • Related