From a47d233c729e7182d7ea77b707fcef12512f42bf Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 16 May 2023 14:51:46 +0000 Subject: Add reserve and simplify MatchDataLayout --- searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp | 8 +++----- searchlib/src/vespa/searchlib/fef/matchdatalayout.h | 9 ++++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp b/searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp index 99326b2c1e6..632bd422581 100644 --- a/searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp +++ b/searchlib/src/vespa/searchlib/fef/matchdatalayout.cpp @@ -6,8 +6,7 @@ namespace search::fef { MatchDataLayout::MatchDataLayout() - : _numTermFields(0), - _fieldIds() + : _fieldIds() { } @@ -17,9 +16,8 @@ MatchDataLayout::~MatchDataLayout() = default; MatchData::UP MatchDataLayout::createMatchData() const { - assert(_numTermFields == _fieldIds.size()); - auto md = std::make_unique(MatchData::params().numTermFields(_numTermFields)); - for (size_t i = 0; i < _numTermFields; ++i) { + auto md = std::make_unique(MatchData::params().numTermFields(_fieldIds.size())); + for (size_t i = 0; i < _fieldIds.size(); ++i) { md->resolveTermField(i)->setFieldId(_fieldIds[i]); } return md; diff --git a/searchlib/src/vespa/searchlib/fef/matchdatalayout.h b/searchlib/src/vespa/searchlib/fef/matchdatalayout.h index 05d25a322db..8f7717ce7ac 100644 --- a/searchlib/src/vespa/searchlib/fef/matchdatalayout.h +++ b/searchlib/src/vespa/searchlib/fef/matchdatalayout.h @@ -14,14 +14,16 @@ namespace search::fef { class MatchDataLayout { private: - uint32_t _numTermFields; std::vector _fieldIds; - public: /** * Create an empty object. **/ MatchDataLayout(); + MatchDataLayout(MatchDataLayout &&) noexcept = default; + MatchDataLayout & operator=(MatchDataLayout &&) noexcept = default; + MatchDataLayout(const MatchDataLayout &) = default; + MatchDataLayout & operator=(const MatchDataLayout &) = delete; ~MatchDataLayout(); /** @@ -32,8 +34,9 @@ public: **/ TermFieldHandle allocTermField(uint32_t fieldId) { _fieldIds.push_back(fieldId); - return _numTermFields++; + return _fieldIds.size() - 1; } + void reserve(size_t sz) { _fieldIds.reserve(sz); } /** * Create a match data object with the layout described by this -- cgit v1.2.3 From c348f78ebc0bb09d5977858c7492ff04202d59b4 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 16 May 2023 14:53:57 +0000 Subject: Add reserve to dot product blueprints --- .../src/vespa/searchlib/queryeval/dot_product_blueprint.cpp | 10 ++++++++-- .../src/vespa/searchlib/queryeval/dot_product_blueprint.h | 1 + .../searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp | 7 +++++++ .../searchlib/queryeval/wand/parallel_weak_and_blueprint.h | 3 ++- .../vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp | 9 ++++++++- .../vespa/searchlib/queryeval/weighted_set_term_blueprint.h | 1 + 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp index 61b717b1104..de5bdc33e3c 100644 --- a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp @@ -24,6 +24,13 @@ DotProductBlueprint::getNextChildField(const FieldSpec &outer) return FieldSpec(outer.getName(), outer.getFieldId(), _layout.allocTermField(outer.getFieldId()), false); } +void +DotProductBlueprint::reserve(size_t num_children) { + _weights.reserve(num_children); + _terms.reserve(num_children); + _layout.reserve(num_children); +} + void DotProductBlueprint::addTerm(Blueprint::UP term, int32_t weight) { @@ -41,8 +48,7 @@ DotProductBlueprint::addTerm(Blueprint::UP term, int32_t weight) } SearchIterator::UP -DotProductBlueprint::createLeafSearch(const search::fef::TermFieldMatchDataArray &tfmda, - bool) const +DotProductBlueprint::createLeafSearch(const search::fef::TermFieldMatchDataArray &tfmda, bool) const { assert(tfmda.size() == 1); assert(getState().numFields() == 1); diff --git a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h index 4ba59ba755f..2975958b5af 100644 --- a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.h @@ -26,6 +26,7 @@ public: FieldSpec getNextChildField(const FieldSpec &outer); // used by create visitor + void reserve(size_t num_children); void addTerm(Blueprint::UP term, int32_t weight); SearchIteratorUP createLeafSearch(const search::fef::TermFieldMatchDataArray &tfmda, bool strict) const override; diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp index fe212666ec9..b4b55098eaa 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp @@ -55,6 +55,12 @@ ParallelWeakAndBlueprint::getNextChildField(const FieldSpec &outer) return FieldSpec(outer.getName(), outer.getFieldId(), _layout.allocTermField(outer.getFieldId()), false); } +void +ParallelWeakAndBlueprint::reserve(size_t num_children) { + _weights.reserve(num_children); + _terms.reserve(num_children); +} + void ParallelWeakAndBlueprint::addTerm(Blueprint::UP term, int32_t weight) { @@ -78,6 +84,7 @@ ParallelWeakAndBlueprint::createLeafSearch(const search::fef::TermFieldMatchData assert(tfmda.size() == 1); fef::MatchData::UP childrenMatchData = _layout.createMatchData(); wand::Terms terms; + terms.reserve(_terms.size()); for (size_t i = 0; i < _terms.size(); ++i) { const State &childState = _terms[i]->getState(); assert(childState.numFields() == 1); diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h index 1a481be5c32..a2c13f12485 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.h @@ -44,7 +44,7 @@ public: score_t scoreThreshold, double thresholdBoostFactor, uint32_t scoresAdjustFrequency); - virtual ~ParallelWeakAndBlueprint() override; + ~ParallelWeakAndBlueprint() override; const WeakAndHeap &getScores() const { return _scores; } @@ -56,6 +56,7 @@ public: FieldSpec getNextChildField(const FieldSpec &outer); // Used by create visitor + void reserve(size_t num_children); void addTerm(Blueprint::UP term, int32_t weight); SearchIterator::UP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override; diff --git a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp index f855b72812a..ee55a89dcdc 100644 --- a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp @@ -73,6 +73,13 @@ WeightedSetTermBlueprint::WeightedSetTermBlueprint(const FieldSpec &field) WeightedSetTermBlueprint::~WeightedSetTermBlueprint() = default; +void +WeightedSetTermBlueprint::reserve(size_t num_children) { + _weights.reserve(num_children); + _terms.reserve(num_children); + _layout.reserve(num_children); +} + void WeightedSetTermBlueprint::addTerm(Blueprint::UP term, int32_t weight) { @@ -100,7 +107,7 @@ WeightedSetTermBlueprint::createLeafSearch(const fef::TermFieldMatchDataArray &t // TODO: pass ownership with unique_ptr children[i] = _terms[i]->createSearch(*md, true).release(); } - return SearchIterator::UP(WeightedSetTermSearch::create(children, *tfmda[0], _children_field.isFilter(), _weights, std::move(md))); + return WeightedSetTermSearch::create(children, *tfmda[0], _children_field.isFilter(), _weights, std::move(md)); } SearchIterator::UP diff --git a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h index 2a3db3ec52d..3827dc8a35f 100644 --- a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.h @@ -30,6 +30,7 @@ public: FieldSpec getNextChildField(const FieldSpec &) { return _children_field; } // used by create visitor + void reserve(size_t num_children); void addTerm(Blueprint::UP term, int32_t weight); SearchIteratorUP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda, bool strict) const override; -- cgit v1.2.3 From 8fd57c5965cf715073acfc67f34bb028a8680330 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 16 May 2023 14:56:05 +0000 Subject: Make single field createBlueprint accessible --- .../proton/matching/blueprintbuilder.cpp | 19 ++++++++------- .../queryeval/create_blueprint_visitor_helper.cpp | 7 +++--- .../src/vespa/searchlib/queryeval/searchable.h | 27 +++++++++++----------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp index eee2b7a7203..03e15830ac5 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/blueprintbuilder.cpp @@ -30,21 +30,21 @@ struct Mixer { } Blueprint::UP mix(Blueprint::UP indexes) { - if (attributes.get() == 0) { - if (indexes.get() == 0) { + if ( ! attributes) { + if ( ! indexes) { return std::make_unique(); } - return Blueprint::UP(std::move(indexes)); + return indexes; } - if (indexes.get() == 0) { + if ( ! indexes) { if (attributes->childCnt() == 1) { return attributes->removeChild(0); } else { - return Blueprint::UP(std::move(attributes)); + return std::move(attributes); } } - attributes->addChild(Blueprint::UP(std::move(indexes))); - return Blueprint::UP(std::move(attributes)); + attributes->addChild(std::move(indexes)); + return std::move(attributes); } }; @@ -88,6 +88,7 @@ private: void buildEquiv(ProtonEquiv &n) { double eqw = n.getWeight().percent(); FieldSpecBaseList specs; + specs.reserve(n.numFields()); for (size_t i = 0; i < n.numFields(); ++i) { specs.add(n.field(i).fieldSpec()); } @@ -123,9 +124,7 @@ private: assert(field.getFieldId() != search::fef::IllegalFieldId); assert(field.getHandle() != search::fef::IllegalHandle); if (field.attribute_field) { - FieldSpecList attrField; - attrField.add(field.fieldSpec()); - mixer.addAttribute(_context.getAttributes().createBlueprint(_requestContext, attrField, n)); + mixer.addAttribute(_context.getAttributes().createBlueprint(_requestContext, field.fieldSpec(), n)); } else { indexFields.add(field.fieldSpec()); } diff --git a/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp b/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp index d9338641a39..a2d244250cf 100644 --- a/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/create_blueprint_visitor_helper.cpp @@ -75,13 +75,12 @@ CreateBlueprintVisitorHelper::handleNumberTermAsText(query::NumberTerm &n) template void CreateBlueprintVisitorHelper::createWeightedSet(std::unique_ptr bp, NODE &n) { - FieldSpecList fields; + bp->reserve(n.getNumTerms()); for (size_t i = 0; i < n.getNumTerms(); ++i) { - fields.clear(); - fields.add(bp->getNextChildField(_field)); auto term = n.getAsString(i); query::SimpleStringTerm node(term.first, n.getView(), 0, term.second); // TODO Temporary - bp->addTerm(_searchable.createBlueprint(_requestContext, fields, node), term.second.percent()); + FieldSpec field = bp->getNextChildField(_field); + bp->addTerm(_searchable.createBlueprint(_requestContext, field, node), term.second.percent()); } setResult(std::move(bp)); } diff --git a/searchlib/src/vespa/searchlib/queryeval/searchable.h b/searchlib/src/vespa/searchlib/queryeval/searchable.h index 2438cbf5a3b..a36a7f34e1c 100644 --- a/searchlib/src/vespa/searchlib/queryeval/searchable.h +++ b/searchlib/src/vespa/searchlib/queryeval/searchable.h @@ -22,23 +22,12 @@ class FieldSpecList; **/ class Searchable { -protected: - /** - * Create a blueprint searching a single field. - * - * @return blueprint - * @param requestContext that belongs to the query - * @param field the field to search - * @param term the query tree term - **/ - virtual std::unique_ptr createBlueprint(const IRequestContext & requestContext, - const FieldSpec &field, - const search::query::Node &term) = 0; - public: using SP = std::shared_ptr; Searchable() = default; + virtual ~Searchable() = default; + /** * Create a blueprint searching a set of fields. The default @@ -53,7 +42,17 @@ public: virtual std::unique_ptr createBlueprint(const IRequestContext & requestContext, const FieldSpecList &fields, const search::query::Node &term); - virtual ~Searchable() = default; + /** + * Create a blueprint searching a single field. + * + * @return blueprint + * @param requestContext that belongs to the query + * @param field the field to search + * @param term the query tree term + **/ + virtual std::unique_ptr createBlueprint(const IRequestContext & requestContext, + const FieldSpec &field, + const search::query::Node &term) = 0; }; } -- cgit v1.2.3 From 79346d5d16c549347a15399505acaab96b4a5506 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 16 May 2023 14:57:46 +0000 Subject: Move the matchdata layout. --- searchlib/src/vespa/searchlib/query/tree/node.h | 1 - searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp | 2 +- searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp | 5 +---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/searchlib/src/vespa/searchlib/query/tree/node.h b/searchlib/src/vespa/searchlib/query/tree/node.h index af9925e2ea3..7123d52a503 100644 --- a/searchlib/src/vespa/searchlib/query/tree/node.h +++ b/searchlib/src/vespa/searchlib/query/tree/node.h @@ -22,4 +22,3 @@ class Node { }; } - diff --git a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp index af6b59dd6ca..384dc0cd227 100644 --- a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp @@ -44,7 +44,7 @@ EquivBlueprint::EquivBlueprint(FieldSpecBaseList fields, fef::MatchDataLayout subtree_mdl) : ComplexLeafBlueprint(std::move(fields)), _estimate(), - _layout(subtree_mdl), + _layout(std::move(subtree_mdl)), _terms(), _exactness() { diff --git a/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp index 3be28ab75de..9c3910b20f9 100644 --- a/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/same_element_blueprint.cpp @@ -3,8 +3,6 @@ #include "same_element_blueprint.h" #include "same_element_search.h" #include "field_spec.hpp" -#include "andsearch.h" -#include "emptysearch.h" #include #include #include @@ -66,8 +64,7 @@ SameElementBlueprint::fetchPostings(const ExecuteInfo &execInfo) std::unique_ptr SameElementBlueprint::create_same_element_search(search::fef::TermFieldMatchData& tfmd, bool strict) const { - fef::MatchDataLayout my_layout = _layout; - fef::MatchData::UP md = my_layout.createMatchData(); + fef::MatchData::UP md = _layout.createMatchData(); std::vector children(_terms.size()); for (size_t i = 0; i < _terms.size(); ++i) { const State &childState = _terms[i]->getState(); -- cgit v1.2.3