Given a C++ codebase simulating execution of a complex SQL query with multiple joins and aggregations that runs in ~20 seconds, optimize it to run below 5 seconds.
Asked in the Round 4: Query Optimization stage. For this SQL exercise, return enabled queries whose total CPU time is at least 100 milliseconds.
query_name, step_count, total_rows_processed, total_cpu_ms, and peak_memory_mb.total_cpu_ms descending, then query_id ascending for ties.| Column | Type | Description |
|---|---|---|
| query_idPK | INTEGER | Unique simulated query identifier |
| query_name | VARCHAR(100) | Descriptive query name |
| is_enabled | BOOLEAN | Whether the query is enabled |
| Column | Type | Description |
|---|---|---|
| step_idPK | INTEGER | Unique execution step identifier |
| query_id | INTEGER | Referenced query |
| step_name | VARCHAR(100) | Name of the execution step |
| step_order | INTEGER | Execution position within the query |
| Column | Type | Description |
|---|---|---|
| metric_idPK | INTEGER | Unique metric sample identifier |
| step_id | INTEGER | Referenced execution step |
| rows_processed | BIGINT | Rows processed in the metric sample |
| cpu_ms | NUMERIC(12,2) | CPU time in milliseconds |
| memory_mb | NUMERIC(12,2) | Peak memory usage in megabytes |