Query optimization to avoid overuse of UNIONs in favor of FILTER + IN