fixed possible privileges leaks in query