Skip to content

Commit

Permalink
Fix #4868.
Browse files Browse the repository at this point in the history
Extra indexes reported in index_status result.
  • Loading branch information
Daniel Mewes committed Sep 23, 2015
1 parent 1fc1004 commit b98848f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/rdb_protocol/terms/sindex.cc
Expand Up @@ -266,22 +266,23 @@ class sindex_status_term_t : public op_term_t {

/* Convert it into an array and return it */
ql::datum_array_builder_t res(ql::configured_limits_t::unlimited);
std::set<std::string> remaining_sindexes = sindexes;
for (const auto &pair : configs_and_statuses) {
if (!sindexes.empty()) {
if (sindexes.count(pair.first) == 0) {
continue;
} else {
sindexes.erase(pair.first);
remaining_sindexes.erase(pair.first);
}
}
res.add(sindex_status_to_datum(
pair.first, pair.second.first, pair.second.second));
}

/* Make sure we found all the requested sindexes. */
rcheck(sindexes.empty(), base_exc_t::OP_FAILED,
rcheck(remaining_sindexes.empty(), base_exc_t::OP_FAILED,
strprintf("Index `%s` was not found on table `%s`.",
sindexes.begin()->c_str(),
remaining_sindexes.begin()->c_str(),
table->display_name().c_str()));

return new_val(std::move(res).to_datum());
Expand Down
24 changes: 22 additions & 2 deletions test/rql_test/src/sindex/status.yaml
Expand Up @@ -2,8 +2,28 @@ desc: sindex status
table_variable_name: tbl2
tests:

# Index status tests. These are separate because they require much bigger
# tables and it would just be a pain to keep them together.
# Index status test on an empty table with two indexes.
# This is also a regression test for #4868
- cd: tbl2.index_create("a")
ot: ({'created':1})
- cd: tbl2.index_create("b")
ot: ({'created':1})

- cd: tbl2.index_status().count()
ot: 2
- cd: tbl2.index_status("a").count()
ot: 1
- cd: tbl2.index_status("b").count()
ot: 1
- cd: tbl2.index_status("a", "b").count()
ot: 2

- cd: tbl2.index_drop("a")
ot: ({'dropped':1})
- cd: tbl2.index_drop("b")
ot: ({'dropped':1})

# Index status tests with bigger tables for a single index

- py: tbl2.insert(r.range(0, 5000).map({'a':r.row}))
rb: tbl2.insert(r.range(0, 5000).map{|row| {'a':row}})
Expand Down

0 comments on commit b98848f

Please sign in to comment.