Commit 0cafc131 authored by Varun Gupta's avatar Varun Gupta

MDEV-17073: Crash during read_histogram_for_table with optimizer_use_condition_selectivity set to 4

No need to read statistics for tables that are not USER tables.
We allocate memory for structures to collect statistics only for USER TABLES.
parent 7d8d37c3
......@@ -577,3 +577,16 @@ SELECT * FROM mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;
#
# MDEV-17023: Crash during read_histogram_for_table with optimizer_use_condition_selectivity set to 4
#
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
set @@optimizer_use_condition_selectivity=4;
set @@use_stat_tables= PREFERABLY;
explain
SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL
1 SIMPLE user ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join)
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;
......@@ -604,5 +604,18 @@ SELECT * FROM mysql.column_stats;
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;
#
# MDEV-17023: Crash during read_histogram_for_table with optimizer_use_condition_selectivity set to 4
#
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
set @@optimizer_use_condition_selectivity=4;
set @@use_stat_tables= PREFERABLY;
explain
SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL
1 SIMPLE user ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join)
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
SET SESSION STORAGE_ENGINE=DEFAULT;
......@@ -356,3 +356,15 @@ SELECT * FROM mysql.column_stats;
DROP TABLE t1;
set use_stat_tables=@save_use_stat_tables;
--echo #
--echo # MDEV-17023: Crash during read_histogram_for_table with optimizer_use_condition_selectivity set to 4
--echo #
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
set @@optimizer_use_condition_selectivity=4;
set @@use_stat_tables= PREFERABLY;
explain
SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user;
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set use_stat_tables=@save_use_stat_tables;
......@@ -3129,6 +3129,9 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
if (!tl->is_view_or_derived() && !is_temporary_table(tl) && tl->table)
{
TABLE_SHARE *table_share= tl->table->s;
if (table_share && !(table_share->table_category == TABLE_CATEGORY_USER))
continue;
if (table_share &&
table_share->stats_cb.stats_can_be_read &&
!table_share->stats_cb.stats_is_read)
......
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