summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-12-18 15:28:13 +0100
committerGitHub <noreply@github.com>2023-12-18 15:28:13 +0100
commitb685f9b60ccf376f816d0a3da884e6d0b61a818c (patch)
tree7616aad7538a128224301857b949197ce81e3abd /searchlib
parenteb0c8204fa2b377542959c2ddfb4002468cea0ec (diff)
parent64a0c8e97e097ea6efb8e828cd67025d3da83a92 (diff)
Merge pull request #29691 from vespa-engine/havardpe/dump-blueprint-cost
dump blueprint cost
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp4
-rw-r--r--searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp68
-rw-r--r--searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/blueprint.cpp1
4 files changed, 70 insertions, 5 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
index 20cf2008e4b..eefca5c82e9 100644
--- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
@@ -646,6 +646,7 @@ getExpectedBlueprint()
" tree_size: 2\n"
" allow_termwise_eval: false\n"
" }\n"
+ " cost: 1\n"
" sourceId: 4294967295\n"
" docid_limit: 0\n"
" children: std::vector {\n"
@@ -666,6 +667,7 @@ getExpectedBlueprint()
" tree_size: 1\n"
" allow_termwise_eval: true\n"
" }\n"
+ " cost: 1\n"
" sourceId: 4294967295\n"
" docid_limit: 0\n"
" }\n"
@@ -696,6 +698,7 @@ getExpectedSlimeBlueprint() {
" tree_size: 2,"
" allow_termwise_eval: false"
" },"
+ " cost: 1.0,"
" sourceId: 4294967295,"
" docid_limit: 0,"
" children: {"
@@ -721,6 +724,7 @@ getExpectedSlimeBlueprint() {
" tree_size: 1,"
" allow_termwise_eval: true"
" },"
+ " cost: 1.0,"
" sourceId: 4294967295,"
" docid_limit: 0"
" }"
diff --git a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
index 53803c9c9e7..234ff5a9d19 100644
--- a/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/intermediate_blueprints_test.cpp
@@ -14,6 +14,10 @@
#include <vespa/searchlib/test/diskindex/testdiskindex.h>
#include <vespa/searchlib/query/tree/simplequery.h>
#include <vespa/searchlib/common/bitvectoriterator.h>
+#include <vespa/vespalib/util/overload.h>
+#include <vespa/vespalib/data/simple_buffer.h>
+#include <vespa/vespalib/data/slime/slime.h>
+#include <vespa/vespalib/data/slime/inserter.h>
#include <filesystem>
#include <vespa/log/log.h>
@@ -24,6 +28,11 @@ using namespace search::fef;
using namespace search::query;
using search::BitVector;
using BlueprintVector = std::vector<std::unique_ptr<Blueprint>>;
+using vespalib::Slime;
+using vespalib::slime::Inspector;
+using vespalib::slime::SlimeInserter;
+using vespalib::make_string_short::fmt;
+using Path = std::vector<std::variant<size_t,vespalib::stringref>>;
struct InvalidSelector : ISourceSelector {
InvalidSelector() : ISourceSelector(Source()) {}
@@ -480,13 +489,62 @@ struct SourceBlenderTestFixture {
void addChildrenForSimpleSBTest(IntermediateBlueprint & parent);
};
+vespalib::string path_to_str(const Path &path) {
+ size_t cnt = 0;
+ vespalib::string str("[");
+ for (const auto &item: path) {
+ if (cnt++ > 0) {
+ str.append(",");
+ }
+ std::visit(vespalib::overload{
+ [&str](size_t value)noexcept{ str.append(fmt("%zu", value)); },
+ [&str](vespalib::stringref value)noexcept{ str.append(value); }}, item);
+ }
+ str.append("]");
+ return str;
+}
+
+vespalib::string to_str(const Inspector &value) {
+ if (!value.valid()) {
+ return "<missing>";
+ }
+ vespalib::SimpleBuffer buf;
+ vespalib::slime::JsonFormat::encode(value, buf, true);
+ return buf.get().make_string();
+}
+
+void compare(const Blueprint &bp1, const Blueprint &bp2, bool expect_eq) {
+ auto ignore_cost = [expect_eq](const auto &path, const auto &a, const auto &b) {
+ if (!path.empty() && std::holds_alternative<vespalib::stringref>(path.back())) {
+ vespalib::stringref field = std::get<vespalib::stringref>(path.back());
+ if (field == "cost") {
+ return true;
+ }
+ }
+ if (expect_eq) {
+ fprintf(stderr, " mismatch at %s: %s vs %s\n", path_to_str(path).c_str(),
+ to_str(a).c_str(), to_str(b).c_str());
+ }
+ return false;
+ };
+ Slime a;
+ Slime b;
+ bp1.asSlime(SlimeInserter(a));
+ bp2.asSlime(SlimeInserter(b));
+ if (expect_eq) {
+ EXPECT_TRUE(vespalib::slime::are_equal(a.get(), b.get(), ignore_cost));
+ } else {
+ EXPECT_FALSE(vespalib::slime::are_equal(a.get(), b.get(), ignore_cost));
+ }
+}
+
void
optimize_and_compare(Blueprint::UP top, Blueprint::UP expect) {
- EXPECT_NOT_EQUAL(expect->asString(), top->asString());
+ TEST_DO(compare(*top, *expect, false));
top = Blueprint::optimize(std::move(top));
- EXPECT_EQUAL(expect->asString(), top->asString());
+ TEST_DO(compare(*top, *expect, true));
expect = Blueprint::optimize(std::move(expect));
- EXPECT_EQUAL(expect->asString(), top->asString());
+ TEST_DO(compare(*expect, *top, true));
}
void SourceBlenderTestFixture::addChildrenForSBTest(IntermediateBlueprint & parent) {
@@ -1120,7 +1178,7 @@ TEST("require that children of near are not optimized") {
addChild(addLeafs(std::make_unique<OrBlueprint>(), {20, {0, true}})).
addChild(addLeafs(std::make_unique<OrBlueprint>(), {{0, true}, 30})));
top_up = Blueprint::optimize(std::move(top_up));
- EXPECT_EQUAL(expect_up->asString(), top_up->asString());
+ TEST_DO(compare(*top_up, *expect_up, true));
}
TEST("require that children of onear are not optimized") {
@@ -1131,7 +1189,7 @@ TEST("require that children of onear are not optimized") {
addChild(addLeafs(std::make_unique<OrBlueprint>(), {20, {0, true}})).
addChild(addLeafs(std::make_unique<OrBlueprint>(), {{0, true}, 30})));
top_up = Blueprint::optimize(std::move(top_up));
- EXPECT_EQUAL(expect_up->asString(), top_up->asString());
+ TEST_DO(compare(*top_up, *expect_up, true));
}
TEST("require that ANDNOT without children is optimized to empty search") {
diff --git a/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp b/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp
index 2a59a578ec9..fa12b453d8c 100644
--- a/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp
+++ b/searchlib/src/tests/queryeval/parallel_weak_and/parallel_weak_and_test.cpp
@@ -599,6 +599,7 @@ TEST_F("require that asString() on blueprint works", BlueprintAsStringFixture)
" tree_size: 2\n"
" allow_termwise_eval: false\n"
" }\n"
+ " cost: 1\n"
" sourceId: 4294967295\n"
" docid_limit: 0\n"
" _weights: std::vector {\n"
@@ -622,6 +623,7 @@ TEST_F("require that asString() on blueprint works", BlueprintAsStringFixture)
" tree_size: 1\n"
" allow_termwise_eval: true\n"
" }\n"
+ " cost: 1\n"
" sourceId: 4294967295\n"
" docid_limit: 0\n"
" }\n"
diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
index b71a579e097..71d53ade2f7 100644
--- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
@@ -358,6 +358,7 @@ Blueprint::visitMembers(vespalib::ObjectVisitor &visitor) const
visitor.visitInt("tree_size", state.tree_size());
visitor.visitBool("allow_termwise_eval", state.allow_termwise_eval());
visitor.closeStruct();
+ visitor.visitFloat("cost", _cost);
visitor.visitInt("sourceId", _sourceId);
visitor.visitInt("docid_limit", _docid_limit);
}