From fe5d7920309ac836c7b45daa0f314de442c00636 Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Wed, 18 May 2022 11:24:44 +0000 Subject: SERVER-66314 improve columnar steady-state write impl --- src/mongo/db/index/column_key_generator.cpp | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/mongo/db/index/column_key_generator.cpp') diff --git a/src/mongo/db/index/column_key_generator.cpp b/src/mongo/db/index/column_key_generator.cpp index aae01066cec..5002236eec3 100644 --- a/src/mongo/db/index/column_key_generator.cpp +++ b/src/mongo/db/index/column_key_generator.cpp @@ -102,6 +102,45 @@ public: } } + static void multiVisit( + const std::vector& recs, + function_ref cb) { + const size_t count = recs.size(); + if (count == 0) + return; + + std::vector shredders; + shredders.reserve(count); + for (auto&& rec : recs) { + shredders.emplace_back(*rec.docPtr); + } + + if (count == 1) { + // Don't need to merge if just 1 record. + shredders[0].visitCells([&](PathView path, const UnencodedCellView& cell) { // + cb(path, recs[0], cell); + }); + return; + } + + // Mapping: column name -> [raw cells and indexes to recs and shredders] + StringDataMap>> columns; + for (size_t i = 0; i < count; i++) { + for (auto&& [path, rcv] : shredders[i]._paths) { + auto&& vec = columns[path]; + if (vec.empty()) + vec.reserve(count); // Optimize for columns existing in all records. + vec.emplace_back(&rcv, i); + } + } + + for (auto&& [path, rows] : columns) { + for (auto&& [rcv, i] : rows) { + cb(path, recs[i], shredders[i].makeCellView(path, *rcv)); + } + } + } + static void visitDiff(const BSONObj& oldObj, const BSONObj& newObj, function_ref cb) { @@ -544,6 +583,12 @@ void visitCellsForInsert(const BSONObj& obj, ColumnShredder(obj).visitCells(cb); } +void visitCellsForInsert( + const std::vector& recs, + function_ref cb) { + ColumnShredder::multiVisit(recs, cb); +} + void visitPathsForDelete(const BSONObj& obj, function_ref cb) { ColumnShredder(obj, ColumnShredder::kOnlyPaths).visitPaths(cb); } -- cgit v1.2.1