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

table: fix zero date in different sqlmode #20206

Merged
merged 17 commits into from
Nov 24, 2020

Conversation

9547
Copy link
Contributor

@9547 9547 commented Sep 24, 2020

What problem does this PR solve?

Issue Number: close #19892, #19634

Problem Summary:

What is changed and how it works?

What's Changed:

How it Works:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Side effects

Release note

  • The same behavior of NO_ZERO_DATE and NO_ZERO_IN_DATE to MySQL's in INSERT/UPDATE statement

@9547 9547 requested a review from a team as a code owner September 24, 2020 15:39
@9547 9547 requested review from lzmhhh123 and removed request for a team September 24, 2020 15:39
@ti-srebot ti-srebot added the contribution This PR is from a community contributor. label Sep 24, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Sep 24, 2020

@9547
Copy link
Contributor Author

9547 commented Sep 24, 2020

@qw4990 PTAL, and curious, why this test case failed, seems not related to my pr? If I've missed something, please let me know.

[2020-09-24T17:15:23.120Z] PASS: session_test.go:1573: testSessionSuite3.TestISColumns	0.005s

[2020-09-24T17:15:23.376Z] panic: runtime error: invalid memory address or nil pointer dereference

[2020-09-24T17:15:23.376Z] [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x2acfdf2]

[2020-09-24T17:15:23.376Z] 

[2020-09-24T17:15:23.376Z] goroutine 5416 [running]:

[2020-09-24T17:15:23.376Z] github.com/pingcap/tidb/util/execdetails.(*BasicRuntimeStats).GetTime(...)

