Skip to content

Commit

Permalink
planner: handle the expected row count for pushed-down selection in m…
Browse files Browse the repository at this point in the history
…pp (#36195)

close #36194
  • Loading branch information
time-and-fate authored Jul 13, 2022
1 parent 2f934d6 commit 24eb419
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ func (ds *DataSource) convertToTableScan(prop *property.PhysicalProperty, candid
ColumnNames: ds.names,
}
ts.cost = cost
mppTask = ts.addPushedDownSelectionToMppTask(mppTask, ds.stats)
mppTask = ts.addPushedDownSelectionToMppTask(mppTask, ds.stats.ScaleByExpectCnt(prop.ExpectedCnt))
return mppTask, nil
}
copTask := &copTask{
Expand Down
28 changes: 28 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6989,3 +6989,31 @@ func TestIssue25813(t *testing.T) {
" └─TableReader(Probe) 10000.00 root data:TableFullScan",
" └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo"))
}

func TestIssue36194(t *testing.T) {
store, dom, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
// create virtual tiflash replica.
is := dom.InfoSchema()
db, exists := is.SchemaByName(model.NewCIStr("test"))
require.True(t, exists)
for _, tblInfo := range db.Tables {
if tblInfo.Name.L == "t" {
tblInfo.TiFlashReplica = &model.TiFlashReplicaInfo{
Count: 1,
Available: true,
}
}
}
tk.MustQuery("explain format = 'brief' select * from t where a + 1 > 20 limit 100;;").Check(testkit.Rows(
"Limit 100.00 root offset:0, count:100",
"└─TableReader 100.00 root data:ExchangeSender",
" └─ExchangeSender 100.00 mpp[tiflash] ExchangeType: PassThrough",
" └─Limit 100.00 mpp[tiflash] offset:0, count:100",
" └─Selection 100.00 mpp[tiflash] gt(plus(test.t.a, 1), 20)",
" └─TableFullScan 125.00 mpp[tiflash] table:t keep order:false, stats:pseudo"))
}
6 changes: 3 additions & 3 deletions planner/core/testdata/integration_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -5952,7 +5952,7 @@
" │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast",
" │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.t.id))",
" │ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo",
" └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.t.id))",
" └─Selection(Probe) 0.80 mpp[tiflash] not(isnull(test.t.id))",
" └─TableFullScan 0.80 mpp[tiflash] table:t1 keep order:false, stats:pseudo"
]
},
Expand All @@ -5968,7 +5968,7 @@
" │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast",
" │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.t.id))",
" │ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo",
" └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.t.id))",
" └─Selection(Probe) 0.80 mpp[tiflash] not(isnull(test.t.id))",
" └─TableFullScan 0.80 mpp[tiflash] table:t1 keep order:false, stats:pseudo"
]
},
Expand All @@ -5985,7 +5985,7 @@
" │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast",
" │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.t.id))",
" │ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo",
" └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.t.id))",
" └─Selection(Probe) 16.00 mpp[tiflash] not(isnull(test.t.id))",
" └─TableFullScan 16.02 mpp[tiflash] table:t1 keep order:false, stats:pseudo"
]
}
Expand Down

0 comments on commit 24eb419

Please sign in to comment.