optimize this mysql query for the maximum performance and avoid redundancy WITH result…
- User
optimize this mysql query for the maximum performance and avoid redundancy WITH result AS ( ( WITH t1 AS ( SELECT tar.analysis_id, NULL AS analysis_err_id, COALESCE(trim(REGEXP_REPLACE(tdui.device_name, '[[:space:]]+', ' ')), '') AS d_device_name, COALESCE(trim(REGEXP_REPLACE(tcui.device_name, '[[:space:]]+', ' ')), '') AS c_device_name, tcri.recipe_no AS recipe_no, COALESCE(trim(REGEXP_REPLACE(tar.measure_hash, '[[:space:]]+', ' ')), '') AS measure_hash, pj.carrier_id AS carrier_id, mpp.lot_id,
COALESCE(trim(REGEXP_REPLACE(tad.wafer_no, '[[:space:]]+', ' ')), '') AS wafer_no, tad.start_date as add_date, COALESCE(trim(REGEXP_REPLACE(tcri.remark, '[[:space:]]+', ' ')), '') AS remark, tar.result, twi.defect_num, COALESCE(trim(REGEXP_REPLACE(tar.pm_time, '[[:space:]]+', ' ')), '') AS pm_time, COALESCE(trim(REGEXP_REPLACE(tar.recovery_time, '[[:space:]]+', ' ')), '') AS recovery_time, COALESCE(trim(REGEXP_REPLACE(tad.mtbc, '[[:space:]]+', ' ')), '') AS mtbc, COALESCE(trim(REGEXP_REPLACE(tad.mwbc, '[[:space:]]+', ' ')), '') AS mwbc, date_format(twi.ls_result_timestamp,'%Y-%m-%d %T') AS ls_result_timestamp, twi.seqno, COALESCE(trim(REGEXP_REPLACE(tar.memo, '[[:space:]]+', ' ')), '') AS memo, me.error_ref_key, tar.error_param, tar.error_id FROM dfa_new.t_analysis_result AS tar INNER JOIN dfa_new.t_project_history AS tph ON tar.pj_history_id = tph.pj_history_id LEFT JOIN dfa_new.m_error AS me ON me.error_id = substring_index(tar.error_id, ',', 1) LEFT JOIN dfa_new.t_asm_detail tad ON tar.asm_id = tad.asm_idcode - Assistant