-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature](inverted index) Add profile statistics for each condition i…
…n inverted index filters
- Loading branch information
Showing
6 changed files
with
244 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "olap/inverted_index_stats.h" | ||
#include "olap/tablet_schema.h" | ||
#include "util/runtime_profile.h" | ||
|
||
namespace doris { | ||
|
||
class InvertedIndexProfileReporter { | ||
public: | ||
InvertedIndexProfileReporter(RuntimeProfile* profile) : _profile(profile) {} | ||
|
||
void update(const InvertedIndexStatistics* statistics, const TabletSchemaSPtr& tablet_schema) { | ||
if (_profile == nullptr) { | ||
return; | ||
} | ||
|
||
std::string inverted_index_filter = "["; | ||
for (auto stats : statistics->stats) { | ||
inverted_index_filter += "("; | ||
inverted_index_filter += | ||
tablet_schema->column_by_uid(stats.column_unique_id).name() + ", "; | ||
inverted_index_filter += PrettyPrinter::print(stats.filter_count, TUnit::UNIT) + ", "; | ||
inverted_index_filter += PrettyPrinter::print(stats.filter_time, TUnit::TIME_NS); | ||
inverted_index_filter += "), "; | ||
} | ||
if (inverted_index_filter.length() > 1) { | ||
inverted_index_filter = | ||
inverted_index_filter.substr(0, inverted_index_filter.length() - 2); | ||
} | ||
inverted_index_filter += "]"; | ||
|
||
auto* child = _profile->create_child("IndexFilter"); | ||
child->add_info_string("InvertedIndexFilter", inverted_index_filter); | ||
} | ||
|
||
private: | ||
RuntimeProfile* _profile = nullptr; | ||
}; | ||
|
||
} // namespace doris |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
|
||
namespace doris { | ||
|
||
struct InvertedIndexQueryStatistics { | ||
int32_t column_unique_id; | ||
int64_t filter_count = 0; | ||
int64_t filter_time = 0; | ||
}; | ||
|
||
struct InvertedIndexStatistics { | ||
std::vector<InvertedIndexQueryStatistics> stats; | ||
}; | ||
|
||
} // namespace doris |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#include "olap/inverted_index_profile.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <memory> | ||
|
||
#include "olap/inverted_index_stats.h" | ||
|
||
namespace doris { | ||
|
||
class InvertedIndexProfileReporterTest : public ::testing::Test { | ||
protected: | ||
void SetUp() override { | ||
_runtime_profile = new RuntimeProfile("test_profile"); | ||
_reporter = new InvertedIndexProfileReporter(_runtime_profile); | ||
} | ||
|
||
void TearDown() override { | ||
delete _reporter; | ||
delete _runtime_profile; | ||
} | ||
|
||
RuntimeProfile* _runtime_profile = nullptr; | ||
InvertedIndexProfileReporter* _reporter = nullptr; | ||
}; | ||
|
||
class MockInvertedIndexStatistics1 : public InvertedIndexStatistics { | ||
public: | ||
MockInvertedIndexStatistics1() { stats.push_back({123, 100, 200}); } | ||
}; | ||
|
||
class MockInvertedIndexStatistics2 : public InvertedIndexStatistics { | ||
public: | ||
MockInvertedIndexStatistics2() { | ||
stats.push_back({123, 100, 200}); | ||
stats.push_back({124, 150, 250}); | ||
stats.push_back({125, 200, 300}); | ||
} | ||
}; | ||
|
||
TEST_F(InvertedIndexProfileReporterTest, UpdateTest) { | ||
MockInvertedIndexStatistics1 statistics; | ||
|
||
TabletColumn tablet_column; | ||
tablet_column.set_unique_id(123); | ||
tablet_column.set_name("test_column"); | ||
|
||
TabletSchemaSPtr tablet_schema = std::make_shared<TabletSchema>(); | ||
tablet_schema->append_column(tablet_column); | ||
|
||
_reporter->update(&statistics, tablet_schema); | ||
|
||
std::vector<RuntimeProfile*> children; | ||
_runtime_profile->get_children(&children); | ||
|
||
ASSERT_EQ(children.size(), 1); | ||
ASSERT_EQ(children[0]->name(), "IndexFilter"); | ||
|
||
const std::string* index_filter = children[0]->get_info_string("InvertedIndexFilter"); | ||
ASSERT_NE(index_filter, nullptr); | ||
|
||
// 验证输出格式是否正确 | ||
ASSERT_TRUE(index_filter->find("test_column") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("100") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("200") != std::string::npos); | ||
} | ||
|
||
TEST_F(InvertedIndexProfileReporterTest, UpdateTestWithMultipleStats) { | ||
MockInvertedIndexStatistics2 statistics; | ||
|
||
TabletColumn tablet_column1, tablet_column2, tablet_column3; | ||
tablet_column1.set_unique_id(123); | ||
tablet_column1.set_name("test_column1"); | ||
tablet_column2.set_unique_id(124); | ||
tablet_column2.set_name("test_column2"); | ||
tablet_column3.set_unique_id(125); | ||
tablet_column3.set_name("test_column3"); | ||
|
||
TabletSchemaSPtr tablet_schema = std::make_shared<TabletSchema>(); | ||
tablet_schema->append_column(tablet_column1); | ||
tablet_schema->append_column(tablet_column2); | ||
tablet_schema->append_column(tablet_column3); | ||
|
||
_reporter->update(&statistics, tablet_schema); | ||
|
||
std::vector<RuntimeProfile*> children; | ||
_runtime_profile->get_children(&children); | ||
|
||
ASSERT_EQ(children.size(), 1); | ||
ASSERT_EQ(children[0]->name(), "IndexFilter"); | ||
|
||
const std::string* index_filter = children[0]->get_info_string("InvertedIndexFilter"); | ||
ASSERT_NE(index_filter, nullptr); | ||
|
||
// 验证输出格式是否正确 | ||
ASSERT_TRUE(index_filter->find("test_column1") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("test_column2") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("test_column3") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("100") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("200") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("150") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("250") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("200") != std::string::npos); | ||
ASSERT_TRUE(index_filter->find("300") != std::string::npos); | ||
} | ||
|
||
} // namespace doris |