Query processing in distributed system