MySql 8.0.32 Cannot convert string from utf8mb4 to binary 버그

bestKimEver·2024년 4월 2일
0

상황

Spring + MySQL (+ MyBatis) 환경에서 view에 있는 컬럼을 대상으로 조건문에 한글을 사용해 SELECT 문 실행 시 Cannot convert string from utf8mb4 to binary오류가 뜨거나, 확실히 1건 이상의 검색 결과가 있어야 함에도 불구하고 검색이 되지 않는 오류가 발생했다.

예시 1: 한글 LIKE 검색

  • 실행한 쿼리
SELECT 
	ARTICLE.ARTICLE_ID,
    ARTICLE.ARTICLE_TITLE
FROM
	VIEW_ARTICLE ARTICLE
WHERE
	ARTICLE.ARTICLE_TITLE LIKE CONCAT('%', '테스트', '%')
  • 결과
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary

예시 2: 한글 = 검색

  • 실행한 쿼리
SELECT 
	ARTICLE.ARTICLE_ID,
    ARTICLE.ARTICLE_TITLE,
    MEMBER.MEMBER_ID,
    MEMBER.MEMBER_NAME
FROM
	VIEW_ARTICLE ARTICLE
    LEFT OUTER JOIN VIEW_MEMBER MEMBER
    	ON ARTICLE.WRITER_ID = MEMBER.MEMBER_ID
WHERE
	MEMBER.MEMBER_NAME = '관리자'
  • 결과
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary
Cannot convert string '\xEA\xB4...' from utf8mb4 to binary

해결

MySql 8.0.32 버전에만 존재하는 버그로, SHOW VARIABLES LIKE 'version';문 실행 시 나오는 버전이 해당 버전이라면 다음과 같은 방법을 통해 조치할 수 있다. 이후 버전에서는 수정되었다고 한다.

SELECT문 실행 전 SET optimizer_switch='derived_condition_pushdown=off'; 문 실행

해당 버그 리포트는 다음 버그와 중복되는 내용이라고 한다.
MySQL Bug Report

  • 꼭 view에 국한되는 문제는 아니며, 대충 'SELECT 문을 실행하면서 파생 테이블을 생성할 때 ASCII 범위를 넘어가는 문자들이 utfmb4로 정상적으로 변환되지 않아 생긴 문제'라는 것 같다. 세계 인구 중 ASCII 범위 외의 문자를 이용하는 사람들이 대다수라는 것을 영어가 모국어인 개발자들이 항상 기억해 줬음 좋겠다...

Documented fix as follows in the MySQL 8.0.33 changelog:

When cloning a condition to push down to a derived table,
characters in strings representing conditions were converted to
utfmb4 correctly only for values less than 128 (the ASCII
subset), and code points outside the ASCII subset were converted
to invalid characters, causing the resulting character strings
to become invalid. For derived tables without UNIONS, this led
to problems when a column name from the derived table used
characters outside the ASCII subset, and was used in the WHERE
condition. For derived tables with UNIONS it created problems
when a character outside the ASCII subset was present in a WHERE
condition.

We fix these issues by initializing the string used in such
cases for representing the condition to the connection character
set.

Closed.

Posted by developer:

As a workaround, set derived condition pushdown to off like this:

set optimizer_switch="derived_condition_pushdown=off";

profile
이제 3년차 개발새발자. 제가 보려고 정리해놓는 글이기 때문에 다소 미흡한 내용이 많습니다.

0개의 댓글