After upgrade from 1.16.3 to 1.17.5 all of a sudden I am getting a bunch of DB Error #1139
Here is just one of them but most of them look similar.
[SELECT COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A1.`dept_id` = 8 AND B5.`value` REGEXP '\"?(?<![0-9])2(\"|,|$)' AND B5.`field_id` = 36 THEN A1.`ticket_id` END) AS `q16`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A1.`dept_id` = 8 AND B5.`value` REGEXP '\"?(?<![0-9])2(\"|,|$)' AND B5.`field_id` = 36 THEN A1.`ticket_id` END) AS `q17`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A1.`dept_id` = 8 AND B5.`value` REGEXP '\"?(?<![0-9])3(\"|,|$)' AND B5.`field_id` = 36 THEN A1.`ticket_id` END) AS `q18`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A1.`dept_id` = 8 AND B5.`value` REGEXP '\"?(?<![0-9])1(\"|,|$)' AND B5.`field_id` = 36 THEN A1.`ticket_id` END) AS `q19`, COUNT(DISTINCT CASE WHEN A2.`state` = 'open' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q1`, COUNT(DISTINCT CASE WHEN (A1.`team_id` IN (1) OR A1.`staff_id` IN (26)) AND A2.`state` = 'open' AND (A1.`team_id` IN (1) OR A1.`staff_id` IN (26)) AND A2.`state` = 'open' AND A1.`staff_id` IN (26) AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q6`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A2.`state` = 'closed' AND A1.`closed` BETWEEN '2024-03-01 00:00:00' AND '2024-03-01 23:59:59' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q9`, COUNT(DISTINCT CASE WHEN (A1.`team_id` IN (1) OR A1.`staff_id` IN (26)) AND A2.`state` = 'open' AND (A1.`team_id` IN (1) OR A1.`staff_id` IN (26)) AND A2.`state` = 'open' AND NOT A1.`staff_id` IN (26) AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q7`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A2.`state` = 'closed' AND A1.`closed` BETWEEN '2024-02-29 00:00:00' AND '2024-02-29 23:59:59' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q10`, COUNT(DISTINCT CASE WHEN (A1.`team_id` IN (1) OR A1.`staff_id` IN (26)) AND A2.`state` = 'open' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q5`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A2.`state` = 'closed' AND A1.`closed` BETWEEN '2024-02-26 00:00:00' AND '2024-03-03 23:59:59' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q11`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q8`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A2.`state` = 'closed' AND A1.`closed` BETWEEN '2024-03-01 00:00:00' AND '2024-03-31 23:59:59' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q12`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A2.`state` = 'closed' AND A1.`closed` BETWEEN '2024-01-01 00:00:00' AND '2024-03-31 23:59:59' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q13`, COUNT(DISTINCT CASE WHEN A2.`state` = 'closed' AND A2.`state` = 'closed' AND A1.`closed` BETWEEN '2024-01-01 00:00:00' AND '2024-12-31 23:59:59' AND A3.`object_type` = 'T' THEN A1.`ticket_id` END) AS `q14` FROM `ost_ticket` A1 JOIN `ost_ticket_status` A2 ON (A1.`status_id` = A2.`id`) LEFT JOIN `ost_thread` A3 ON (A3.`object_type` = 'T' AND A1.`ticket_id` = A3.`object_id`) LEFT JOIN `ost_thread_referral` A4 ON (A3.`id` = A4.`thread_id`) LEFT JOIN `ost_staff` A5 ON (A4.`object_type` = 'S' AND A4.`object_id` = A5.`staff_id`) LEFT JOIN `ost_thread` A6 ON (A1.`ticket_id` = A6.`object_id` AND A6.`object_type` = 'C') LEFT JOIN `ost_thread_referral` A7 ON (A6.`id` = A7.`thread_id`) LEFT JOIN `ost_staff` A8 ON (A7.`object_type` = 'S' AND A7.`object_id` = A8.`staff_id`) LEFT JOIN `ost_team` B0 ON (A4.`object_type` = 'E' AND A4.`object_id` = B0.`team_id`) LEFT JOIN `ost_team` B1 ON (A7.`object_type` = 'E' AND A7.`object_id` = B1.`team_id`) LEFT JOIN `ost_department` B2 ON (A4.`object_type` = 'D' AND A4.`object_id` = B2.`id`) LEFT JOIN `ost_department` B3 ON (A7.`object_type` = 'D' AND A7.`object_id` = B3.`id`) JOIN `ost_form_entry` B4 ON (B4.`object_type` = 'T' AND A1.`ticket_id` = B4.`object_id`) LEFT JOIN `ost_form_entry_values` B5 ON (B4.`id` = B5.`entry_id`) WHERE ((A2.`state` = 'open' AND (A1.`staff_id` = 26 OR A5.`staff_id` = 26 OR A6.`object_type` = 'C' AND A8.`staff_id` = 26 OR A1.`team_id` IN (1) OR B0.`team_id` IN (1) OR A6.`object_type` = 'C' AND B1.`team_id` IN (1))) OR (A2.`state` IN ('open', 'closed') AND (A1.`dept_id` IN (8, 9) OR B2.`id` IN (8, 9))) OR A6.`object_type` = 'C' AND B3.`id` IN (8, 9))]