Skip to content
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 search index also when following links #3432

Merged
merged 5 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# NEXT RELEASE

### Enhancements
* None.
* Performance significantly improved when making a query on the property of a linked table, when the property is indexed.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
Expand Down
6 changes: 6 additions & 0 deletions src/realm/column_binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ class BinaryColumn : public ColumnBaseSimple {
void verify() const override;
void to_dot(std::ostream&, StringData title) const override;
void do_dump_node_structure(std::ostream&, int) const override;
void find_all(IntegerColumn&, BinaryData, size_t, size_t) const
{
// Dummy implementation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert false here too?

REALM_ASSERT(false);
}


private:
/// \param row_ndx Must be `realm::npos` if appending.
Expand Down
9 changes: 9 additions & 0 deletions src/realm/column_timestamp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ class TimestampColumn : public ColumnBaseSimple {
return npos;
}

void find_all(IntegerColumn& result, Timestamp value, size_t begin, size_t end) const
{
if (m_search_index && begin == 0 && end == npos) {
m_search_index->find_all(result, value); // Throws
return;
}
REALM_ASSERT(false);
}

typedef Timestamp value_type;

private:
Expand Down
8 changes: 8 additions & 0 deletions src/realm/column_type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ struct ColumnTypeTraits<OldDateTime> : ColumnTypeTraits<int64_t> {
static const ColumnType column_id = col_type_OldDateTime;
};

template <>
struct ColumnTypeTraits<Timestamp> {
using column_type = TimestampColumn;
static const DataType id = type_Timestamp;
static const ColumnType column_id = col_type_Timestamp;
};

template <>
struct ColumnTypeTraits<util::Optional<OldDateTime>> : ColumnTypeTraits<util::Optional<int64_t>> {
static const DataType id = type_OldDateTime;
Expand All @@ -106,6 +113,7 @@ struct ColumnTypeTraits<util::Optional<OldDateTime>> : ColumnTypeTraits<util::Op

template <>
struct ColumnTypeTraits<StringData> {
using column_type = StringColumn;
static const DataType id = type_String;
static const ColumnType column_id = col_type_String;
};
Expand Down
52 changes: 52 additions & 0 deletions src/realm/mixed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class Mixed {
return m_type;
}

template <class T>
T get() const noexcept;

int64_t get_int() const noexcept;
bool get_bool() const noexcept;
float get_float() const noexcept;
Expand Down Expand Up @@ -349,6 +352,55 @@ inline Timestamp Mixed::get_timestamp() const noexcept
return m_timestamp;
}

template <>
inline int64_t Mixed::get<Int>() const noexcept
{
return get_int();
}

template <>
inline bool Mixed::get<bool>() const noexcept
{
return get_bool();
}

template <>
inline float Mixed::get<float>() const noexcept
{
return get_float();
}

template <>
inline double Mixed::get<double>() const noexcept
{
return get_double();
}

template <>
inline OldDateTime Mixed::get<OldDateTime>() const noexcept
{
return get_olddatetime();
}

template <>
inline StringData Mixed::get<StringData>() const noexcept
{
return get_string();
}

template <>
inline BinaryData Mixed::get<BinaryData>() const noexcept
{
return get_binary();
}

template <>
inline Timestamp Mixed::get<Timestamp>() const noexcept
{
return get_timestamp();
}


inline void Mixed::set_int(int64_t v) noexcept
{
m_type = type_Int;
Expand Down
8 changes: 7 additions & 1 deletion src/realm/query_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ size_t NotNode::find_first_no_overlap(size_t start, size_t end)
ExpressionNode::ExpressionNode(std::unique_ptr<Expression> expression)
: m_expression(std::move(expression))
{
m_dD = 10.0;
m_dD = 100.0;
m_dT = 50.0;
}

Expand All @@ -642,6 +642,12 @@ void ExpressionNode::table_changed()
m_expression->set_base_table(m_table.get());
}

void ExpressionNode::init()
{
ParentNode::init();
m_dT = m_expression->init();
}

std::string ExpressionNode::describe(util::serializer::SerialisationState& state) const
{
if (m_expression) {
Expand Down
2 changes: 2 additions & 0 deletions src/realm/query_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ class IntegerNode<ColType, Equal> : public IntegerNodeBase<ColType> {
IntegerNodeBase<ColType>::m_condition_column->find_all(*m_result, this->m_value, 0, realm::npos);
m_index_get = 0;
m_index_end = m_result->size();
IntegerNodeBase<ColType>::m_dT = 0;
}
}

Expand Down Expand Up @@ -2374,6 +2375,7 @@ class ExpressionNode : public ParentNode {
public:
ExpressionNode(std::unique_ptr<Expression>);

void init() override;
size_t find_first_local(size_t start, size_t end) override;

void table_changed() override;
Expand Down
43 changes: 43 additions & 0 deletions src/realm/query_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,52 @@
**************************************************************************/

#include <realm/query_expression.hpp>
#include <realm/group.hpp>

namespace realm {

std::vector<size_t> LinkMap::get_origin_ndxs(size_t index, size_t column) const
{
if (column == m_link_columns.size()) {
return {index};
}
std::vector<size_t> ndxs = get_origin_ndxs(index, column + 1);
std::vector<size_t> ret;
auto origin_col = m_link_column_indexes[column];
auto origin = m_tables[column];
auto link_type = m_link_types[column];
if (link_type == col_type_BackLink) {
auto table_ndx = origin->m_spec->get_opposite_link_table_ndx(origin_col);
auto link_table = origin->get_parent_group()->get_table(table_ndx);
size_t link_col_ndx = origin->m_spec->get_origin_column_ndx(origin_col);
auto forward_type = link_table->get_column_type(link_col_ndx);

for (size_t ndx : ndxs) {
if (forward_type == type_Link) {
ret.push_back(link_table->get_link(link_col_ndx, ndx));
}
else {
REALM_ASSERT(forward_type == type_LinkList);
auto ll = link_table->get_linklist(link_col_ndx, ndx);
auto sz = ll->size();
for (size_t i = 0; i < sz; i++) {
ret.push_back(ll->get(i).get_index());
}
}
}
}
else {
auto target = m_tables[column + 1];
for (size_t ndx : ndxs) {
auto cnt = target->get_backlink_count(ndx, *origin, origin_col);
for (size_t i = 0; i < cnt; i++) {
ret.push_back(target->get_backlink(ndx, *origin, origin_col, i));
}
}
}
return ret;
}

void Columns<Link>::evaluate(size_t index, ValueBase& destination)
{
std::vector<size_t> links = m_link_map.get_links(index);
Expand Down
Loading