I'm getting a 2013 Lost Connection to MySQL server During Query on MySQL hosted on an AWS instance. The query below is the only one that causes this error (other queries run fine), and this query also runs with no issues on my Synology Docker container running MySQL. The only unique thing I have identified is that this query uses a CTE and the others that run successfully do not. The AWS MySQL is 8.0.23 and the NAS Docker MySQL is 8.0.28. I have checked the first things such as max connections, timeouts, etc and the values in use for the AWS instance are the same or higher than the settings on the NAS Docker instance. I have also tried a smaller data table and reorganizing the data table to weed out the possibility of data corruption. I have been searching for a couple of days and have not been able to find any hints on what the issue is. Does anyone here have any suggestions about where I should look next? Thanks!
USE ce_test;
SET @lowlim = 0;
SET @upplim = 0;
with orderedList AS (
SELECT
576_VMC_Sol_Savings_Pct,
ROW_NUMBER() OVER (ORDER BY 576_VMC_Sol_Savings_Pct) AS row_n
FROM vmctco
),
quartile_breaks AS (
SELECT
576_VMC_Sol_Savings_Pct,
(
SELECT 576_VMC_Sol_Savings_Pct AS quartile_break
FROM orderedList
WHERE row_n = FLOOR((SELECT COUNT(*) FROM vmctco)*0.75)
) AS q_three_lower,
(
SELECT 576_VMC_Sol_Savings_Pct AS quartile_break
FROM orderedList
WHERE row_n = FLOOR((SELECT COUNT(*) FROM vmctco)*0.75) + 1
) AS q_three_upper,
(
SELECT 576_VMC_Sol_Savings_Pct AS quartile_break
FROM orderedList
WHERE row_n = FLOOR((SELECT COUNT(*) FROM vmctco)*0.25)
) AS q_one_lower,
(
SELECT 576_VMC_Sol_Savings_Pct AS quartile_break
FROM orderedList
WHERE row_n = FLOOR((SELECT COUNT(*) FROM vmctco)*0.25) + 1
) AS q_one_upper
FROM orderedList
),
iqr AS (
SELECT
576_VMC_Sol_Savings_Pct,
(
(SELECT MAX(q_three_lower)
FROM quartile_breaks) +
(SELECT MAX(q_three_upper)
FROM quartile_breaks)
)/2 AS q_three,
(
(SELECT MAX(q_one_lower)
FROM quartile_breaks) +
(SELECT MAX(q_one_upper)
FROM quartile_breaks)
)/2 AS q_one,
1.5 * ((
(SELECT MAX(q_three_lower)
FROM quartile_breaks) +
(SELECT MAX(q_three_upper)
FROM quartile_breaks)
)/2 - (
(SELECT MAX(q_one_lower)
FROM quartile_breaks) +
(SELECT MAX(q_one_upper)
FROM quartile_breaks)
)/2) AS outlier_range
FROM quartile_breaks
)
SELECT MAX(q_one) OVER () - MAX(outlier_range) OVER () AS lower_limit,
MAX(q_three) OVER () + MAX(outlier_range) OVER () AS upper_limit
INTO @lowlim, @upplim
FROM iqr
LIMIT 1;
SELECT @lowlim, @upplim;
SOLVED: I went ahead and updated the version on the AWS instance to the same version as the NAS (8.0.28) and the query runs correctly now.