This is a small tweak to the query to help get the "most likely" branches to have the issue:
select aou.shortname,count(*)
from
actor.org_unit aou
join action.hold_request ahr2 on (ahr2.pickup_lib=aou.id)
join
(
select ahr.id,count(*)
from
action.hold_request ahr
join actor.usr au on(au.id=ahr.usr)
join actor.usr_standing_penalty ausp on(ausp.usr=au.id and (ausp.stop_date IS NULL OR ausp.stop_date > NOW()))
LEFT JOIN config.standing_penalty csp
ON (
csp.id = ausp.standing_penalty AND
csp.block_list LIKE '%CAPTURE%' AND (
(csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR
(csp.org_depth IS NOT NULL AND ahr.pickup_lib IN (
SELECT id FROM actor.org_unit_descendants(ausp.org_unit, csp.org_depth))
)
)
)
where
ahr.capture_time IS NULL AND
ahr.cancel_time IS NULL AND
csp.id IS NULL AND
(ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND
csp.id is null
group by 1
having count(*) > 1
) bug_ids
on (bug_ids.id=ahr2.id)
group by 1
order by 2 desc
This is a small tweak to the query to help get the "most likely" branches to have the issue:
select aou.shortname, count(* ) lib=aou. id) standing_ penalty ausp on(ausp.usr=au.id and (ausp.stop_date IS NULL OR ausp.stop_date > NOW())) standing_ penalty csp penalty AND unit_descendant s(ausp. org_unit, csp.org_depth)) id=ahr2. id)
from
actor.org_unit aou
join action.hold_request ahr2 on (ahr2.pickup_
join
(
select ahr.id,count(*)
from
action.hold_request ahr
join actor.usr au on(au.id=ahr.usr)
join actor.usr_
LEFT JOIN config.
ON (
csp.id = ausp.standing_
csp.block_list LIKE '%CAPTURE%' AND (
(csp.org_depth IS NULL AND ahr.pickup_lib = ausp.org_unit) OR
(csp.org_depth IS NOT NULL AND ahr.pickup_lib IN (
SELECT id FROM actor.org_
)
)
)
where
ahr.capture_time IS NULL AND
ahr.cancel_time IS NULL AND
csp.id IS NULL AND
(ahr.expire_time is NULL OR ahr.expire_time > NOW()) AND
csp.id is null
group by 1
having count(*) > 1
) bug_ids
on (bug_ids.
group by 1
order by 2 desc
Start testing from the first returned result.