Skip to content

Commit

Permalink
fix null queries over links to an indexed property (#4460)
Browse files Browse the repository at this point in the history
  • Loading branch information
ironage authored Mar 2, 2021
1 parent e126fc1 commit 2f08393
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Fixed queries for constant null across links to an indexed property not returning matches when the link was null. ([#4460]https://github.com/realm/realm-core/pull/4460), since 5.23.6).
* Support upgrading from file format 5. ([#7089](https://github.com/realm/realm-cocoa/issues/7089), since v6.0.0)
* On 32bit devices you may get exception with "No such object" when upgrading to v10.* ([#7314](https://github.com/realm/realm-java/issues/7314), since v10.0.0)
* The notification worker thread would rerun queries after every commit rather than only commits which modified tables which could effect the query results if the table had any outgoing links to tables not used in the query (since v6.0.0).
Expand Down
10 changes: 9 additions & 1 deletion src/realm/query_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4319,7 +4319,15 @@ class Compare : public Expression {
if (std::is_same_v<TCond, Equal> && m_left_is_const && m_right->has_search_index() &&
m_right->get_comparison_type() == ExpressionComparisonType::Any) {
if (m_left_value.is_null()) {
m_matches = m_right->find_all(Mixed());
const ObjPropertyBase* prop = dynamic_cast<const ObjPropertyBase*>(m_right.get());
// when checking for null across links, null links are considered matches,
// so we must compute the slow matching even if there is an index.
if (!prop || prop->links_exist()) {
return dT;
}
else {
m_matches = m_right->find_all(Mixed());
}
}
else {
if (m_right->get_type() != m_left_value.get_type()) {
Expand Down
2 changes: 2 additions & 0 deletions test/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ TEST(Parser_basic_serialisation)
verify_query(test_context, t, "buddy == nil", 4);
verify_query(test_context, t, "buddy != NULL", 1);
verify_query(test_context, t, "buddy <> NULL", 1);
verify_query(test_context, t, "buddy.name == NULL", 4); // matches null links
verify_query(test_context, t, "buddy.age == NULL", 4);
verify_query(test_context, t, "age > 2", 2);
verify_query(test_context, t, "!(age >= 2)", 2);
verify_query(test_context, t, "!(age => 2)", 2);
Expand Down

0 comments on commit 2f08393

Please sign in to comment.