fix complex query bug