Skip to content

Commit

Permalink
Merge duplicated TermQueryNode children
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhichang committed May 21, 2024
1 parent 1a841eb commit 7c18472
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/references/benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ options:
| | Time to insert & build index | Time to import & build index | P95 Latency(ms)| QPS (8 python clients) | Memory | vCPU |
| ----------------- | ---------------------------- | ---------------------------- | ---------------| -----------------------| --------| ----- |
| **Elasticsearch** | 2289 s | N/A | 14.75 | 1174 | 21.0GB | 10.0 |
| **Infinity** | 2321 s | 944 s | 3.51 | 3294 | 9.0GB | 5.7 |
| **Infinity** | 2321 s | 944 s | 3.51 | 3925 | 9.0GB | 4.2 |

---

Expand Down
29 changes: 29 additions & 0 deletions src/storage/invertedindex/search/query_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,35 @@ std::unique_ptr<QueryNode> OrQueryNode::InnerGetNewOptimizedQueryTree() {
not_node->children_.emplace_back(std::move(optimized_node));
return not_node;
} else if (not_list.empty()) {
// merge duplicated TermQueryNode children
std::vector<std::unique_ptr<QueryNode>> or_list_tmp;
for (auto &child1 : or_list) {
if (child1->GetType() != QueryNodeType::TERM) {
or_list_tmp.emplace_back(std::move(child1));
continue;
}
TermQueryNode *term_query_node1 = static_cast<TermQueryNode *>(child1.get());
bool duplicated = false;
for (auto &child2 : or_list_tmp) {
if (child2->GetType() == QueryNodeType::TERM) {
TermQueryNode *term_query_node2 = static_cast<TermQueryNode *>(child2.get());
if (term_query_node1->term_ == term_query_node2->term_ && term_query_node1->column_ == term_query_node2->column_ &&
term_query_node1->position_ == term_query_node2->position_) {
term_query_node2->weight_ += term_query_node1->weight_;
duplicated = true;
break;
}
}
}
if (!duplicated) {
or_list_tmp.emplace_back(std::move(child1));
}
}
or_list = std::move(or_list_tmp);

if (or_list.size() == 1) {
return std::move(or_list[0]);
}
// at least 2 children
auto or_node = std::make_unique<OrQueryNode>(); // new node, weight is reset to 1.0
or_node->children_ = std::move(or_list);
Expand Down

0 comments on commit 7c18472

Please sign in to comment.