Skip to content

Commit

Permalink
*:move explain_test to tidb repository (pingcap#6555)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored and zz-jason committed May 17, 2018
1 parent 1931bd3 commit 0b1b523
Show file tree
Hide file tree
Showing 39 changed files with 2,638 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tags
temp_parser_file
y.output
profile.coverprofile
explain_test
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ todo:
@grep -n BUG */*.go parser/parser.y || true
@grep -n println */*.go parser/parser.y || true

test: checklist gotest
test: checklist gotest explaintest

explaintest: server
@cd cmd/explaintest && ./run-tests.sh -s ../../bin/tidb-server

gotest: parserlib
go get github.com/coreos/gofail
Expand Down Expand Up @@ -166,6 +169,7 @@ benchraw:

benchdb:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/benchdb cmd/benchdb/main.go

importer:
$(GOBUILD) -ldflags '$(LDFLAGS)' -o bin/importer ./cmd/importer

Expand Down
65 changes: 65 additions & 0 deletions cmd/explaintest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ExplainTest

ExplainTest is a explain test command tool, also with some useful test cases for TiDB execute plan logic, we can run case via `run-tests.sh`.

```
Usage: ./run-tests.sh [options]
-h: Print this help message.
-s <tidb-server-path>: Use tidb-server in <tidb-server-path> for testing.
eg. "./run-tests.sh -s ./explaintest_tidb-server"
-b <y|Y|n|N>: "y" or "Y" for building test binaries [default "y" if this option is not specified].
"n" or "N" for not to build.
The building of tidb-server will be skiped if "-s <tidb-server-path>" is provided.
-r <test-name>|all: Run tests in file "t/<test-name>.test" and record result to file "r/<test-name>.result".
"all" for running all tests and record their results.
-t <test-name>: Run tests in file "t/<test-name>.test".
This option will be ignored if "-r <test-name>" is provided.
Run all tests if this option is not provided.
-v <vendor-path>: Add <vendor-path> to $GOPATH.
-c <test-name>|all: Create data according to creating statements in file "t/<test-name>.test" and save stats in "s/<test-name>_tableName.json".
<test-name> must has a suffix of '_stats'.
"all" for creating stats of all tests.
-i <importer-path>: Use importer in <importer-path> for creating data.
```

## How it works

ExplainTest will read test case in `t/*.test`, and execute them in TiDB server with `s/*.json` stat, and compare explain result in `r/*.result`.

For convenience, we can generate new `*.result` and `*.json` from execute by use `-r` parameter for `run-tests.sh`

## Usage

### Regression Execute Plan Modification

After modify code and before commit, please run this command under TiDB root folder.

```sh
make dev
```

or

```sh
make explaintest
```
It will identify execute plan change.

### Generate New Stats and Result from Execute

First, add new test query in `t/` folder.

```sh
cd cmd/explaintest
./run-tests.sh -r [casename]
./run-tests.sh -c [casename]
``
It will generate result and stats base on last execution, and then we can reuse them or open editor to do some modify.
31 changes: 31 additions & 0 deletions cmd/explaintest/_helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# set -ueax
# when you want to debug, please uncomment the above line and comment the following line.
set -uea

OLD_GOPATH=$GOPATH
PINGCAP_PATH="$(dirname $PWD)"
while [ "$(basename $PINGCAP_PATH)" != "pingcap" ]; do
PINGCAP_PATH="$(dirname $PINGCAP_PATH)"
done
TIDB_VENDOR_PATH=$PINGCAP_PATH/tidb/vendor

function prepare_env {
export GOPATH=$GOPATH:$TIDB_VENDOR_PATH
}

function recover_env {
export GOPATH=$OLD_GOPATH
}

function kill_proc_by_port() {
if [ ! -z $1 ]; then
kill $(lsof -t -i:$1)
else
echo "please specify port number"
fi
}

set +uea
trap 'set +e; PIDS=$(jobs -p); [ -n "$PIDS" ] && kill -9 $PIDS' EXIT

11 changes: 11 additions & 0 deletions cmd/explaintest/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
port = 4001
lease = "0"

[log]
level = "error"

[status]
status-port = 10081

[performance]
stats-lease = "0"
Loading

0 comments on commit 0b1b523

Please sign in to comment.