Commit 364a20fe authored by Igor Babaev's avatar Igor Babaev

MDEV-16507 SIGSEGV when use_stat_tables = preferably and

           optimizer_use_condition_selectivity = 4

It does not makes sense to try to read statistics for temporary tables
because it's not collected.
parent d8192f54
...@@ -1659,3 +1659,23 @@ id ...@@ -1659,3 +1659,23 @@ id
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1,t2; drop table t1,t2;
#
# MDEV-16507: statistics for temporary tables should not be used
#
SET
@save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
SET @@use_stat_tables = preferably ;
SET @@optimizer_use_condition_selectivity = 4;
CREATE TABLE t1 (
TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP
);
SET @had_t1_table= @@warning_count != 0;
CREATE TEMPORARY TABLE tmp_t1 LIKE t1;
INSERT INTO tmp_t1 VALUES (now());
INSERT INTO t1 SELECT * FROM tmp_t1 WHERE @had_t1_table=0;
DROP TABLE t1;
SET
use_stat_tables=@save_use_stat_tables;
SET
optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
...@@ -737,3 +737,27 @@ set use_stat_tables=@save_use_stat_tables; ...@@ -737,3 +737,27 @@ set use_stat_tables=@save_use_stat_tables;
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1,t2; drop table t1,t2;
--echo #
--echo # MDEV-16507: statistics for temporary tables should not be used
--echo #
SET
@save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
SET @@use_stat_tables = preferably ;
SET @@optimizer_use_condition_selectivity = 4;
CREATE TABLE t1 (
TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP
);
SET @had_t1_table= @@warning_count != 0;
CREATE TEMPORARY TABLE tmp_t1 LIKE t1;
INSERT INTO tmp_t1 VALUES (now());
INSERT INTO t1 SELECT * FROM tmp_t1 WHERE @had_t1_table=0;
DROP TABLE t1;
SET
use_stat_tables=@save_use_stat_tables;
SET
optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
...@@ -2952,7 +2952,7 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables) ...@@ -2952,7 +2952,7 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables)
for (TABLE_LIST *tl= tables; tl; tl= tl->next_global) for (TABLE_LIST *tl= tables; tl; tl= tl->next_global)
{ {
if (!tl->is_view_or_derived() && tl->table) if (!tl->is_view_or_derived() && !is_temporary_table(tl) && tl->table)
{ {
TABLE_SHARE *table_share= tl->table->s; TABLE_SHARE *table_share= tl->table->s;
if (table_share && if (table_share &&
...@@ -2964,7 +2964,7 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables) ...@@ -2964,7 +2964,7 @@ bool statistics_for_tables_is_needed(THD *thd, TABLE_LIST *tables)
for (TABLE_LIST *tl= tables; tl; tl= tl->next_global) for (TABLE_LIST *tl= tables; tl; tl= tl->next_global)
{ {
if (!tl->is_view_or_derived() && tl->table) if (!tl->is_view_or_derived() && !is_temporary_table(tl) && tl->table)
{ {
TABLE_SHARE *table_share= tl->table->s; TABLE_SHARE *table_share= tl->table->s;
if (table_share && if (table_share &&
...@@ -3093,7 +3093,7 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables) ...@@ -3093,7 +3093,7 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
for (TABLE_LIST *tl= tables; tl; tl= tl->next_global) for (TABLE_LIST *tl= tables; tl; tl= tl->next_global)
{ {
if (!tl->is_view_or_derived() && tl->table) if (!tl->is_view_or_derived() && !is_temporary_table(tl) && tl->table)
{ {
TABLE_SHARE *table_share= tl->table->s; TABLE_SHARE *table_share= tl->table->s;
if (table_share && if (table_share &&
...@@ -3867,4 +3867,4 @@ bool is_stat_table(const char *db, const char *table) ...@@ -3867,4 +3867,4 @@ bool is_stat_table(const char *db, const char *table)
} }
} }
return false; return false;
} }
\ No newline at end of file
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