Skip to content

fix(function): prevent md5 truncation for text and blob - #27883

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
Lundomn:codex/fix-md5-large-object-27798
Aug 31, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
Lundomn:codex/fix-md5-large-object-27798

Conversation

@Lundomn

@Lundomn Lundomn commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

close #27798

What this PR does / why we need it:

MD5 only registered a T_varchar overload. Stored LONGTEXT and LONGBLOB values were therefore implicitly converted to VARCHAR before hashing, truncating inputs at 65,535 bytes.

This PR:

  • registers direct T_text and T_blob overloads that reuse the existing Md5 implementation;
  • adds a unit regression that verifies both types avoid implicit casts and hash the complete 65,536-byte value;
  • adds distributed SQL regression cases for LONGTEXT and LONGBLOB.

The existing T_varchar overload, return type, digest implementation, SQL schema, and protocol behavior remain unchanged. No dependency or configuration changes are introduced.

Testing

On the final branch based on matrixorigin/main@4dedea1ebe391c55715d324804ba4cd6ab1e4f08:

  • go test -vet=off ./pkg/sql/plan/function -run TestMd5 -count=1
    • PASS: ok github.com/matrixorigin/matrixone/pkg/sql/plan/function 1.542s
  • the same test with -coverprofile
    • PASS: package coverage 0.6% for the targeted test selection; Md5 function coverage 100.0%
  • git diff --check origin/main...HEAD
    • PASS

Before the final main sync, the same patch was also built as an independent mo-service and exercised with the exact 65,536-byte SQL reproduction. MatrixOne returned 2d61aa54b58c2e94403fb092c3dbc027 for both stored LONGBLOB and LONGTEXT, matching MySQL 8.0.42.

Not run: full repository test suite, race, lint, vet, or the complete mo-tester distributed suite.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep-reviewed exact head 9c46d67. The root cause and fix boundary match: stored LONGTEXT and LONGBLOB previously took the sole VARCHAR overload and could truncate at 65,535 bytes; direct TEXT and BLOB overloads now reuse the byte-oriented MD5 executor without changing digest, NULL, return-type, or protocol behavior. The focused test proves no implicit cast and the complete 65,536-byte digest for both physical types, while BVT compares stored-column output with an independently constructed full-length expression. I found no blocking correctness, performance, or unhappy-path issue.

@XuPeng-SH

Copy link
Copy Markdown
Contributor

@Mergifyio Refresh

@mergify

mergify Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Refresh

❌ Sorry but I didn't understand the command. Please consult the commands documentation 📚.

@mergify mergify Bot added the kind/bug Something isn't working label Aug 31, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#27883)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

close matrixorigin#27798

## What this PR does / why we need it:

`MD5` only registered a `T_varchar` overload. Stored `LONGTEXT` and
`LONGBLOB` values were therefore implicitly converted to `VARCHAR`
before hashing, truncating inputs at 65,535 bytes.

This PR:

- registers direct `T_text` and `T_blob` overloads that reuse the
existing `Md5` implementation;
- adds a unit regression that verifies both types avoid implicit casts
and hash the complete 65,536-byte value;
- adds distributed SQL regression cases for `LONGTEXT` and `LONGBLOB`.

The existing `T_varchar` overload, return type, digest implementation,
SQL schema, and protocol behavior remain unchanged. No dependency or
configuration changes are introduced.

## Testing

On the final branch based on
`matrixorigin/main@4dedea1`:

- `go test -vet=off ./pkg/sql/plan/function -run TestMd5 -count=1`
- PASS: `ok github.com/matrixorigin/matrixone/pkg/sql/plan/function
1.542s`
- the same test with `-coverprofile`
- PASS: package coverage 0.6% for the targeted test selection; `Md5`
function coverage 100.0%
- `git diff --check origin/main...HEAD`
  - PASS

Before the final main sync, the same patch was also built as an
independent `mo-service` and exercised with the exact 65,536-byte SQL
reproduction. MatrixOne returned `2d61aa54b58c2e94403fb092c3dbc027` for
both stored `LONGBLOB` and `LONGTEXT`, matching MySQL 8.0.42.

Not run: full repository test suite, race, lint, vet, or the complete
mo-tester distributed suite.

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#27883)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

close matrixorigin#27798

## What this PR does / why we need it:

`MD5` only registered a `T_varchar` overload. Stored `LONGTEXT` and
`LONGBLOB` values were therefore implicitly converted to `VARCHAR`
before hashing, truncating inputs at 65,535 bytes.

This PR:

- registers direct `T_text` and `T_blob` overloads that reuse the
existing `Md5` implementation;
- adds a unit regression that verifies both types avoid implicit casts
and hash the complete 65,536-byte value;
- adds distributed SQL regression cases for `LONGTEXT` and `LONGBLOB`.

The existing `T_varchar` overload, return type, digest implementation,
SQL schema, and protocol behavior remain unchanged. No dependency or
configuration changes are introduced.

## Testing

On the final branch based on
`matrixorigin/main@4dedea1`:

- `go test -vet=off ./pkg/sql/plan/function -run TestMd5 -count=1`
- PASS: `ok github.com/matrixorigin/matrixone/pkg/sql/plan/function
1.542s`
- the same test with `-coverprofile`
- PASS: package coverage 0.6% for the targeted test selection; `Md5`
function coverage 100.0%
- `git diff --check origin/main...HEAD`
  - PASS

Before the final main sync, the same patch was also built as an
independent `mo-service` and exercised with the exact 65,536-byte SQL
reproduction. MatrixOne returned `2d61aa54b58c2e94403fb092c3dbc027` for
both stored `LONGBLOB` and `LONGTEXT`, matching MySQL 8.0.42.

Not run: full repository test suite, race, lint, vet, or the complete
mo-tester distributed suite.

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#27883)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

close matrixorigin#27798

## What this PR does / why we need it:

`MD5` only registered a `T_varchar` overload. Stored `LONGTEXT` and
`LONGBLOB` values were therefore implicitly converted to `VARCHAR`
before hashing, truncating inputs at 65,535 bytes.

This PR:

- registers direct `T_text` and `T_blob` overloads that reuse the
existing `Md5` implementation;
- adds a unit regression that verifies both types avoid implicit casts
and hash the complete 65,536-byte value;
- adds distributed SQL regression cases for `LONGTEXT` and `LONGBLOB`.

The existing `T_varchar` overload, return type, digest implementation,
SQL schema, and protocol behavior remain unchanged. No dependency or
configuration changes are introduced.

## Testing

On the final branch based on
`matrixorigin/main@4dedea1`:

- `go test -vet=off ./pkg/sql/plan/function -run TestMd5 -count=1`
- PASS: `ok github.com/matrixorigin/matrixone/pkg/sql/plan/function
1.542s`
- the same test with `-coverprofile`
- PASS: package coverage 0.6% for the targeted test selection; `Md5`
function coverage 100.0%
- `git diff --check origin/main...HEAD`
  - PASS

Before the final main sync, the same patch was also built as an
independent `mo-service` and exercised with the exact 65,536-byte SQL
reproduction. MatrixOne returned `2d61aa54b58c2e94403fb092c3dbc027` for
both stored `LONGBLOB` and `LONGTEXT`, matching MySQL 8.0.42.

Not run: full repository test suite, race, lint, vet, or the complete
mo-tester distributed suite.

Co-authored-by: XuPeng-SH <[email protected]>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MD5(LONGBLOB) hashes only the first 65535 bytes

3 participants