-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Columns<Link> when property is Dictionary of links #6705
Changes from 6 commits
adfd6d8
7a33c49
3a1cad3
54eff5e
f9307b1
5de3e5b
330189d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -819,23 +819,43 @@ ExpressionNode::ExpressionNode(const ExpressionNode& from) | |
template <> | ||
size_t LinksToNode<Equal>::find_first_local(size_t start, size_t end) | ||
{ | ||
if (m_column_type == col_type_LinkList || m_condition_column_key.is_set()) { | ||
// LinkLists never contain null | ||
if (!m_target_keys[0] && m_target_keys.size() == 1 && start != end) | ||
return not_found; | ||
|
||
BPlusTree<ObjKey> links(m_table.unchecked_ptr()->get_alloc()); | ||
for (size_t i = start; i < end; i++) { | ||
if (ref_type ref = get_ref(i)) { | ||
links.init_from_ref(ref); | ||
for (auto& key : m_target_keys) { | ||
if (key) { | ||
if (links.find_first(key) != not_found) | ||
if (m_condition_column_key.is_collection()) { | ||
Allocator& alloc = m_table.unchecked_ptr()->get_alloc(); | ||
if (m_condition_column_key.is_dictionary()) { | ||
auto target_table_key = m_table->get_opposite_table(m_condition_column_key)->get_key(); | ||
Array top(alloc); | ||
for (size_t i = start; i < end; i++) { | ||
if (ref_type ref = get_ref(i)) { | ||
top.init_from_ref(ref); | ||
BPlusTree<Mixed> values(alloc); | ||
values.set_parent(&top, 1); | ||
values.init_from_parent(); | ||
for (auto& key : m_target_keys) { | ||
ObjLink link(target_table_key, key); | ||
if (values.find_first(link) != not_found) | ||
return i; | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
// LinkLists never contain null | ||
if (!m_target_keys[0] && m_target_keys.size() == 1 && start != end) | ||
return not_found; | ||
|
||
BPlusTree<ObjKey> links(alloc); | ||
for (size_t i = start; i < end; i++) { | ||
if (ref_type ref = get_ref(i)) { | ||
links.init_from_ref(ref); | ||
for (auto& key : m_target_keys) { | ||
if (key) { | ||
if (links.find_first(key) != not_found) | ||
return i; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
else if (m_list) { | ||
for (auto& key : m_target_keys) { | ||
|
@@ -856,15 +876,41 @@ size_t LinksToNode<NotEqual>::find_first_local(size_t start, size_t end) | |
REALM_ASSERT(m_target_keys.size() == 1); | ||
ObjKey key = m_target_keys[0]; | ||
|
||
if (m_column_type == col_type_LinkList || m_condition_column_key.is_set()) { | ||
BPlusTree<ObjKey> links(m_table.unchecked_ptr()->get_alloc()); | ||
for (size_t i = start; i < end; i++) { | ||
if (ref_type ref = get_ref(i)) { | ||
links.init_from_ref(ref); | ||
auto sz = links.size(); | ||
for (size_t j = 0; j < sz; j++) { | ||
if (links.get(j) != key) { | ||
if (m_condition_column_key.is_collection()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code seems the same of the one that starts at line 822, maybe this can be encapsulated into some utility method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably could, but I am not sure the code would be much nicer to read. |
||
Allocator& alloc = m_table.unchecked_ptr()->get_alloc(); | ||
if (m_condition_column_key.is_dictionary()) { | ||
auto target_table_key = m_table->get_opposite_table(m_condition_column_key)->get_key(); | ||
Array top(alloc); | ||
for (size_t i = start; i < end; i++) { | ||
if (ref_type ref = get_ref(i)) { | ||
top.init_from_ref(ref); | ||
BPlusTree<Mixed> values(alloc); | ||
values.set_parent(&top, 1); | ||
values.init_from_parent(); | ||
|
||
ObjLink link(target_table_key, key); | ||
bool found = false; | ||
values.for_all([&](const Mixed& val) { | ||
if (val != link) { | ||
found = true; | ||
} | ||
return !found; | ||
}); | ||
if (found) | ||
return i; | ||
} | ||
} | ||
} | ||
else { | ||
BPlusTree<ObjKey> links(alloc); | ||
for (size_t i = start; i < end; i++) { | ||
if (ref_type ref = get_ref(i)) { | ||
links.init_from_ref(ref); | ||
auto sz = links.size(); | ||
for (size_t j = 0; j < sz; j++) { | ||
if (links.get(j) != key) { | ||
return i; | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it makes sense to do it here, but we should know the size of the values to insert in the list of obj keys, so we could do something like:
values.reserve(link_values.size());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure