revision-id: 511eda6d520fb06c59edd24ef15438932c7c088b (mariadb-10.0.36-8-g511eda6d520) parent(s): bcc677bb7264db08b22284998706b44c377ed8ec author: Varun Gupta committer: Varun Gupta timestamp: 2018-08-22 12:06:06 +0530 message: 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. --- mysql-test/r/stat_tables.result | 13 +++++++++++++ mysql-test/r/stat_tables_innodb.result | 13 +++++++++++++ mysql-test/t/stat_tables.test | 12 ++++++++++++ sql/sql_statistics.cc | 3 +++ 4 files changed, 41 insertions(+) diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result index c1457d5e91a..cd78d44462e 100644 --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@ -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; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result index 2ac868e9341..02a07fa8bbb 100644 --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@ -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; diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test index d69b00618ea..a0b2a22b946 100644 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@ -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; diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 537ede91710..cb75a5c2176 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -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)