diff options
-rw-r--r-- | mysql-test/r/analyze_stmt_orderby.result | 45 | ||||
-rw-r--r-- | mysql-test/t/analyze_stmt_orderby.test | 27 | ||||
-rw-r--r-- | sql/sql_explain.cc | 32 |
3 files changed, 101 insertions, 3 deletions
diff --git a/mysql-test/r/analyze_stmt_orderby.result b/mysql-test/r/analyze_stmt_orderby.result index 0f5c7c8437b..c4c4fbf4ce3 100644 --- a/mysql-test/r/analyze_stmt_orderby.result +++ b/mysql-test/r/analyze_stmt_orderby.result @@ -531,4 +531,49 @@ EXPLAIN } drop table t5,t6,t7; drop table t3; +# +# Tabular ANALYZE must get its data from execution tracker (and not from +# the query plan) +# +CREATE TABLE t2( +col1 int, +col2 int, +UNIQUE INDEX idx (col1, col2)) engine=myisam; +INSERT INTO t2(col1, col2) VALUES +(1,20),(2,19),(3,18),(4,17),(5,16),(6,15),(7,14),(8,13),(9,12),(10,11), +(11,10),(12,9),(13,8),(14,7),(15,6),(16,5),(17,4),(18,3),(19,2),(20,1); +flush status; +explain +select col1 f1, col2 f2, col1 f3 from t2 group by f1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range NULL idx 5 NULL 7 Using index for group-by +analyze +select col1 f1, col2 f2, col1 f3 from t2 group by f1; +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t2 range NULL idx 5 NULL 7 20.00 100.00 100.00 Using index for group-by +analyze format=json +select col1 f1, col2 f2, col1 f3 from t2 group by f1; +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "range", + "key": "idx", + "key_length": "5", + "used_key_parts": ["col1"], + "r_loops": 1, + "rows": 7, + "r_rows": 20, + "r_total_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100, + "using_index_for_group_by": true + } + } +} +drop table t2; drop table t0,t1; diff --git a/mysql-test/t/analyze_stmt_orderby.test b/mysql-test/t/analyze_stmt_orderby.test index 4e280bebd37..a40f34805d1 100644 --- a/mysql-test/t/analyze_stmt_orderby.test +++ b/mysql-test/t/analyze_stmt_orderby.test @@ -147,6 +147,31 @@ select count(distinct t5.b) as sum from t5, t6 where t5.a=t6.a and t6.b > 0 and t5.a <= 5 group by t5.a order by sum limit 1; drop table t5,t6,t7; - drop table t3; + +--echo # +--echo # Tabular ANALYZE must get its data from execution tracker (and not from +--echo # the query plan) +--echo # + +CREATE TABLE t2( + col1 int, + col2 int, + UNIQUE INDEX idx (col1, col2)) engine=myisam; + +INSERT INTO t2(col1, col2) VALUES + (1,20),(2,19),(3,18),(4,17),(5,16),(6,15),(7,14),(8,13),(9,12),(10,11), + (11,10),(12,9),(13,8),(14,7),(15,6),(16,5),(17,4),(18,3),(19,2),(20,1); + +flush status; +explain +select col1 f1, col2 f2, col1 f3 from t2 group by f1; +analyze +select col1 f1, col2 f2, col1 f3 from t2 group by f1; +--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/ /"r_buffer_size": "[^"]+"/"r_buffer_size": "REPLACED"/ +analyze format=json +select col1 f1, col2 f2, col1 f3 from t2 group by f1; +drop table t2; + + drop table t0,t1; diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 9f4b635fbf4..41d4268748c 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -726,8 +726,36 @@ int Explain_select::print_explain(Explain_query *query, } else { - bool using_tmp= using_temporary; - bool using_fs= using_filesort; + bool using_tmp; + bool using_fs; + + if (is_analyze) + { + /* + Get the data about "Using temporary; Using filesort" from execution + tracking system. + */ + using_tmp= false; + using_fs= false; + Sort_and_group_tracker::Iterator iter(&ops_tracker); + enum_qep_action action; + Filesort_tracker *dummy; + + while ((action= iter.get_next(&dummy)) != EXPL_ACTION_EOF) + { + if (action == EXPL_ACTION_FILESORT) + using_fs= true; + else if (action == EXPL_ACTION_TEMPTABLE) + using_tmp= true; + } + } + else + { + /* Use imprecise "estimates" we got with the query plan */ + using_tmp= using_temporary; + using_fs= using_filesort; + } + for (uint i=0; i< n_join_tabs; i++) { join_tabs[i]->print_explain(output, explain_flags, is_analyze, select_id, |