From 3c46a1e072caab295a5fc36e7f18a58175d3cf79 Mon Sep 17 00:00:00 2001 From: xhe Date: Mon, 1 Jul 2024 18:22:29 +0800 Subject: [PATCH] *: panic guard for warnings (#54043) close pingcap/tidb#48756 --- pkg/executor/show.go | 6 +++++- pkg/executor/test/executor/executor_test.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/executor/show.go b/pkg/executor/show.go index de0b8f9657827..d8d001992b703 100644 --- a/pkg/executor/show.go +++ b/pkg/executor/show.go @@ -1887,7 +1887,11 @@ func (e *ShowExec) fetchShowWarnings(errOnly bool) error { sqlErr := terror.ToSQLError(x) e.appendRow([]any{w.Level, int64(sqlErr.Code), sqlErr.Message}) default: - e.appendRow([]any{w.Level, int64(mysql.ErrUnknown), warn.Error()}) + var err string + if warn != nil { + err = warn.Error() + } + e.appendRow([]any{w.Level, int64(mysql.ErrUnknown), err}) } } return nil diff --git a/pkg/executor/test/executor/executor_test.go b/pkg/executor/test/executor/executor_test.go index 365b154841a2c..46339514352ed 100644 --- a/pkg/executor/test/executor/executor_test.go +++ b/pkg/executor/test/executor/executor_test.go @@ -2928,3 +2928,22 @@ func TestDecimalDivPrecisionIncrement(t *testing.T) { tk.MustExec("set div_precision_increment = 10") tk.MustQuery("select avg(a/b) from t").Check(testkit.Rows("1.21428571428571428550")) } + +func TestIssue48756(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("CREATE TABLE t (id INT, a VARBINARY(20), b BIGINT)") + tk.MustExec(`INSERT INTO t VALUES(1, _binary '2012-05-19 09:06:07', 20120519090607), +(1, _binary '2012-05-19 09:06:07', 20120519090607), +(2, _binary '12012-05-19 09:06:07', 120120519090607), +(2, _binary '12012-05-19 09:06:07', 120120519090607)`) + tk.MustQuery("SELECT SUBTIME(BIT_OR(b), '1 1:1:1.000002') FROM t GROUP BY id").Sort().Check(testkit.Rows( + "2012-05-18 08:05:05.999998", + "", + )) + tk.MustQuery("show warnings").Check(testkit.Rows( + "Warning 1292 Incorrect time value: '120120519090607'", + "Warning 1105 ", + )) +}