CDB-1818 extracted to a method the batched query logic