[2020-09-24T17:15:23.376Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/util/execdetails/execdetails.go:555

[2020-09-24T17:15:23.376Z] github.com/pingcap/tidb/executor.(*insertRuntimeStat).String(0xc01085d500, 0x3acaa40, 0xc0107b9920)

[2020-09-24T17:15:23.376Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/executor/insert_common.go:1072 +0x1d2

[2020-09-24T17:15:23.376Z] github.com/pingcap/tidb/util/execdetails.(*RootRuntimeStats).String(0xc00f769920, 0x1, 0xc00f769920)

[2020-09-24T17:15:23.376Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/util/execdetails/execdetails.go:530 +0x235

[2020-09-24T17:15:23.376Z] github.com/pingcap/tidb/planner/core.getRuntimeInfo(0x3b0f9e0, 0xc00ebc8780, 0x3af92a0, 0xc01066a180, 0xc010861260, 0xc010861230, 0x203004, 0x203004, 0x203004, 0xc010861170, ...)

[2020-09-24T17:15:23.376Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/planner/core/common_plans.go:1069 +0x38b

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/planner/core.(*planEncoder).encodePlan(0xc00e2bcde0, 0x3af92a0, 0xc01066a180, 0x1, 0x0)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/planner/core/encode.go:64 +0xaa

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/planner/core.(*planEncoder).encodePlanTree(0xc00e2bcde0, 0x3af92a0, 0xc01066a180, 0x0, 0x2)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/planner/core/encode.go:58 +0x84

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/planner/core.EncodePlan(0x3af92a0, 0xc01066a180, 0x0, 0x0)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/planner/core/encode.go:52 +0x123

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/executor.getPlanTree(0x3af92a0, 0xc01066a180, 0x3af92a0, 0xc01066a180)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/executor/adapter.go:955 +0x87

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/executor.(*ExecStmt).LogSlowQuery(0xc00f589c30, 0x5d3047314c8000b, 0x3ac0000)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/executor/adapter.go:899 +0x456

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/executor.(*ExecStmt).FinishExecuteStmt(0xc00f589c30, 0x5d3047314c8000b, 0xc00ebc0000)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/executor/adapter.go:810 +0xeb

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/session.runStmt(0x3ac7f00, 0xc000062070, 0xc00ebc8780, 0x3ae6680, 0xc00f589c30, 0x0, 0x0, 0x3a6c260, 0xc01085d420)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/session/session.go:1235 +0x446

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/session.(*session).ExecuteStmt(0xc00ebc8780, 0x3ac7f00, 0xc000062070, 0x3ad1000, 0xc00f599a00, 0x0, 0x0, 0x0, 0x0)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/session/session.go:1171 +0x7b9

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/util/testkit.(*TestKit).Exec(0xc00f94bf88, 0x357dfcb, 0x24, 0x0, 0x0, 0x0, 0xc00f74e758, 0x12523b2, 0xc00e1df5d0, 0xc00f74e780)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/util/testkit/testkit.go:160 +0x215

[2020-09-24T17:15:23.377Z] github.com/pingcap/tidb/session_test.(*testSessionSuite2).TestErrorRollback.func1(0xc00f6e94c0, 0xc00eb9cff0, 0xc0007fea80, 0x14)

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/session/session_test.go:300 +0x180

[2020-09-24T17:15:23.377Z] created by github.com/pingcap/tidb/session_test.(*testSessionSuite2).TestErrorRollback

[2020-09-24T17:15:23.377Z] 	/home/jenkins/agent/workspace/tidb_ghpr_check_2/go/src/github.com/pingcap/tidb/session/session_test.go:295 +0x1d9

[2020-09-24T17:15:23.377Z] exit status 2

[2020-09-24T17:15:23.377Z] FAIL	github.com/pingcap/tidb/session	4.716s

@rebelice
Copy link
Contributor

/run-check_dev_2

tk.MustExec("TRUNCATE TABLE dd")
tk.MustExec("INSERT INTO dd(a) values('2000-10-01')")
tk.MustExec("UPDATE dd SET a = '0000-00-00'")
// tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '0000-00-00'"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you tell me why comment it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems there was two identical warning messages , but I have no idea why that happened

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it's to check insert and update both generating a warning

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the insert stmt is valid, no warnings should generated

Copy link
Contributor

Choose a reason for hiding this comment

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

i mean line 7521 and 7527 should both be checked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the advice, and is there any way to clear warnings before an stmt executing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems the warning messages are automatically deleted after a valid STMT executed, IMO, line 7521's warning will not affect this line.

Copy link
Contributor

Choose a reason for hiding this comment

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

seems our communication is misleading 🤣 i mean this line shouldn't be commented as it could check above update generated a warning. and maybe you say that it generated two identical warnings? that's an unexpected behaviour, maybe some bug in code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😂 sorry for the misunderstanding. In my local tests, the warning count maybe 1 or 2. currently, rebase from the master branch and remove the comment, the local test seems passed. Push it up to see the CI passed or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's passed 🎉

table/column.go Outdated Show resolved Hide resolved
Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

good work

@lance6716
Copy link
Contributor

PTAL @rebelice @lzmhhh123

table/column.go Outdated Show resolved Hide resolved
table/column.go Outdated Show resolved Hide resolved
expression/integration_test.go Outdated Show resolved Hide resolved
@9547 9547 force-pushed the fix/no-zero-date-sqlmode branch 2 times, most recently from a300651 to 54158e2 Compare October 17, 2020 19:15
@github-actions github-actions bot added the sig/execution SIG execution label Oct 17, 2020
@9547
Copy link
Contributor Author

9547 commented Oct 17, 2020

@rebelice Sorry for the late reply, please have a look again

Copy link
Contributor

@rebelice rebelice left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot
Copy link
Contributor

@rebelice, Thanks for your review. The bot only counts LGTMs from Reviewers and higher roles, but you're still welcome to leave your comments. See the corresponding SIG page for more information. Related SIG: execution(slack).

@rebelice
Copy link
Contributor

/run-all-tests

@rebelice
Copy link
Contributor

/rebuild

@lzmhhh123
Copy link
Contributor

@ichn-hu Please help to review this PR.

Copy link
Contributor

@ichn-hu ichn-hu left a comment

Choose a reason for hiding this comment

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

Rest LGTM

table/column.go Outdated
}

innerErr := types.ErrWrongValue.GenWithStackByArgs(zeroT, val.GetString())
ignoreErr := sc.DupKeyAsWarning
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use DupKeyAsWarning for ignore error? I think here it is not about dup key, but zero date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 17, 2020
@ghost
Copy link

ghost commented Nov 23, 2020

OK. In the worst case, we can add a rand DateTime for each inserted row.

That was my initial plan, but the zero date is used on a table which uses this to signify a deleted_at date:

INSERT INTO `addresses` (`address1`,`address2`,`post`,`created_at`,`updated_at`,`deleted_at`) VALUES (?,?,?,?,?,?) [arguments: (Billing Address pluck_user3, , , 2020-11-19 20:30:17.882469, 2020-11-19 20:30:17.882469, 0000-00-00)];

I would have to create a special valid date to replace this, which is not ideal. In anycase, the gorm test is now passing with an expicit sql mode.

@ghost
Copy link

ghost commented Nov 23, 2020

/run-common-test tidb-test=pr/1109
/run-integration-common-test tidb-test=pr/1109

@ghost
Copy link

ghost commented Nov 23, 2020

/run-common-test tidb-test=pr/1109
/run-integration-common-test tidb-test=pr/1109

@ghost
Copy link

ghost commented Nov 23, 2020

/run-common-test tidb-test=pr/1109

1 similar comment
@ghost
Copy link

ghost commented Nov 23, 2020

/run-common-test tidb-test=pr/1109

@ghost
Copy link

ghost commented Nov 23, 2020

There were more broken tests than I first noticed:

  • Gorm test (fixed in pr/1109)
  • JDBC test (fixed in pr/1109)
  • mysql_test (fixed)

@9547
Copy link
Contributor Author

9547 commented Nov 23, 2020

@nullnotnil Is there anything I need to fix first, or I can help?

@ghost
Copy link

ghost commented Nov 23, 2020

@nullnotnil Is there anything I need to fix first, or I can help?

It's okay. I took another look at it, and I think I will fix the mysql_test cases that break and close pingcap/mysql-tester#9 . It doesn't look as bad as I thought - give me a few hours :-)

@ghost
Copy link

ghost commented Nov 23, 2020

I don't think that we should cherry-pick this into the release branch (v4.0). Given that the regression test suite is breaking in a few places, there are likely apps that are depending on this without knowing it. It is better to have them discover the issue when upgrading to the next major release.

@ghost
Copy link

ghost commented Nov 24, 2020

/run-common-test tidb-test=pr/1109
/run-integration-common-test tidb-test=pr/1109

@lzmhhh123
Copy link
Contributor

I don't think that we should cherry-pick this into the release branch (v4.0). Given that the regression test suite is breaking in a few places, there are likely apps that are depending on this without knowing it. It is better to have them discover the issue when upgrading to the next major release.

OK, I agree.

@lzmhhh123
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor

Your auto merge job has been accepted, waiting for:

  • 21182
  • 21124

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@9547 merge failed.

@ichn-hu
Copy link
Contributor

ichn-hu commented Nov 24, 2020

/run-unit-tests

@wjhuang2016
Copy link
Member

/run-cherry-picker

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Dec 8, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #21553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

different behaviour of NO_ZERO_DATE with mysql
10 participants