Fix a bug in query builder