From 6339df7ae2d575c0f4ebae8e5e658b2bc890a396 Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Thu, 14 May 2020 13:48:23 +0800 Subject: [PATCH] planner: fix TiDB server panic when uses indexMerge with the virtual generated column (#17065) (#17126) --- expression/integration_test.go | 10 ++++++++++ planner/core/find_best_task.go | 1 + planner/core/resolve_indices.go | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/expression/integration_test.go b/expression/integration_test.go index dec5fb198b5db..71dedf0d9d411 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -6352,3 +6352,13 @@ func (s *testIntegrationSuite) TestIssue16505(c *C) { tk.MustQuery("select /*+ IGNORE_INDEX(t, idx) */* from t where c;").Sort().Check(testkit.Rows("0.0001deadsfeww", "1", "123e456")) tk.MustExec("drop table t;") } + +func (s *testIntegrationSuite) TestIssue17045(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int,b varchar(20),c datetime,d double,e int,f int as(a+b),key(a),key(b),key(c),key(d),key(e),key(f));") + tk.MustExec("insert into t(a,b,e) values(null,\"5\",null);") + tk.MustExec("insert into t(a,b,e) values(\"5\",null,null);") + tk.MustQuery("select /*+ use_index_merge(t)*/ * from t where t.e=5 or t.a=5;").Check(testkit.Rows("5 ")) +} diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index d7044c8cebe98..f3d0bd6c60664 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -671,6 +671,7 @@ func (ds *DataSource) buildIndexMergeTableScan(prop *property.PhysicalProperty, physicalTableID: ds.physicalTableID, }.Init(ds.ctx, ds.blockOffset) ts.SetSchema(ds.schema.Clone()) + ts.Columns = ExpandVirtualColumn(ts.Columns, ts.schema, ts.Table.Columns) if ts.Table.PKIsHandle { if pkColInfo := ts.Table.GetPkColInfo(); pkColInfo != nil { if ds.statisticTable.Columns[pkColInfo.ID] != nil { diff --git a/planner/core/resolve_indices.go b/planner/core/resolve_indices.go index c9e67a95a3cba..f322e00dad4bc 100644 --- a/planner/core/resolve_indices.go +++ b/planner/core/resolve_indices.go @@ -300,6 +300,10 @@ func (p *PhysicalIndexLookUpReader) ResolveIndices() (err error) { // ResolveIndices implements Plan interface. func (p *PhysicalIndexMergeReader) ResolveIndices() (err error) { + err = resolveIndicesForVirtualColumn(p.tablePlan.Schema().Columns, p.schema) + if err != nil { + return err + } if p.tablePlan != nil { err = p.tablePlan.ResolveIndices() if err != nil {