added checks for situations when all queries target other databases