How to compile XiaoMi SOAR – SQL Optimizer And Rewriter from source.

New photo by WuNan Lin / Google Photos

SOAR (SQL Optimizer And Rewriter) is a tool, which can help SQL optimization and rewrite. It’s developed and maintained by the DBA Team of Xiaomi AI&Cloud.
This is an amazing tool for DBA.
But I still want to check the content and then compile to binary before using it.
You may need the following:

  1. Mac Pro with macOS 10.14 Mojave
  2. SOAP Version: https://github.com/XiaoMi/soar.git (Tag v0.8.0)
  3. Ref & Read The Manual.

git clone source first.

wnlin:git wn.lin$ git clone https://github.com/XiaoMi/soar.git
Cloning into 'soar'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 582 (delta 4), reused 2 (delta 0), pack-reused 564
Receiving objects: 100% (582/582), 2.08 MiB | 307.00 KiB/s, done.
Resolving deltas: 100% (141/141), done.

Check PATH & GOPATH

wnlin:git wn.lin$ echo ${PATH}
/usr/local/Cellar/go/bin:/usr/local/opt/mysql@5.7/bin:/usr/local/opt/mysql-client/bin:/Users/user/work/6_gcp/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
wnlin:git wn.lin$ echo ${GOPATH}
/usr/local/Cellar/go/bin

Check dependencies by # make deps

wnlin:soar wn.lin$ make deps
Dependency check
mysql found
docker found
git found
go found
govendor found
retool found
# The retool tools.json is setup from retool-install.sh
retool sync
retool: downloading gopkg.in/alecthomas/gometalinter.v2
retool: setting version for gopkg.in/alecthomas/gometalinter.v2
retool: downloading github.com/client9/misspell/cmd/misspell
retool: setting version for github.com/client9/misspell/cmd/misspell
retool: downloading github.com/chzchzchz/goword
retool: setting version for github.com/chzchzchz/goword
retool: downloading github.com/gordonklaus/ineffassign
retool: setting version for github.com/gordonklaus/ineffassign
retool: downloading github.com/dnephin/govet
retool: setting version for github.com/dnephin/govet
retool: downloading github.com/securego/gosec/cmd/gosec
retool: setting version for github.com/securego/gosec/cmd/gosec
retool: downloading github.com/kisielk/errcheck
retool: setting version for github.com/kisielk/errcheck
retool: downloading github.com/mgechev/revive
retool: setting version for github.com/mgechev/revive
retool: downloading github.com/golangci/golangci-lint/cmd/golangci-lint
retool: setting version for github.com/golangci/golangci-lint/cmd/golangci-lint
retool: downloading honnef.co/go/tools/cmd/megacheck
retool: setting version for honnef.co/go/tools/cmd/megacheck
retool: installing gopkg.in/alecthomas/gometalinter.v2
retool: installing github.com/client9/misspell/cmd/misspell
retool: installing github.com/chzchzchz/goword
retool: installing github.com/gordonklaus/ineffassign
retool: installing github.com/dnephin/govet
retool: installing github.com/securego/gosec/cmd/gosec
retool: installing github.com/kisielk/errcheck
retool: installing github.com/mgechev/revive
retool: installing github.com/golangci/golangci-lint/cmd/golangci-lint
retool: installing honnef.co/go/tools/cmd/megacheck
retool do gometalinter.v2 intall
WARNING: exec: "gotype": executable file not found in $PATH
WARNING: exec: "maligned": executable file not found in $PATH
WARNING: exec: "deadcode": executable file not found in $PATH
WARNING: exec: "unconvert": executable file not found in $PATH
WARNING: exec: "goconst": executable file not found in $PATH
WARNING: exec: "varcheck": executable file not found in $PATH
WARNING: exec: "structcheck": executable file not found in $PATH
WARNING: exec: "gotype": executable file not found in $PATH
WARNING: exec: "golint": executable file not found in $PATH
WARNING: exec: "gas": executable file not found in $PATH
WARNING: exec: "gocyclo": executable file not found in $PATH
WARNING: exec: "interfacer": executable file not found in $PATH
retool: fatal err: failed on 'gometalinter.v2 intall': exit status 2
make: *** [deps] Error 1

gometalinter.v2 version problem, soar already using last version.

diff --git a/retool-install.sh b/retool-install.sh
index 23e441e..877ef91 100755
--- a/retool-install.sh
 +++ b/retool-install.sh
 @@ -6,7 +6,7 @@ set -euo pipefail
  which retool >/dev/null || go get -u github.com/twitchtv/retool
  # This tool can run other checks in a standardized way
 -retool add gopkg.in/alecthomas/gometalinter.v2 v2.0.5
 +retool add gopkg.in/alecthomas/gometalinter.v2 v2.0.11
  # check spelling
  # misspell works with gometalinter

