From 9f786dd7520ccaec20f322b7155338e9b3bb9e37 Mon Sep 17 00:00:00 2001 From: bigsheeper Date: Mon, 6 Jun 2022 17:38:05 +0800 Subject: [PATCH] Remove unnecessary bitset flip in Search and Query (#17387) Signed-off-by: bigsheeper --- .../core/src/query/visitors/ExecPlanNodeVisitor.cpp | 6 +++--- internal/core/src/segcore/SegmentSealedImpl.cpp | 10 +++++----- internal/core/src/segcore/TimestampIndex.cpp | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/core/src/query/visitors/ExecPlanNodeVisitor.cpp b/internal/core/src/query/visitors/ExecPlanNodeVisitor.cpp index 43e4083495..57cd39c919 100644 --- a/internal/core/src/query/visitors/ExecPlanNodeVisitor.cpp +++ b/internal/core/src/query/visitors/ExecPlanNodeVisitor.cpp @@ -92,11 +92,11 @@ ExecPlanNodeVisitor::VectorVisitorImpl(VectorPlanNode& node) { BitsetType bitset_holder; if (node.predicate_.has_value()) { bitset_holder = ExecExprVisitor(*segment, active_count, timestamp_).call_child(*node.predicate_.value()); + bitset_holder.flip(); } else { - bitset_holder.resize(active_count, true); + bitset_holder.resize(active_count, false); } segment->mask_with_timestamps(bitset_holder, timestamp_); - bitset_holder.flip(); segment->mask_with_delete(bitset_holder, active_count, timestamp_); BitsetView final_view = bitset_holder; @@ -123,10 +123,10 @@ ExecPlanNodeVisitor::visit(RetrievePlanNode& node) { BitsetType bitset_holder; if (node.predicate_ != nullptr) { bitset_holder = ExecExprVisitor(*segment, active_count, timestamp_).call_child(*(node.predicate_)); + bitset_holder.flip(); } segment->mask_with_timestamps(bitset_holder, timestamp_); - bitset_holder.flip(); segment->mask_with_delete(bitset_holder, active_count, timestamp_); BitsetView final_view = bitset_holder; diff --git a/internal/core/src/segcore/SegmentSealedImpl.cpp b/internal/core/src/segcore/SegmentSealedImpl.cpp index 17970ff3cd..a255eb2ed6 100644 --- a/internal/core/src/segcore/SegmentSealedImpl.cpp +++ b/internal/core/src/segcore/SegmentSealedImpl.cpp @@ -775,19 +775,19 @@ SegmentSealedImpl::mask_with_timestamps(BitsetType& bitset_chunk, Timestamp time // range == (size_, size_) and size_ is this->timestamps_.size(). // it means these data are all useful, we don't need to update bitset_chunk. - // It can be thought of as an AND operation with another bitmask that is all 1s, but it is not necessary to do so. + // It can be thought of as an OR operation with another bitmask that is all 0s, but it is not necessary to do so. if (range.first == range.second && range.first == timestamps_data.size()) { // just skip return; } - // range == (0, 0). it means these data can not be used, directly set bitset_chunk to all 0s. - // It can be thought of as an AND operation with another bitmask that is all 0s. + // range == (0, 0). it means these data can not be used, directly set bitset_chunk to all 1s. + // It can be thought of as an OR operation with another bitmask that is all 1s. if (range.first == range.second && range.first == 0) { - bitset_chunk.reset(); + bitset_chunk.set(); return; } auto mask = TimestampIndex::GenerateBitset(timestamp, range, timestamps_data.data(), timestamps_data.size()); - bitset_chunk &= mask; + bitset_chunk |= mask; } } // namespace milvus::segcore diff --git a/internal/core/src/segcore/TimestampIndex.cpp b/internal/core/src/segcore/TimestampIndex.cpp index ad8d9d5ab0..adcdd1e142 100644 --- a/internal/core/src/segcore/TimestampIndex.cpp +++ b/internal/core/src/segcore/TimestampIndex.cpp @@ -72,10 +72,10 @@ TimestampIndex::GenerateBitset(Timestamp query_timestamp, Assert(beg < end); BitsetType bitset; bitset.reserve(size); - bitset.resize(beg, true); - bitset.resize(size, false); + bitset.resize(beg, false); + bitset.resize(size, true); for (int64_t i = beg; i < end; ++i) { - bitset[i] = timestamps[i] <= query_timestamp; + bitset[i] = timestamps[i] > query_timestamp; } return bitset; }