Query optimization for retrieving printer information