summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-12-11 13:40:03 +0100
committerGitHub <noreply@github.com>2023-12-11 13:40:03 +0100
commitceab4f213058cefa2458a76e82244cf49956bacc (patch)
tree8ea218d66c00dd06e46a815c2b04a1a8a1637f19 /searchcore
parent0fd1433ae0b506a7b3771cfa6307d2a3567614fe (diff)
Revert "Revert "relative estimate""
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp23
-rw-r--r--searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp4
2 files changed, 23 insertions, 4 deletions
diff --git a/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp b/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp
index b2fa8675835..e136e491f05 100644
--- a/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp
+++ b/searchcore/src/tests/proton/documentmetastore/lid_allocator/lid_allocator_test.cpp
@@ -102,10 +102,15 @@ protected:
}
return result;
}
-
- SimpleResult get_active_lids_in_search_iterator(uint32_t docid_limit, bool filter) {
+
+ Blueprint::UP make_whitelist_blueprint(uint32_t docid_limit) {
auto blueprint = _allocator.createWhiteListBlueprint();
blueprint->setDocIdLimit(docid_limit);
+ return blueprint;
+ }
+
+ SimpleResult get_active_lids_in_search_iterator(uint32_t docid_limit, bool filter) {
+ auto blueprint = make_whitelist_blueprint(docid_limit);
std::unique_ptr<SearchIterator> iterator;
MatchData md(MatchData::params());
if (filter) {
@@ -119,8 +124,7 @@ protected:
}
Trinary filter_search_iterator_matches_any(uint32_t docid_limit) {
- auto blueprint = _allocator.createWhiteListBlueprint();
- blueprint->setDocIdLimit(docid_limit);
+ auto blueprint = make_whitelist_blueprint(docid_limit);
auto iterator = blueprint->createFilterSearch(true, Blueprint::FilterConstraint::UPPER_BOUND);
return iterator->matches_any();
}
@@ -170,6 +174,17 @@ TEST_F(LidAllocatorTest, filter_search_iterator_matches_all_when_all_lids_are_ac
EXPECT_EQ(SimpleResult({1, 2, 3, 4}), get_active_lids_in_search_iterator(6, false));
}
+TEST_F(LidAllocatorTest, whitelist_blueprint_can_maximize_relative_estimate)
+{
+ register_lids({ 1, 2, 3, 4 });
+ activate_lids({ 1, 2, 3, 4 }, true);
+ // the number of hits are overestimated based on the number of
+ // documents that could be active (100 in this test fixture)
+ EXPECT_EQ(make_whitelist_blueprint(1000)->estimate(), 0.1);
+ EXPECT_EQ(make_whitelist_blueprint(200)->estimate(), 0.5);
+ EXPECT_EQ(make_whitelist_blueprint(5)->estimate(), 1.0);
+}
+
class LidAllocatorPerformanceTest : public LidAllocatorTest,
public testing::WithParamInterface<bool>
{
diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp
index 95e4eac437c..9e9199bc8ba 100644
--- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp
+++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.cpp
@@ -222,6 +222,10 @@ public:
setEstimate(HitEstimate(_activeLids.size(), false));
}
+ double calculate_relative_estimate() const final {
+ return abs_to_rel_est(getState().estimate().estHits, get_docid_limit());
+ }
+
bool isWhiteList() const noexcept final { return true; }
SearchIterator::UP createFilterSearch(bool strict, FilterConstraint) const override {