Skip to content

Commit

Permalink
planner: fix bug in PhysicalTableReader::Clone() (#45302) (#45309)
Browse files Browse the repository at this point in the history
close #45299
  • Loading branch information
ti-chi-bot authored Jul 13, 2023
1 parent 79bb998 commit 905a155
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 2 additions & 3 deletions planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,8 @@ func (p *PhysicalTableReader) Clone() (PhysicalPlan, error) {
if cloned.tablePlan, err = p.tablePlan.Clone(); err != nil {
return nil, err
}
if cloned.TablePlans, err = clonePhysicalPlan(p.TablePlans); err != nil {
return nil, err
}
// TablePlans are actually the flattened plans in tablePlan, so can't copy them, just need to extract from tablePlan
cloned.TablePlans = flattenPushDownPlan(cloned.tablePlan)
return cloned, nil
}

Expand Down
30 changes: 30 additions & 0 deletions planner/core/planbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,36 @@ func TestDeepClone(t *testing.T) {
require.NoError(t, checkDeepClone(sort1, sort2))
}

func TestTablePlansAndTablePlanInPhysicalTableReaderClone(t *testing.T) {
ctx := mock.NewContext()
col, cst := &expression.Column{RetType: types.NewFieldType(mysql.TypeString)}, &expression.Constant{RetType: types.NewFieldType(mysql.TypeLonglong)}
schema := expression.NewSchema(col)
tblInfo := &model.TableInfo{}
hist := &statistics.Histogram{Bounds: chunk.New(nil, 0, 0)}

// table scan
tableScan := &PhysicalTableScan{
AccessCondition: []expression.Expression{col, cst},
Table: tblInfo,
Hist: hist,
}
tableScan = tableScan.Init(ctx, 0)
tableScan.SetSchema(schema)

// table reader
tableReader := &PhysicalTableReader{
tablePlan: tableScan,
TablePlans: []PhysicalPlan{tableScan},
StoreType: kv.TiFlash,
}
tableReader = tableReader.Init(ctx, 0)
clonedPlan, err := tableReader.Clone()
require.NoError(t, err)
newTableReader, ok := clonedPlan.(*PhysicalTableReader)
require.True(t, ok)
require.True(t, newTableReader.tablePlan == newTableReader.TablePlans[0])
}

func TestPhysicalPlanClone(t *testing.T) {
ctx := mock.NewContext()
col, cst := &expression.Column{RetType: types.NewFieldType(mysql.TypeString)}, &expression.Constant{RetType: types.NewFieldType(mysql.TypeLonglong)}
Expand Down

0 comments on commit 905a155

Please sign in to comment.