diff options
author | Igor Babaev <igor@askmonty.org> | 2011-11-20 04:53:07 -0800 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2011-11-20 04:53:07 -0800 |
commit | 3c496ea9ad4e7ef289eee35f9775c58a0e5f82b8 (patch) | |
tree | 6f4161966352a836565b43307f7eaec0f3a0f5c5 | |
parent | 5a4c91003a73c551d89e0c6878edfe03704352fe (diff) | |
download | mariadb-git-3c496ea9ad4e7ef289eee35f9775c58a0e5f82b8.tar.gz |
Fixed LP bug #892725.
A non-first execution of a prepared statement missed a call of the
TABLE_LIST::process_index_hints() method in the code of the function
setup_tables().
At some scenarios this could lead to the choice of a quite inefficient
execution plan for the base query of the prepared statement.
-rw-r--r-- | mysql-test/r/ps.result | 57 | ||||
-rw-r--r-- | mysql-test/t/ps.test | 27 | ||||
-rw-r--r-- | sql/sql_base.cc | 2 |
3 files changed, 86 insertions, 0 deletions
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index ca847188ce9..90981166fb6 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -3058,3 +3058,60 @@ date('2010-10-10') between '2010-09-09' and ? execute stmt using @a; date('2010-10-10') between '2010-09-09' and ? 0 +# +# Bug #892725: look-up is changed for a full scan when executing PS +# +create table t1 (a int primary key, b int); +insert into t1 values +(7,70), (3,40), (4,40), (8,70), (1,70), (9,50), (2,70); +prepare st from 'select * from t1 where a=8'; +flush status; +execute st; +a b +8 70 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 1 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_next 0 +flush status; +execute st; +a b +8 70 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 1 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_next 0 +flush status; +select * from t1 use index() where a=3; +a b +3 40 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_next 8 +flush status; +execute st; +a b +8 70 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 1 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_next 0 +deallocate prepare st; +drop table t1; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 55ddad701c4..f4e27f3ba42 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -3119,3 +3119,30 @@ set @a='2010-08-08'; execute stmt using @a; execute stmt using @a; +--echo # +--echo # Bug #892725: look-up is changed for a full scan when executing PS +--echo # + +create table t1 (a int primary key, b int); +insert into t1 values + (7,70), (3,40), (4,40), (8,70), (1,70), (9,50), (2,70); + +prepare st from 'select * from t1 where a=8'; + +flush status; +execute st; +show status like '%Handler_read%'; +flush status; +execute st; +show status like '%Handler_read%'; +flush status; +select * from t1 use index() where a=3; +show status like '%Handler_read%'; +flush status; +execute st; +show status like '%Handler_read%'; + +deallocate prepare st; + +drop table t1; + diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 3e27355cc26..dded0105be7 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -7864,6 +7864,8 @@ bool setup_tables(THD *thd, Name_resolution_context *context, table_list->table->map= table_list->map_exec; table_list->table->maybe_null= table_list->maybe_null_exec; table_list->table->pos_in_table_list= table_list; + if (table_list->process_index_hints(table_list->table)) + DBUG_RETURN(1); } select_lex->leaf_tables.push_back(table_list); } |