diff options
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/analyze_stmt.result | 199 | ||||
-rw-r--r-- | mysql-test/r/ps.result | 1 | ||||
-rw-r--r-- | mysql-test/r/show_explain.result | 2 | ||||
-rw-r--r-- | mysql-test/t/analyze_stmt.test | 148 | ||||
-rw-r--r-- | mysql-test/t/ps.test | 1 |
5 files changed, 350 insertions, 1 deletions
diff --git a/mysql-test/r/analyze_stmt.result b/mysql-test/r/analyze_stmt.result new file mode 100644 index 00000000000..41fdce43807 --- /dev/null +++ b/mysql-test/r/analyze_stmt.result @@ -0,0 +1,199 @@ +drop table if exists t0,t1,t2,t3; +create table t0 (a int) engine=myisam; +INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int) engine=myisam; +INSERT INTO t1 select * from t0; +# Try a few basic selects to see that r_rows and r_filtered columns work +analyze select * from t1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 100.00 +analyze select * from t1 where a<5; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 50.00 Using where +analyze select * from t1 where a>100; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 0.00 Using where +# ANALYZE DELETE will delete rows: +analyze delete from t1 where a in (2,3,4); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 NULL 100.00 30.00 Using where +select * from t1; +a +0 +1 +5 +6 +7 +8 +9 +drop table t1; +# ANALYZE UPDATE will make updates: +create table t1(a int, b int); +insert into t1 select a,a from t0; +analyze update t1 set b=100+b where a in (6,7,8); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 NULL 100.00 30.00 Using where +select * from t1; +a b +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 106 +7 107 +8 108 +9 9 +drop table t1; +# Check that UNION works +create table t1(a int, b int); +insert into t1 select a,a from t0; +analyze (select * from t1 A where a<5) union (select * from t1 B where a in (5,6)); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 10 100.00 50.00 Using where +2 UNION B ALL NULL NULL NULL NULL 10 10 100.00 20.00 Using where +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 7 NULL NULL +analyze (select * from t1 A where a<5) union (select * from t1 B where a in (1,2)); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 10 100.00 50.00 Using where +2 UNION B ALL NULL NULL NULL NULL 10 10 100.00 20.00 Using where +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 5 NULL NULL +drop table t1; +drop table t0; +# +# Try a subquery. +# +create table t0 (a int, b int); +insert into t0 values +(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +create table t1 (a int, b int); +insert into t1 values (1,1),(2,2),(3,3); +# See .test file for the right values of r_rows and r_filtered. +analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00 +2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 3 100.00 33.33 Using where +# Try a subquery that is never executed +analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1 where t1.a > 5; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 3 100.00 0.00 Using where +2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 NULL 100.00 NULL Using where +drop table t0, t1; +# +# Tests for join buffering +# +create table t0 (a int, b int); +insert into t0 values +(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +create table t1 like t0; +insert into t1 select * from t0; +explain select * from t0, t1 where t0.a<5 and t1.a<5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) +# These should have filtered=50 +analyze select * from t0, t1 where t0.a<5 and t1.a<5; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 50.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 50.00 Using where; Using join buffer (flat, BNL join) +explain select * from t0, t1 where t0.a<5 and t1.b=t0.b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) +# Now, t1 should have filtered=10 +analyze select * from t0, t1 where t0.a<5 and t1.b=t0.b; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 50.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 10.00 Using where; Using join buffer (flat, BNL join) +explain select * from t0, t1 where t0.a<5 and t1.a<5 and t1.b=t0.b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) +# Now, t1 should have filtered=10 +analyze select * from t0, t1 where t0.a<5 and t1.a<5 and t1.b=t0.b; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 50.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 10.00 Using where; Using join buffer (flat, BNL join) +# TODO: Check what is counted for "range checked for each record". +# +# Test for joins +# +create table t2 (key1 int, key2x int, col1 int, key(key1), key(key2x)); +insert into t2 select A.a + 10 *B.a +100 * C.a, +(A.a + 10 *B.a +100 * C.a)*2, +A.a + 10 *B.a +100 * C.a +from t0 A, t0 B, t0 C; +# This always has matches, filtered=100%. +analyze select * from t1,t2 where t2.key1=t1.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 100.00 Using where +1 SIMPLE t2 ref key1 key1 5 test.t1.a 1 1 100.00 100.00 +# This shows r_rows=0. It is actually 0.5 (should r_rows be changed to double?) +analyze select * from t1,t2 where t2.key2x=t1.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 100.00 Using where +1 SIMPLE t2 ref key2x key2x 5 test.t1.a 1 0 100.00 100.00 +select * from t1,t2 where t2.key2x=t1.a; +a b key1 key2x col1 +0 0 0 0 0 +2 2 1 2 1 +4 4 2 4 2 +6 6 3 6 3 +8 8 4 8 4 +# This has t2.filtered=40% (there are 5 values: {0,1,2,3,4}. two of them have mod=0) +analyze select * from t1,t2 where t2.key2x=t1.a and mod(t2.col1,4)=0; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10 100.00 100.00 Using where +1 SIMPLE t2 ref key2x key2x 5 test.t1.a 1 0 100.00 40.00 Using where +drop table t0,t1,t2; +# +# Check non-merged derived tables +# +create table t0 (a int, b int); +insert into t0 values +(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +update t0 set b=b/3; +analyze select * from (select count(*),max(a),b from t0 group by b) T; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 10 4 100.00 100.00 +2 DERIVED t0 ALL NULL NULL NULL NULL 10 10 100.00 100.00 Using temporary; Using filesort +drop table t0; +# +# Check ORDER/GROUP BY +# +create table t0 (a int, b int); +insert into t0 values +(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +analyze select count(*),max(a),b from t0 where a<7 group by b; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 10 100.00 70.00 Using where; Using temporary; Using filesort +drop table t0; +# +# Check multi-table UPDATE/DELETE. +# +create table t0 (a int, b int); +create table t1 (a int, b int); +insert into t0 values (0,0),(2,2),(4,4), (8,8); +insert into t1 values (0,0),(2,2), (6,6); +analyze select * from t0,t1 where t0.a=t1.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00 +1 SIMPLE t0 ALL NULL NULL NULL NULL 4 4 100.00 16.67 Using where; Using join buffer (flat, BNL join) +analyze update t0,t1 set t1.b=5555 where t0.a=t1.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00 +1 SIMPLE t0 ALL NULL NULL NULL NULL 4 4 100.00 16.67 Using where +select * from t1; +a b +0 5555 +2 5555 +6 6 +analyze delete t1 from t1, t0 where t0.a=t1.a; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 3 100.00 100.00 +1 SIMPLE t0 ALL NULL NULL NULL NULL 4 4 100.00 16.67 Using where +select * from t1; +a b +6 6 +drop table t0, t1; diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 31fcea528aa..3217a10ed6d 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -1,5 +1,6 @@ call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.'); drop table if exists t1,t2,t3,t4; +drop database if exists mysqltest1; drop database if exists client_test_db; create table t1 ( diff --git a/mysql-test/r/show_explain.result b/mysql-test/r/show_explain.result index a4d12ce05ce..3695384bac4 100644 --- a/mysql-test/r/show_explain.result +++ b/mysql-test/r/show_explain.result @@ -641,7 +641,7 @@ set debug_dbug='+d,show_explain_probe_join_exec_start'; SHOW INDEX FROM t1; show explain for $thr2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE STATISTICS ALL NULL NULL NULL NULL NULL Skip_open_table; Scanned all databases +1 SIMPLE STATISTICS ALL NULL TABLE_SCHEMA,TABLE_NAME NULL NULL NULL Open_full_table; Scanned 0 databases Warnings: Note 1003 SHOW INDEX FROM t1 Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment diff --git a/mysql-test/t/analyze_stmt.test b/mysql-test/t/analyze_stmt.test new file mode 100644 index 00000000000..2f9de4a3763 --- /dev/null +++ b/mysql-test/t/analyze_stmt.test @@ -0,0 +1,148 @@ +# +# Tests for "ANALYZE $statement" feature (PostgreSQL's analog is called EXPLAIN ANALYZE) +# +--disable_warnings +drop table if exists t0,t1,t2,t3; +--enable_warnings + +create table t0 (a int) engine=myisam; +INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (a int) engine=myisam; +INSERT INTO t1 select * from t0; + +--echo # Try a few basic selects to see that r_rows and r_filtered columns work +analyze select * from t1; +analyze select * from t1 where a<5; +analyze select * from t1 where a>100; + +--echo # ANALYZE DELETE will delete rows: +analyze delete from t1 where a in (2,3,4); +select * from t1; +drop table t1; + +--echo # ANALYZE UPDATE will make updates: +create table t1(a int, b int); +insert into t1 select a,a from t0; +analyze update t1 set b=100+b where a in (6,7,8); +select * from t1; +drop table t1; + +--echo # Check that UNION works +create table t1(a int, b int); +insert into t1 select a,a from t0; +analyze (select * from t1 A where a<5) union (select * from t1 B where a in (5,6)); +analyze (select * from t1 A where a<5) union (select * from t1 B where a in (1,2)); +drop table t1; +drop table t0; + +--echo # +--echo # Try a subquery. +--echo # +create table t0 (a int, b int); +insert into t0 values + (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); + +create table t1 (a int, b int); +insert into t1 values (1,1),(2,2),(3,3); + +# +# t1 t0 +# a=1 (0,1) 2 rows +# a=2 (0,1,2) 3 rows +# a=3 (0,1,2,3) 4 rows +# +# TOTAL TOTAL= 9 rows. 3 executions, avg=3 rows. +# WHERE is satisfied for 1 row per query, which gives filtered=33.3 + +--echo # See .test file for the right values of r_rows and r_filtered. +analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1; + +--echo # Try a subquery that is never executed +analyze select a, a in (select t0.b from t0 where t0.b+1=t1.b+1) from t1 where t1.a > 5; + +drop table t0, t1; + +--echo # +--echo # Tests for join buffering +--echo # +create table t0 (a int, b int); +insert into t0 values + (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +create table t1 like t0; +insert into t1 select * from t0; + +explain select * from t0, t1 where t0.a<5 and t1.a<5; +--echo # These should have filtered=50 +analyze select * from t0, t1 where t0.a<5 and t1.a<5; + +explain select * from t0, t1 where t0.a<5 and t1.b=t0.b; +--echo # Now, t1 should have filtered=10 +analyze select * from t0, t1 where t0.a<5 and t1.b=t0.b; + +explain select * from t0, t1 where t0.a<5 and t1.a<5 and t1.b=t0.b; +--echo # Now, t1 should have filtered=10 +analyze select * from t0, t1 where t0.a<5 and t1.a<5 and t1.b=t0.b; + +--echo # TODO: Check what is counted for "range checked for each record". + +--echo # +--echo # Test for joins +--echo # +create table t2 (key1 int, key2x int, col1 int, key(key1), key(key2x)); +insert into t2 select A.a + 10 *B.a +100 * C.a, + (A.a + 10 *B.a +100 * C.a)*2, + A.a + 10 *B.a +100 * C.a + from t0 A, t0 B, t0 C; + +--echo # This always has matches, filtered=100%. +analyze select * from t1,t2 where t2.key1=t1.a; + +--echo # This shows r_rows=0. It is actually 0.5 (should r_rows be changed to double?) +analyze select * from t1,t2 where t2.key2x=t1.a; + select * from t1,t2 where t2.key2x=t1.a; + +--echo # This has t2.filtered=40% (there are 5 values: {0,1,2,3,4}. two of them have mod=0) +analyze select * from t1,t2 where t2.key2x=t1.a and mod(t2.col1,4)=0; + +drop table t0,t1,t2; + +--echo # +--echo # Check non-merged derived tables +--echo # +create table t0 (a int, b int); +insert into t0 values + (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); + +update t0 set b=b/3; +analyze select * from (select count(*),max(a),b from t0 group by b) T; +drop table t0; + +--echo # +--echo # Check ORDER/GROUP BY +--echo # +create table t0 (a int, b int); +insert into t0 values + (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); + +analyze select count(*),max(a),b from t0 where a<7 group by b; +drop table t0; + +--echo # +--echo # Check multi-table UPDATE/DELETE. +--echo # +create table t0 (a int, b int); +create table t1 (a int, b int); +insert into t0 values (0,0),(2,2),(4,4), (8,8); +insert into t1 values (0,0),(2,2), (6,6); + +analyze select * from t0,t1 where t0.a=t1.a; + +analyze update t0,t1 set t1.b=5555 where t0.a=t1.a; +select * from t1; + +analyze delete t1 from t1, t0 where t0.a=t1.a; +select * from t1; + +drop table t0, t1; + diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 0233b2e428b..491594a3045 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -7,6 +7,7 @@ call mtr.add_suppression('Unsafe statement written to the binary log using state --disable_warnings drop table if exists t1,t2,t3,t4; +drop database if exists mysqltest1; # Avoid wrong warnings if mysql_client_test fails drop database if exists client_test_db; --enable_warnings |