summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Zolnierz <nicholas.zolnierz@mongodb.com>2022-05-05 18:22:13 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-05 22:08:29 +0000
commit74d27a4f0d7fa53fb8ba261185a54ea61c9fbd58 (patch)
tree13b944ea5c7e9453a219e448a3bfa5dcc4b4e479
parent883238375b56d7a4a11f48583a5f79a5f7192d87 (diff)
downloadmongo-74d27a4f0d7fa53fb8ba261185a54ea61c9fbd58.tar.gz
SERVER-62043 Add more gdb pretty printers for new optimizer
-rw-r--r--buildscripts/gdb/mongo_printers.py69
-rw-r--r--src/mongo/db/query/optimizer/explain.cpp26
-rw-r--r--src/mongo/db/query/optimizer/explain.h12
3 files changed, 75 insertions, 32 deletions
diff --git a/buildscripts/gdb/mongo_printers.py b/buildscripts/gdb/mongo_printers.py
index edfef5c22c2..29844d2a98b 100644
--- a/buildscripts/gdb/mongo_printers.py
+++ b/buildscripts/gdb/mongo_printers.py
@@ -838,7 +838,7 @@ class ABTPrinter(object):
def __init__(self, val):
"""Initialize ABTPrinter."""
self.val = val
- (print_fn_symbol, _) = gdb.lookup_symbol("_printNode")
+ (print_fn_symbol, _) = gdb.lookup_symbol("ExplainGenerator::explainNode")
if print_fn_symbol is None:
raise gdb.GdbError("Could not find ABT print function")
self.print_fn = print_fn_symbol.value()
@@ -874,6 +874,70 @@ class ABTPrinter(object):
return "%s" % (res)
+class OptimizerTypePrinter(object):
+ """Base class that pretty prints via a single argument C++ function."""
+
+ def __init__(self, val, print_fn_name):
+ """Initialize base printer."""
+ self.val = val
+ (print_fn_symbol, _) = gdb.lookup_symbol(print_fn_name)
+ if print_fn_symbol is None:
+ raise gdb.GdbError("Could not find pretty print function: " + print_fn_name)
+ self.print_fn = print_fn_symbol.value()
+
+ @staticmethod
+ def display_hint():
+ """Display hint."""
+ return None
+
+ def to_string(self):
+ """Return string for printing."""
+ return eval_print_fn(self.val, self.print_fn)
+
+
+class IntervalPrinter(OptimizerTypePrinter):
+ """Pretty-printer for mongo::optimizer::IntervalRequirement."""
+
+ def __init__(self, val):
+ """Initialize IntervalPrinter."""
+ super().__init__(val, "ExplainGenerator::explainInterval")
+
+
+class PartialSchemaReqMapPrinter(OptimizerTypePrinter):
+ """Pretty-printer for mongo::optimizer::PartialSchemaRequirements."""
+
+ def __init__(self, val):
+ """Initialize PartialSchemaReqMapPrinter."""
+ super().__init__(val, "ExplainGenerator::explainPartialSchemaReqMap")
+
+
+class MemoPrinter(OptimizerTypePrinter):
+ """Pretty-printer for mongo::optimizer::cascades::Memo."""
+
+ def __init__(self, val):
+ """Initialize MemoPrinter."""
+ super().__init__(val, "ExplainGenerator::explainMemo")
+
+
+def register_abt_printers(pp):
+ """Registers a number of pretty printers related to the CQF optimizer."""
+
+ # ABT printer.
+ abt_type = gdb.lookup_type("mongo::optimizer::ABT").strip_typedefs()
+ pp.add('ABT', abt_type.name, True, ABTPrinter)
+
+ # IntervalRequirement printer.
+ pp.add("Interval", "mongo::optimizer::IntervalRequirement", False, IntervalPrinter)
+
+ # PartialSchemaRequirements printer.
+ schema_req_type = gdb.lookup_type(
+ "mongo::optimizer::PartialSchemaRequirements").strip_typedefs()
+ pp.add("PartialSchemaRequirements", schema_req_type.name, False, PartialSchemaReqMapPrinter)
+
+ # Memo printer.
+ pp.add("Memo", "mongo::optimizer::cascades::Memo", False, MemoPrinter)
+
+
def build_pretty_printer():
"""Build a pretty printer."""
pp = MongoPrettyPrinterCollection()
@@ -897,8 +961,7 @@ def build_pretty_printer():
pp.add('CodeFragment', 'mongo::sbe::vm::CodeFragment', False, SbeCodeFragmentPrinter)
# Optimizer/ABT related pretty printers that can be used only with a running process.
- abt_type = gdb.lookup_type("mongo::optimizer::ABT").strip_typedefs()
- pp.add('ABT', abt_type.name, True, ABTPrinter)
+ register_abt_printers(pp)
return pp
diff --git a/src/mongo/db/query/optimizer/explain.cpp b/src/mongo/db/query/optimizer/explain.cpp
index 07c770b92ba..8c5148e3e40 100644
--- a/src/mongo/db/query/optimizer/explain.cpp
+++ b/src/mongo/db/query/optimizer/explain.cpp
@@ -2272,6 +2272,13 @@ std::string ExplainGenerator::explainV2(const ABT& node,
return gen.generate(node).str();
}
+std::string ExplainGenerator::explainNode(const ABT& node) {
+ if (node.empty()) {
+ return "Empty\n";
+ }
+ return explainV2(node);
+}
+
std::pair<sbe::value::TypeTags, sbe::value::Value> ExplainGenerator::explainBSON(
const ABT& node,
const bool displayProperties,
@@ -2390,23 +2397,4 @@ std::string ExplainGenerator::explainIntervalExpr(const IntervalReqExpr::Node& i
return gen.printIntervalExpr(intervalExpr).str();
}
-std::string _printNode(const ABT& node) {
- if (node.empty()) {
- return "Empty\n";
- }
- return ExplainGenerator::explainV2(node);
-}
-
-std::string _printInterval(const IntervalRequirement& interval) {
- return ExplainGenerator::explainInterval(interval);
-}
-
-std::string _printLogicalProps(const properties::LogicalProps& props) {
- return ExplainGenerator::explainLogicalProps("Logical Properties", props);
-}
-
-std::string _printPhysProps(const properties::PhysProps& props) {
- return ExplainGenerator::explainPhysProps("Physical Properties", props);
-}
-
} // namespace mongo::optimizer
diff --git a/src/mongo/db/query/optimizer/explain.h b/src/mongo/db/query/optimizer/explain.h
index 5c79006143b..5cc0f29fafe 100644
--- a/src/mongo/db/query/optimizer/explain.h
+++ b/src/mongo/db/query/optimizer/explain.h
@@ -75,6 +75,8 @@ public:
const cascades::Memo* memo = nullptr,
const NodeToGroupPropsMap& nodeMap = {});
+ static std::string explainNode(const ABT& node);
+
static std::pair<sbe::value::TypeTags, sbe::value::Value> explainBSON(
const ABT& node,
bool displayProperties = false,
@@ -105,14 +107,4 @@ public:
static std::string explainIntervalExpr(const IntervalReqExpr::Node& intervalExpr);
};
-// Functions used by GDB for pretty-printing. For whatever reason GDB cannot find the static
-// methods of ExplainGenerator, while it can find the functions below.
-
-std::string _printNode(const ABT& node);
-
-std::string _printInterval(const IntervalRequirement& interval);
-
-std::string _printLogicalProps(const properties::LogicalProps& props);
-std::string _printPhysProps(const properties::PhysProps& props);
-
} // namespace mongo::optimizer