def ScanAttributes(self,
                     subject_prefix,
                     attributes,
                     after_urn=None,
                     max_records=None,
                     token=None,
                     relaxed_order=False):
    self.security_manager.CheckDataStoreAccess(token, [subject_prefix], "rq")

    subject_prefix = utils.SmartStr(rdfvalue.RDFURN(subject_prefix))
    if subject_prefix[-1] != "/":
      subject_prefix += "/"

    if after_urn:
      after_urn = str(after_urn)

    connection_iter = self.cache.GetPrefix(subject_prefix)
    if relaxed_order:
      for sqlite_connection in connection_iter:
        with sqlite_connection:
          for r in self._GroupSubjects(list(sqlite_connection.ScanAttributes(
              subject_prefix,
              attributes,
              after_urn=after_urn,
              max_records=max_records)), max_records):
            yield r
      return
    first_connections = []
    try:
      first_connections.append(connection_iter.next())
      first_connections.append(connection_iter.next())
    except __HOLE__:
      pass
    if not first_connections:
      return
    if len(first_connections) == 1:
      with first_connections[0] as sqlite_connection:
        for r in self._GroupSubjects(list(sqlite_connection.ScanAttributes(
            subject_prefix,
            attributes,
            after_urn=after_urn,
            max_records=max_records)), max_records):
          yield r
      return
    raw_results = []
    for sqlite_connection in itertools.chain(first_connections,
                                             connection_iter):
      for record in sqlite_connection.ScanAttributes(subject_prefix,
                                                     attributes,
                                                     after_urn=after_urn,
                                                     max_records=max_records):
        raw_results.append(record)
    for r in self._GroupSubjects(sorted(raw_results, key=lambda x: x[0]),
                                 max_records):
      yield r
dataset/ETHPy150Open google/grr/grr/lib/data_stores/sqlite_data_store.py/SqliteDataStore.ScanAttributes