안녕하세요. 저는 개발자입니다. 현재 사이트에서 deadlock이 너무 빈번하게 일어나서 질문을 드립니다. 아래 query는 5초에 한번씩 조회 하는 쿼리인데, 회사의 DBA분은 실제 update 대상이 얼마 없기 때문에 아래 쿼리 때문에 deadlock이 발생하는 건 아닐것이다 라고 말을 합니다. 궁금한것은 설사 from 대상이 없더라도 select가 table을 스캔하는 행위 자체도 영향이 있을거란 생각이거든요. from절에서 대상이 되는 ordno 가 없을때는 전혀 영향이 없을 거라는 건데 그게 맞는 것일까요? update ordmst om set om.pantype = 2 where om.shopno=ifnull(NULL,1) and om.ordno in ( select ordno from ( select omm.OrdNo , ifnull(json_extract(omm.RefJson, '$.pauto.pautono'), '') wai_pautono , ifnull(json_extract(omm.RefJson, '$.pauto.presetno'), '') wai_presetno from ordmst omm where omm.shopno=ifnull(NULL,1) and omm.RokDT > current_timestamp() - interval 1 day and omm.PanType in (4) and omm.jobstat = 101 ) uwai where uwai.wai_pautono = ifnull('88' , '-99999') and uwai.wai_presetno = ifnull('35', '-99999') )
락은 잘 모르겠고...
일단. 쿼리가 너무 복잡하네요.
불필요한 서브쿼리 제거했습니다.
UPDATE ordmst SET pantype = 2 WHERE shopno = IFNULL(NULL, 1) AND RokDT > current_timestamp() - INTERVAL 1 DAY AND PanType IN (4) AND jobstat = 101 AND IFNULL(json_extract(RefJson, '$.pauto.pautono' ), '') = IFNULL('88', '-99999') AND IFNULL(json_extract(RefJson, '$.pauto.presetno'), '') = IFNULL('35', '-99999') ;