message: Randomly choose a column for set_unique.
diff: @@ -157,6 +157,39 @@ std::string get_current_time_stamp()
  return str_buffer;
  }
  +// randomly choose a table and column which meets the requirements for set_unique.
  +std::pair<size_t, size_t> get_target_for_set_unique(const Group& g, State &s) {
  + std::vector<std::pair<size_t, size_t>> candidates;
  + for (size_t table_ndx = 0; table_ndx < g.size(); ++table_ndx) {
  +
  + // We are looking for a non-empty table
  + ConstTableRef t = g.get_table(table_ndx);
  + if (t->size() == 0) {
  + continue;
  + }
  +
  + for (size_t col_ndx = 0; col_ndx < t->get_column_count(); ++col_ndx) {
  + // The column we want to set a unique value on must a have a search index
  + if (!t->has_search_index(col_ndx)) {
  + continue;
  + }
  + DataType type = t->get_column_type(col_ndx);
  + if (type == type_String || type == type_Int) {
  + candidates.push_back({table_ndx, col_ndx});
  + }
  + }
  + }
  +
  + if (candidates.empty()) {
  + return {g.size(), -1}; // not found
  + } else if (candidates.size() == 1) {
  + return candidates[0]; // don't bother consuming another input
  + }
  +
  + unsigned char r = get_next(s) % candidates.size();
  + return candidates[r];
  +}
  +
  void parse_and_apply_instructions(std::string& in, const std::string& path, util::Optional<std::ostream&> log)
  {
  const size_t add_empty_row_max = REALM_MAX_BPNODE_SIZE * REALM_MAX_BPNODE_SIZE + 1000;
  @@ -710,23 +743,11 @@ void parse_and_apply_instructions(std::string& in, const std::string& path, util
  REALM_DO_IF_VERIFY(log, g_r.verify());
  }
  else if (instr == SET_UNIQUE && g.size() > 0) {
  - // Setting a unique value has a lot of prerequisites, so instead of randomly trying to find a
  - // suitable table and column we search for it. TODO: consider shuffling the search order
  -
  - for (size_t table_ndx = 0; table_ndx < g.size(); ++table_ndx) {
  -
  - // We are looking for a non-empty table
  + std::pair<size_t, size_t> target = get_target_for_set_unique(g, s);
  + if (target.first < g.size()) {
  + size_t table_ndx = target.first;
  + size_t col_ndx = target.second;
  TableRef t = g.get_table(table_ndx);
  - if (t->size() == 0)
  - continue;
  -
  - bool set_unique_called = false;
  - for (size_t col_ndx = 0; col_ndx < t->get_column_count(); ++col_ndx) {
  -
  - // The column we want to set a unique value on must a have a search index
  - if (!t->has_search_index(col_ndx)) {
  - continue;
  - }
  // Only integer and string columns are supported. We let the fuzzer choose to set either
  // null or a value (depending also on the nullability of the column).
  @@ -821,14 +842,6 @@ void parse_and_apply_instructions(std::string& in, const std::string& path, util
  break;
  }
  default:
  - continue;
  - }
  -
  - set_unique_called = true;
  - break;
  - }
  -
  - if (set_unique_called) {
  break;
  }
  }
  