Datadog Database Monitoring Fundamentals free question 2 / 10 · Domain 1: Datadog Database Monitoring Fundamentals
Two queries show explain plan costs of 8.5 and 8.7 in Query Samples. A developer concludes that the first one performs better. How should this be read?
- Not necessarily, because cost is a unitless figure for relative comparisons
- Not so, because cost is reported for queries that have already finished with an error
- Correctly, because cost counts the rows returned and fewer rows means faster
- Correctly, because cost is measured in milliseconds so the lower number wins
Show the answer and explanation
Answer: A
Why this is correct
The documentation calls explain plan cost a unitless measure that the database uses to compare two plans with each other. It roughly corresponds to blocks or pages and is useful for relative comparisons, not absolute ones. Hence 8.5 is not necessarily better than 8.7, but vastly different costs for similar queries deserve investigation.
Why the other options are wrong
"Correctly, because cost is measured in milliseconds so the lower number wins" … Explain plan cost is unitless. It is not a duration, and it is not an absolute measure of how fast a single query runs.
"Correctly, because cost counts the rows returned and fewer rows means faster" … Cost roughly corresponds to things like blocks or pages on the database. Rows returned are a separate facet in Query Samples.
"Not so, because cost is reported for queries that have already finished with an error" … Cost is a property of a plan that the database uses to choose between plans. It is unrelated to whether a query errored.
Key points
Treat explain plan cost as a relative signal, not an absolute speed. Sorting by cost is still useful: it shows the most expensive plans separately from external factors such as network latency, which affect duration but not the plan cost. The documentation puts it this way: "Explain plan cost is a unitless measure that the database uses to compare two plans with each other." "A query with an explain plan cost of 8.5 is not necessarily performing better than one with a cost of 8.7."