The reason why is that there is no complexity to your code. Here's a query you can run on 20 rows that will take hours to get your first result:
WITH RECURSIVE MatrixGen AS (
-- Generate a recursive matrix-like structure based on col1 values
SELECT
col1 AS base_value,
1 AS iteration,
col2 AS derived_value
FROM spreadsheet
WHERE col1 IS NOT NULL
UNION ALL
SELECT
m.base_value,
m.iteration 1,
s.col2 * m.iteration SIN(m.base_value) * COS(s.col3)
FROM MatrixGen m
JOIN spreadsheet s ON m.base_value = s.col1
WHERE m.iteration < 50 -- Arbitrary depth to increase computation
),
AggregatedLayers AS (
-- Multiple self-joins with complex conditions and window functions
SELECT
s1.col1,
s1.col2,
s2.col3,
s3.col4,
SUM(s1.col5 * s2.col6 * s3.col7) OVER (PARTITION BY s1.col1 ORDER BY s2.col2 ROWS BETWEEN 10 PRECEDING AND 10 FOLLOWING) AS sliding_sum,
RANK() OVER (PARTITION BY s3.col4 ORDER BY s2.col3 DESC) AS rank_col3,
(SELECT AVG(s4.col8 s5.col9)
FROM spreadsheet s4
JOIN spreadsheet s5 ON s4.col10 = s5.col11
WHERE s4.col1 = s1.col1 AND s5.col2 > s2.col2) AS nested_avg
FROM spreadsheet s1
LEFT JOIN spreadsheet s2 ON s1.col1 = s2.col1 AND s1.col2 > s2.col3 LN(ABS(s2.col4) 1)
INNER JOIN spreadsheet s3 ON s2.col2 = s3.col3 AND s3.col5 BETWEEN s1.col6 AND s2.col7
CROSS JOIN MatrixGen mg
WHERE mg.iteration > 10 AND s1.col1 != s3.col4
),
FinalComputation AS (
-- Introduce trigonometric functions, string manipulations, and more joins
SELECT
a.col1,
a.col2,
a.col3,
a.col4,
a.sliding_sum,
a.rank_col3,
a.nested_avg,
EXP(a.col2) * TAN(a.col3) * POWER(a.col4, 3) AS complex_calc,
STRING_AGG(
CAST(a.col1 AS VARCHAR) || '-' ||
SUBSTRING(CAST(mg.derived_value AS VARCHAR) FROM 1 FOR 5),
','
) OVER (PARTITION BY a.col1) AS concatenated_string,
COUNT(*) OVER (PARTITION BY a.col4 ORDER BY a.col3) AS running_count
FROM AggregatedLayers a
JOIN MatrixGen mg ON a.col1 = mg.base_value
JOIN spreadsheet s6 ON mg.derived_value BETWEEN s6.col12 AND s6.col13
WHERE a.sliding_sum > (SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY col14) FROM spreadsheet)
)
SELECT
f.col1,
f.col2,
f.col3,
f.col4,
f.sliding_sum,
f.rank_col3,
f.nested_avg,
f.complex_calc,
f.concatenated_string,
f.running_count,
(SELECT STDDEV(s7.col15 * s8.col16)
FROM spreadsheet s7
JOIN spreadsheet s8 ON s7.col17 = s8.col18
WHERE s7.col1 = f.col1 AND s8.col2 < f.col2) AS stddev_layer
FROM FinalComputation f
JOIN spreadsheet s9 ON f.col1 = s9.col19 AND f.col3 < s9.col20
WHERE f.complex_calc > 1000
ORDER BY f.running_count DESC, f.sliding_sum ASC;