summaryrefslogtreecommitdiff
path: root/src/mongo/db/sorter
diff options
context:
space:
mode:
authorNikita Lapkov <nikita.lapkov@mongodb.com>2021-04-26 16:03:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-21 09:41:14 +0000
commitc35c11a7aa7fd7c585268d05204cdb00efbb1852 (patch)
tree7c9308282f8beda0ba23a30c61c21a6242c3caa1 /src/mongo/db/sorter
parenteae62a64d0306f761dc110b2148baa4fd1fff126 (diff)
downloadmongo-c35c11a7aa7fd7c585268d05204cdb00efbb1852.tar.gz
SERVER-55601 Improve performance of Queries.CoveredBlockingSort benchmark in SBE
Diffstat (limited to 'src/mongo/db/sorter')
-rw-r--r--src/mongo/db/sorter/sorter.cpp11
-rw-r--r--src/mongo/db/sorter/sorter.h15
2 files changed, 25 insertions, 1 deletions
diff --git a/src/mongo/db/sorter/sorter.cpp b/src/mongo/db/sorter/sorter.cpp
index 4a0aa54156f..330b3b6cc1f 100644
--- a/src/mongo/db/sorter/sorter.cpp
+++ b/src/mongo/db/sorter/sorter.cpp
@@ -159,6 +159,8 @@ public:
template <typename Container>
InMemIterator(const Container& input) : _data(input.begin(), input.end()) {}
+ InMemIterator(std::deque<Data> data) : _data(std::move(data)) {}
+
void openSource() {}
void closeSource() {}
@@ -622,6 +624,9 @@ public:
if (this->_iters.empty()) {
sort();
+ if (this->_opts.moveSortedDataIntoIterator) {
+ return new InMemIterator<Key, Value>(std::move(_data));
+ }
return new InMemIterator<Key, Value>(_data);
}
@@ -717,6 +722,9 @@ public:
Iterator* done() {
if (_haveData) {
+ if (this->_opts.moveSortedDataIntoIterator) {
+ return new InMemIterator<Key, Value>(std::move(_best));
+ }
return new InMemIterator<Key, Value>(_best);
} else {
return new InMemIterator<Key, Value>();
@@ -823,6 +831,9 @@ public:
Iterator* done() {
if (this->_iters.empty()) {
sort();
+ if (this->_opts.moveSortedDataIntoIterator) {
+ return new InMemIterator<Key, Value>(std::move(_data));
+ }
return new InMemIterator<Key, Value>(_data);
}
diff --git a/src/mongo/db/sorter/sorter.h b/src/mongo/db/sorter/sorter.h
index 782d0389f57..423638d7a8a 100644
--- a/src/mongo/db/sorter/sorter.h
+++ b/src/mongo/db/sorter/sorter.h
@@ -114,7 +114,15 @@ struct SortOptions {
// extSortAllowed is true.
std::string tempDir;
- SortOptions() : limit(0), maxMemoryUsageBytes(64 * 1024 * 1024), extSortAllowed(false) {}
+ // If set to true and sorted data fits into memory, sorted data will be moved into iterator
+ // instead of copying.
+ bool moveSortedDataIntoIterator;
+
+ SortOptions()
+ : limit(0),
+ maxMemoryUsageBytes(64 * 1024 * 1024),
+ extSortAllowed(false),
+ moveSortedDataIntoIterator(false) {}
// Fluent API to support expressions like SortOptions().Limit(1000).ExtSortAllowed(true)
@@ -142,6 +150,11 @@ struct SortOptions {
dbName = std::move(newDbName);
return *this;
}
+
+ SortOptions& MoveSortedDataIntoIterator(bool newMoveSortedDataIntoIterator = true) {
+ moveSortedDataIntoIterator = newMoveSortedDataIntoIterator;
+ return *this;
+ }
};
/**