Expiring Deals

WordPress database error: [Lost connection to MySQL server during query]
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) LEFT JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id ) LEFT JOIN wp_postmeta AS mt2 ON ( wp_posts.ID = mt2.post_id ) LEFT JOIN wp_postmeta AS mt3 ON (wp_posts.ID = mt3.post_id AND mt3.meta_key = 'registered_members_only' ) WHERE 1=1 AND ( wp_postmeta.meta_key = 'expiring_date' AND ( ( ( mt1.meta_key = 'expiring_date' AND CAST(mt1.meta_value AS UNSIGNED) >= '20190520' ) OR ( mt1.meta_key = 'expiring_date' AND mt1.meta_value = '' ) ) AND ( ( mt2.meta_key = 'registered_members_only' AND CAST(mt2.meta_value AS UNSIGNED) = '' ) OR mt3.post_id IS NULL ) ) ) AND wp_posts.post_type = 'deal' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value ASC LIMIT 0, 30