This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new cc933107d [common] small optimisation on PartitionContainsRow
cc933107d is described below
commit cc933107d9be7398b42e6c8473daea6a835ef7d7
Author: Alexey Serbin <[email protected]>
AuthorDate: Thu Dec 8 19:03:56 2022 -0800
[common] small optimisation on PartitionContainsRow
This patch updates PartitionSchema::PartitionContainsRow() to avoid
calling EncodeColumns() twice for the same data.
That's to improve performance of Tablet::CheckRowInTablet() which
is in a hot path when inserting data into a tablet.
Change-Id: Iaf1d8a9ea533a859d218292a6a0e2a0818781111
Reviewed-on: http://gerrit.cloudera.org:8080/19333
Tested-by: Alexey Serbin <[email protected]>
Reviewed-by: Yingchun Lai <[email protected]>
---
src/kudu/common/partition.cc | 20 ++++++++++++--------
src/kudu/common/partition.h | 4 ++++
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/kudu/common/partition.cc b/src/kudu/common/partition.cc
index 475d9d0ed..1669f3f5a 100644
--- a/src/kudu/common/partition.cc
+++ b/src/kudu/common/partition.cc
@@ -701,8 +701,7 @@ bool PartitionSchema::PartitionContainsRowImpl(const
Partition& partition,
return false;
}
}
-
- return RangePartitionContainsRowImpl(partition, row);
+ return RangePartitionContainsEncodedKey(partition, range_key);
}
template<typename Row>
@@ -727,12 +726,7 @@ bool PartitionSchema::RangePartitionContainsRowImpl(
string key;
EncodeColumns(row, range_schema_.column_ids, &key);
- // When all hash buckets match, then the row is contained in the partition
- // if the row's key is greater or equal to the lower bound, and if there is
- // either no upper bound or the row's key is less than the upper bound.
- return
- (partition.begin().range_key() <= key) &&
- (partition.end().range_key().empty() || key <
partition.end().range_key());
+ return RangePartitionContainsEncodedKey(partition, key);
}
bool PartitionSchema::PartitionContainsRow(const Partition& partition,
@@ -1384,6 +1378,16 @@ vector<Partition>
PartitionSchema::GenerateHashPartitions(
return hash_partitions;
}
+bool PartitionSchema::RangePartitionContainsEncodedKey(
+ const Partition& partition, const string& key) {
+ // When all hash buckets match, then the row is contained in the partition
+ // if the row's key is greater or equal to the lower bound, and if there is
+ // either no upper bound or the row's key is less than the upper bound.
+ return
+ (partition.begin().range_key() <= key) &&
+ (partition.end().range_key().empty() || key <
partition.end().range_key());
+}
+
Status PartitionSchema::ValidateHashSchema(const Schema& schema,
const HashSchema& hash_schema) {
set<ColumnId> hash_columns;
diff --git a/src/kudu/common/partition.h b/src/kudu/common/partition.h
index 575c73218..20c88222e 100644
--- a/src/kudu/common/partition.h
+++ b/src/kudu/common/partition.h
@@ -564,6 +564,10 @@ class PartitionSchema {
const HashSchema& hash_schema,
const KeyEncoder<std::string>& hash_encoder);
+ // Helper for PartitionContainsRowImpl.
+ static bool RangePartitionContainsEncodedKey(const Partition& partition,
+ const std::string& key);
+
// PartitionKeyDebugString implementation for row types.
template<typename Row>
std::string PartitionKeyDebugStringImpl(const Row& row) const;