From 0091eb381dd8c1d655f5da0a2a755f50006fb886 Mon Sep 17 00:00:00 2001 From: arenatlx <314806019@qq.com> Date: Tue, 7 Jan 2025 17:52:42 +0800 Subject: [PATCH 1/7] . Signed-off-by: arenatlx <314806019@qq.com> --- README.md | 9 +++++++++ r/example.casult | 49 +++++++++++++++++++++++++++++++++++++++++++++ r/extensions.casult | 2 ++ src/main.go | 13 +++++++++++- 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 r/example.casult create mode 100644 r/extensions.casult diff --git a/README.md b/README.md index 8f78f77..5f1dcb8 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ Usage of ./mysql-tester: The user for connecting to the database. (default "root") -xunitfile string The xml file path to record testing results. + -check-error + If --error ERR does not match, return error instead of just warn + -cascades + Record the result based on cascades planner into result file with .casult suffix. ``` By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` and no passward: @@ -46,6 +50,11 @@ By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` ./mysql-tester # run all the tests ./mysql-tester example # run a specified test ./mysql-tester example1 example2 example3 # seperate different tests with one or more spaces +# modify current example cases for .result output. +./mysql-tester ./mysql-tester -record=1 -check-error=1 +# modify current example cases for .casult output. +./mysql-tester ./mysql-tester -record=1 -check-error=1 -cascades=1 + ``` For more details about how to run and write test cases, see the [Wiki](https://github.com/pingcap/mysql-tester/wiki) page. diff --git a/r/example.casult b/r/example.casult new file mode 100644 index 0000000..91fbf60 --- /dev/null +++ b/r/example.casult @@ -0,0 +1,49 @@ +create table t(a bigint, b bigint); +insert into t values(1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +select * from t where a = 1; +a b +1 1 +SELECT 1 FROM NON_EXISTING_TABLE; +Error 1146 (42S02): Table 'example.NON_EXISTING_TABLE' doesn't exist +SELECT 2 FROM NON_EXISTING_TABLE; +SELECT 3 FROM NON_EXISTING_TABLE; +Got one of the listed errors +SELECT 4; +4 +4 +SELECT 5; +5 +5 +SELECT 6; +6 +6 +1 SELECT; +Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 1 near "1 SELECT" +2 SELECT; +3 SELECT; +Got one of the listed errors +explain analyze format='brief' select * from t; +id estRows actRows task access object execution info operator info memory disk +TableReader 10000.00 5 root NULL time:, open:, close:, loops:, RU:, cop_task: {num:, max:, proc_keys:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:, rpc_info:{Cop:{num_rpc:, total_time:}} data:TableFullScan Bytes N/A +└─TableFullScan 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A +explain analyze select * from t; +id estRows actRows task access object execution info operator info memory disk +TableReader_5 10000.00 5 root NULL time:, open:, close:, loops:, RU:, cop_task: {num:, max:, proc_keys:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:, rpc_info:{Cop:{num_rpc:, total_time:}} data:TableFullScan_4 Bytes N/A +└─TableFullScan_4 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A +insert into t values (6, 6); +affected rows: 1 +info: +DROP TABLE IF EXISTS t1; +affected rows: 0 +info: +CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT NOT NULL UNIQUE); +affected rows: 0 +info: +INSERT t1 VALUES (1, 1); +affected rows: 1 +info: +INSERT t1 VALUES (1, 1), (1, 1) ON DUPLICATE KEY UPDATE f1 = 2, f2 = 2; +affected rows: 3 +info: Records: 2 Duplicates: 1 Warnings: 0 +1 +use `test`;; diff --git a/r/extensions.casult b/r/extensions.casult new file mode 100644 index 0000000..814e650 --- /dev/null +++ b/r/extensions.casult @@ -0,0 +1,2 @@ +SELECT 1 FROM NON_EXISTING_TABLE; +Got one of the listed errors diff --git a/src/main.go b/src/main.go index cec17c6..367781a 100644 --- a/src/main.go +++ b/src/main.go @@ -47,6 +47,7 @@ var ( retryConnCount int collationDisable bool checkErr bool + cascades bool ) func init() { @@ -63,6 +64,7 @@ func init() { flag.IntVar(&retryConnCount, "retry-connection-count", 120, "The max number to retry to connect to the database.") flag.BoolVar(&checkErr, "check-error", false, "if --error ERR does not match, return error instead of just warn") flag.BoolVar(&collationDisable, "collation-disable", false, "run collation related-test with new-collation disabled") + flag.BoolVar(&cascades, "cascades", false, "run exec and query based on cascades planner") } const ( @@ -196,6 +198,11 @@ func setSessionVariable(db *Conn) { if _, err := db.conn.ExecContext(ctx, "SET @@tidb_enable_clustered_index='int_only'"); err != nil { log.Fatalf("Executing \"SET @@tidb_enable_clustered_index='int_only'\" err[%v]", err) } + if cascades { + if _, err := db.conn.ExecContext(ctx, "SET @@tidb_enable_cascades_planner=1"); err != nil { + log.Fatalf("Executing \"SET @@tidb_enable_cascades_planner=1\" err[%v]", err) + } + } } // isTiDB returns true if the DB is confirmed to be TiDB @@ -1081,7 +1088,11 @@ func (t *tester) resultFileName() string { name = name + "_enabled" } } - return fmt.Sprintf("./r/%s.result", name) + suffix := "result" + if cascades { + suffix = "casult" + } + return fmt.Sprintf("./r/%s.%s", name, suffix) } func loadAllTests() ([]string, error) { From f47c770d159eae2dc969dc882e7219ec72f2b8e7 Mon Sep 17 00:00:00 2001 From: arenatlx <314806019@qq.com> Date: Wed, 8 Jan 2025 13:35:28 +0800 Subject: [PATCH 2/7] . Signed-off-by: arenatlx <314806019@qq.com> --- README.md | 2 ++ src/main.go | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f1dcb8..a36a267 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ Usage of ./mysql-tester: If --error ERR does not match, return error instead of just warn -cascades Record the result based on cascades planner into result file with .casult suffix. + -cascades-suffix + Specify the result file suffix for cascades planner, default with .casult suffix. ``` By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` and no passward: diff --git a/src/main.go b/src/main.go index 367781a..6cfb60a 100644 --- a/src/main.go +++ b/src/main.go @@ -48,6 +48,7 @@ var ( collationDisable bool checkErr bool cascades bool + cascadesSuffix string ) func init() { @@ -65,6 +66,7 @@ func init() { flag.BoolVar(&checkErr, "check-error", false, "if --error ERR does not match, return error instead of just warn") flag.BoolVar(&collationDisable, "collation-disable", false, "run collation related-test with new-collation disabled") flag.BoolVar(&cascades, "cascades", false, "run exec and query based on cascades planner") + flag.StringVar(&cascadesSuffix, "cascades-suffix", "casult", "the result file suffix for cascades planner") } const ( @@ -202,6 +204,10 @@ func setSessionVariable(db *Conn) { if _, err := db.conn.ExecContext(ctx, "SET @@tidb_enable_cascades_planner=1"); err != nil { log.Fatalf("Executing \"SET @@tidb_enable_cascades_planner=1\" err[%v]", err) } + } else { + if _, err := db.conn.ExecContext(ctx, "SET @@tidb_enable_cascades_planner=0"); err != nil { + log.Fatalf("Executing \"SET @@tidb_enable_cascades_planner=0\" err[%v]", err) + } } } @@ -1090,7 +1096,7 @@ func (t *tester) resultFileName() string { } suffix := "result" if cascades { - suffix = "casult" + suffix = cascadesSuffix } return fmt.Sprintf("./r/%s.%s", name, suffix) } From 1329b2a7edb045335b4e04a06170837cc5a0547f Mon Sep 17 00:00:00 2001 From: arenatlx <314806019@qq.com> Date: Wed, 8 Jan 2025 14:08:55 +0800 Subject: [PATCH 3/7] . Signed-off-by: arenatlx <314806019@qq.com> --- README.md | 8 ++------ r/example.result | 6 +++--- src/main.go | 19 ++----------------- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index a36a267..ccfe868 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,6 @@ Usage of ./mysql-tester: The xml file path to record testing results. -check-error If --error ERR does not match, return error instead of just warn - -cascades - Record the result based on cascades planner into result file with .casult suffix. - -cascades-suffix - Specify the result file suffix for cascades planner, default with .casult suffix. ``` By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` and no passward: @@ -54,8 +50,8 @@ By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` ./mysql-tester example1 example2 example3 # seperate different tests with one or more spaces # modify current example cases for .result output. ./mysql-tester ./mysql-tester -record=1 -check-error=1 -# modify current example cases for .casult output. -./mysql-tester ./mysql-tester -record=1 -check-error=1 -cascades=1 +# modify current example cases for .casult output, set the tidb planner as cascades manually. +./mysql-tester ./mysql-tester -record=1 -check-error=1 -suffix="casult" ``` diff --git a/r/example.result b/r/example.result index 6e5cb8d..91fbf60 100644 --- a/r/example.result +++ b/r/example.result @@ -18,17 +18,17 @@ SELECT 6; 6 6 1 SELECT; -Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 1 near "1 SELECT;" +Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 1 near "1 SELECT" 2 SELECT; 3 SELECT; Got one of the listed errors explain analyze format='brief' select * from t; id estRows actRows task access object execution info operator info memory disk -TableReader 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan Bytes N/A +TableReader 10000.00 5 root NULL time:, open:, close:, loops:, RU:, cop_task: {num:, max:, proc_keys:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:, rpc_info:{Cop:{num_rpc:, total_time:}} data:TableFullScan Bytes N/A └─TableFullScan 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A explain analyze select * from t; id estRows actRows task access object execution info operator info memory disk -TableReader_5 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan_4 Bytes N/A +TableReader_5 10000.00 5 root NULL time:, open:, close:, loops:, RU:, cop_task: {num:, max:, proc_keys:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:, rpc_info:{Cop:{num_rpc:, total_time:}} data:TableFullScan_4 Bytes N/A └─TableFullScan_4 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A insert into t values (6, 6); affected rows: 1 diff --git a/src/main.go b/src/main.go index 6cfb60a..f4dec9c 100644 --- a/src/main.go +++ b/src/main.go @@ -47,8 +47,7 @@ var ( retryConnCount int collationDisable bool checkErr bool - cascades bool - cascadesSuffix string + suffix string ) func init() { @@ -65,8 +64,7 @@ func init() { flag.IntVar(&retryConnCount, "retry-connection-count", 120, "The max number to retry to connect to the database.") flag.BoolVar(&checkErr, "check-error", false, "if --error ERR does not match, return error instead of just warn") flag.BoolVar(&collationDisable, "collation-disable", false, "run collation related-test with new-collation disabled") - flag.BoolVar(&cascades, "cascades", false, "run exec and query based on cascades planner") - flag.StringVar(&cascadesSuffix, "cascades-suffix", "casult", "the result file suffix for cascades planner") + flag.StringVar(&suffix, "suffix", "result", "the result file suffix for result file") } const ( @@ -200,15 +198,6 @@ func setSessionVariable(db *Conn) { if _, err := db.conn.ExecContext(ctx, "SET @@tidb_enable_clustered_index='int_only'"); err != nil { log.Fatalf("Executing \"SET @@tidb_enable_clustered_index='int_only'\" err[%v]", err) } - if cascades { - if _, err := db.conn.ExecContext(ctx, "SET @@tidb_enable_cascades_planner=1"); err != nil { - log.Fatalf("Executing \"SET @@tidb_enable_cascades_planner=1\" err[%v]", err) - } - } else { - if _, err := db.conn.ExecContext(ctx, "SET @@tidb_enable_cascades_planner=0"); err != nil { - log.Fatalf("Executing \"SET @@tidb_enable_cascades_planner=0\" err[%v]", err) - } - } } // isTiDB returns true if the DB is confirmed to be TiDB @@ -1094,10 +1083,6 @@ func (t *tester) resultFileName() string { name = name + "_enabled" } } - suffix := "result" - if cascades { - suffix = cascadesSuffix - } return fmt.Sprintf("./r/%s.%s", name, suffix) } From 9def54904fcad9f95259aef845df9f1083c5c65d Mon Sep 17 00:00:00 2001 From: arenatlx <314806019@qq.com> Date: Wed, 8 Jan 2025 16:27:43 +0800 Subject: [PATCH 4/7] fix read me Signed-off-by: arenatlx <314806019@qq.com> --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ccfe868..b9b676d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ Usage of ./mysql-tester: The xml file path to record testing results. -check-error If --error ERR does not match, return error instead of just warn + -suffix + Specify the suffix of result file under special requirement, default as ".result" ``` By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` and no passward: From 232b5cd2867d95c5801c76ecf609103e9073e298 Mon Sep 17 00:00:00 2001 From: arenatlx <314806019@qq.com> Date: Wed, 8 Jan 2025 16:38:14 +0800 Subject: [PATCH 5/7] address cong Signed-off-by: arenatlx <314806019@qq.com> --- README.md | 8 ++++---- src/main.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b9b676d..b627fee 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ Usage of ./mysql-tester: The xml file path to record testing results. -check-error If --error ERR does not match, return error instead of just warn - -suffix - Specify the suffix of result file under special requirement, default as ".result" + -extension + Specify the extension of result file under special requirement, default as ".result" ``` By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` and no passward: @@ -51,9 +51,9 @@ By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` ./mysql-tester example # run a specified test ./mysql-tester example1 example2 example3 # seperate different tests with one or more spaces # modify current example cases for .result output. -./mysql-tester ./mysql-tester -record=1 -check-error=1 +./mysql-tester -record=1 -check-error=1 # modify current example cases for .casult output, set the tidb planner as cascades manually. -./mysql-tester ./mysql-tester -record=1 -check-error=1 -suffix="casult" +./mysql-tester -record=1 -check-error=1 -extension="casult" ``` diff --git a/src/main.go b/src/main.go index f4dec9c..67ea7f4 100644 --- a/src/main.go +++ b/src/main.go @@ -47,7 +47,7 @@ var ( retryConnCount int collationDisable bool checkErr bool - suffix string + extension string ) func init() { @@ -64,7 +64,7 @@ func init() { flag.IntVar(&retryConnCount, "retry-connection-count", 120, "The max number to retry to connect to the database.") flag.BoolVar(&checkErr, "check-error", false, "if --error ERR does not match, return error instead of just warn") flag.BoolVar(&collationDisable, "collation-disable", false, "run collation related-test with new-collation disabled") - flag.StringVar(&suffix, "suffix", "result", "the result file suffix for result file") + flag.StringVar(&extension, "extension", "result", "the result file extension for result file") } const ( @@ -1083,7 +1083,7 @@ func (t *tester) resultFileName() string { name = name + "_enabled" } } - return fmt.Sprintf("./r/%s.%s", name, suffix) + return fmt.Sprintf("./r/%s.%s", name, extension) } func loadAllTests() ([]string, error) { From 1a834e35f714b952999b96bf7570f0ec298601d2 Mon Sep 17 00:00:00 2001 From: arenatlx <314806019@qq.com> Date: Wed, 8 Jan 2025 16:39:57 +0800 Subject: [PATCH 6/7] address cong Signed-off-by: arenatlx <314806019@qq.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b627fee..08be039 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This is a golang implementation of [MySQL Test Framework](https://github.com/mys ## Requirements - All the tests should be put in [`t`](./t), take [t/example.test](./t/example.test) as an example. -- All the expected test results should be put in [`r`](./r). Result file has the same file name with the corresponding test file, but with a `.result` file suffix, take [r/example.result](./r/example.result) as an examle. +- All the expected test results should be put in [`r`](./r). Result file has the same file name with the corresponding test file, but with a default `.result` file extension, it can be changed by `-extension`, take [r/example.result](./r/example.result) as an examle. ## How to use From 6be21af48a266b5a3a45d4464512d74f3f11dd30 Mon Sep 17 00:00:00 2001 From: arenatlx <314806019@qq.com> Date: Wed, 8 Jan 2025 18:07:30 +0800 Subject: [PATCH 7/7] . Signed-off-by: arenatlx <314806019@qq.com> --- README.md | 2 -- r/example.casult | 49 --------------------------------------------- r/extensions.casult | 2 -- 3 files changed, 53 deletions(-) delete mode 100644 r/example.casult delete mode 100644 r/extensions.casult diff --git a/README.md b/README.md index 08be039..1e32f2f 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,6 @@ By default, it connects to the TiDB/MySQL server at `127.0.0.1:4000` with `root` ./mysql-tester example1 example2 example3 # seperate different tests with one or more spaces # modify current example cases for .result output. ./mysql-tester -record=1 -check-error=1 -# modify current example cases for .casult output, set the tidb planner as cascades manually. -./mysql-tester -record=1 -check-error=1 -extension="casult" ``` diff --git a/r/example.casult b/r/example.casult deleted file mode 100644 index 91fbf60..0000000 --- a/r/example.casult +++ /dev/null @@ -1,49 +0,0 @@ -create table t(a bigint, b bigint); -insert into t values(1, 1), (2, 2), (3, 3), (4, 4), (5, 5); -select * from t where a = 1; -a b -1 1 -SELECT 1 FROM NON_EXISTING_TABLE; -Error 1146 (42S02): Table 'example.NON_EXISTING_TABLE' doesn't exist -SELECT 2 FROM NON_EXISTING_TABLE; -SELECT 3 FROM NON_EXISTING_TABLE; -Got one of the listed errors -SELECT 4; -4 -4 -SELECT 5; -5 -5 -SELECT 6; -6 -6 -1 SELECT; -Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 1 near "1 SELECT" -2 SELECT; -3 SELECT; -Got one of the listed errors -explain analyze format='brief' select * from t; -id estRows actRows task access object execution info operator info memory disk -TableReader 10000.00 5 root NULL time:, open:, close:, loops:, RU:, cop_task: {num:, max:, proc_keys:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:, rpc_info:{Cop:{num_rpc:, total_time:}} data:TableFullScan Bytes N/A -└─TableFullScan 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A -explain analyze select * from t; -id estRows actRows task access object execution info operator info memory disk -TableReader_5 10000.00 5 root NULL time:, open:, close:, loops:, RU:, cop_task: {num:, max:, proc_keys:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:, rpc_info:{Cop:{num_rpc:, total_time:}} data:TableFullScan_4 Bytes N/A -└─TableFullScan_4 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A -insert into t values (6, 6); -affected rows: 1 -info: -DROP TABLE IF EXISTS t1; -affected rows: 0 -info: -CREATE TABLE t1 (f1 INT PRIMARY KEY, f2 INT NOT NULL UNIQUE); -affected rows: 0 -info: -INSERT t1 VALUES (1, 1); -affected rows: 1 -info: -INSERT t1 VALUES (1, 1), (1, 1) ON DUPLICATE KEY UPDATE f1 = 2, f2 = 2; -affected rows: 3 -info: Records: 2 Duplicates: 1 Warnings: 0 -1 -use `test`;; diff --git a/r/extensions.casult b/r/extensions.casult deleted file mode 100644 index 814e650..0000000 --- a/r/extensions.casult +++ /dev/null @@ -1,2 +0,0 @@ -SELECT 1 FROM NON_EXISTING_TABLE; -Got one of the listed errors