Repository navigation
fix: align INSERT/UPDATE string width enforcement with MySQL sql_mode (#25200) (cherry-pick #25262) - #25312
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
# Conflicts: # pkg/sql/plan/function/func_cast.go # pkg/sql/plan/function/function_id.go # pkg/sql/plan/function/function_id_test.go
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Requesting changes on 432e06217e7ecd552251d0e89b8da7ef185d36b2.
The earlier remote sql_mode and function-ID findings are fixed, but the latest head still has four correctness/compatibility blockers:
-
[P1] Cast warnings are dropped at the first real pipeline-process boundary.
newCastcaptures warnings throughproc.GetSession()(pkg/sql/plan/function/func_cast.go:950-957), butProcess.Sessionis a field on the individualProcess, whileNewNoContextChildProc/NewContextChildProccopy onlyBase(pkg/vm/process/process2.go:107-147). Consequently the processes that execute pipeline expressions have a nil session, andaddCastWarningToSessionsilently returns. A decoded remote process has no frontend session either, so the same loss happens across CNs.Concrete failure: an over-width non-strict/IGNORE assignment is truncated successfully, but the OK packet reports zero warnings and
SHOW WARNINGSis empty. I reproduced this by assigning a warning-capable session to a top process, executingNewAssignCastontop.NewContextChildProc(0), and observing the expected value"abc"with no 1265 recorded. The existing warning unit test setsSessiondirectly on the same process used for evaluation, so it does not exercise the production boundary.Please put warning collection on state shared by child processes and close the remote-result aggregation path (or explicitly defer/remove the partial warning feature until that end-to-end path exists).
-
[P1] SELECT responses still advertise zero warnings.
castModeExplicitnow recordsER_TRUNCATED_WRONG_VALUE, but the*tree.Selectbranch inrespStreamResultRowstill callsWriteEOFOrOK(0, ...)(pkg/frontend/result_row_stmt.go:297-302). Thus even after warning collection is fixed,SELECT CAST(...)sends a zero warning count in its final EOF/OK packet. The addedTestStreamResultResponseCarriesWarningsusesSHOW WARNINGS, which takes the default branch and misses this case. I reproduced it with atree.Selectresponse carrying one stored warning: the writer received 0.Pass
ses.WarningCount()in the SELECT branch and cover the final result-set terminator (includingCLIENT_DEPRECATE_EOF). -
[P1] The protocol-v4 compatibility plan now returns a DDL error for DML.
During a mixed-version rollout,
assignmentCastFunctionNameintentionally emitscast_strict(pkg/sql/plan/build_constraint_util.go:1094-1106). However, this PR changedNewStrictCastwidth failures toNewErrInvalidDefaultin theallowTrailingSpaceTrim == falsepath (pkg/sql/plan/function/func_cast.go:7007-7010, with equivalent branches for other sources). Therefore the new binary executing the v4-compatible DML plan returns 1067/ErrInvalidDefault, while the old binary executing the samecast_strictplan returns the legacy DML/internal cast error. Client-visible behavior now depends on which CN executes the plan.A focused execution of
NewStrictCast(TEXT('abcd') -> VARCHAR(3))on this head returnedErrInvalidDefault; the same path on the base returnsErrInternal. Please keepcast_strict's stable contract and use a DDL-specific operator/mode/context for DEFAULT validation. -
[P1] Persisting
cast_assignin generated-column metadata breaks a 5→4 rollback.At protocol v5,
buildGeneratedExprstorescast_assign(ID 554) directly in the catalog expression (pkg/sql/plan/build_util.go:488-516). The previous binary hasFUNCTION_END_NUMBER = 554, nocast_assignregistration, and expression execution resolves the encoded ID rather thanObjName; it therefore fails withfunction overload id not found.applyGeneratedColumnAssignmentCastonly protects planners running the new code and cannot help a rolled-back CN reading the catalog.Concrete sequence: upgrade and set protocol 5 → create a VARCHAR generated column → set protocol back to 4/roll a CN back → INSERT/UPDATE planned on that old CN cannot execute the stored generated expression. Since this PR explicitly handles and tests protocol rollback for cached plans, catalog state needs the same closure. Keep the persisted expression on the stable
cast_strictID and rewrite it tocast_assign/cast_ignoreonly while building an execution plan.
Focused existing tests for function semantics, protocol-gated planning, generated-column rewriting, prepared-plan/cache invalidation, and frontend warning responses pass. The boundary regressions above are not covered by those tests.
# Conflicts: # pkg/pb/pipeline/pipeline.pb.go
XuPeng-SH
left a comment
There was a problem hiding this comment.
Requesting changes on 9c1c54c8b99043cf72ab44b0a86fd09ed3f59e14.
The earlier cast-strict contract and generated-column rollback findings are fixed, and the focused cast/planner/protocol tests pass. Three warning-path correctness gaps remain:
- [P1] Warning collection still stops at the first production
Processboundary and has no remote return path.
newCast captures its sink from proc.GetSession() (pkg/sql/plan/function/func_cast.go:948-957), but Process.Session is outside the shared BaseProcess (pkg/vm/process/types.go:421-430). NewNoContextChildProc and NewContextChildProc copy only Base (pkg/vm/process/process2.go:109-147), so the child processes used to evaluate pipeline expressions have a nil session. Remote execution is also incomplete: remoterunServer.newCompile reconstructs a top process and restores only Base.SessionInfo (pkg/sql/compile/remoterunServer.go:669-685), and neither the pipeline protocol nor the terminal envelope carries warnings back to the initiating CN.
Concrete failures: SELECT CAST('abcd' AS CHAR(3)), a non-strict over-width INSERT/UPDATE, or INSERT/UPDATE IGNORE can truncate successfully while the client sees warning_count=0 and SHOW WARNINGS is empty; the same loss is guaranteed when the cast executes remotely. TestAssignmentCastTypedSourceAndWarnings sets proc.Session directly on the exact evaluator process, so it bypasses this production boundary.
Please put the warning sink/counter on state shared by child processes and close the remote aggregation path (or defer the warning feature until that end-to-end path exists). Add a child-process regression and a multi-CN remote regression.
- [P1] Ordinary SELECT still writes a zero warning count in its final EOF/OK packet.
The *tree.Select branch still calls WriteEOFOrOK(0, ...) at pkg/frontend/result_row_stmt.go:296-302. Thus even after collection is fixed, explicit CAST warnings are hidden from the protocol response. TestStreamResultResponseCarriesWarnings uses tree.ShowWarnings, which reaches the default branch and does not exercise SELECT.
Pass ses.WarningCount() in the SELECT branch and test both EOF and CLIENT_DEPRECATE_EOF terminators for a warning-producing SELECT.
- [P2] Protocol warning_count is derived from the bounded display buffer, so bulk warnings are under-counted.
AddWarning stores warnings in errInfo, whose default max is 64, while WarningCount returns len(ses.warnings.codes) (pkg/frontend/session.go:1934-1962). errInfo.push also uses len > maxCnt rather than >= (pkg/frontend/session.go:711-717), so the buffer stabilizes at 65 entries. A statement that truncates 100 rows therefore advertises 65 warnings, not 100. The storage limit should bound SHOW WARNINGS retention, not the statement total used by the protocol; track the total separately (capped at uint16 for the wire) and cover a batch larger than the retention limit.
Validation on this head: the newly added focused tests in pkg/common/moerr, pkg/vm/process, pkg/sql/plan/function, pkg/sql/plan, and pkg/frontend all pass with the repository CGo wrapper. CI is green except for the still-running arm64 SCA job.
|
@XuPeng-SH Thanks for the review. The three remaining findings are all related to warning collection, propagation, protocol warning counts, and SHOW WARNINGS behavior. MatrixOne does not currently support an end-to-end warning mechanism, so warning-related features and change requests are explicitly out of scope for this PR and will not be addressed here. The previously reported non-warning issues—the cast_strict compatibility contract and generated-column rollback compatibility—have been fixed. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-review on unchanged head 9c1c54c8b99043cf72ab44b0a86fd09ed3f59e14: the requested changes remain.
Calling warning behavior out of scope does not resolve the blockers because this PR itself adds warning production (newCast), storage/counting (Session), SHOW WARNINGS, and protocol warning counts. Either complete that behavior end to end or remove/defer those warning-facing changes from this PR.
- [P1] Warning collection is still lost at real process/CN boundaries.
Process.Sessionis outside sharedBaseProcess;NewNoContextChildProc/NewContextChildProccopy onlyBase, so evaluator child processes have no warning sink. Remote execution also has no terminal warning aggregation back to the initiating CN. The current cast test attaches the session directly to the evaluator and bypasses both boundaries. - [P1] Ordinary SELECT still advertises zero warnings. The
*tree.Selectbranch inrespStreamResultRowcallsWriteEOFOrOK(0, ...); the added test usestree.ShowWarnings, which takes a different branch. - [P2] Protocol warning_count is the retained-buffer length, not the statement total.
errInfo.pushretains at most 65 entries with the currentlen > maxCntcondition, andWarningCountreturns that retained length, so 100 truncations are reported as 65.
The focused cast/frontend warning tests pass on this head, but they confirm only the bypassing unit-test paths above. CI is green; these are uncovered correctness gaps, not CI failures.
|
@XuPeng-SH Thanks for the clarification. I removed the warning-facing changes introduced by this PR instead of extending MatrixOne's currently incomplete warning mechanism. The cast warning production/context, session warning storage/counting, Validation:
Fixed in |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed the latest head bb5fb41. The incomplete warning pipeline that caused the remaining blockers has been fully removed, while the core strict/non-strict/IGNORE string-width behavior remains intact. I also rechecked remote sql_mode propagation, function-ID/protocol-version gating, plan-cache invalidation, and generated-column rolling-upgrade compatibility. Local full-package tests passed for pkg/common/moerr, pkg/vm/process, pkg/sql/plan/function, pkg/sql/plan, and pkg/frontend.
Merge Queue Status
This pull request spent 3 hours 27 minutes 10 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks Failing checks:
HintYou may have to fix your CI before adding the pull request to the queue again. Requeued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 45 minutes 21 seconds in the queue, including 35 minutes 30 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #25200
What this PR does / why we need it:
Cherry-pick of PR #25262 from 3.0-dev to main.
Rework CHAR/VARCHAR width enforcement on DML assignment paths so it matches MySQL's sql_mode semantics:
cast_assignfunction used by DML assignment paths for CHAR/VARCHAR targets. It reads sql_mode at runtime (strict -> reject 1406, non-strict -> truncate), avoiding plan-cache staleness.Notes
func_cast.goandfunc_cast_test.gowere taken from the 3.0-dev version. Main-specific functions in these files may need review.build_test.gochanges were not included in this cherry-pick due to significant divergence from feat(insert): align ON DUPLICATE KEY UPDATE with MySQL, drop legacy operator #24973.🤖 Generated with Claude Code