[Commits] de0ecf1c921: MDEV-19352: Server crash in alloc_histograms_for_table_share upon query from information schema

Varun varunraiko1803 at gmail.com
Tue Apr 30 23:34:04 EEST 2019


revision-id: de0ecf1c9211a33071c078c90e940ff1d8419f1d (mariadb-10.1.38-156-gde0ecf1c921)
parent(s): 4383265ccbbd7bb7339f3f79faf84a28a2b51120
author: Varun Gupta
committer: Varun Gupta
timestamp: 2019-05-01 01:44:45 +0530
message:

MDEV-19352: Server crash in alloc_histograms_for_table_share upon query from information schema

To read histograms for a table, we should check if the allocation of statistics was done or not,
if not done we should not try to read histograms for such a table.

---
 mysql-test/r/stat_tables.result        | 18 ++++++++++++++++++
 mysql-test/r/stat_tables_innodb.result | 18 ++++++++++++++++++
 mysql-test/t/stat_tables.test          | 21 +++++++++++++++++++++
 sql/sql_statistics.cc                  |  5 +++--
 4 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result
index bd3e9ed7a40..0a53a5ae99d 100644
--- a/mysql-test/r/stat_tables.result
+++ b/mysql-test/r/stat_tables.result
@@ -692,5 +692,23 @@ DROP DATABASE dbt3_s001;
 delete from mysql.table_stats;
 delete from mysql.column_stats;
 delete from mysql.index_stats;
+#
+# MDEV-19352: Server crash in alloc_histograms_for_table_share upon query from information schema
+#
+use test;
+set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+set @@optimizer_use_condition_selectivity= 4;
+set use_stat_tables='preferably';
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
+INSERT INTO t2 SELECT * FROM x;
+ERROR 42S02: Table 'test.x' doesn't exist
+select * from information_schema.tables where table_name='v';
+TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE	ENGINE	VERSION	ROW_FORMAT	TABLE_ROWS	AVG_ROW_LENGTH	DATA_LENGTH	MAX_DATA_LENGTH	INDEX_LENGTH	DATA_FREE	AUTO_INCREMENT	CREATE_TIME	UPDATE_TIME	CHECK_TIME	TABLE_COLLATION	CHECKSUM	CREATE_OPTIONS	TABLE_COMMENT
+def	test	v	VIEW	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	VIEW
+drop table t1,t2;
+drop view v;
+set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
 set @save_optimizer_switch=@@optimizer_switch;
 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 579d19462e7..9a93b479664 100644
--- a/mysql-test/r/stat_tables_innodb.result
+++ b/mysql-test/r/stat_tables_innodb.result
@@ -719,6 +719,24 @@ DROP DATABASE dbt3_s001;
 delete from mysql.table_stats;
 delete from mysql.column_stats;
 delete from mysql.index_stats;
+#
+# MDEV-19352: Server crash in alloc_histograms_for_table_share upon query from information schema
+#
+use test;
+set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+set @@optimizer_use_condition_selectivity= 4;
+set use_stat_tables='preferably';
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
+INSERT INTO t2 SELECT * FROM x;
+ERROR 42S02: Table 'test.x' doesn't exist
+select * from information_schema.tables where table_name='v';
+TABLE_CATALOG	TABLE_SCHEMA	TABLE_NAME	TABLE_TYPE	ENGINE	VERSION	ROW_FORMAT	TABLE_ROWS	AVG_ROW_LENGTH	DATA_LENGTH	MAX_DATA_LENGTH	INDEX_LENGTH	DATA_FREE	AUTO_INCREMENT	CREATE_TIME	UPDATE_TIME	CHECK_TIME	TABLE_COLLATION	CHECKSUM	CREATE_OPTIONS	TABLE_COMMENT
+def	test	v	VIEW	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	VIEW
+drop table t1,t2;
+drop view v;
+set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
 set @save_optimizer_switch=@@optimizer_switch;
 set use_stat_tables=@save_use_stat_tables;
 set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
diff --git a/mysql-test/t/stat_tables.test b/mysql-test/t/stat_tables.test
index 97f9f08569f..2727f8d8bb1 100644
--- a/mysql-test/t/stat_tables.test
+++ b/mysql-test/t/stat_tables.test
@@ -453,6 +453,27 @@ delete from mysql.table_stats;
 delete from mysql.column_stats;
 delete from mysql.index_stats;
 
+--echo #
+--echo # MDEV-19352: Server crash in alloc_histograms_for_table_share upon query from information schema
+--echo #
+
+use test;
+set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
+set @@optimizer_use_condition_selectivity= 4;
+set use_stat_tables='preferably';
+
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
+--error ER_NO_SUCH_TABLE
+INSERT INTO t2 SELECT * FROM x;
+
+select * from information_schema.tables where table_name='v';
+
+drop table t1,t2;
+drop view v;
+set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
+
 set @save_optimizer_switch=@@optimizer_switch;
 
 set use_stat_tables=@save_use_stat_tables;
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index 061622a2cd6..8dc78e0327e 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -3285,12 +3285,13 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
       if (table_share->stats_cb.stats_is_read)
         tl->table->stats_is_read= TRUE;
       if (thd->variables.optimizer_use_condition_selectivity > 3 && 
-          table_share && !table_share->stats_cb.histograms_are_read)
+          table_share && table_share->stats_cb.stats_can_be_read &&
+          !table_share->stats_cb.histograms_are_read)
       {
         (void) read_histograms_for_table(thd, tl->table, stat_tables);
         table_share->stats_cb.histograms_are_read= TRUE;
       }
-      if (table_share->stats_cb.stats_is_read)
+      if (table_share->stats_cb.histograms_are_read)
         tl->table->histograms_are_read= TRUE;
     }
   }  


More information about the commits mailing list