这是oracle 查询语句,查出来需要200s,返回行数100,表都不到100w,不加sum很快,加了sum很慢,sql如下:
select sum(qty) tag_qty, rc_id
from (select ser_id,
func_get_pdr_count(service_tag, dispatch_time) as qty,
rc_id
from (select s.ser_id,
p.rc_id,
s.service_tag,
s.bill_id,
s.dispatch_time
from bill_list a, ser_inf s, part_list p
where a.bill_id = s.bill_id
and p.ser_id = s.ser_id
and p.back_class <> ‘1306’
and a.service_tag <> ‘MONITOR’
and a.service_tag <> ‘N/A’
and p.ts_dsp_date > to_date(‘2021-01-30’, ‘yyyy-mm-dd’)
and p.ts_dsp_date < to_date(‘2021-02-06’, ‘yyyy-mm-dd’)
group by s.ser_id,
p.rc_id,
s.service_tag,
s.bill_id,
s.dispatch_time))
group by q.rc_id;
如下为sql执行计划:
DescriptionObject ownerObject nameCostCardinalityBytes
SELECT STATEMENT, GOAL = ALL_ROWS2,163911,638
HASH GROUP BY2,163911,638
VIEWSYSVM_NWVW_02,163911,638
HASH GROUP BY2,1639110,010
NESTED LOOPS
NESTED LOOPS2,16218920,790
NESTED LOOPS1,97218917,010
TABLE ACCESS BY INDEX ROWIDU_DELLPART_LIST1,8211404,900
INDEX RANGE SCANU_DELLIDX_PART_LIST_TS_DSP_DATE222,803
TABLE ACCESS BY INDEX ROWIDU_DELLSER_INF2155
INDEX UNIQUE SCANU_DELLSYS_C001014411
INDEX UNIQUE SCANU_DELLSYS_C00959501
TABLE ACCESS BY INDEX ROWIDU_DELLBILL_LIST1120