Skip to content

Commit

Permalink
use binary_plan (#1284)
Browse files Browse the repository at this point in the history
  • Loading branch information
srstack authored Jun 23, 2022
1 parent f27ece9 commit 130a049
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ require (
moul.io/zapgorm2 v1.1.0
)

replace github.com/pingcap/tipb => github.com/time-and-fate/tipb v0.0.0-20220422062657-6cbe68f6f792
replace github.com/pingcap/tipb => github.com/time-and-fate/tipb v0.0.0-20220620062228-0abb96df1346
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/time-and-fate/tipb v0.0.0-20220422062657-6cbe68f6f792 h1:0qivTgwynumUOEniZdvhRXhCJhuab6ionraB2PapMbM=
github.com/time-and-fate/tipb v0.0.0-20220422062657-6cbe68f6f792/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs=
github.com/time-and-fate/tipb v0.0.0-20220620062228-0abb96df1346 h1:piwDubHK1EBkMJbOoDbQ1swQFpMEe9v0VKrCKEFRjOk=
github.com/time-and-fate/tipb v0.0.0-20220620062228-0abb96df1346/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8 h1:ndzgwNDnKIqyCvHTXaCqh9KlOWKvBry6nuXMJmonVsE=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/slowquery/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Model struct {
// Detail
PrevStmt string `gorm:"column:Prev_stmt" json:"prev_stmt"`
Plan string `gorm:"column:Plan" json:"plan"`
VisualPlan string `gorm:"column:Visual_plan" json:"visual_plan"`
BinaryPlan string `gorm:"column:Binary_plan" json:"binary_plan"`

// Basic
IsInternal int `gorm:"column:Is_internal" json:"is_internal"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/apiserver/slowquery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func (s *Service) getDetails(c *gin.Context) {
return
}

// get visual plan
result.VisualPlan, err = utils.GenerateVisualPlanJSON(result.VisualPlan)
// generate binary plan
result.BinaryPlan, err = utils.GenerateBinaryPlanJSON(result.BinaryPlan)
if err != nil {
rest.Error(c, err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/statement/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type Model struct {
AggPlanCount int `json:"plan_count" agg:"COUNT(DISTINCT plan_digest)" related:"plan_digest"`
AggPlan string `json:"plan" agg:"ANY_VALUE(plan)"`
AggPlanDigest string `json:"plan_digest" agg:"ANY_VALUE(plan_digest)"`
AggVisualPlan string `json:"visual_plan" agg:"ANY_VALUE(VISUAL_PLAN)"`
AggBinaryPlan string `json:"binary_plan" agg:"ANY_VALUE(binary_plan)"`
// RocksDB
AggMaxRocksdbDeleteSkippedCount uint `json:"max_rocksdb_delete_skipped_count" agg:"MAX(max_rocksdb_delete_skipped_count)"`
AggAvgRocksdbDeleteSkippedCount uint `json:"avg_rocksdb_delete_skipped_count" agg:"CAST(SUM(exec_count * avg_rocksdb_delete_skipped_count) / SUM(exec_count) as SIGNED)"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/apiserver/statement/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ func (s *Service) planDetailHandler(c *gin.Context) {
return
}

// get visual plan
result.AggVisualPlan, err = utils.GenerateVisualPlanJSON(result.AggVisualPlan)
// get binary plan
result.AggBinaryPlan, err = utils.GenerateBinaryPlanJSON(result.AggBinaryPlan)
if err != nil {
rest.Error(c, err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/pingcap/tipb/go-tipb"
)

// GenerateVisualPlan generate visual plan from raw data.
func GenerateVisualPlan(v string) (*tipb.VisualData, error) {
// GenerateBinaryPlan generate visual plan from raw data.
func GenerateBinaryPlan(v string) (*tipb.ExplainData, error) {
if v == "" {
return nil, nil
}
Expand All @@ -24,36 +24,36 @@ func GenerateVisualPlan(v string) (*tipb.VisualData, error) {
}

// snappy uncompress
vpBytes, err := snappy.Decode(nil, compressVPBytes)
bpBytes, err := snappy.Decode(nil, compressVPBytes)
if err != nil {
return nil, err
}

// proto unmarshal
visual := &tipb.VisualData{}
err = visual.Unmarshal(vpBytes)
bp := &tipb.ExplainData{}
err = bp.Unmarshal(bpBytes)
if err != nil {
return nil, err
}
return visual, nil
return bp, nil
}

func GenerateVisualPlanJSON(v string) (string, error) {
// generate vp
vp, err := GenerateVisualPlan(v)
func GenerateBinaryPlanJSON(b string) (string, error) {
// generate bp
bp, err := GenerateBinaryPlan(b)
if err != nil {
return "", err
}

if vp == nil {
if bp == nil {
return "", nil
}

// json marshal
vpJSON, err := json.Marshal(vp)
bpJSON, err := json.Marshal(bp)
if err != nil {
return "", err
}

return string(vpJSON), nil
return string(bpJSON), nil
}
21 changes: 21 additions & 0 deletions pkg/apiserver/utils/binary_plan_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0.

package utils

import "testing"

var bpTestStr = "SiwKRgoGU2hvd18yKQAFAYjwPzAFOAFAAWoVdGltZTozNC44wrVzLCBsb29wczoygAH//w0COAGIAf///////////wEYAQ=="

func TestGenerateBinaryPlan(t *testing.T) {
_, err := GenerateBinaryPlan(bpTestStr)
if err != nil {
t.Fatalf("generate Visual plan failed: %v", err)
}
}

func TestGenerateBinaryPlanJson(t *testing.T) {
_, err := GenerateBinaryPlanJSON(bpTestStr)
if err != nil {
t.Fatalf("generate Visual plan failed: %v", err)
}
}
21 changes: 0 additions & 21 deletions pkg/apiserver/utils/visual_plan_test.go

This file was deleted.

0 comments on commit 130a049

Please sign in to comment.