Skip to content

Commit

Permalink
Correctly update case insensitive queries on indexed string columns
Browse files Browse the repository at this point in the history
jedelbo committed Oct 2, 2020
1 parent ee8d60a commit 34961c2
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* None.
* If you make a case insignificant query on an indexed string column, it may fail in a way that results in a "No such key" exception. ([#6830](https://github.com/realm/realm-cocoa/issues/6830), since v6.0.0)

### Breaking changes
* None.
1 change: 1 addition & 0 deletions src/realm/query_engine.cpp
Original file line number Diff line number Diff line change
@@ -367,6 +367,7 @@ std::string StringNode<Equal>::describe(util::serializer::SerialisationState& st
void StringNode<EqualIns>::_search_index_init()
{
auto index = ParentNode::m_table->get_search_index(ParentNode::m_condition_column_key);
m_index_matches.clear();
index->find_all(m_index_matches, StringData(StringNodeBase::m_value), true);
m_results_start = 0;
m_results_ndx = 0;
14 changes: 14 additions & 0 deletions test/test_query.cpp
Original file line number Diff line number Diff line change
@@ -2556,7 +2556,9 @@ TEST(Query_StrIndexUpdating)
auto col = t->add_column(type_String, "value");
t->add_search_index(col);
TableView tv = t->where().equal(col, "").find_all();
TableView tv_ins = t->where().equal(col, "", false).find_all();
CHECK_EQUAL(tv.size(), 0);
CHECK_EQUAL(tv_ins.size(), 0);
group->commit_and_continue_as_read();

// Queries on indexes have different codepaths for 0, 1, and multiple results,
@@ -2570,46 +2572,58 @@ TEST(Query_StrIndexUpdating)
t->create_object();
group->commit_and_continue_as_read();
tv.sync_if_needed();
tv_ins.sync_if_needed();
CHECK_EQUAL(tv.size(), 1);
CHECK_EQUAL(tv_ins.size(), 1);

// 1 -> multiple results
group->promote_to_write();
t->create_object();
t->create_object();
group->commit_and_continue_as_read();
tv.sync_if_needed();
tv_ins.sync_if_needed();
CHECK_EQUAL(tv.size(), 3);
CHECK_EQUAL(tv_ins.size(), 3);

// multiple -> 1
group->promote_to_write();
t->remove_object(tv.get_key(0));
t->remove_object(tv.get_key(1));
group->commit_and_continue_as_read();
tv.sync_if_needed();
tv_ins.sync_if_needed();
CHECK_EQUAL(tv.size(), 1);
CHECK_EQUAL(tv_ins.size(), 1);

// 1 -> 0
group->promote_to_write();
t->remove_object(tv.get_key(0));
group->commit_and_continue_as_read();
tv.sync_if_needed();
tv_ins.sync_if_needed();
CHECK_EQUAL(tv.size(), 0);
CHECK_EQUAL(tv_ins.size(), 0);

// 0 -> multiple
group->promote_to_write();
t->create_object();
t->create_object();
group->commit_and_continue_as_read();
tv.sync_if_needed();
tv_ins.sync_if_needed();
CHECK_EQUAL(tv.size(), 2);
CHECK_EQUAL(tv_ins.size(), 2);

// multiple -> 0
group->promote_to_write();
t->remove_object(tv.get_key(0));
t->remove_object(tv.get_key(1));
group->commit_and_continue_as_read();
tv.sync_if_needed();
tv_ins.sync_if_needed();
CHECK_EQUAL(tv.size(), 0);
CHECK_EQUAL(tv_ins.size(), 0);
}

TEST(Query_GA_Crash)

0 comments on commit 34961c2

Please sign in to comment.