Remove the nested sql queries when applying tenant filtering