Commit a1b6befc authored by Monty's avatar Monty

Fixed crash in is_stat_table() when using hash joins.

Other usage if persistent statistics is checking 'stats_is_read' in
caller, which is why this was not noticed earlier.

Other things:
- Simplified no_stat_values_provided
parent 6991b1c4
......@@ -417,5 +417,31 @@ test t1 B 1 NULL
test t1 B 2 NULL
drop table t1;
#
# Crash inis_eits_usable()
#
CREATE TABLE t1 (a int) ENGINE=MyISAM;
CREATE TABLE t2 (b int) ENGINE=MyISAM;
INSERT INTO t1 (a) VALUES (4), (6);
INSERT INTO t2 (b) VALUES (0), (8);
set @save_join_cache_level=@@join_cache_level;
set @save_optimizer_switch=@@optimizer_switch;
SET join_cache_level=3;
SET optimizer_switch='join_cache_hashed=on';
SET optimizer_switch='join_cache_bka=on';
set optimizer_switch='hash_join_cardinality=on';
select benchmark(1,1);
benchmark(1,1)
0
EXPLAIN
SELECT * FROM t1, t2 WHERE b=a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t2 hash_ALL NULL #hash#$hj 5 test.t1.a 2 Using where; Using join buffer (flat, BNLH join)
SELECT * FROM t1, t2 WHERE b=a;
a b
DROP TABLE t1,t2;
set @@optimizer_switch=@save_optimizer_switch;
set @@join_cache_level=@save_join_cache_level;
#
# End of 10.6 tests
#
......@@ -269,6 +269,33 @@ alter ignore table t1 rename key `b` to `B`, LOCK=shared;
select * from mysql.index_stats where table_name= "t1";
drop table t1;
--echo #
--echo # Crash inis_eits_usable()
--echo #
CREATE TABLE t1 (a int) ENGINE=MyISAM;
CREATE TABLE t2 (b int) ENGINE=MyISAM;
INSERT INTO t1 (a) VALUES (4), (6);
INSERT INTO t2 (b) VALUES (0), (8);
set @save_join_cache_level=@@join_cache_level;
set @save_optimizer_switch=@@optimizer_switch;
SET join_cache_level=3;
SET optimizer_switch='join_cache_hashed=on';
SET optimizer_switch='join_cache_bka=on';
set optimizer_switch='hash_join_cardinality=on';
select benchmark(1,1);
EXPLAIN
SELECT * FROM t1, t2 WHERE b=a;
SELECT * FROM t1, t2 WHERE b=a;
DROP TABLE t1,t2;
set @@optimizer_switch=@save_optimizer_switch;
set @@join_cache_level=@save_join_cache_level;
--echo #
--echo # End of 10.6 tests
--echo #
......@@ -3125,7 +3125,8 @@ void TABLE_STATISTICS_CB::update_stats_in_table(TABLE *table)
for ( ; *field_ptr; field_ptr++, column_stats++)
(*field_ptr)->read_stats= column_stats;
/* Mark that stats are now usable */
table->stats_is_read= true;
table->stats_is_read= (table->stats_cb->stats_available !=
TABLE_STAT_NO_STATS);
}
......@@ -3246,8 +3247,6 @@ read_statistics_for_tables(THD *thd, TABLE_LIST *tables, bool force_reload)
}
mysql_mutex_unlock(&table_share->LOCK_statistics);
table->stats_cb->update_stats_in_table(table);
table->stats_is_read= (stats_cb->stats_available !=
TABLE_STAT_NO_STATS);
}
}
......@@ -4312,11 +4311,9 @@ bool is_eits_usable(Field *field)
Column_statistics* col_stats= field->read_stats;
// check if column_statistics was allocated for this field
if (!col_stats)
if (!col_stats || !field->table->stats_is_read)
return false;
DBUG_ASSERT(field->table->stats_is_read);
/*
(1): checks if we have EITS statistics for a particular column
(2): Don't use EITS for GEOMETRY columns
......
......@@ -445,9 +445,7 @@ class Column_statistics
*/
bool no_stat_values_provided()
{
if (column_stat_nulls == no_values_provided_bitmap())
return true;
return false;
return (column_stat_nulls == no_values_provided_bitmap());
}
};
......
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