aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/queryeval/blueprint
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2019-09-04 14:10:42 +0000
committerHåvard Pettersen <havardpe@oath.com>2019-09-05 14:04:52 +0000
commit2b190dd7259d390392a95a601075ceccc3528627 (patch)
tree4d77a397421c7ba13490825e4fbd63dc4f3ade44 /searchlib/src/tests/queryeval/blueprint
parentd71937c4f9f3c7b69d6d39cbac1ccdce23df3abe (diff)
added cost tier to blueprints
Diffstat (limited to 'searchlib/src/tests/queryeval/blueprint')
-rw-r--r--searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp6
-rw-r--r--searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp61
-rw-r--r--searchlib/src/tests/queryeval/blueprint/mysearch.h17
3 files changed, 82 insertions, 2 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
index 108b7b9d20d..72a686fddda 100644
--- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
@@ -31,7 +31,7 @@ public:
}
virtual void sort(std::vector<Blueprint*> &children) const override {
- std::sort(children.begin(), children.end(), GreaterEstimate());
+ std::sort(children.begin(), children.end(), TieredGreaterEstimate());
}
virtual bool inheritStrict(size_t i) const override {
@@ -672,6 +672,7 @@ getExpectedBlueprint()
" estimate: HitEstimate {\n"
" empty: false\n"
" estHits: 9\n"
+ " cost_tier: 1\n"
" tree_size: 2\n"
" allow_termwise_eval: 0\n"
" }\n"
@@ -690,6 +691,7 @@ getExpectedBlueprint()
" estimate: HitEstimate {\n"
" empty: false\n"
" estHits: 9\n"
+ " cost_tier: 1\n"
" tree_size: 1\n"
" allow_termwise_eval: 1\n"
" }\n"
@@ -718,6 +720,7 @@ getExpectedSlimeBlueprint() {
" '[type]': 'HitEstimate',"
" empty: false,"
" estHits: 9,"
+ " cost_tier: 1,"
" tree_size: 2,"
" allow_termwise_eval: 0"
" },"
@@ -741,6 +744,7 @@ getExpectedSlimeBlueprint() {
" '[type]': 'HitEstimate',"
" empty: false,"
" estHits: 9,"
+ " cost_tier: 1,"
" tree_size: 1,"
" allow_termwise_eval: 1"
" },"
diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
index eaab732d970..9be238edba9 100644
--- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
@@ -1335,4 +1335,65 @@ TEST("require that ANDNOT without children is optimized to empty search") {
EXPECT_EQUAL(expect_up->asString(), top_up->asString());
}
+TEST("require that highest cost tier sorts last for OR") {
+ //-------------------------------------------------------------------------
+ Blueprint::UP top_up(
+ ap((new OrBlueprint())->
+ addChild(ap(MyLeafSpec(50).cost_tier(1).create())).
+ addChild(ap(MyLeafSpec(30).cost_tier(3).create())).
+ addChild(ap(MyLeafSpec(20).cost_tier(2).create())).
+ addChild(ap(MyLeafSpec(10).cost_tier(1).create()))));
+ //-------------------------------------------------------------------------
+ Blueprint::UP expect_up(
+ ap((new OrBlueprint())->
+ addChild(ap(MyLeafSpec(50).cost_tier(1).create())).
+ addChild(ap(MyLeafSpec(10).cost_tier(1).create())).
+ addChild(ap(MyLeafSpec(20).cost_tier(2).create())).
+ addChild(ap(MyLeafSpec(30).cost_tier(3).create()))));
+ //-------------------------------------------------------------------------
+ EXPECT_NOT_EQUAL(expect_up->asString(), top_up->asString());
+ top_up = Blueprint::optimize(std::move(top_up));
+ EXPECT_EQUAL(expect_up->asString(), top_up->asString());
+ expect_up = Blueprint::optimize(std::move(expect_up));
+ EXPECT_EQUAL(expect_up->asString(), top_up->asString());
+}
+
+TEST("require that highest cost tier sorts last for AND") {
+ //-------------------------------------------------------------------------
+ Blueprint::UP top_up(
+ ap((new AndBlueprint())->
+ addChild(ap(MyLeafSpec(10).cost_tier(1).create())).
+ addChild(ap(MyLeafSpec(20).cost_tier(3).create())).
+ addChild(ap(MyLeafSpec(30).cost_tier(2).create())).
+ addChild(ap(MyLeafSpec(50).cost_tier(1).create()))));
+ //-------------------------------------------------------------------------
+ Blueprint::UP expect_up(
+ ap((new AndBlueprint())->
+ addChild(ap(MyLeafSpec(10).cost_tier(1).create())).
+ addChild(ap(MyLeafSpec(50).cost_tier(1).create())).
+ addChild(ap(MyLeafSpec(30).cost_tier(2).create())).
+ addChild(ap(MyLeafSpec(20).cost_tier(3).create()))));
+ //-------------------------------------------------------------------------
+ EXPECT_NOT_EQUAL(expect_up->asString(), top_up->asString());
+ top_up = Blueprint::optimize(std::move(top_up));
+ EXPECT_EQUAL(expect_up->asString(), top_up->asString());
+ expect_up = Blueprint::optimize(std::move(expect_up));
+ EXPECT_EQUAL(expect_up->asString(), top_up->asString());
+}
+
+TEST("require that intermediate cost tier is minimum cost tier of children") {
+ Blueprint::UP bp1(
+ ap((new AndBlueprint())->
+ addChild(ap(MyLeafSpec(10).cost_tier(1).create())).
+ addChild(ap(MyLeafSpec(20).cost_tier(2).create())).
+ addChild(ap(MyLeafSpec(30).cost_tier(3).create()))));
+ Blueprint::UP bp2(
+ ap((new AndBlueprint())->
+ addChild(ap(MyLeafSpec(10).cost_tier(3).create())).
+ addChild(ap(MyLeafSpec(20).cost_tier(2).create())).
+ addChild(ap(MyLeafSpec(30).cost_tier(2).create()))));
+ EXPECT_EQUAL(bp1->getState().cost_tier(), 1u);
+ EXPECT_EQUAL(bp2->getState().cost_tier(), 2u);
+}
+
TEST_MAIN() { TEST_DEBUG("lhs.out", "rhs.out"); TEST_RUN_ALL(); }
diff --git a/searchlib/src/tests/queryeval/blueprint/mysearch.h b/searchlib/src/tests/queryeval/blueprint/mysearch.h
index c47014e1e77..dbd73b6f40e 100644
--- a/searchlib/src/tests/queryeval/blueprint/mysearch.h
+++ b/searchlib/src/tests/queryeval/blueprint/mysearch.h
@@ -2,6 +2,7 @@
#include <vespa/searchlib/queryeval/blueprint.h>
#include <vespa/searchlib/queryeval/multisearch.h>
#include <vespa/vespalib/objects/visit.hpp>
+#include <cassert>
namespace search::queryeval {
@@ -124,6 +125,11 @@ public:
setEstimate(HitEstimate(hits, empty));
return *this;
}
+
+ MyLeaf &cost_tier(uint32_t value) {
+ set_cost_tier(value);
+ return *this;
+ }
};
//-----------------------------------------------------------------------------
@@ -133,18 +139,27 @@ class MyLeafSpec
private:
FieldSpecBaseList _fields;
Blueprint::HitEstimate _estimate;
+ uint32_t _cost_tier;
public:
explicit MyLeafSpec(uint32_t estHits, bool empty = false)
- : _fields(), _estimate(estHits, empty) {}
+ : _fields(), _estimate(estHits, empty), _cost_tier(0) {}
MyLeafSpec &addField(uint32_t fieldId, uint32_t handle) {
_fields.add(FieldSpecBase(fieldId, handle));
return *this;
}
+ MyLeafSpec &cost_tier(uint32_t value) {
+ assert(value > 0);
+ _cost_tier = value;
+ return *this;
+ }
MyLeaf *create() const {
MyLeaf *leaf = new MyLeaf(_fields);
leaf->estimate(_estimate.estHits, _estimate.empty);
+ if (_cost_tier > 0) {
+ leaf->cost_tier(_cost_tier);
+ }
return leaf;
}
};