Skip to main content

Module profiling

Module profiling 

Source
Expand description

Query profiling support for DuckDB.

This module provides access to DuckDB’s query profiling infrastructure, allowing you to inspect per-operator metrics for executed queries.

§Usage

Profiling must be explicitly enabled on a connection before metrics are collected. Use the enable_profiling and profiling_mode PRAGMAs to configure it:

let conn = Connection::open_in_memory().unwrap();

// Prevents DuckDB from printing profiling output to stdout after each query,
// which is the default behavior when profiling is enabled.
conn.execute("PRAGMA enable_profiling = 'no_output'", []).unwrap();

// Enables standard profiling mode, which collects a comprehensive set of metrics for each operator in the query plan.
// There is also `detailed` mode for even more fine-grained metrics. See DuckDB's documentation for more details.
conn.execute("PRAGMA profiling_mode = 'standard'", []).unwrap();

// Now we can execute a query and retrieve its profiling info.
conn.execute("SELECT 42", []).unwrap();

let info = conn.get_profiling_info().expect("profiling should be enabled");
println!("rows returned: {}", info.metrics["ROWS_RETURNED"]);

§Structure

ProfilingInfo is a tree that mirrors DuckDB’s query plan. The root node (QUERY_ROOT) holds metrics for the entire query (e.g. total LATENCY and ROWS_RETURNED). Each child node represents a plan operator and carries its own metrics such as OPERATOR_NAME and OPERATOR_CARDINALITY.

Structs§

ProfilingInfo
ProfilingInfo is a recursive type containing metrics for each node in DuckDB’s query plan. There are two types of nodes: the “QUERY_ROOT” and “OPERATOR” nodes. The “QUERY_ROOT” refers exclusively to the top-level node; its metrics are measured over the entire query. The “OPERATOR” nodes refer to the individual operators in the query plan.