Try to test reinstall.

wnlin:bin wn.lin$ gometalinter.v2 --install
Installing:
  deadcode
  dupl
  errcheck
  gochecknoglobals
  gochecknoinits
  goconst
  gocyclo
  goimports
  golint
  gosec
  gosimple
  gotype
  gotypex
  ineffassign
  interfacer
  lll
  maligned
  megacheck
  misspell
  nakedret
  safesql
  staticcheck
  structcheck
  unconvert
  unparam
  unused
  varcheck

Make deps again.

wnlin:soar wn.lin$ make deps
Dependency check
mysql found
docker found
git found
go found
govendor found
retool found
# The retool tools.json is setup from retool-install.sh
retool sync
retool: downloading gopkg.in/alecthomas/gometalinter.v2
retool: setting version for gopkg.in/alecthomas/gometalinter.v2
retool: downloading github.com/client9/misspell/cmd/misspell
retool: setting version for github.com/client9/misspell/cmd/misspell
retool: downloading github.com/chzchzchz/goword
retool: setting version for github.com/chzchzchz/goword
retool: downloading github.com/gordonklaus/ineffassign
retool: setting version for github.com/gordonklaus/ineffassign
retool: downloading github.com/dnephin/govet
retool: setting version for github.com/dnephin/govet
retool: downloading github.com/securego/gosec/cmd/gosec
retool: setting version for github.com/securego/gosec/cmd/gosec
retool: downloading github.com/kisielk/errcheck
retool: setting version for github.com/kisielk/errcheck
retool: downloading github.com/mgechev/revive
retool: setting version for github.com/mgechev/revive
retool: downloading github.com/golangci/golangci-lint/cmd/golangci-lint
retool: setting version for github.com/golangci/golangci-lint/cmd/golangci-lint
retool: downloading honnef.co/go/tools/cmd/megacheck
retool: setting version for honnef.co/go/tools/cmd/megacheck
retool: installing gopkg.in/alecthomas/gometalinter.v2
retool: installing github.com/client9/misspell/cmd/misspell
retool: installing github.com/chzchzchz/goword
retool: installing github.com/gordonklaus/ineffassign
retool: installing github.com/dnephin/govet
retool: installing github.com/securego/gosec/cmd/gosec
retool: installing github.com/kisielk/errcheck
retool: installing github.com/mgechev/revive
retool: installing github.com/golangci/golangci-lint/cmd/golangci-lint
retool: installing honnef.co/go/tools/cmd/megacheck
retool do gometalinter.v2 intall

Finally, We can make & build binary file

