With friends like this…
As part of a larger piece of work I wrote a SQL query on a 1 billion row table to calculate some aggregates on a subset of the data, to get timings to compare to Rust and Bash versions of the same query.
It took 0.8 seconds to run and delivered a single row containing the aggregated data.
-- This took 0.08s to run
with cteLimit as (
select * from loadschema.t_nameaddr_flat LIMIT 10_000
)
select avg(salary) as salavg, min(salary) as salmin, max(salary) as salmax
from cteLimit;
As I couldn’t see any non-server configuration improvements, I asked CoPilot if it had any SQL recommendations to speed this up.
It did and it did so cosmically badly.
It chose to run the query on the entire data set, then limit the single result row to 1,000 rows (?!).
-- With CoPilot's help, this one took 59,000 times longer.
SELECT
AVG(salary) AS salavg,
MIN(salary) AS salmin,
MAX(salary) AS salmax
FROM loadschema.t_nameaddr_flat
LIMIT 1000;
It was 59,000 times slower.
Be careful what you wish for.