Skip to content

Fix data branch decimal results on main - #24894

Merged
XuPeng-SH merged 16 commits into
matrixorigin:mainfrom
gouhongshen:codex/fix-data-branch-decimal-main
Jul 7, 2026
Merged

XuPeng-SH merged 16 commits into
matrixorigin:mainfrom
gouhongshen:codex/fix-data-branch-decimal-main

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Jun 9, 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:

issue #24847

What this PR does / why we need it:

Port the data branch decimal/year result conversion and tuple handling fixes to latest main.

  • Preserve decimal precision/scale metadata from MySQL result columns, validate invalid/missing decimal metadata, and align year result metadata/output formatting.
  • Materialize decimal64/decimal128/decimal256/year row values as typed MatrixOne vectors when building data branch output and pick batches.
  • Decode, encode, compare, and merge decimal256/year tuple values across data branch hashdiff, pick, apply SQL generation, logtail replay, branch hashmap, read filter, lock fetch, and merge-sort paths.
  • Fix fuzzy-check subquery string-literal quoting with tree.WithSingleQuoteString().
  • Add focused Go tests plus BVT coverage: diff_15.sql for decimal64/decimal128/decimal256 data branch diff, diff_16.sql for year data branch diff, and pick_12.sql/pick_13.sql for pick paths.

Notes:

  • Rebased onto main at 890a3800c44932b4dd190ba59277aa73c502bd05; conflict with upstream diff_14.sql was resolved by keeping upstream diff_14 and moving this PR's decimal/year cases to diff_15/diff_16.
  • The decimal256 PK pick issue is tracked separately in [Bug]: data branch pick does not support decimal256 primary keys #24902 and intentionally not fixed in this PR.

Checks:

  • git diff --check upstream/main...HEAD passed.
  • make -C thirdparties passed locally.
  • source $HOME/.zshrc && moenv && go test ./pkg/container/types ./pkg/frontend ./pkg/vm/engine/disttae/logtailreplay: pkg/container/types passed; pkg/frontend and pkg/vm/engine/disttae/logtailreplay are locally blocked by the current upstream/main thirdparty mismatch where github.com/unum-cloud/usearch/[email protected] expects symbols such as usearch_scalar_u8_k and usearch_hardware_acceleration_*, but thirdparties/install/include/usearch.h built from usearch-2.25.3.tar.gz does not provide them.
  • GitHub CI was re-triggered after the rebase push.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jun 9, 2026
@gouhongshen gouhongshen changed the title [codex] Fix data branch decimal results on main Fix data branch decimal results on main Jun 9, 2026
@gouhongshen
gouhongshen force-pushed the codex/fix-data-branch-decimal-main branch from 53ecf84 to 0903902 Compare June 10, 2026 02:54
aunjgr

This comment was marked as low quality.

@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.

The decimal round-trip fix looks useful, but the new generic DECIMAL metadata inference still has a real type-selection hole.

pkg/frontend/util.go now derives decimal precision as length - 2 in mysqlDecimalPrecisionFromColumn(). That only matches MatrixOne's own internal setColLength() convention, where DECIMAL length is encoded as width + 2 (pkg/defines/type.go). It is not a general rule for MySQL DECIMAL metadata.

For example, a signed DECIMAL(19,0) can be reported with display length 20, which this code would infer as precision 18. That downgrades the value from T_decimal128 to T_decimal64. If this path consumes real MySQL-compatible column metadata, 19-digit scale-0 decimals can be materialized into the wrong engine type and then overflow or misparse.

Please avoid reverse-engineering precision from Length() with a fixed offset, and add coverage for metadata that does not come from MO's own width + 2 producer path.

@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.

I re-checked the latest head. The decimal fixes look useful, but there is still one remaining typed-value hole in the new tuple normalization path.

normalizeTupleColumnValue() was added so values coming back from the branch hashmap as raw []byte can be decoded back into fixed-width MatrixOne types before compare / format / append. But its fixed-width decode switch still omits types.T_year.

That leaves a real runtime gap:

  • YEAR is otherwise treated as a supported typed value in the surrounding data-branch helpers (formatting / compare paths already have types.T_year branches)
  • the branch hashmap still uses the raw-byte/default path for fixed-width types it does not specially materialize
  • so a YEAR value coming back through this new normalization path still falls into "unexpected byte slice for fixed-width column type" instead of being decoded

In other words, the decimal regression is fixed, but data branch diff can still break on tables containing YEAR columns because this new byte->typed normalization path is now the choke point.

Concrete suggestions

  1. Add types.T_year to the fixed-width decode switch in normalizeTupleColumnValue().
  2. Add one focused regression test that actually drives the byte-slice path for a YEAR column through data branch diff / tuple normalization, not just helper-level formatting.
  3. If you want a user-visible proof, a small git4data branch diff case with a YEAR column would lock the full path.

@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.