wnlin:soar wnlin# make
Run gofmt on all source files ...
gofmt -l -s -w ...
Update tidb deps ...
-n Current TiDB commit hash:
Already on 'master'
Your branch is up to date with 'origin/master'.
d65ce8655cd26bb5ec44f9239562013af692d2fa
go get -v -u github.com/pingcap/tidb/store/tikv
github.com/pingcap/tidb (download)
github.com/pingcap/tidb/vendor/google.golang.org/grpc/resolver
github.com/pingcap/tidb/vendor/golang.org/x/text/transform
github.com/pingcap/tidb/vendor/github.com/golang/protobuf/proto
github.com/pingcap/tidb/vendor/golang.org/x/net/context
github.com/pingcap/tidb/vendor/golang.org/x/net/http2/hpack
github.com/pingcap/tidb/vendor/golang.org/x/text/unicode/bidi
github.com/pingcap/tidb/vendor/golang.org/x/text/secure/bidirule
github.com/pingcap/tidb/vendor/golang.org/x/text/unicode/norm
github.com/pingcap/tidb/vendor/golang.org/x/net/internal/timeseries
github.com/pingcap/tidb/vendor/google.golang.org/grpc/grpclog
github.com/pingcap/tidb/vendor/golang.org/x/net/trace
github.com/pingcap/tidb/vendor/google.golang.org/grpc/connectivity
github.com/pingcap/tidb/vendor/google.golang.org/grpc/credentials
github.com/pingcap/tidb/vendor/golang.org/x/net/idna
github.com/pingcap/tidb/vendor/google.golang.org/grpc/channelz
github.com/pingcap/tidb/vendor/google.golang.org/grpc/balancer
github.com/pingcap/tidb/vendor/golang.org/x/net/lex/httplex
github.com/pingcap/tidb/vendor/google.golang.org/grpc/codes
github.com/pingcap/tidb/vendor/google.golang.org/grpc/encoding
github.com/pingcap/tidb/vendor/golang.org/x/net/http2
github.com/pingcap/tidb/vendor/google.golang.org/grpc/internal
github.com/pingcap/tidb/vendor/github.com/coreos/etcd/auth/authpb
github.com/pingcap/tidb/vendor/google.golang.org/grpc/encoding/proto
github.com/pingcap/tidb/vendor/google.golang.org/grpc/balancer/base
github.com/pingcap/tidb/vendor/google.golang.org/grpc/grpclb/grpc_lb_v1/messages
github.com/pingcap/tidb/vendor/google.golang.org/grpc/keepalive
github.com/pingcap/tidb/vendor/google.golang.org/grpc/balancer/roundrobin
github.com/pingcap/tidb/vendor/google.golang.org/grpc/metadata
github.com/pingcap/tidb/vendor/google.golang.org/grpc/naming
github.com/pingcap/tidb/vendor/google.golang.org/grpc/peer
github.com/pingcap/tidb/vendor/google.golang.org/grpc/resolver/dns
github.com/pingcap/tidb/vendor/google.golang.org/grpc/resolver/passthrough
github.com/pingcap/tidb/vendor/google.golang.org/grpc/stats
github.com/pingcap/tidb/vendor/github.com/golang/protobuf/ptypes/any
github.com/pingcap/tidb/vendor/github.com/golang/protobuf/ptypes/duration
github.com/pingcap/tidb/vendor/github.com/golang/protobuf/ptypes/timestamp
github.com/pingcap/tidb/vendor/google.golang.org/genproto/googleapis/rpc/status
github.com/pingcap/tidb/vendor/google.golang.org/grpc/tap
github.com/pingcap/tidb/vendor/github.com/golang/protobuf/ptypes
github.com/pingcap/tidb/vendor/github.com/coreos/etcd/mvcc/mvccpb
github.com/pingcap/tidb/vendor/github.com/golang/protobuf/protoc-gen-go/descriptor
github.com/pingcap/tidb/vendor/google.golang.org/grpc/status
github.com/pingcap/tidb/vendor/github.com/coreos/etcd/pkg/types
github.com/pingcap/tidb/vendor/github.com/cznic/mathutil
github.com/pingcap/tidb/vendor/google.golang.org/genproto/googleapis/api/annotations
github.com/pingcap/tidb/vendor/github.com/google/btree
github.com/pingcap/tidb/vendor/google.golang.org/grpc/transport
github.com/pingcap/tidb/vendor/github.com/grpc-ecosystem/go-grpc-middleware/util/metautils
github.com/pingcap/tidb/vendor/github.com/opentracing/opentracing-go/log
github.com/pingcap/tidb/vendor/google.golang.org/grpc
github.com/pingcap/tidb/vendor/github.com/opentracing/opentracing-go
github.com/pingcap/tidb/vendor/github.com/beorn7/perks/quantile
github.com/pingcap/tidb/vendor/github.com/prometheus/client_model/go
github.com/pingcap/tidb/vendor/github.com/opentracing/opentracing-go/ext
github.com/pingcap/tidb/vendor/github.com/matttproud/golang_protobuf_extensions/pbutil
github.com/pingcap/tidb/vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg
github.com/pingcap/tidb/vendor/github.com/pingcap/kvproto/pkg/metapb
github.com/pingcap/tidb/vendor/github.com/pingcap/tipb/sharedbytes
github.com/pingcap/tidb/vendor/github.com/prometheus/common/model
github.com/pingcap/tidb/vendor/github.com/prometheus/procfs
github.com/pingcap/tidb/vendor/github.com/pingcap/kvproto/pkg/errorpb
github.com/pingcap/tidb/vendor/github.com/prometheus/common/expfmt
github.com/pingcap/tidb/vendor/github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes
github.com/pingcap/tidb/vendor/github.com/coreos/etcd/etcdserver/etcdserverpb
github.com/pingcap/tidb/vendor/google.golang.org/grpc/health/grpc_health_v1
github.com/pingcap/tidb/vendor/github.com/grpc-ecosystem/go-grpc-middleware
github.com/pingcap/tidb/vendor/github.com/pingcap/kvproto/pkg/kvrpcpb
github.com/pingcap/tidb/vendor/github.com/prometheus/client_golang/prometheus
github.com/pingcap/tidb/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tags
github.com/pingcap/tidb/vendor/github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing
github.com/pingcap/tidb/vendor/github.com/pingcap/kvproto/pkg/eraftpb
github.com/pingcap/tidb/vendor/github.com/grpc-ecosystem/go-grpc-prometheus
github.com/pingcap/tidb/vendor/github.com/pkg/errors
github.com/pingcap/tidb/vendor/github.com/pingcap/kvproto/pkg/raft_serverpb
github.com/pingcap/tidb/vendor/github.com/pingcap/kvproto/pkg/pdpb
github.com/pingcap/tidb/vendor/github.com/pingcap/kvproto/pkg/coprocessor
github.com/pingcap/tidb/vendor/github.com/sirupsen/logrus
github.com/pingcap/tidb/vendor/github.com/pingcap/kvproto/pkg/tikvpb
github.com/pingcap/tidb/vendor/github.com/BurntSushi/toml
github.com/pingcap/tidb/vendor/gopkg.in/natefinch/lumberjack.v2
github.com/pingcap/tidb/util/logutil
github.com/pingcap/tidb/vendor/github.com/pingcap/pd/client
github.com/pingcap/tidb/vendor/github.com/coreos/etcd/clientv3
github.com/pingcap/tidb/vendor/github.com/apache/thrift/lib/go/thrift
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/internal/spanlog
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/log
github.com/pingcap/tidb/vendor/github.com/codahale/hdrhistogram
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/util
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-lib/metrics
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/cache
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/comparer
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/storage
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/filter
github.com/pingcap/tidb/vendor/github.com/golang/snappy
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/errors
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/opt
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/thrift-gen/jaeger
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/thrift-gen/sampling
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/thrift-gen/zipkincore
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/iterator
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/journal
github.com/pingcap/tidb/store/tikv/oracle
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/memdb
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/thrift-gen/agent
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/utils
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb/table
github.com/pingcap/tidb/util/execdetails
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go
github.com/pingcap/tidb/vendor/github.com/pingcap/goleveldb/leveldb
github.com/pingcap/tidb/vendor/github.com/coreos/etcd/clientv3/concurrency
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/rpcmetrics
github.com/pingcap/tidb/mysql
github.com/pingcap/tidb/vendor/github.com/klauspost/cpuid
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding/internal/identifier
github.com/pingcap/tidb/vendor/github.com/uber/jaeger-client-go/config
github.com/pingcap/tidb/terror
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding
github.com/pingcap/tidb/config
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding/internal
github.com/pingcap/tidb/kv
github.com/pingcap/tidb/vendor/golang.org/x/text/internal/utf8internal
github.com/pingcap/tidb/metrics
github.com/pingcap/tidb/util
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding/charmap
github.com/pingcap/tidb/owner
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding/korean
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding/japanese
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding/simplifiedchinese
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding/traditionalchinese
github.com/pingcap/tidb/vendor/golang.org/x/text/runes
github.com/pingcap/tidb/util/format
github.com/pingcap/tidb/parser/opcode
github.com/pingcap/tidb/util/auth
github.com/pingcap/tidb/vendor/golang.org/x/text/encoding/unicode
github.com/pingcap/tidb/util/memory
github.com/pingcap/tidb/vendor/github.com/pingcap/tipb/go-tipb
github.com/pingcap/tidb/util/hack
github.com/pingcap/tidb/sessionctx/stmtctx
github.com/pingcap/tidb/util/charset
github.com/pingcap/tidb/util/timeutil
github.com/pingcap/tidb/types/json
github.com/pingcap/tidb/util/kvcache
github.com/pingcap/tidb/vendor/github.com/pingcap/tipb/go-binlog
github.com/pingcap/tidb/vendor/github.com/spaolacci/murmur3
github.com/pingcap/tidb/store/tikv/oracle/oracles
github.com/pingcap/tidb/store/tikv/tikvrpc
github.com/pingcap/tidb/store/tikv/latch
github.com/pingcap/tidb/parser/types
github.com/pingcap/tidb/vendor/github.com/twinj/uuid
github.com/pingcap/tidb/model
github.com/pingcap/tidb/types
github.com/pingcap/tidb/ast
github.com/pingcap/tidb/util/chunk
github.com/pingcap/tidb/util/codec
github.com/pingcap/tidb/tablecodec
github.com/pingcap/tidb/structure
github.com/pingcap/tidb/meta
github.com/pingcap/tidb/meta/autoid
github.com/pingcap/tidb/sessionctx/variable
github.com/pingcap/tidb/sessionctx
github.com/pingcap/tidb/sessionctx/binloginfo
-n TiDB update to:
d65ce8655cd26bb5ec44f9239562013af692d2fa
importing tidb sql parser ...
Note: checking out 'ec9672cea6612481b1da845dbab620b7a5581ca4'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
  git checkout -b <new-branch-name>
HEAD is now at ec9672cea stats: update delta info for partition table (#7947)
CGO_ENABLED=0 go build  -o bin/goyacc parser/goyacc/main.go
bin/goyacc -o /dev/null parser/parser.y
Parse table entries: 758041 of 1909026, x 16 bits == 1516082 bytes
bin/goyacc -o parser/parser.go parser/parser.y 2>&1 | egrep "(shift|reduce)/reduce" | awk '{print} END {if (NR > 0) {print "Find conflict in parser.y. Please check y.output for more information."; exit 1;}}'
rm -f y.output
Building ...
==> Checking that build is using go version >= 1.10...
build Success!

Have fun.

https://blog.wnlin.org

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *