Development
Detailed Profiling
When the `profiling_mode` is set to `detailed`, an extra set of metrics are enabled, which are only available in the `QUERY_ROOT` node.
These include [`OPTIMIZER`](#::optimizer-metrics), [`PLANNER`](#::planner-metrics), and [`PHYSICAL_PLANNER`](#::physical-planner-metrics) metrics.
They are measured in seconds and returned as a `double`.
It is possible to toggle each of these additional metrics individually.  
#### Optimizer Metrics {#docs:dev:profiling::optimizer-metrics}  
At the `QUERY_ROOT` node, there are metrics that measure the time taken by each [optimizer](#docs:internals:overview::optimizer).
These metrics are only available when the specific optimizer is enabled.
The available optimizations can be queried using the [`duckdb_optimizers() table function`](#docs:sql:meta:duckdb_table_functions::duckdb_optimizers).  
Each optimizer has a corresponding metric that follows the template: `OPTIMIZER_⟨OPTIMIZER_NAME⟩`.
For example, the `OPTIMIZER_JOIN_ORDER` metric corresponds to the `JOIN_ORDER` optimizer.  
Additionally, the following metrics are available to support the optimizer metrics:  
* `ALL_OPTIMIZERS`: Enables all optimizer metrics and measures the time the optimizer parent node takes.
* `CUMMULATIVE_OPTIMIZER_TIMING`: The cumulative sum of all optimizer metrics. It is usable without turning on all optimizer metrics.  
#### Planner Metrics {#docs:dev:profiling::planner-metrics}  
The planner is responsible for generating the logical plan. Currently, DuckDB measures two metrics in the planner:  
* `PLANNER`: The time to generate the logical plan from the parsed SQL nodes.
* `PLANNER_BINDING`: The time taken to bind the logical plan.  
#### Physical Planner Metrics {#docs:dev:profiling::physical-planner-metrics}  
The physical planner is responsible for generating the physical plan from the logical plan.
The following are the metrics supported in the physical planner:  
* `PHYSICAL_PLANNER`: The time spent generating the physical plan.
* `PHYSICAL_PLANNER_COLUMN_BINDING`: The time spent binding the columns in the logical plan to physical columns.
* `PHYSICAL_PLANNER_RESOLVE_TYPES`: The time spent resolving the types in the logical plan to physical types.
* `PHYSICAL_PLANNER_CREATE_PLAN`: The time spent creating the physical plan.