General query processing engine