Commit ca94ce2a authored by Varun Gupta's avatar Varun Gupta

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.
parent 57c37e6c
......@@ -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;
......@@ -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;
......
......@@ -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;
......@@ -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;
}
}
......
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