Skip to content

to 3.0: Fix data branch result conversion on 3.0-dev - #24876

Merged
XuPeng-SH merged 9 commits into
matrixorigin:3.0-devfrom
gouhongshen:codex/fix-data-branch-decimal-3.0
Jun 15, 2026
Merged

XuPeng-SH merged 9 commits into
matrixorigin:3.0-devfrom
gouhongshen:codex/fix-data-branch-decimal-3.0

Conversation

@gouhongshen

Copy link
Copy Markdown
Contributor

Summary

  • Preserve DECIMAL precision and scale in DATA BRANCH DIFF output schemas so save_query_result=on can convert full-row diff results into vectors.
  • Add DECIMAL conversion support for query-result batches across decimal64, decimal128, and decimal256.
  • Cherry-pick main commit 565a0f71f671cb98c6693a762595f200010fdd1a to preserve string literal quotes in DATA BRANCH PICK subquery SQL.

Root Cause

DATA BRANCH DIFF built its output columns by converting only the engine type OID to a MySQL type. For DECIMAL columns, the width and scale metadata was lost, so saving query results could not map the MySQL DECIMAL column back to a MatrixOne decimal vector type and failed with unsupported mysql type 0.

The cherry-picked DATA BRANCH PICK fix addresses a separate 3.0-dev issue where formatting the KEYS subquery without single-quote string formatting could turn predicates like customer = 'Grace' into invalid or changed SQL.

Validation

  • source $HOME/.zshrc && moenv && go test ./pkg/frontend -run 'TestDataBranchOutput|Test_convertRowsIntoBatch|TestMaterializeSubqueryUnified_PreservesStringLiteralQuotes' -count=1
  • make build
  • Manual SQL verification on a local rebuilt 3.0-dev cluster: save_query_result=on with data branch diff over a DECIMAL column returned rows instead of unsupported mysql type 0.

Refs #24847

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Jun 8, 2026
@mergify
mergify Bot requested a review from XuPeng-SH June 8, 2026 03:53
@gouhongshen gouhongshen changed the title [codex] Fix data branch result conversion on 3.0-dev to 3.0: Fix data branch result conversion on 3.0-dev Jun 8, 2026
@gouhongshen

gouhongshen commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated this PR for the review comments:

  • Removed the silent decimal scale fallback in mysqlDecimalColType; decimal scale metadata is now required and covered by unit tests.
  • Added decimal256 support for the non-PK data branch diff/save-result path:
    • logtail replay row materialization
    • fixed-width tuple raw-byte normalization
    • DecodeValue / CompareValue
    • diff output SQL value formatting
  • Added BVT coverage: diff_14.sql exercises set save_query_result=on; data branch diff ... with decimal64, decimal128, and decimal256 columns.

Local verification:

  • go test ./pkg/container/types ./pkg/frontend ./pkg/vm/engine/disttae/logtailreplay
  • ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-2nd/test/distributed/cases/ -m genrs -i diff_14
  • ./run.sh -p /Users/ghs-mo/MOWorkSpace/matrixone-2nd/test/distributed/cases/ -i diff_14

@gouhongshen

Copy link
Copy Markdown
Contributor Author

CI rerun is green now. The decimal precision boundary review has been addressed in the current head: mysqlDecimalColType now keeps decimal64 through precision 18 and switches to decimal128 at precision 19, and Test_mysqlDecimalColTypePrecisionBoundary covers 17/18/19. @XuPeng-SH could you please re-review when you have time?

@gouhongshen

Copy link
Copy Markdown
Contributor Author

Updated the branch with the same decimal256 coverage improvements used for the port PRs.

Covered in this push:

  • Added focused appendFromEntry() coverage for decimal256, including null handling.
  • Expanded diff_14 to cover decimal UPDATE / INSERT / DELETE paths under save_query_result=on.
  • Added a product-level pick_12 conflict case using decimal(39,4) as a non-PK value, covering fail / skip / accept behavior. This exposed and fixed decimal256 row materialization in data branch pick output.

Local validation on 3.0-dev:

  • source $HOME/.zshrc && moenv && go test ./pkg/frontend ./pkg/vm/engine/disttae/logtailreplay
  • BVT diff_14: 15/15 passed
  • BVT pick_12: 69/69 passed

Re-requesting review.

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

Found one remaining blocker: DATA BRANCH PICK still does not handle decimal256 primary keys. The PR adds decimal256 support for row materialization/output, but the PICK PK paths still only cover decimal64/decimal128. In pkg/frontend/data_branch_pick.go, extractPKVal decodes decimal64/decimal128/time-like fixed values but omits decimal256, and appendNumericStringToVec only parses decimal64/decimal128 literals. As a result, a table with primary key decimal(39,4) can reject literal KEYS(...) as an unsupported PK type, and subquery-key conflict formatting can read a fixed decimal256 vector through the fallback varlen path. Please add decimal256 handling to the PICK PK parse/format/extract paths and add regression coverage with decimal(39,4) as the primary key for literal and subquery KEYS. Required CI is green and the broader decimal/data-branch coverage looks good otherwise.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

已处理 @XuPeng-SH 在 review PRR_kwDOFEPiGM8AAAABC-rnFQ 里提到的 decimal256 PK blocker。

这次补齐了:

  • DATA BRANCH PICK 的 decimal256 PK literal parse / subquery key reformat / conflict PK format / PK extract。
  • decimal256 PK 需要经过的复用路径:tuple/packer 编码、lock fetch、readutil PK filter、sort/mergeutil、TAE mergesort、Type.DescString()。
  • 回归:pick_12.sql 增加 decimal(39,4) primary key,覆盖 literal KEYS(...) 和 subquery KEYS(select cast(id as decimal(40,4)) ...)。

本地验证:

  • targeted UT: go test ./pkg/container/types ./pkg/container/vector ./pkg/frontend ./pkg/sql/colexec/lockop ./pkg/vm/engine/readutil ./pkg/sort ./pkg/objectio/mergeutil ./pkg/vm/engine/tae/mergesort -run 'TestSimpleTupleAllTypes|TestSingleTypeTuple|TestDecimal256OrderTuple|TestTupleSQLStrings|TestTupleSQLStringsWithEncodeDecode|TestDecodeTupleWithSchema|TestUnpackNthElement|TestType_DescString|TestFetchDecimal256Rows|TestFetchDecimal256RowsWithFilter|TestFetchDecimal256RowsWithFilterAll|TestNumericGap_AllTypes|TestIsNumericType|TestAppendNumericStringToVec_AllTypes|TestCoercePickKeyVectorToType_Decimal256ReformatsToTargetType|TestExtractPKValDecimal256|TestFormatPickKeyVectorValueAsString_AllSupportedKinds|TestLCAProbeJoinCastType|TestConstructBlockPKFilter|TestMergeBaseFilterInKind|TestSortDecimal256|TestMergeSortBatchesDecimal256|TestAObjMergeDecimal256' -count=1
  • make build
  • 新 build 的本地 mo-service 上跑 pick_12: genrs + run,82/82 success,并扫过 result 无 syntax / unsupported / panic 等错误关键字。

@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 with CI status ignored. The previous decimal256 DATA BRANCH PICK blocker is resolved: decimal256 is now handled in PK extraction, key formatting, literal parsing, numeric gap/PK filtering paths, and the related tuple/sort/merge/filter helpers. The added BVT covers decimal(39,4) primary-key PICK via both literal KEYS and subquery KEYS, plus remaining diff verification; existing/new unit coverage covers the helper paths. No blocking issue found in the fix approach.

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

size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants