Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plancodec: add test for plan id to avoid change the plan id. #17385

Merged
merged 12 commits into from
Jun 2, 2020
81 changes: 41 additions & 40 deletions util/plancodec/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,47 +105,48 @@ const (
)

// plan id.
// Attention: for compatibility of encode/decode plan, The plan id shouldn't be changed.
const (
typeSelID int = iota + 1
typeSetID
typeProjID
typeAggID
typeStreamAggID
typeHashAggID
typeShowID
typeJoinID
typeUnionID
typeTableScanID
typeMemTableScanID
typeUnionScanID
typeIdxScanID
typeSortID
typeTopNID
typeLimitID
typeHashJoinID
typeMergeJoinID
typeIndexJoinID
typeIndexMergeJoinID
typeIndexHashJoinID
typeApplyID
typeMaxOneRowID
typeExistsID
typeDualID
typeLockID
typeInsertID
typeUpdateID
typeDeleteID
typeIndexLookUpID
typeTableReaderID
typeIndexReaderID
typeWindowID
typeTiKVSingleGatherID
typeIndexMergeID
typePointGet
typeShowDDLJobs
typeBatchPointGet
typeClusterMemTableReader
typeDataSourceID
typeSelID int = 1
typeSetID = 2
typeProjID = 3
typeAggID = 4
typeStreamAggID = 5
typeHashAggID = 6
typeShowID = 7
typeJoinID = 8
typeUnionID = 9
typeTableScanID = 10
typeMemTableScanID = 11
typeUnionScanID = 12
typeIdxScanID = 13
typeSortID = 14
typeTopNID = 15
typeLimitID = 16
typeHashJoinID = 17
typeMergeJoinID = 18
typeIndexJoinID = 19
typeIndexMergeJoinID = 20
typeIndexHashJoinID = 21
typeApplyID = 22
typeMaxOneRowID = 23
typeExistsID = 24
typeDualID = 25
typeLockID = 26
typeInsertID = 27
typeUpdateID = 28
typeDeleteID = 29
typeIndexLookUpID = 30
typeTableReaderID = 31
typeIndexReaderID = 32
typeWindowID = 33
typeTiKVSingleGatherID = 34
typeIndexMergeID = 35
typePointGet = 36
typeShowDDLJobs = 37
typeBatchPointGet = 38
typeClusterMemTableReader = 39
typeDataSourceID = 40
)

// TypeStringToPhysicalID converts the plan type string to plan id.
Expand Down
73 changes: 73 additions & 0 deletions util/plancodec/id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package plancodec

import (
"testing"

. "github.com/pingcap/check"
)

func TestT(t *testing.T) {
CustomVerboseFlag = true
TestingT(t)
}

var _ = Suite(&testPlanIDSuite{})

type testPlanIDSuite struct{}

func (s *testPlanIDSuite) TestPlanIDChanged(c *C) {
// Attention: for compatibility, shouldn't modify the below test, you can only add test when add new plan ID.
c.Assert(typeSelID, Equals, 1)
c.Assert(typeSetID, Equals, 2)
c.Assert(typeProjID, Equals, 3)
c.Assert(typeAggID, Equals, 4)
c.Assert(typeStreamAggID, Equals, 5)
c.Assert(typeHashAggID, Equals, 6)
c.Assert(typeShowID, Equals, 7)
c.Assert(typeJoinID, Equals, 8)
c.Assert(typeUnionID, Equals, 9)
c.Assert(typeTableScanID, Equals, 10)
c.Assert(typeMemTableScanID, Equals, 11)
c.Assert(typeUnionScanID, Equals, 12)
c.Assert(typeIdxScanID, Equals, 13)
c.Assert(typeSortID, Equals, 14)
c.Assert(typeTopNID, Equals, 15)
c.Assert(typeLimitID, Equals, 16)
c.Assert(typeHashJoinID, Equals, 17)
c.Assert(typeMergeJoinID, Equals, 18)
c.Assert(typeIndexJoinID, Equals, 19)
c.Assert(typeIndexMergeJoinID, Equals, 20)
c.Assert(typeIndexHashJoinID, Equals, 21)
c.Assert(typeApplyID, Equals, 22)
c.Assert(typeMaxOneRowID, Equals, 23)
c.Assert(typeExistsID, Equals, 24)
c.Assert(typeDualID, Equals, 25)
c.Assert(typeLockID, Equals, 26)
c.Assert(typeInsertID, Equals, 27)
c.Assert(typeUpdateID, Equals, 28)
c.Assert(typeDeleteID, Equals, 29)
c.Assert(typeIndexLookUpID, Equals, 30)
c.Assert(typeTableReaderID, Equals, 31)
c.Assert(typeIndexReaderID, Equals, 32)
c.Assert(typeWindowID, Equals, 33)
c.Assert(typeTiKVSingleGatherID, Equals, 34)
c.Assert(typeIndexMergeID, Equals, 35)
c.Assert(typePointGet, Equals, 36)
c.Assert(typeShowDDLJobs, Equals, 37)
c.Assert(typeBatchPointGet, Equals, 38)
c.Assert(typeClusterMemTableReader, Equals, 39)
c.Assert(typeDataSourceID, Equals, 40)
}