From df020753cb91c9b51a1b57d1b4241f4dfc7774b8 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Mon, 25 May 2020 16:30:10 +0800 Subject: [PATCH 1/4] plancodec: add test for plan id Signed-off-by: crazycs520 --- util/plancodec/id.go | 1 + util/plancodec/id_test.go | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 util/plancodec/id_test.go diff --git a/util/plancodec/id.go b/util/plancodec/id.go index d4fb2828703a5..00bca1b2e80da 100644 --- a/util/plancodec/id.go +++ b/util/plancodec/id.go @@ -103,6 +103,7 @@ const ( ) // plan id. +// Attention: For compatibility of encode/decode plan, The plan id shouldn't be changed. const ( typeSelID int = iota + 1 typeSetID diff --git a/util/plancodec/id_test.go b/util/plancodec/id_test.go new file mode 100644 index 0000000000000..81b0523256563 --- /dev/null +++ b/util/plancodec/id_test.go @@ -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) +} From fa9e30a956e17380a134ec4eb4245fefdca6cf76 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Mon, 25 May 2020 16:34:24 +0800 Subject: [PATCH 2/4] refine code Signed-off-by: crazycs520 --- util/plancodec/id.go | 80 ++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/util/plancodec/id.go b/util/plancodec/id.go index 00bca1b2e80da..f5ec233de47af 100644 --- a/util/plancodec/id.go +++ b/util/plancodec/id.go @@ -105,46 +105,46 @@ 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. From a58b9aee1b0aaeebce7dea29433242c6cd591146 Mon Sep 17 00:00:00 2001 From: crazycs Date: Mon, 25 May 2020 16:41:07 +0800 Subject: [PATCH 3/4] Update util/plancodec/id.go --- util/plancodec/id.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/plancodec/id.go b/util/plancodec/id.go index f5ec233de47af..a4073d4c1cf35 100644 --- a/util/plancodec/id.go +++ b/util/plancodec/id.go @@ -103,7 +103,7 @@ const ( ) // plan id. -// Attention: For compatibility of encode/decode plan, The plan id shouldn't be changed. +// Attention: for compatibility of encode/decode plan, The plan id shouldn't be changed. const ( typeSelID int = 1 typeSetID = 2 From b92af707f94a6e975c6fd7491b724473977ba9bf Mon Sep 17 00:00:00 2001 From: crazycs Date: Fri, 29 May 2020 20:12:23 +0800 Subject: [PATCH 4/4] Update util/plancodec/id_test.go Co-authored-by: Zhi Qi <30543181+LittleFall@users.noreply.github.com> --- util/plancodec/id_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/plancodec/id_test.go b/util/plancodec/id_test.go index 81b0523256563..3c008eb609659 100644 --- a/util/plancodec/id_test.go +++ b/util/plancodec/id_test.go @@ -29,7 +29,7 @@ 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. + // 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)