Fix(mysql): SYSDATE()를 NOW()로 변경하여 타임스탬프 일관성 보장 #111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
수정 사유 Reason for modification
MySQL에서
SYSDATE()
함수는 호출되는 시점의 시간을 반환하여, 단일 SQL문 내에서도 지연이 발생할 경우 타임스탬프가 다르게 기록될 수 있는 잠재적인 데이터 불일치 문제를 가지고 있습니다.이를 문장의 시작 시간을 기준으로 일관된 타임스탬프를 반환하는
NOW()
함수로 변경하여 데이터 정합성을 보장하도록 수정합니다.근거 자료: MySQL 공식 문서
이러한 동작 방식의 차이는 MySQL 8.4 공식 레퍼런스 문서에도 명시되어 있습니다.
Reference: [MySQL 8.4 Manual / Date and Time Functions]
공식 문서 예제:
수정된 소스 내용 Modified source
EgovBoard_SQL_mysql.xml
insertBoardArticle
,deleteBoardArticle
등 여러 쿼리에서 사용되던SYSDATE()
를NOW()
로 모두 변경하여 일관성을 확보했습니다.BbsTimestampConsistencyTest.java
(신규 테스트)SYSDATE()
와NOW()
가 단일 SQL문 내에서 어떻게 다르게 동작하는지 명확하게 증명하는 JUnit 테스트 코드를 추가했습니다.JUnit 테스트 JUnit tests
테스트 결과 및 증명
공식 문서의 예제와 동일한 원리를 JUnit 테스트로 증명했습니다. 단일 SQL문 내에서 1초의 지연(
SLEEP(1)
)을 두고 각 함수의 반환값을 비교한 결과,SYSDATE()
는 시간이 변경되고NOW()
는 시간이 고정됨을 확인했습니다.테스트 실행 결과 로그:
테스트 환경 정보
테스트는 Docker를 사용한 임시 MySQL 8.0 데이터베이스 환경에서 진행했습니다.
테스트 브라우저 Test Browser
이번 수정은 백엔드 로직 개선에 해당하므로 브라우저 테스트는 진행하지 않았습니다.
테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video