set @lst := NULL;
set @grp := 0;
SELECT MAX(grp.cnt) AS max_range
FROM (
SELECT COUNT( rp.grp) AS cnt
FROM (
SELECT
MIN(r1.id) AS r1_id,
MIN(r1.num) AS r1_num,
MIN(r2.num) AS r2_num,
if ( r1.num > @lst + 1, @grp := @grp + 1, @grp) AS grp,
@lst := r1.num AS lst
FROM testing.integer_range as r1
JOIN testing.integer_range AS r2 ON r1.num = r2.num + 1 OR r1.num = r2.num - 1
GROUP BY r1.num
ORDER BY r1.num ASC
) AS rp
GROUP BY rp.grp
) AS grp;