From bdf75812485ece490a983e506e9916669a3870f4 Mon Sep 17 00:00:00 2001 From: Zhou Kunqin <25057648+time-and-fate@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:10:22 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #40429 Signed-off-by: ti-chi-bot --- planner/core/integration_test.go | 9 +++++++++ planner/core/logical_plan_builder.go | 4 +++- planner/core/plan_cost_ver2_test.go | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 521e928a12edf..dce3b884b02cf 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -8350,6 +8350,7 @@ func TestAutoIncrementCheckWithCheckConstraint(t *testing.T) { )`) } +<<<<<<< HEAD // https://github.com/pingcap/tidb/issues/41273 func TestIssue41273(t *testing.T) { store := testkit.CreateMockStore(t) @@ -8796,4 +8797,12 @@ FROM ( WHERE res.state != 2 ORDER BY res.branch_id; `, errno.ErrNotSupportedYet) +======= +func TestIssue40285(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("CREATE TABLE t(col1 enum('p5', '9a33x') NOT NULL DEFAULT 'p5',col2 tinyblob DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = latin1 COLLATE = latin1_bin;") + tk.MustQuery("(select last_value(col1) over () as r0 from t) union all (select col2 as r0 from t);") +>>>>>>> 362defb112d (planner: add nil check when handling empty charset in `setUnionFlen` (#40429)) } diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 02cd8e00d7b36..3c330c341d728 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1729,7 +1729,9 @@ func (*PlanBuilder) setUnionFlen(resultTp *types.FieldType, cols []expression.Ex childTp := cols[i].GetType() childTpCharLen := 1 if isBinary { - childTpCharLen = charset.CharacterSetInfos[childTp.GetCharset()].Maxlen + if charsetInfo, ok := charset.CharacterSetInfos[childTp.GetCharset()]; ok { + childTpCharLen = charsetInfo.Maxlen + } } resultTp.SetFlen(mathutil.Max(resultTp.GetFlen(), childTpCharLen*childTp.GetFlen())) } diff --git a/planner/core/plan_cost_ver2_test.go b/planner/core/plan_cost_ver2_test.go index f6384a14f3cf7..16540cb784fa2 100644 --- a/planner/core/plan_cost_ver2_test.go +++ b/planner/core/plan_cost_ver2_test.go @@ -177,6 +177,7 @@ func TestCostModelVer2ScanRowSize(t *testing.T) { tk.MustExec(`create table t (pk int, a int, b int, c int, d int, primary key(pk), index ab(a, b), index abc(a, b, c))`) tk.MustExec("insert into t values (1, 1, 1, 1, 1)") tk.MustExec(`set @@tidb_cost_model_version=2`) + tk.MustExec("set global tidb_enable_collect_execution_info=1;") cases := []struct { query string From 5fb5d80e59bbe317044de29b8c5f0960479cf148 Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:57:31 +0800 Subject: [PATCH 2/2] resolve conflicts --- planner/core/integration_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index dce3b884b02cf..cdcc4bfbac1e9 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -8350,7 +8350,6 @@ func TestAutoIncrementCheckWithCheckConstraint(t *testing.T) { )`) } -<<<<<<< HEAD // https://github.com/pingcap/tidb/issues/41273 func TestIssue41273(t *testing.T) { store := testkit.CreateMockStore(t) @@ -8797,12 +8796,12 @@ FROM ( WHERE res.state != 2 ORDER BY res.branch_id; `, errno.ErrNotSupportedYet) -======= +} + func TestIssue40285(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") tk.MustExec("CREATE TABLE t(col1 enum('p5', '9a33x') NOT NULL DEFAULT 'p5',col2 tinyblob DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = latin1 COLLATE = latin1_bin;") tk.MustQuery("(select last_value(col1) over () as r0 from t) union all (select col2 as r0 from t);") ->>>>>>> 362defb112d (planner: add nil check when handling empty charset in `setUnionFlen` (#40429)) }