# # Tests for "ANALYZE FORMAT=JSON $statement" syntax # --disable_warnings drop table if exists t0,t1,t2,t3; --enable_warnings create table t0 (a int); INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); --echo # r_filtered=30%, because 3 rows match: 0,1,2 --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t0 where a<3; create table t1 (a int, b int, c int, key(a)); insert into t1 select A.a*10 + B.a, A.a*10 + B.a, A.a*10 + B.a from t0 A, t0 B; --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze select * from t0, t1 where t1.a=t0.a and t0.a > 9; --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t0, t1 where t1.a=t0.a and t0.a > 9; analyze select * from t0, t1 where t1.a=t0.a and t1.b<4; --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t0, t1 where t1.a=t0.a and t1.b<4; analyze select * from t1 tbl1, t1 tbl2 where tbl1.b<2 and tbl2.b>5; --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60; --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t1 tbl1, t1 tbl2 where tbl1.b<20 and tbl2.b<60 and tbl1.c > tbl2.c; drop table t1; drop table t0; --echo # --echo # MDEV-7674: ANALYZE shows r_rows=0 --echo # create table t1(a int); insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t2 (a int, key(a)); insert into t2 values (0),(1); --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t1 straight_join t2 force index(a) where t2.a=t1.a; drop table t1,t2; create table t1(a int); insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); --echo # --echo # MDEV-7679: ANALYZE crashes when printing WHERE when no default db --echo # select database(); connect (con1,localhost,root,,*NO-ONE*); connection con1; select database(); --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from test.t1 where t1.a<5; disconnect con1; connection default; drop table t1; --echo # --echo # MDEV-7812: ANALYZE FORMAT=JSON UPDATE/DELETE doesnt print --echo # the r_total_time_ms --echo # create table t2(a int); insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t3(a int); insert into t3 select A.a + B.a* 10 + C.a * 100 from t2 A, t2 B, t2 C; create table t1 (pk int primary key); insert into t1 select a from t3; alter table t1 add b int; --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json update t1 set b=pk; --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json select * from t1 where pk < 10 and b > 4; --replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ analyze format=json delete from t1 where pk < 10 and b > 4; drop table t1, t3, t2;