summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHaavard <havardpe@yahoo-inc.com>2016-09-02 13:01:37 +0000
committerHaavard <havardpe@yahoo-inc.com>2016-09-02 14:27:36 +0000
commit61400a4b3e910c650c5648374eb921f49968fc12 (patch)
tree418201a2411ed18f00e88a9167faf3dd19e279ee /searchlib
parenta04647ceea6852cba7f2a8b6bd51cf7d796fa4e8 (diff)
do not copy blueprints, freeze blueprints
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp9
-rw-r--r--searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp23
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp21
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/blueprint.cpp33
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/blueprint.h20
6 files changed, 41 insertions, 67 deletions
diff --git a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
index 79fec3770b3..7fcb1c20932 100644
--- a/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/blueprint_test.cpp
@@ -651,17 +651,8 @@ Test::testBlueprintMakeNew()
orig->setSourceId(42);
MyOr *myOr = dynamic_cast<MyOr*>(orig.get());
ASSERT_TRUE(myOr != 0);
- Blueprint::UP copy1 = makeNew(myOr);
- Blueprint::UP copy2 = makeNew(myOr);
- TEST_DO(check_equal(*copy1, *copy2));
- TEST_DO(check_not_equal(*orig, *copy1));
- TEST_DO(check_not_equal(*orig, *copy2));
- EXPECT_TRUE(dynamic_cast<MyOr*>(copy1.get()) != 0);
- EXPECT_TRUE(dynamic_cast<MyOr*>(copy2.get()) != 0);
EXPECT_EQUAL(42u, orig->getSourceId());
- EXPECT_EQUAL(42u, copy1->getSourceId());
EXPECT_EQUAL(2u, orig->getState().numFields());
- EXPECT_EQUAL(0u, copy1->getState().numFields());
}
vespalib::string
diff --git a/searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp b/searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp
index a2353184c9f..6efa3454d01 100644
--- a/searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp
+++ b/searchlib/src/tests/queryeval/blueprint/leaf_blueprints_test.cpp
@@ -24,13 +24,12 @@ Test::testEmptyBlueprint()
{
MatchData::UP md(MatchData::makeTestInstance(0, 100, 10));
EmptyBlueprint empty(FieldSpecBase(1, 11));
- EmptyBlueprint copy(empty);
- ASSERT_TRUE(copy.getState().numFields() == 1u);
- EXPECT_EQUAL(1u, copy.getState().field(0).getFieldId());
- EXPECT_EQUAL(11u, copy.getState().field(0).getHandle());
+ ASSERT_TRUE(empty.getState().numFields() == 1u);
+ EXPECT_EQUAL(1u, empty.getState().field(0).getFieldId());
+ EXPECT_EQUAL(11u, empty.getState().field(0).getHandle());
- copy.fetchPostings(true);
- SearchIterator::UP search = copy.createSearch(*md, true);
+ empty.fetchPostings(true);
+ SearchIterator::UP search = empty.createSearch(*md, true);
SimpleResult res;
res.search(*search);
@@ -46,10 +45,9 @@ Test::testSimpleBlueprint()
a.addHit(3).addHit(5).addHit(7);
SimpleBlueprint simple(a);
simple.tag("tag");
- SimpleBlueprint copy(simple);
- EXPECT_EQUAL("tag", copy.tag());
- copy.fetchPostings(true);
- SearchIterator::UP search = copy.createSearch(*md, true);
+ EXPECT_EQUAL("tag", simple.tag());
+ simple.fetchPostings(true);
+ SearchIterator::UP search = simple.createSearch(*md, true);
SimpleResult res;
res.search(*search);
@@ -69,10 +67,9 @@ Test::testFakeBlueprint()
uint32_t fieldId = 0;
TermFieldHandle handle = 0;
FakeBlueprint orig(FieldSpec("<field>", fieldId, handle), fake);
- FakeBlueprint copy(orig);
- copy.fetchPostings(true);
- SearchIterator::UP search = copy.createSearch(*md, true);
+ orig.fetchPostings(true);
+ SearchIterator::UP search = orig.createSearch(*md, true);
search->initFullRange();
EXPECT_TRUE(!search->seek(1u));
EXPECT_EQUAL(10u, search->getDocId());
diff --git a/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp b/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp
index 258eaac51cf..10849b4b70a 100644
--- a/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.cpp
@@ -53,27 +53,6 @@ DiskTermBlueprint::DiskTermBlueprint(const FieldSpecBase & field,
_lookupRes->counts._numDocs == 0));
}
-
-DiskTermBlueprint::DiskTermBlueprint(const DiskTermBlueprint & rhs)
- : SimpleLeafBlueprint(rhs),
- _field(rhs._field),
- _diskIndex(rhs._diskIndex),
- _lookupRes(new DiskIndex::LookupResult(*rhs._lookupRes)),
- _useBitVector(rhs._useBitVector),
- _fetchPostingsDone(rhs._fetchPostingsDone),
- _hasEquivParent(rhs._hasEquivParent),
- _postingHandle(),
- _bitVector()
-{
- if (_fetchPostingsDone) {
- if (rhs._bitVector.get() != NULL)
- _bitVector = BitVector::create(*rhs._bitVector);
- if (_bitVector.get() == NULL) {
- _postingHandle = _diskIndex.readPostingList(*_lookupRes);
- }
- }
-}
-
namespace {
bool
diff --git a/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h b/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h
index f1790cd0cbd..f3fdca2617a 100644
--- a/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h
+++ b/searchlib/src/vespa/searchlib/diskindex/disktermblueprint.h
@@ -37,8 +37,6 @@ public:
search::diskindex::DiskIndex::LookupResult::UP lookupRes,
bool useBitVector);
- DiskTermBlueprint(const DiskTermBlueprint &);
-
// Inherit doc from Blueprint.
// For now, this DiskTermBlueprint instance must have longer lifetime than the created iterator.
virtual search::queryeval::SearchIterator::UP
diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
index 3b75b5caa42..df970f4cc7e 100644
--- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp
@@ -71,14 +71,8 @@ Blueprint::min(const std::vector<HitEstimate> &data)
Blueprint::Blueprint()
: _parent(0),
_sourceId(0xffffffff),
- _docid_limit(0)
-{
-}
-
-Blueprint::Blueprint(const Blueprint &x)
- : _parent(0),
- _sourceId(x.getSourceId()),
- _docid_limit(x.get_docid_limit())
+ _docid_limit(0),
+ _frozen(false)
{
}
@@ -343,14 +337,6 @@ IntermediateBlueprint::IntermediateBlueprint()
{
}
-IntermediateBlueprint::
-IntermediateBlueprint(const IntermediateBlueprint &x)
- : StateCache(x),
- _children()
-{
- // children are not copied
-}
-
const Blueprint &
IntermediateBlueprint::getChild(size_t n) const
{
@@ -411,6 +397,15 @@ IntermediateBlueprint::fetchPostings(bool strict)
}
}
+void
+IntermediateBlueprint::freeze()
+{
+ for (size_t i = 0; i < _children.size(); ++i) {
+ _children[i]->freeze();
+ }
+ freeze_self();
+}
+
namespace {
bool
@@ -477,6 +472,12 @@ LeafBlueprint::fetchPostings(bool strict)
(void) strict;
}
+void
+LeafBlueprint::freeze()
+{
+ freeze_self();
+}
+
SearchIterator::UP
LeafBlueprint::createSearch(fef::MatchData &md, bool strict) const
{
diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.h b/searchlib/src/vespa/searchlib/queryeval/blueprint.h
index b01d60d529c..c1b1f1311eb 100644
--- a/searchlib/src/vespa/searchlib/queryeval/blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.h
@@ -127,8 +127,7 @@ private:
Blueprint *_parent;
uint32_t _sourceId;
uint32_t _docid_limit;
-
- Blueprint &operator=(const Blueprint &); // disable
+ bool _frozen;
protected:
virtual void notifyChange() {
@@ -136,6 +135,10 @@ protected:
_parent->notifyChange();
}
}
+ void freeze_self() {
+ getState();
+ _frozen = true;
+ }
public:
class IPredicate {
@@ -145,7 +148,8 @@ public:
};
Blueprint();
- Blueprint(const Blueprint &x);
+ Blueprint(const Blueprint &) = delete;
+ Blueprint &operator=(const Blueprint &) = delete;
virtual ~Blueprint();
void setParent(Blueprint *parent) { _parent = parent; }
@@ -172,6 +176,8 @@ public:
double hit_ratio() const { return getState().hit_ratio(_docid_limit); }
virtual void fetchPostings(bool strict) = 0;
+ virtual void freeze() = 0;
+ bool frozen() const { return _frozen; }
virtual SearchIterator::UP createSearch(fef::MatchData &md, bool strict) const = 0;
@@ -196,6 +202,7 @@ private:
protected:
void notifyChange() override final {
+ assert(!frozen());
Blueprint::notifyChange();
_stale = true;
}
@@ -203,10 +210,9 @@ protected:
public:
StateCache() : _stale(true), _state(FieldSpecBaseList()) {}
- StateCache(const StateCache &x)
- : Blueprint(x), _stale(true), _state(FieldSpecBaseList()) {}
const State &getState() const override final {
if (_stale) {
+ assert(!frozen());
updateState();
}
return _state;
@@ -243,7 +249,6 @@ protected:
public:
typedef std::vector<size_t> IndexList;
IntermediateBlueprint();
- IntermediateBlueprint(const IntermediateBlueprint &x);
virtual ~IntermediateBlueprint();
void setDocIdLimit(uint32_t limit) override final;
@@ -269,6 +274,8 @@ public:
void visitMembers(vespalib::ObjectVisitor &visitor) const override;
void fetchPostings(bool strict) override;
+ void freeze() override final;
+
UnpackInfo calculateUnpackInfo(const fef::MatchData & md) const;
bool isIntermediate() const override { return true; }
};
@@ -293,6 +300,7 @@ public:
const State &getState() const override final { return _state; }
void setDocIdLimit(uint32_t limit) override final { Blueprint::setDocIdLimit(limit); }
void fetchPostings(bool strict) override;
+ void freeze() override final;
SearchIterator::UP createSearch(fef::MatchData &md, bool strict) const override;
virtual SearchIterator::UP createLeafSearch(const fef::TermFieldMatchDataArray &tfmda,