Skip to content

fix: honor PAD_CHAR_TO_FULL_LENGTH for CHAR retrieval - #27100

Merged
XuPeng-SH merged 33 commits into
matrixorigin:mainfrom
iamlinjunhong:m-27036
Aug 30, 2026
Merged

XuPeng-SH merged 33 commits into
matrixorigin:mainfrom
iamlinjunhong:m-27036

Conversation

@iamlinjunhong

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 #27036

What this PR does / why we need it:

fix: honor PAD_CHAR_TO_FULL_LENGTH for CHAR retrieval

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

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Aug 13, 2026

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

Blocking correctness issue:

[P1] Preserve CHAR comparison/join semantics when padding scan vectors — pkg/sql/colexec/table_scan/table_scan.go:291

evalFilter pads every CHAR value before evaluating predicates. MatrixOne's current string equality path compares the varlena bytes directly (func_compare.go uses v1 == v2, and CHAR/VARCHAR is cast to VARCHAR), so enabling this retrieval mode changes ordinary predicates. I reproduced this exact head with a focused expression test: a stored CHAR(8) value "MO" is padded to "MO ", then c = 'MO' evaluates false. The same query matches with the mode off. Hash/join keys are affected too: a VARCHAR "abc" and CHAR(10) "abc", which currently join, become different byte keys once the CHAR side is padded.

PAD_CHAR_TO_FULL_LENGTH may make value-observing expressions such as LENGTH see the padded representation, but it must not make equality predicates and joins lose rows under PAD SPACE character semantics. Please preserve comparison/hash semantics for padded CHAR values and add regressions for at least WHERE c = 'MO' plus CHAR/VARCHAR (and differing-width CHAR) joins while the mode is enabled.

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

[P1] Preserve PAD SPACE comparison and hash semantics before exposing the padded CHAR representation.

TableScan.evalFilter now calls padCharColumnsToFullLength before evaluating predicates, and the same padded scan vectors flow into joins. MatrixOne currently compares CHAR/VARCHAR values by their exact bytes (equalFn uses string equality and ordering uses bytes.Compare); hash keys likewise consume the resulting bytes.

I reproduced this on exact head 7b9aa59 with a focused control/counterexample: an unpadded CHAR(8) value "MO" compares equal to VARCHAR "MO"; after this PRs padding helper changes it to "MO ", the same equality returns false. Therefore enabling PAD_CHAR_TO_FULL_LENGTH can make WHERE c = 'MO' lose rows, and CHAR/VARCHAR or differing-width CHAR joins can stop matching values that matched with the mode disabled.

The mode may change retrieved representation and value-observing expressions such as LENGTH/HEX, but it must not break PAD SPACE comparison/join semantics. Please close both expression and hash consumers and add public regressions for at least the equality predicate, CHAR/VARCHAR join, and differing-width CHAR join. The current tests only cover returned bytes/LENGTH and do not exercise these counterexamples.

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

Request changes on exact head 7b9aa59. The existing blocker remains: evalFilter pads every CHAR vector before allFilterExecutors run. That changes predicate and hash semantics, so PAD_CHAR_TO_FULL_LENGTH can make WHERE c = MO fail for a stored CHAR value MO, and can split CHAR/VARCHAR or different-width CHAR join keys. Padding should happen only after filtering, or comparison and hash paths must canonicalize CHAR values under PAD SPACE semantics. Please add public equality and join regressions; the current tests cover retrieval formatting only.

@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 re-review on exact head cc530896da7430ea6d8e5d739bc1f5024d07533d.

All three blockers from review 5059969267 are closed. The RFC now records the independent design decision and is in-progress; the visible-value/canonical-key split and fail-closed rolling-upgrade model remain sound. PAD SPACE COUNT(DISTINCT) keeps the duplicate-heavy local pre-dedup topology and shuffles the canonical physical-key column, with planner assertions covering the local/final ownership markers. The v40 protocol check now returns before reflective traversal on compatible sender and receiver paths, with a 1,000-instruction zero-allocation regression.

I also rechecked version ownership after the rebase: main owns v37-v39 and this feature uniquely owns v40, with sender-side pre-v40 rejection before marshal/dispatch and receiver defense in depth. Mode-off behavior, ordinary VARCHAR/TEXT semantics, late-materialized unloaded vectors, derived-value provenance, set/hash/window/aggregate consumers, generated protobuf identity, and cleanup ownership remain closed. The enabled-mode padding/normalization work is bounded and intentional; the ordinary remote fast path is free. Exact-head required CI is green. No remaining correctness, compatibility, performance, unhappy-path, or lifecycle blocker found.

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.

7 participants