What is the primary purpose of collecting metrics in a database system?
Think about why you would want to watch how the database behaves over time.
Metrics collection helps track performance and identify issues early, ensuring smooth operation.
Given a metrics table with columns metric_name, value, and timestamp, what will this query return?
SELECT metric_name, AVG(value) FROM metrics WHERE timestamp > NOW() - INTERVAL '1 hour' GROUP BY metric_name;
Look at the AVG(value) and the time filter in the WHERE clause.
The query calculates the average value for each metric recorded within the last hour.
Which option contains a syntax error in this metrics collection SQL query?
SELECT metric_name, COUNT(*) FROM metrics GROUP BY metric_name HAVING COUNT(*) > 10;
Remember that WHERE cannot filter on aggregate functions like COUNT().
Option A incorrectly uses WHERE COUNT(*) > 10, which is invalid SQL syntax because WHERE cannot filter aggregates.
You have a large metrics table with millions of rows. Which index would best improve the performance of this query?
SELECT metric_name, AVG(value) FROM metrics WHERE timestamp > NOW() - INTERVAL '1 day' GROUP BY metric_name;
Think about which columns are used in filtering and grouping.
Indexing on (timestamp, metric_name) helps quickly filter by time and group by metric name efficiently.
A metrics collection system shows no data for the last hour, but older data exists. Which issue is most likely causing this?
Consider how timestamps affect filtering recent data.
If the system clock is wrong and timestamps are in the future, queries filtering for recent data won't find any matching rows.