I re-checked the current head from a first-principles / unhappy-path angle. The decimal fixes look useful, but I still see a few substantive type-handling holes in the broader path this PR is touching.

  1. CompareValue is still not a valid comparator for several numeric types

    • The current implementation uses subtraction + int(...) for uint8/16/32 and float32/64.
    • That is not comparator-safe in Go: unsigned subtraction can wrap (uint8(1)-uint8(2) -> 255), and float deltas smaller than 1 can collapse to 0 after int(...).
    • This matters here because the new data-branch logic relies on CompareValue for row comparison and PK sorting.
    • Suggestion: switch those branches to explicit < / > / == comparisons that return -1/0/1, and add tests for float deltas < 1 plus ascending/descending unsigned cases.
  2. Tuple.SQLStrings() no longer returns SQL literals, but fuzzyCheck still concatenates its output directly into SQL

    • Tuple.SQLStrings() now returns raw values for text/date/time/uuid-ish types without quoting/escaping.
    • pkg/sql/compile/fuzzyCheck.go still injects those strings directly into col = %s predicates.
    • So composite keys containing plain strings, dates, timestamps, UUIDs, or embedded quotes can now generate invalid or semantically wrong SQL.
    • Suggestion: either restore SQL-literal quoting/escaping in Tuple.SQLStrings(), or stop using it for SQL generation and quote/parameterize at the fuzzyCheck call site.
  3. YEAR is still incomplete across the end-to-end data-branch path

    • The PR adds some low-level YEAR handling, but the full data-branch diff/pick path still has gaps: normalization, PK extraction, formatting, and decode paths are not consistently updated together.
    • In particular, normalizeTupleColumnValue() / PK extraction / DecodeValue() are still the choke points for YEAR values coming back as raw bytes.
    • Suggestion: add explicit T_year handling consistently across encode/decode/normalize/format/PK extraction, then add at least one focused DATA BRANCH DIFF/PICK regression using YEAR columns.

Given the comparator correctness bug and the Tuple.SQLStrings() SQL-generation regression, I think this should stay at request changes on the current head.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

Addressed the latest review in 3be9969f87.

  • CompareValue now uses comparator semantics for ordered scalar types instead of subtraction/int casts. Added coverage for unsigned reverse ordering and float deltas smaller than 1.
  • fuzzyCheck no longer feeds raw Tuple.SQLStrings() values directly into compound-key SQL predicates. It now formats compound collision keys with per-column SQL literal quoting while still preserving decimal scale formatting. Added coverage for string values with quotes, DATE, YEAR, and DECIMAL in one compound key.
  • Completed the remaining YEAR pick path: PK extraction, literal parsing, subquery coercion formatting, and branch pick BVT coverage. Added pick_13 for YEAR primary-key DATA BRANCH PICK via string literal key and YEAR subquery key.

Verification:

  • git diff --check
  • go test ./pkg/container/types -count=1

Local pkg/frontend / pkg/sql/compile targeted tests are still blocked by the local usearch C-symbol mismatch; CI should cover those packages on the PR branch.

@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.

The new compound-key quoting in pkg/sql/compile/fuzzyCheck.go is still semantically wrong.

formatCompoundCollisionKey now uses strconv.Quote, but that produces Go double-quoted / backslash-escaped string literals, not SQL literals. Those values are then concatenated into f.condition and executed by backgroundSQLCheck() via runSqlWithResultAndOptions(), which propagates the current session's variable resolver (WithResolveVariableFunc(...)). So this sub-SQL still runs under the caller's sql_mode behavior.

That leaves at least two real failure modes:

  1. Under ANSI_QUOTES, values like "2025-01-03" / "O'Reilly" are no longer string literals, so the duplicate-check SQL for compound keys can parse or evaluate incorrectly.
  2. Under NO_BACKSLASH_ESCAPES, the Go-style escaping emitted by strconv.Quote is also not the right SQL literal escaping, so strings / binary-ish payloads containing backslashes or escapes can be misparsed.

So the new fuzzy-check path is still not SQL-mode-safe for the exact string/date/year/blob/uuid-style cases this patch is trying to fix, and TestFillCompoundConditionQuotesSQLLiterals is currently locking in the wrong representation. Please switch this to repo-consistent single-quoted SQL literal generation (for example the existing tree.WithSingleQuoteString() / SQL-string escaping style used elsewhere) and add a regression that exercises at least ANSI_QUOTES.

@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.

Re-reviewed latest head cb18ec8 from the data-flow and unhappy-path angles.

The previously requested blockers look closed now:

  • decimal metadata inference no longer hard-codes length - 2; it accounts for scale/sign and has boundary/error coverage, including signed DECIMAL(19,0) and decimal256.
  • CompareValue no longer uses subtraction/truncation for unsigned/float comparators, and the regression tests cover unsigned direction plus sub-1 float deltas.
  • YEAR is now covered consistently across decode/normalize/format/PK extraction/comparison/output surfaces, with helper and BVT coverage.
  • decimal256 is covered across tuple encode/decode, SQL string formatting, branch diff/pick conversion, logtail replay appendFromEntry, readutil PK filters, lock fetch, and merge sort.
  • compound fuzzy-check SQL generation no longer uses Go strconv.Quote; it uses single-quoted SQL literals through sqlquote.String, with coverage for embedded quote/backslash and ANSI_QUOTES-sensitive no-double-quote output.

I also checked the latest CI rollup: Summary is green. Local targeted tests passed for the touched hot paths:

  • ./pkg/common/sqlquote
  • ./pkg/container/types
  • ./pkg/frontend
  • ./pkg/sql/compile
  • ./pkg/sql/colexec/lockop
  • ./pkg/vm/engine/readutil
  • ./pkg/objectio/mergeutil
  • ./pkg/vm/engine/disttae/logtailreplay
  • ./pkg/frontend/databranchutils

Non-blocking: the PR is still marked BEHIND, so it should be updated with latest main before merge if the queue requires it.

@mergify

mergify Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-07 07:46 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-07-07 08:02 UTC · at cb18ec8c710125927ed06b8770140d62c6e73616

This pull request spent 16 minutes 4 seconds in the queue, with no time running CI.

Reason

Pull request #24894 has been dequeued

Queue conditions are not satisfied:

  • -conflict [📌 queue requirement]

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-07 11:29 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-07 14:16 UTC · at ce4c897af7b6d31b84ef68fce639a7543e074ec5

This pull request spent 2 hours 46 minutes 44 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64

Reason

Pull request #24894 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

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 kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants