Commit 6ab9d162 authored by Varun Gupta's avatar Varun Gupta

MDEV-19407: Assertion `field->table->stats_is_read' failed in is_eits_usable

Statistics were not read for a table when we had a CREATE TABLE query.
Enforce reading statistics for commands CREATE TABLE, SET and DO.
parent a941e58f
...@@ -707,8 +707,27 @@ ERROR 42S02: Table 'test.x' doesn't exist ...@@ -707,8 +707,27 @@ ERROR 42S02: Table 'test.x' doesn't exist
select * from information_schema.tables where table_name='v'; 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 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 def test v VIEW NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL VIEW
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1,t2; drop table t1,t2;
drop view v; drop view v;
#
# MDEV-19407: Assertion `field->table->stats_is_read' failed in is_eits_usable
#
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set @@optimizer_use_condition_selectivity= 1;
set @@use_stat_tables='never';
create table t1(pk int);
insert into t1 values (4),(3);
set @@optimizer_use_condition_selectivity= 4;
set use_stat_tables='preferably';
INSERT INTO t1 SELECT * FROM x;
ERROR 42S02: Table 'test.x' doesn't exist
CREATE TABLE t2 SELECT pk FROM t1 WHERE pk>2;
select * from t2;
pk
4
3
drop table t1,t2;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
...@@ -734,8 +734,27 @@ ERROR 42S02: Table 'test.x' doesn't exist ...@@ -734,8 +734,27 @@ ERROR 42S02: Table 'test.x' doesn't exist
select * from information_schema.tables where table_name='v'; 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 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 def test v VIEW NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL VIEW
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1,t2; drop table t1,t2;
drop view v; drop view v;
#
# MDEV-19407: Assertion `field->table->stats_is_read' failed in is_eits_usable
#
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set @@optimizer_use_condition_selectivity= 1;
set @@use_stat_tables='never';
create table t1(pk int);
insert into t1 values (4),(3);
set @@optimizer_use_condition_selectivity= 4;
set use_stat_tables='preferably';
INSERT INTO t1 SELECT * FROM x;
ERROR 42S02: Table 'test.x' doesn't exist
CREATE TABLE t2 SELECT pk FROM t1 WHERE pk>2;
select * from t2;
pk
4
3
drop table t1,t2;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set use_stat_tables=@save_use_stat_tables; set use_stat_tables=@save_use_stat_tables;
......
...@@ -469,9 +469,29 @@ CREATE VIEW v AS SELECT * FROM t1 JOIN t2; ...@@ -469,9 +469,29 @@ CREATE VIEW v AS SELECT * FROM t1 JOIN t2;
INSERT INTO t2 SELECT * FROM x; INSERT INTO t2 SELECT * FROM x;
select * from information_schema.tables where table_name='v'; select * from information_schema.tables where table_name='v';
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1,t2; drop table t1,t2;
drop view v; drop view v;
--echo #
--echo # MDEV-19407: Assertion `field->table->stats_is_read' failed in is_eits_usable
--echo #
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set @@optimizer_use_condition_selectivity= 1;
set @@use_stat_tables='never';
create table t1(pk int);
insert into t1 values (4),(3);
set @@optimizer_use_condition_selectivity= 4;
set use_stat_tables='preferably';
--error ER_NO_SUCH_TABLE
INSERT INTO t1 SELECT * FROM x;
CREATE TABLE t2 SELECT pk FROM t1 WHERE pk>2;
select * from t2;
drop table t1,t2;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
......
...@@ -2191,6 +2191,9 @@ inline bool statistics_for_command_is_needed(THD *thd) ...@@ -2191,6 +2191,9 @@ inline bool statistics_for_command_is_needed(THD *thd)
case SQLCOM_DELETE_MULTI: case SQLCOM_DELETE_MULTI:
case SQLCOM_REPLACE: case SQLCOM_REPLACE:
case SQLCOM_REPLACE_SELECT: case SQLCOM_REPLACE_SELECT:
case SQLCOM_CREATE_TABLE:
case SQLCOM_SET_OPTION:
case SQLCOM_DO:
break; break;
default: default:
return FALSE; return FALSE;
......
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