Commit 70a5fb49 authored by Varun Gupta's avatar Varun Gupta

Fixed the case when statistics were not getting read because

we had the statistics tables in the FROM list of the select.
The statistics for tables are not read in such cases, so we need
to check this case separately.
parent 6ab9d162
...@@ -728,6 +728,17 @@ pk ...@@ -728,6 +728,17 @@ pk
4 4
3 3
drop table t1,t2; drop table t1,t2;
create table t1(a int,b int, key k1(a) );
insert into t1 values(1,1),(2,2),(3,3);
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
select * from mysql.index_stats, t1 where index_name='k1' and t1.a > 1 and t1.b > 1;
db_name table_name index_name prefix_arity avg_frequency a b
test t1 k1 1 1.0000 2 2
test t1 k1 1 1.0000 3 3
drop table t1;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
...@@ -755,6 +755,17 @@ pk ...@@ -755,6 +755,17 @@ pk
4 4
3 3
drop table t1,t2; drop table t1,t2;
create table t1(a int,b int, key k1(a) );
insert into t1 values(1,1),(2,2),(3,3);
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
select * from mysql.index_stats, t1 where index_name='k1' and t1.a > 1 and t1.b > 1;
db_name table_name index_name prefix_arity avg_frequency a b
test t1 k1 1 1.0000 2 2
test t1 k1 1 1.0000 3 3
drop table t1;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
......
...@@ -492,6 +492,12 @@ CREATE TABLE t2 SELECT pk FROM t1 WHERE pk>2; ...@@ -492,6 +492,12 @@ CREATE TABLE t2 SELECT pk FROM t1 WHERE pk>2;
select * from t2; select * from t2;
drop table t1,t2; drop table t1,t2;
create table t1(a int,b int, key k1(a) );
insert into t1 values(1,1),(2,2),(3,3);
analyze table t1;
select * from mysql.index_stats, t1 where index_name='k1' and t1.a > 1 and t1.b > 1;
drop table t1;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
......
...@@ -3050,7 +3050,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) ...@@ -3050,7 +3050,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
if (thd->variables.optimizer_use_condition_selectivity > 2 && if (thd->variables.optimizer_use_condition_selectivity > 2 &&
!bitmap_is_clear_all(used_fields) && !bitmap_is_clear_all(used_fields) &&
thd->variables.use_stat_tables > 0) thd->variables.use_stat_tables > 0 && table->stats_is_read)
{ {
PARAM param; PARAM param;
MEM_ROOT alloc; MEM_ROOT alloc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment