Glostarep

Datadog’s New Feature Maps PostgreSQL Explain Plans to SQL in Real Time

Datadog’s New Feature Maps PostgreSQL Explain Plans to SQL in Real Time

Debugging a slow PostgreSQL query just got significantly easier. Datadog has introduced explain plan correlation inside Datadog Database Monitoring, a feature that links each explain plan node directly to the SQL clause it represents. Engineers no longer need to juggle two windows or manually trace the connection between a plan and a query.

PostgreSQL’s EXPLAIN ANALYZE command is a standard first step when a query runs slowly. However, complex queries with multiple joins and subqueries can produce 20 or more plan nodes. Until now, figuring out which node matched which SQL clause required manual detective work. A single misread could send the entire investigation off track.

With PostgreSQL explain plan correlation, that guesswork is gone. Hovering over any node in the plan tree highlights the matching clause in the SQL text. The reverse also works, clicking a clause in the SQL pane highlights its corresponding node. Furthermore, the mapping holds correctly across parameterized queries and table aliases, which are common sources of confusion.

The feature is available directly in the normalized query panel and on the Explain Plan Samples page inside Database Monitoring. Both views keep the plan and SQL side by side, so engineers stay in context throughout the investigation. A “View in Query” button inside the node tooltip also lets users jump straight to a matched clause, even deep inside a long query.

Datadog tested PostgreSQL explain plan correlation on their own internal Agent query to pg_stat_statements. The result was immediate: a Function Scan node stood out as the culprit, accounting for 73.3% of the total plan cost. Because the node mapped directly to the pg_stat_statements reference in the FROM clause, the source of the cost was instantly clear.

The explain plan correlation feature uses execution plan metadata, including table scans, join keys, filter conditions, and sort operations, to build the node-to-SQL mapping. This makes it precise even when the query structure is deeply nested.

Teams without a Datadog account can also try the node-to-SQL mapping using Datadog’s public explain plan visualizer by pasting any PostgreSQL plan and opening the Query Shape tab.

For full documentation, Datadog directs users to the Database Monitoring docs.

Leave a Comment

Your email address will not be published. Required fields are marked *