Skip to content

[Bug]: LIKE underscore wildcard does not match one multibyte utf8mb4 character #27389

Closed

Description

@iamlinjunhong

Problem

For utf8mb4 strings, MatrixOne evaluates the SQL LIKE underscore wildcard byte-wise (or ASCII-only) instead of character-wise. A one-character Chinese, emoji, or accented string does not match _, while a one-character ASCII string does.

This is visible through MatrixOne ODBC and reproduces identically with a direct MySQL CLI, so it is a server issue rather than an ODBC conversion issue.

Versions and environment

  • MatrixOne commit: 592ad2190a90e063e3877059f4018427a10a4998 (latest main tested on 2026-08-20)
  • MatrixOne ODBC source commit: 8f1ca365289a0f8ea0d22e6581cce1ea4ae67454
  • Installed preview driver used by pyodbc: MatrixOne ODBC 9.7 Unicode Driver, file version 9.7.0.0 (v9.7.0-mo.3)
  • OS: Windows 11 x64 client; Ubuntu 24.04 under WSL2 server
  • Clients: Python 3.12.13 + pyodbc 5.3.0; direct MySQL 9.7.1 CLI

Minimal reproduction

create database if not exists odbc_like_repro;
use odbc_like_repro;
drop table if exists t;
create table t(id int primary key, v varchar(40));
insert into t values
  (1,'🙂'),
  (2,'中'),
  (3,'é'),
  (4,'A');

select id,v,hex(v),char_length(v) from t order by id;
select id from t where v like '_' order by id;

The ODBC scenario executes the same predicate through SQLExecDirectW; no client-side wildcard expansion is involved.

Actual result

CHAR_LENGTH(v) is 1 for all four rows, but LIKE '_' returns only:

id
4

The same test also confirmed that LIKE ... ESCAPE works for literal _ and %, so the failure is specific to wildcard character width.

Expected result

The query should return ids 1,2,3,4. MySQL defines _ as matching one character, and these are all one-character utf8mb4 strings.

MySQL reference: https://dev.mysql.com/doc/refman/8.0/en/pattern-matching.html

Evidence

  • ODBC scenario result: server-scenarios-round3.json, R309
  • Direct SQL: server-candidate-repros-round3.sql, marker UNICODE_LIKE
  • Direct result: direct-mysql-candidate-repros-round3.log

Workaround

For a predicate consisting only of _ wildcards, an application can use CHAR_LENGTH(v) = n. There is no straightforward equivalent workaround for general mixed %/_ patterns without rewriting the match logic.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions