Skip to content

Commit f1844c9

Browse files
authored
enhance: optimize term expr performance (#45490)
issue: #45641 pr: #45491 --------- Signed-off-by: sunby <sunbingyi1992@gmail.com>
1 parent e695d8a commit f1844c9

File tree

11 files changed

+35
-28
lines changed

11 files changed

+35
-28
lines changed

internal/core/src/common/Chunk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class FixedWidthChunk : public Chunk {
113113
std::unique_ptr<MmapFileRAII> mmap_file_raii = nullptr)
114114
: Chunk(row_nums, data, size, nullable, std::move(mmap_file_raii)),
115115
dim_(dim),
116-
element_size_(element_size) {};
116+
element_size_(element_size){};
117117

118118
milvus::SpanBase
119119
Span() const {

internal/core/src/common/init_c.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ InitDefaultDeleteDumpBatchSize(int32_t val) {
139139
val);
140140
}
141141

142-
143142
void
144143
InitTrace(CTraceConfig* config) {
145144
auto traceConfig = milvus::tracer::TraceConfig{config->exporter,

internal/core/src/exec/expression/Element.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class FlatVectorElement : public MultiElement {
198198
In(const ValueType& value) const override {
199199
if (std::holds_alternative<T>(value)) {
200200
for (const auto& v : values_) {
201-
if (v == value)
201+
if (v == std::get<T>(value))
202202
return true;
203203
}
204204
}

internal/core/src/exec/expression/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ class SegmentExpr : public Expr {
908908

909909
template <typename T, typename FUNC, typename... ValTypes>
910910
VectorPtr
911-
ProcessIndexChunks(FUNC func, ValTypes... values) {
911+
ProcessIndexChunks(FUNC func, const ValTypes&... values) {
912912
typedef std::
913913
conditional_t<std::is_same_v<T, std::string_view>, std::string, T>
914914
IndexInnerType;

internal/core/src/exec/expression/GISFunctionFilterExpr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class PhyGISFunctionFilterExpr : public SegmentExpr {
6666
}
6767
}
6868

69-
7069
private:
7170
VectorPtr
7271
EvalForIndexSegment();

internal/core/src/exec/expression/TermExpr.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -810,29 +810,36 @@ PhyTermFilterExpr::ExecVisitorImplForIndex() {
810810
return nullptr;
811811
}
812812

813-
std::vector<IndexInnerType> vals;
814-
for (auto& val : expr_->vals_) {
815-
if constexpr (std::is_same_v<T, double>) {
816-
if (val.has_int64_val()) {
817-
// only json field will cast int to double because other fields are casted in proxy
818-
vals.emplace_back(static_cast<double>(val.int64_val()));
819-
continue;
813+
if (!arg_inited_) {
814+
std::vector<IndexInnerType> vals;
815+
for (auto& val : expr_->vals_) {
816+
if constexpr (std::is_same_v<T, double>) {
817+
if (val.has_int64_val()) {
818+
// only json field will cast int to double because other fields are casted in proxy
819+
vals.emplace_back(static_cast<double>(val.int64_val()));
820+
continue;
821+
}
820822
}
821-
}
822823

823-
// Generic overflow handling for all types
824-
bool overflowed = false;
825-
auto converted_val = GetValueFromProtoWithOverflow<T>(val, overflowed);
826-
if (!overflowed) {
827-
vals.emplace_back(converted_val);
824+
// Generic overflow handling for all types
825+
bool overflowed = false;
826+
auto converted_val =
827+
GetValueFromProtoWithOverflow<T>(val, overflowed);
828+
if (!overflowed) {
829+
vals.emplace_back(converted_val);
830+
}
828831
}
832+
arg_set_ = std::make_shared<FlatVectorElement<IndexInnerType>>(vals);
833+
arg_inited_ = true;
829834
}
830835
auto execute_sub_batch = [](Index* index_ptr,
831836
const std::vector<IndexInnerType>& vals) {
832837
TermIndexFunc<T> func;
833838
return func(index_ptr, vals.size(), vals.data());
834839
};
835-
auto res = ProcessIndexChunks<T>(execute_sub_batch, vals);
840+
auto args =
841+
std::dynamic_pointer_cast<FlatVectorElement<IndexInnerType>>(arg_set_);
842+
auto res = ProcessIndexChunks<T>(execute_sub_batch, args->values_);
836843
AssertInfo(res->size() == real_batch_size,
837844
"internal error: expr processed rows {} not equal "
838845
"expect batch size {}",

internal/core/src/exec/expression/UnaryExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ PhyUnaryRangeFilterExpr::ExecArrayEqualForIndex(EvalCtx& context,
575575
};
576576
} else {
577577
auto size_per_chunk = segment_->size_per_chunk();
578-
retrieve = [ size_per_chunk, this ](int64_t offset) -> auto{
578+
retrieve = [ size_per_chunk, this ](int64_t offset) -> auto {
579579
auto chunk_idx = offset / size_per_chunk;
580580
auto chunk_offset = offset % size_per_chunk;
581581
const auto& chunk =

internal/core/src/expr/ITypeExpr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ class GISFunctionFilterExpr : public ITypeFilterExpr {
767767
: column_(cloumn),
768768
op_(op),
769769
geometry_wkt_(geometry_wkt),
770-
distance_(distance) {};
770+
distance_(distance){};
771771
std::string
772772
ToString() const override {
773773
if (op_ == proto::plan::GISFunctionFilterExpr_GISOp_DWithin) {

internal/core/src/segcore/DeletedRecord.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ class DeletedRecord {
214214
SortedDeleteList::Accessor accessor(deleted_lists_);
215215
int total_size = accessor.size();
216216

217-
while (total_size - dumped_entry_count_.load() > DELETE_DUMP_BATCH_SIZE) {
217+
while (total_size - dumped_entry_count_.load() >
218+
DELETE_DUMP_BATCH_SIZE) {
218219
int32_t bitsize = 0;
219220
if constexpr (is_sealed) {
220221
bitsize = sealed_row_count_;
@@ -232,11 +233,14 @@ class DeletedRecord {
232233
snapshots_.back().second.size());
233234
}
234235

235-
while (total_size - dumped_entry_count_.load() > DELETE_DUMP_BATCH_SIZE &&
236+
while (total_size - dumped_entry_count_.load() >
237+
DELETE_DUMP_BATCH_SIZE &&
236238
it != accessor.end()) {
237239
Timestamp dump_ts = 0;
238240

239-
for (auto size = 0; size < DELETE_DUMP_BATCH_SIZE && it != accessor.end(); ++it, ++size) {
241+
for (auto size = 0;
242+
size < DELETE_DUMP_BATCH_SIZE && it != accessor.end();
243+
++it, ++size) {
240244
bitmap.set(it->second);
241245
dump_ts = it->first;
242246
}

internal/core/src/storage/FileWriter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ class FileWriter {
294294
// for global configuration
295295
static WriteMode
296296
mode_; // The write mode, which can be 'buffered' (default) or 'direct'.
297-
static size_t
298-
buffer_size_;
297+
static size_t buffer_size_;
299298

300299
// for rate limiter
301300
io::Priority priority_;

0 commit comments

Comments
 (0)