From b854b4ffd64684d969129343bb271c59ec4faf4e Mon Sep 17 00:00:00 2001
From: Meng Xin <tregoldmeng@gmail.com>
Date: Thu, 17 Feb 2022 10:13:41 +0800
Subject: [PATCH] =?UTF-8?q?expression:=20fix=20date=20format=20identifies?=
 =?UTF-8?q?=20'\n'=20as=20invalid=20separator=20(#32=E2=80=A6=20(#32391)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* expression: fix date format identifies '\n' as invalid separator (#32358)
---
 types/time.go                         | 3 ++-
 types/time_test.go                    | 5 +++++
 util/stmtsummary/statement_summary.go | 6 +++---
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/types/time.go b/types/time.go
index 3aac6c82f..35bae2600 100644
--- a/types/time.go
+++ b/types/time.go
@@ -786,7 +786,8 @@ func isValidSeparator(c byte, prevParts int) bool {
 		return true
 	}
 
-	if prevParts == 2 && (c == ' ' || c == 'T') {
+	// for https://github.com/pingcap/tidb/issues/32232
+	if prevParts == 2 && (c == 'T' || c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r') {
 		return true
 	}
 
diff --git a/types/time_test.go b/types/time_test.go
index e1f0d9162..bb381be49 100644
--- a/types/time_test.go
+++ b/types/time_test.go
@@ -1077,6 +1077,11 @@ func (s *testTimeSuite) TestParseDateFormat(c *C) {
 		{"T10:10:10", nil},
 		{"2011-11-11x", []string{"2011", "11", "11x"}},
 		{"xxx 10:10:10", nil},
+		{"2022-02-01\n16:33:00", []string{"2022", "02", "01", "16", "33", "00"}},
+		{"2022-02-01\f16:33:00", []string{"2022", "02", "01", "16", "33", "00"}},
+		{"2022-02-01\v16:33:00", []string{"2022", "02", "01", "16", "33", "00"}},
+		{"2022-02-01\r16:33:00", []string{"2022", "02", "01", "16", "33", "00"}},
+		{"2022-02-01\t16:33:00", []string{"2022", "02", "01", "16", "33", "00"}},
 	}
 
 	for _, t := range tbl {
diff --git a/util/stmtsummary/statement_summary.go b/util/stmtsummary/statement_summary.go
index f4c934561..36c22e092 100644
--- a/util/stmtsummary/statement_summary.go
+++ b/util/stmtsummary/statement_summary.go
@@ -980,9 +980,9 @@ func (ssElement *stmtSummaryByDigestElement) toDatum(ssbd *stmtSummaryByDigest)
 		avgInt(int64(ssElement.sumPDTotal), ssElement.commitCount),
 		avgInt(int64(ssElement.sumBackoffTotal), ssElement.commitCount),
 		avgInt(int64(ssElement.sumWriteSQLRespTotal), ssElement.commitCount),
-		int64(ssElement.maxResultRows),
-		int64(ssElement.minResultRows),
-		avgInt(int64(ssElement.sumResultRows), ssElement.execCount),
+		ssElement.maxResultRows,
+		ssElement.minResultRows,
+		avgInt(ssElement.sumResultRows, ssElement.execCount),
 		ssElement.prepared,
 		avgFloat(int64(ssElement.sumAffectedRows), ssElement.execCount),
 		types.NewTime(types.FromGoTime(ssElement.firstSeen), mysql.TypeTimestamp, 0),
-- 
GitLab