Skip to content

[Bug]: SOUNDEX uses a fixed four-character algorithm unlike MySQL #28212

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

#22944 and #23000 were closed feature requests from before SOUNDEX() was implemented.

Branch Name

main

Commit ID

e7bb0572235ec4bac81eb098eb0ad8900f0065ab

Other Environment Information

  • Local standalone MatrixOne; MySQL text protocol
  • Reference: MySQL 8.3.0

Actual Behavior

The implemented SOUNDEX() uses a fixed four-character algorithm that differs from MySQL's enhanced Soundex and mishandles the first letter's code:

SELECT SOUNDEX('Ashcraft'), SOUNDEX('Pfister'), SOUNDEX('Tymczak');
-- MatrixOne: A261,  P123, T520
-- MySQL:    A2613, P236, T520

SELECT SOUNDEX(''), SOUNDEX('123');
-- MatrixOne: 0000, 0000
-- MySQL:    '',   ''

The same behavior occurs for column values and was reproduced three times.

Expected Behavior

SOUNDEX() must follow MySQL's enhanced Soundex result contract, including variable-length codes, first-letter duplicate suppression, and an empty result when no input character can seed a code.

Steps to Reproduce

SELECT SOUNDEX('Ashcraft'), SOUNDEX('Pfister'), SOUNDEX('Tymczak');
SELECT SOUNDEX(''), SOUNDEX('123');

Additional information

SoundexString caps the builder at four bytes, pads every nonempty path to four bytes, returns 0000 when no ASCII letter exists, and initializes the previous digit to zero instead of the first letter's Soundex digit.

Activity

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. self-assigned this
    on Sep 5, 2026
  5. XuPeng-SH commented on Sep 12, 2026

    @XuPeng-SH
    Contributor

    Design clarification for the fix

    One terminology correction before implementation: the issue calls the target “enhanced Soundex”, but MySQL's manual says SOUNDEX() implements the original algorithm, not the enhanced variant: https://dev.mysql.com/doc/refman/8.4/en/string-functions.html. The MySQL 8.3 examples recorded in this issue remain valid acceptance criteria; I will implement those actual outputs, including vowel/H/W discard-before-duplicate behavior, rather than follow the incorrect label.

    Source trace confirms three concrete causes in SoundexString: output is capped at four characters, all nonempty results are padded to four (and no-letter input becomes 0000), and duplicate tracking starts at zero rather than the retained first letter's code. The current full-string Unicode uppercase also creates an avoidable copy; the focused fix will scan ASCII case-insensitively without introducing an unrelated Unicode/transliteration redesign.

    The existing overloads return generic VARCHAR and the executor appends actual varlena lengths. I will add an executor/public-SQL control with a TEXT input whose result exceeds 65,535 bytes before considering any result-type metadata change.

    No PR exists yet. The fix is being developed in an isolated branch; local CGo test execution remains subject to the previously recorded native-artifact provenance prerequisite, and will not be bypassed.

  6. XuPeng-SH commented on Sep 12, 2026

    @XuPeng-SH
    Contributor

    Fix submitted: PR #28760

    PR: #28760
    Commit: ba258866cc55d14ad34d19f2c3d14ff5f7a064cf

    The fix follows the MySQL 8.3 outputs recorded above. One wording correction is important: MySQL documents SOUNDEX() as the original Soundex algorithm, not the enhanced variant; the original algorithm discards vowels/code-zero characters before duplicate suppression. Reference: https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_soundex.

    The implementation now suppresses a consonant code matching the first retained letter, preserves variable-length results, returns empty for empty/no-letter input, and pads only non-empty results shorter than four. It keeps the existing SQL wrapper and VARCHAR overload metadata. Tests cover issue examples, discarded-character duplicate behavior, NULL/empty/no-letter cases, vector/column/CHAR/prepared paths, capacity growth, and a 65,538-byte TEXT result.

    Performance review rejected an exact-reservation optimization: it cut allocations for dense long output but slowed it, and nearly doubled CPU on a sparse 8,201-byte input with only nine output bytes and no allocation-count benefit. The submitted code uses one streaming pass and grows output only as codes are emitted.

    Validation so far: formatting, diff checks, and incremental golangci-lint passed (0 issues). molint exited 0 with its existing diagnostic in unchanged byte_like_wildcard_search.go:17. Local Go UT/BVT were not run: the supported CGo wrapper is blocked by missing native-artifact provenance, and unrelated active MatrixOne services prevent safe local BVT. The PR's UT/BVT checks are pending; no runtime pass is claimed. The long SQL test checks exact server-side length/content, not a 65KB client result field. The change targets ASCII compatibility and does not add Unicode transliteration.

  7. added a commit that references this issue on Sep 12, 2026
    0d701bb
  8. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:07b25969bfea9d4b76d3bf05d5b0497e4f36eba0
    • 部署:本地独立 1 CN / 1 TN / 1 LogService;每轮均重新启动服务后执行。
    • 执行:每项 SQL 回归连续 3 轮,输出逐轮一致。

    原问题验证

    • SOUNDEX 不再固定为四字符算法。

    Happy Path 覆盖

    • 覆盖 alphabetic 输入,A2613、P236、T520 等结果符合可变长度算法。

    Unhappy Path 覆盖

    • 覆盖空串和纯数字输入,均返回空结果而不会异常。

    白盒验证

    • 以 MOTR 固定正常及空输入输出。

    回归测试

    测试证据

    • 以上结果均在该 main commit 的独立环境获得;每轮无 stderr,三轮结果一致。

    测试结论

    测试通过。

  9. added 3 commits that reference this issue on Sep 17, 2026
    fa0af88
    5dad47e
    7d27c67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions