Skip to content

Commit

Permalink
Merge pull request #30920 from vespa-engine/havardpe/improve-non-stri…
Browse files Browse the repository at this point in the history
…ct-and-sorting

pass in_flow to intermediate sort functions
  • Loading branch information
geirst authored Apr 16, 2024
2 parents 9ee70cf + 7370074 commit 643fe99
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MyOr : public IntermediateBlueprint
return mixChildrenFields();
}

void sort(Children &children, bool, bool) const override {
void sort(Children &children, InFlow) const override {
std::sort(children.begin(), children.end(), TieredGreaterEstimate());
}

Expand Down
2 changes: 1 addition & 1 deletion searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ IntermediateBlueprint::sort(InFlow in_flow)
{
resolve_strict(in_flow);
if (!opt_keep_order()) [[likely]] {
sort(_children, in_flow.strict(), opt_sort_by_cost());
sort(_children, in_flow);
}
auto flow = my_flow(in_flow);
for (size_t i = 0; i < _children.size(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion searchlib/src/vespa/searchlib/queryeval/blueprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class IntermediateBlueprint : public blueprint::StateCache

virtual HitEstimate combine(const std::vector<HitEstimate> &data) const = 0;
virtual FieldSpecBaseList exposeFields() const = 0;
virtual void sort(Children &children, bool strict, bool sort_by_cost) const = 0;
virtual void sort(Children &children, InFlow in_flow) const = 0;
virtual SearchIteratorUP
createIntermediateSearch(MultiSearch::Children subSearches, fef::MatchData &md) const = 0;

Expand Down
36 changes: 18 additions & 18 deletions searchlib/src/vespa/searchlib/queryeval/intermediate_blueprints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ AndNotBlueprint::get_replacement()
}

void
AndNotBlueprint::sort(Children &children, bool strict, bool sort_by_cost) const
AndNotBlueprint::sort(Children &children, InFlow in_flow) const
{
if (sort_by_cost) {
AndNotFlow::sort(children, strict);
if (opt_sort_by_cost()) {
AndNotFlow::sort(children, in_flow.strict());
} else {
if (children.size() > 2) {
std::sort(children.begin() + 1, children.end(), TieredGreaterEstimate());
Expand Down Expand Up @@ -257,12 +257,12 @@ AndBlueprint::get_replacement()
}

void
AndBlueprint::sort(Children &children, bool strict, bool sort_by_cost) const
AndBlueprint::sort(Children &children, InFlow in_flow) const
{
if (sort_by_cost) {
AndFlow::sort(children, strict);
if (strict && opt_allow_force_strict()) {
AndFlow::reorder_for_extra_strictness(children, true, 3);
if (opt_sort_by_cost()) {
AndFlow::sort(children, in_flow.strict());
if (opt_allow_force_strict()) {
AndFlow::reorder_for_extra_strictness(children, in_flow, 3);
}
} else {
std::sort(children.begin(), children.end(), TieredLessEstimate());
Expand Down Expand Up @@ -360,10 +360,10 @@ OrBlueprint::get_replacement()
}

void
OrBlueprint::sort(Children &children, bool strict, bool sort_by_cost) const
OrBlueprint::sort(Children &children, InFlow in_flow) const
{
if (sort_by_cost) {
OrFlow::sort(children, strict);
if (opt_sort_by_cost()) {
OrFlow::sort(children, in_flow.strict());
} else {
std::sort(children.begin(), children.end(), TieredGreaterEstimate());
}
Expand Down Expand Up @@ -449,7 +449,7 @@ WeakAndBlueprint::exposeFields() const
}

void
WeakAndBlueprint::sort(Children &, bool, bool) const
WeakAndBlueprint::sort(Children &, InFlow) const
{
// order needs to stay the same as _weights
}
Expand Down Expand Up @@ -511,10 +511,10 @@ NearBlueprint::exposeFields() const
}

void
NearBlueprint::sort(Children &children, bool strict, bool sort_by_cost) const
NearBlueprint::sort(Children &children, InFlow in_flow) const
{
if (sort_by_cost) {
AndFlow::sort(children, strict);
if (opt_sort_by_cost()) {
AndFlow::sort(children, in_flow.strict());
} else {
std::sort(children.begin(), children.end(), TieredLessEstimate());
}
Expand Down Expand Up @@ -576,7 +576,7 @@ ONearBlueprint::exposeFields() const
}

void
ONearBlueprint::sort(Children &, bool, bool) const
ONearBlueprint::sort(Children &, InFlow) const
{
// ordered near cannot sort children here
}
Expand Down Expand Up @@ -662,7 +662,7 @@ RankBlueprint::get_replacement()
}

void
RankBlueprint::sort(Children &, bool, bool) const
RankBlueprint::sort(Children &, InFlow) const
{
}

Expand Down Expand Up @@ -743,7 +743,7 @@ SourceBlenderBlueprint::exposeFields() const
}

void
SourceBlenderBlueprint::sort(Children &, bool, bool) const
SourceBlenderBlueprint::sort(Children &, InFlow) const
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AndNotBlueprint : public IntermediateBlueprint
void optimize_self(OptimizePass pass) override;
AndNotBlueprint * asAndNot() noexcept final { return this; }
Blueprint::UP get_replacement() override;
void sort(Children &children, bool strict, bool sort_by_cost) const override;
void sort(Children &children, InFlow in_flow) const override;
SearchIterator::UP
createIntermediateSearch(MultiSearch::Children subSearches,
fef::MatchData &md) const override;
Expand All @@ -48,7 +48,7 @@ class AndBlueprint : public IntermediateBlueprint
void optimize_self(OptimizePass pass) override;
AndBlueprint * asAnd() noexcept final { return this; }
Blueprint::UP get_replacement() override;
void sort(Children &children, bool strict, bool sort_by_cost) const override;
void sort(Children &children, InFlow in_flow) const override;
SearchIterator::UP
createIntermediateSearch(MultiSearch::Children subSearches,
fef::MatchData &md) const override;
Expand All @@ -72,7 +72,7 @@ class OrBlueprint : public IntermediateBlueprint
void optimize_self(OptimizePass pass) override;
OrBlueprint * asOr() noexcept final { return this; }
Blueprint::UP get_replacement() override;
void sort(Children &children, bool strict, bool sort_by_cost) const override;
void sort(Children &children, InFlow in_flow) const override;
SearchIterator::UP
createIntermediateSearch(MultiSearch::Children subSearches,
fef::MatchData &md) const override;
Expand All @@ -96,7 +96,7 @@ class WeakAndBlueprint : public IntermediateBlueprint
FlowStats calculate_flow_stats(uint32_t docid_limit) const final;
HitEstimate combine(const std::vector<HitEstimate> &data) const override;
FieldSpecBaseList exposeFields() const override;
void sort(Children &children, bool strict, bool sort_on_cost) const override;
void sort(Children &children, InFlow in_flow) const override;
bool always_needs_unpack() const override;
WeakAndBlueprint * asWeakAnd() noexcept final { return this; }
SearchIterator::UP
Expand Down Expand Up @@ -126,7 +126,7 @@ class NearBlueprint : public IntermediateBlueprint
FlowStats calculate_flow_stats(uint32_t docid_limit) const final;
HitEstimate combine(const std::vector<HitEstimate> &data) const override;
FieldSpecBaseList exposeFields() const override;
void sort(Children &children, bool strict, bool sort_by_cost) const override;
void sort(Children &children, InFlow in_flow) const override;
SearchIteratorUP createSearch(fef::MatchData &md) const override;
SearchIterator::UP
createIntermediateSearch(MultiSearch::Children subSearches,
Expand All @@ -148,7 +148,7 @@ class ONearBlueprint : public IntermediateBlueprint
FlowStats calculate_flow_stats(uint32_t docid_limit) const final;
HitEstimate combine(const std::vector<HitEstimate> &data) const override;
FieldSpecBaseList exposeFields() const override;
void sort(Children &children, bool strict, bool sort_by_cost) const override;
void sort(Children &children, InFlow in_flow) const override;
SearchIteratorUP createSearch(fef::MatchData &md) const override;
SearchIterator::UP
createIntermediateSearch(MultiSearch::Children subSearches,
Expand All @@ -168,7 +168,7 @@ class RankBlueprint final : public IntermediateBlueprint
FieldSpecBaseList exposeFields() const override;
void optimize_self(OptimizePass pass) override;
Blueprint::UP get_replacement() override;
void sort(Children &children, bool strict, bool sort_by_cost) const override;
void sort(Children &children, InFlow in_flow) const override;
bool isRank() const noexcept final { return true; }
SearchIterator::UP
createIntermediateSearch(MultiSearch::Children subSearches,
Expand Down Expand Up @@ -196,7 +196,7 @@ class SourceBlenderBlueprint final : public IntermediateBlueprint
FlowStats calculate_flow_stats(uint32_t docid_limit) const final;
HitEstimate combine(const std::vector<HitEstimate> &data) const override;
FieldSpecBaseList exposeFields() const override;
void sort(Children &children, bool strict, bool sort_by_cost) const override;
void sort(Children &children, InFlow in_flow) const override;
SearchIterator::UP
createIntermediateSearch(MultiSearch::Children subSearches,
fef::MatchData &md) const override;
Expand Down

0 comments on commit 643fe99

Please sign in to comment.