Skip to content

Commit 69d7bfd

Browse files
Varun Guptadr-m
authored andcommitted
MDEV-17023: 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.
1 parent 7d8d37c commit 69d7bfd

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

mysql-test/r/stat_tables.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,3 +577,16 @@ SELECT * FROM mysql.column_stats;
577577
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
578578
DROP TABLE t1;
579579
set use_stat_tables=@save_use_stat_tables;
580+
#
581+
# MDEV-17023: Crash during read_histogram_for_table with optimizer_use_condition_selectivity set to 4
582+
#
583+
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
584+
set @@optimizer_use_condition_selectivity=4;
585+
set @@use_stat_tables= PREFERABLY;
586+
explain
587+
SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user;
588+
id select_type table type possible_keys key key_len ref rows Extra
589+
1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL
590+
1 SIMPLE user ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join)
591+
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
592+
set use_stat_tables=@save_use_stat_tables;

mysql-test/r/stat_tables_innodb.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,5 +604,18 @@ SELECT * FROM mysql.column_stats;
604604
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
605605
DROP TABLE t1;
606606
set use_stat_tables=@save_use_stat_tables;
607+
#
608+
# MDEV-17023: Crash during read_histogram_for_table with optimizer_use_condition_selectivity set to 4
609+
#
610+
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
611+
set @@optimizer_use_condition_selectivity=4;
612+
set @@use_stat_tables= PREFERABLY;
613+
explain
614+
SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user;
615+
id select_type table type possible_keys key key_len ref rows Extra
616+
1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL
617+
1 SIMPLE user ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join)
618+
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
619+
set use_stat_tables=@save_use_stat_tables;
607620
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
608621
SET SESSION STORAGE_ENGINE=DEFAULT;

mysql-test/t/stat_tables.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,15 @@ SELECT * FROM mysql.column_stats;
356356
DROP TABLE t1;
357357

358358
set use_stat_tables=@save_use_stat_tables;
359+
360+
--echo #
361+
--echo # MDEV-17023: Crash during read_histogram_for_table with optimizer_use_condition_selectivity set to 4
362+
--echo #
363+
364+
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
365+
set @@optimizer_use_condition_selectivity=4;
366+
set @@use_stat_tables= PREFERABLY;
367+
explain
368+
SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user;
369+
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
370+
set use_stat_tables=@save_use_stat_tables;

sql/sql_statistics.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,6 +3129,9 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
31293129
if (!tl->is_view_or_derived() && !is_temporary_table(tl) && tl->table)
31303130
{
31313131
TABLE_SHARE *table_share= tl->table->s;
3132+
if (table_share && !(table_share->table_category == TABLE_CATEGORY_USER))
3133+
continue;
3134+
31323135
if (table_share &&
31333136
table_share->stats_cb.stats_can_be_read &&
31343137
!table_share->stats_cb.stats_is_read)

0 commit comments

Comments
 (0)