From fec5ab5a56cb9a45c621207620cc85079cddf537 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sun, 12 Oct 2014 20:48:07 +0400 Subject: [PATCH] MDEV-6396: ANALYZE INSERT/REPLACE is accepted, but does not produce a plan Add ANALYZE STMT handling into INSERT command. --- mysql-test/r/analyze_stmt.result | 17 +++++++++++++++++ mysql-test/t/analyze_stmt.test | 11 +++++++++++ sql/sql_insert.cc | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/mysql-test/r/analyze_stmt.result b/mysql-test/r/analyze_stmt.result index 53c3188cd4c..e5b3b804202 100644 --- a/mysql-test/r/analyze_stmt.result +++ b/mysql-test/r/analyze_stmt.result @@ -259,3 +259,20 @@ analyze delete from t1 returning *; 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 0 0 100.00 100.00 drop table t1; +# +# MDEV-6396: ANALYZE INSERT/REPLACE is accepted, but does not produce a plan +# +create table t1 (a int primary key, b int); +analyze insert into t1 values (1,1); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +select * from t1; +a b +1 1 +analyze replace t1 values (1,2); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL 100.00 100.00 NULL +select * from t1; +a b +1 2 +drop table t1; diff --git a/mysql-test/t/analyze_stmt.test b/mysql-test/t/analyze_stmt.test index 214d80d840d..4c89890ac29 100644 --- a/mysql-test/t/analyze_stmt.test +++ b/mysql-test/t/analyze_stmt.test @@ -206,3 +206,14 @@ create table t1 (i int); analyze delete from t1 returning *; drop table t1; +--echo # +--echo # MDEV-6396: ANALYZE INSERT/REPLACE is accepted, but does not produce a plan +--echo # +create table t1 (a int primary key, b int); +analyze insert into t1 values (1,1); +select * from t1; + +analyze replace t1 values (1,2); +select * from t1; +drop table t1; + diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 8b01acb2a87..2b68f7766ac 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1100,6 +1100,11 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, if (error) goto abort; + if (thd->lex->analyze_stmt) + { + retval= thd->lex->explain->send_explain(thd); + goto abort; + } if (values_list.elements == 1 && (!(thd->variables.option_bits & OPTION_WARNINGS) || !thd->cuted_fields)) {