Skip to content

Commit

Permalink
add a switch to avoid plan generation fail before tiflash side merged
Browse files Browse the repository at this point in the history
Signed-off-by: AilinKid <[email protected]>
  • Loading branch information
AilinKid committed Feb 20, 2023
1 parent 7fd6766 commit b353681
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
7 changes: 5 additions & 2 deletions planner/core/casetest/enforce_mpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (

"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/planner/core/internal"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/external"
"github.com/pingcap/tidb/testkit/testdata"
"github.com/pingcap/tidb/util/collate"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -492,7 +494,7 @@ func TestMPPSingleDistinct3Stage(t *testing.T) {
//
// since it doesn't change the schema out (index ref is still the right), so by now it's fine. SEE case: EXPLAIN select count(distinct a), count(distinct b), sum(c) from t.
func TestMPPMultiDistinct3Stage(t *testing.T) {
store := testkit.CreateMockStore(t, withMockTiFlash(2))
store := testkit.CreateMockStore(t, internal.WithMockTiFlash(2))
tk := testkit.NewTestKit(t, store)

// test table
Expand All @@ -503,6 +505,7 @@ func TestMPPMultiDistinct3Stage(t *testing.T) {
tb := external.GetTableByName(t, tk, "test", "t")
err := domain.GetDomain(tk.Session()).DDL().UpdateTableReplicaInfo(tk.Session(), tb.Meta().ID, true)
require.NoError(t, err)
tk.MustExec("set @@session.tidb_opt_enable_three_stage_multi_distinct_agg=1")
tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\";")
tk.MustExec("set @@session.tidb_enforce_mpp=1")
tk.MustExec("set @@session.tidb_allow_mpp=ON;")
Expand All @@ -525,7 +528,7 @@ func TestMPPMultiDistinct3Stage(t *testing.T) {
Plan []string
Warn []string
}
enforceMPPSuiteData := plannercore.GetEnforceMPPSuiteData()
enforceMPPSuiteData := GetEnforceMPPSuiteData()
enforceMPPSuiteData.LoadTestCases(t, &input, &output)
for i, tt := range input {
testdata.OnRecord(func() {
Expand Down
2 changes: 1 addition & 1 deletion planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ func (p *basePhysicalAgg) scale3StageForDistinctAgg() (bool, expression.Grouping

// canUse3Stage4MultiDistinctAgg returns true if this agg can use 3 stage for multi distinct aggregation
func (p *basePhysicalAgg) canUse3Stage4MultiDistinctAgg() (can bool, gss expression.GroupingSets) {
if !p.ctx.GetSessionVars().Enable3StageDistinctAgg || len(p.GroupByItems) > 0 {
if !p.ctx.GetSessionVars().Enable3StageDistinctAgg || !p.ctx.GetSessionVars().Enable3StageMultiDistinctAgg || len(p.GroupByItems) > 0 {
return false, nil
}
defer func() {
Expand Down
3 changes: 3 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,9 @@ type SessionVars struct {
// Enable3StageDistinctAgg indicates whether to allow 3 stage distinct aggregate
Enable3StageDistinctAgg bool

// Enable3StageMultiDistinctAgg indicates whether to allow 3 stage multi distinct aggregate
Enable3StageMultiDistinctAgg bool

// MultiStatementMode permits incorrect client library usage. Not recommended to be turned on.
MultiStatementMode int

Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ var defaultSysVars = []*SysVar{
s.Enable3StageDistinctAgg = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBOptEnable3StageMultiDistinctAgg, Value: BoolToOnOff(DefTiDB3StageMultiDistinctAgg), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.Enable3StageMultiDistinctAgg = TiDBOptOn(val)
return nil
}},
{Scope: ScopeSession, Name: TiDBOptWriteRowID, Value: BoolToOnOff(DefOptWriteRowID), Type: TypeBool, SetSession: func(s *SessionVars, val string) error {
s.AllowWriteRowID = TiDBOptOn(val)
return nil
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const (
// TiDBOpt3StageDistinctAgg is used to indicate whether to plan and execute the distinct agg in 3 stages
TiDBOpt3StageDistinctAgg = "tidb_opt_three_stage_distinct_agg"

// TiDBOptEnable3StageMultiDistinctAgg is used to indicate whether to plan and execute the multi distinct agg in 3 stages
TiDBOptEnable3StageMultiDistinctAgg = "tidb_opt_enable_three_stage_multi_distinct_agg"

// TiDBBCJThresholdSize is used to limit the size of small table for mpp broadcast join.
// Its unit is bytes, if the size of small table is larger than it, we will not use bcj.
TiDBBCJThresholdSize = "tidb_broadcast_join_threshold_size"
Expand Down Expand Up @@ -1106,6 +1109,7 @@ const (
DefTiDBRemoveOrderbyInSubquery = false
DefTiDBSkewDistinctAgg = false
DefTiDB3StageDistinctAgg = true
DefTiDB3StageMultiDistinctAgg = false
DefTiDBReadStaleness = 0
DefTiDBGCMaxWaitTime = 24 * 60 * 60
DefMaxAllowedPacket uint64 = 67108864
Expand Down

0 comments on commit b353681

Please sign in to comment.