diff --git a/mysql-test/r/empty_table.result b/mysql-test/r/empty_table.result index cea787f4abd21..2bca3e792fa2e 100644 --- a/mysql-test/r/empty_table.result +++ b/mysql-test/r/empty_table.result @@ -7,4 +7,12 @@ select * from t1; nr b str select * from t1 limit 0; nr b str +show status like "Empty_queries"; +Variable_name Value +Empty_queries 2 drop table t1; +select * from t2; +ERROR 42S02: Table 'test.t2' doesn't exist +show status like "Empty_queries"; +Variable_name Value +Empty_queries 2 diff --git a/mysql-test/t/empty_table.test b/mysql-test/t/empty_table.test index e8e532832f4f5..754671868ba51 100644 --- a/mysql-test/t/empty_table.test +++ b/mysql-test/t/empty_table.test @@ -10,6 +10,15 @@ create table t1 (nr int(5) not null auto_increment,b blob,str char(10), primary select count(*) from t1; select * from t1; select * from t1 limit 0; +show status like "Empty_queries"; drop table t1; +# +# Accessing a non existing table should not increase Empty_queries +# + +--error 1146 +select * from t2; +show status like "Empty_queries"; + # End of 4.1 tests diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 266c6119f1356..effc023053617 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -6359,7 +6359,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) } } /* Count number of empty select queries */ - if (!thd->get_sent_row_count()) + if (!thd->get_sent_row_count() && !res) status_var_increment(thd->status_var.empty_queries); else status_var_add(thd->status_var.rows_sent, thd->get_sent_row_count());