sql优化前:
SELECT DISTINCT a.acti_prce_id prce_id, a.acti_id, a.aggregate_code code
FROM wf_activity_instances a,
wf_activity_instances_pati f, --这个表全表扫描了
(SELECT pati_id_arg2 column_value
FROM wf_participant_relations a,
(SELECT pati_id_arg1 user_id
FROM wf_participant_relations p
WHERE p.pati_id_arg2 = 11521
AND p.relation_type = 'GRANT_H'
UNION
SELECT 11521 user_id FROM dual) h
WHERE a.pati_id_arg1 = h.user_id
AND a.relation_type IN ('MEMBER OF', 'GRANT')
UNION
SELECT 11521 column_value
FROM dual
UNION
SELECT 5 column_value
FROM dual
UNION
SELECT pati_id_arg1 column_value
FROM wf_participant_relations p
WHERE p.pati_id_arg2 = 11521
AND p.relation_type = 'GRANT_H') g
WHERE 11521 != 1
AND a.state = 'NOTRUNNING'
AND a.negation_ind = 'N'
AND a.date_created <= SYSDATE
AND (a.id = f.acin_id AND g.column_value = f.pati_id);
优化后:
select distinct a.acti_prce_id prce_id,
a.acti_id,
a.aggregate_code code
from (select x.*
from wf_activity_instances x
where x.state = 'NOTRUNNING'
and x.negation_ind = 'N'
and x.date_created <= sysdate) a
where 11521 != 1
and exists (select 1
from wf_activity_instances_pati zz
where zz.acin_id = a.id
and exists (select 1
from (select pati_id_arg2 column_value
from wf_participant_relations a,
(select pati_id_arg1 user_id
from wf_participant_relations p
where p.pati_id_arg2 = 11521
and p.relation_type = 'GRANT_H'
union
select 11521 user_id from dual) h
where a.pati_id_arg1 = h.user_id
and a.relation_type in ('MEMBER OF', 'GRANT')
union
select 11521 column_value
from dual
union
select 5 column_value
from dual
union
select pati_id_arg1 column_value
from wf_participant_relations p
where p.pati_id_arg2 = 11521
and p.relation_type = 'GRANT_H') g
where g.column_value = zz.pati_id))
wf_activity_instances,wf_activity_instances_pati
两个表均是百万级数据量