Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix issue that update ignore stmt return error when meet incorrect timestamp value error #54878

Merged
merged 4 commits into from
Jul 30, 2024

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #50308

Problem Summary: As title said, see more detail in issue #50308

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: crazycs520 <[email protected]>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 24, 2024
Copy link

tiprow bot commented Jul 24, 2024

Hi @crazycs520. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

codecov bot commented Jul 24, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 57.5471%. Comparing base (47179ae) to head (38a5139).
Report is 55 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54878         +/-   ##
=================================================
- Coverage   72.8127%   57.5471%   -15.2657%     
=================================================
  Files          1557       1694        +137     
  Lines        438081     634110     +196029     
=================================================
+ Hits         318979     364912      +45933     
- Misses        99416     245350     +145934     
- Partials      19686      23848       +4162     
Flag Coverage Δ
integration 38.7434% <70.0000%> (?)
unit 72.9196% <60.0000%> (+1.0930%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.3749% <ø> (+0.4092%) ⬆️
parser ∅ <ø> (∅)
br 53.1053% <ø> (+7.2231%) ⬆️

Signed-off-by: crazycs520 <[email protected]>
@crazycs520
Copy link
Contributor Author

/retest-required

Copy link

tiprow bot commented Jul 25, 2024

@crazycs520: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest-required

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@crazycs520
Copy link
Contributor Author

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Jul 25, 2024
@crazycs520
Copy link
Contributor Author

/retest-required

1 similar comment
@crazycs520
Copy link
Contributor Author

/retest-required

Signed-off-by: crazycs520 <[email protected]>

if types.ErrTruncatedWrongVal.Equal(err) && col != nil && col.ColumnInfo != nil && col.ColumnInfo.GetType() == mysql.TypeTimestamp {
ec := e.Ctx().GetSessionVars().StmtCtx.ErrCtx()
return errors.AddStack(ec.HandleErrorWithAlias(kv.ErrKeyExists, err, err))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related error handling logic in Insert statement:

// TODO: should not filter all types of errors here.
if err != nil {
ec := e.Ctx().GetSessionVars().StmtCtx.ErrCtx()
return errors.AddStack(ec.HandleErrorWithAlias(kv.ErrKeyExists, err, err))
}

I've added error type and column type checking to avoid mishandling other errors here.

@crazycs520
Copy link
Contributor Author

@lcwangchao @cfzjywxk PTAL

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 30, 2024
@@ -351,7 +351,10 @@ func (*UpdateExec) handleErr(colName model.CIStr, rowIdx int, err error) error {
if types.ErrOverflow.Equal(err) {
return types.ErrWarnDataOutOfRange.GenWithStackByArgs(colName.O, rowIdx+1)
}

if types.ErrTruncatedWrongVal.Equal(err) && col != nil && col.ColumnInfo != nil && col.ColumnInfo.GetType() == mysql.TypeTimestamp {
Copy link
Contributor

Choose a reason for hiding this comment

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

So the condition here allowed to be igmored is "timestamp column && truncated value", right?
Is this condition check consistent with MySQL behaviour?

Copy link
Contributor Author

@crazycs520 crazycs520 Jul 30, 2024

Choose a reason for hiding this comment

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

Yes, this is compatible with MySQL, except for the error message.

MySQL 8.0.29

mysql> create table t(t timestamp);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t values("2000-01-01");
Query OK, 1 row affected (0.00 sec)

mysql> update ignore t set t=cast("2099-01-01" as date);
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> show warnings;
+---------+------+--------------------------------------------+
| Level   | Code | Message                                    |
+---------+------+--------------------------------------------+
| Warning | 1264 | Out of range value for column 't' at row 1 |
+---------+------+--------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from t;
+---------------------+
| t                   |
+---------------------+
| 0000-00-00 00:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.29    |
+-----------+

This PR

mysql> create table t(t timestamp);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t values("2000-01-01");
Query OK, 1 row affected (0.00 sec)

mysql> update ignore t set t=cast("2099-01-01" as date);
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> show warnings;
+---------+------+-----------------------------------------+
| Level   | Code | Message                                 |
+---------+------+-----------------------------------------+
| Warning | 1292 | Incorrect timestamp value: '2099-01-01' |
+---------+------+-----------------------------------------+
1 row in set (0.00 sec)

mysql> select * from t;
+---------------------+
| t                   |
+---------------------+
| 0000-00-00 00:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                              |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.2.0-alpha-675-g38a5139c3e
Edition: Community
Git Commit Hash: 38a5139c3eae82d3e2ea5f82f6ea89ceeabb505f
Git Branch: fix-50308
UTC Build Time: 2024-07-30 09:04:16
GoVersion: go1.21.5
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

@crazycs520
Copy link
Contributor Author

/ok-to-test

Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

ti-chi-bot bot commented Jul 30, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, lcwangchao

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [cfzjywxk,lcwangchao]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 30, 2024
Copy link

ti-chi-bot bot commented Jul 30, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-30 06:24:31.88898499 +0000 UTC m=+250588.169033059: ☑️ agreed by lcwangchao.
  • 2024-07-30 12:18:09.318706049 +0000 UTC m=+271805.598754123: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot bot merged commit af9c839 into pingcap:master Jul 30, 2024
23 checks passed
@crazycs520 crazycs520 deleted the fix-50308 branch July 31, 2024 06:10
@crazycs520 crazycs520 added the needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. label Jul 31, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #55086.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

should not return error when updating timestamp to an overflowed value with 'ignore'
4 participants