MDEV-16760 CREATE OR REPLACE TABLE never updates statistical tables
If the command CREATE OR REPLACE TABLE really replaces a table then it should remove all data on this table from all statistical tables.
This commit is contained in:
parent
c89bb15c31
commit
1fd84f9129
@ -552,3 +552,28 @@ pk
|
|||||||
2
|
2
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
set use_stat_tables=@save_use_stat_tables;
|
set use_stat_tables=@save_use_stat_tables;
|
||||||
|
#
|
||||||
|
# MDEV-16760: CREATE OR REPLACE TABLE after ANALYZE TABLE
|
||||||
|
#
|
||||||
|
SET use_stat_tables= PREFERABLY;
|
||||||
|
CREATE TABLE t1 (pk int PRIMARY KEY, c varchar(32));
|
||||||
|
INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
|
||||||
|
ANALYZE TABLE t1;
|
||||||
|
Table Op Msg_type Msg_text
|
||||||
|
test.t1 analyze status Engine-independent statistics collected
|
||||||
|
test.t1 analyze status OK
|
||||||
|
SELECT * FROM t1;
|
||||||
|
pk c
|
||||||
|
1 foo
|
||||||
|
2 bar
|
||||||
|
SELECT * FROM mysql.column_stats;
|
||||||
|
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
|
||||||
|
test t1 pk 1 2 0.0000 4.0000 1.0000 0 NULL NULL
|
||||||
|
test t1 c bar foo 0.0000 3.0000 1.0000 0 NULL NULL
|
||||||
|
CREATE OR REPLACE TABLE t1 (pk int PRIMARY KEY, a char(7));
|
||||||
|
SELECT * FROM t1;
|
||||||
|
pk a
|
||||||
|
SELECT * FROM mysql.column_stats;
|
||||||
|
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
|
||||||
|
DROP TABLE t1;
|
||||||
|
set use_stat_tables=@save_use_stat_tables;
|
||||||
|
@ -579,5 +579,30 @@ pk
|
|||||||
2
|
2
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
set use_stat_tables=@save_use_stat_tables;
|
set use_stat_tables=@save_use_stat_tables;
|
||||||
|
#
|
||||||
|
# MDEV-16760: CREATE OR REPLACE TABLE after ANALYZE TABLE
|
||||||
|
#
|
||||||
|
SET use_stat_tables= PREFERABLY;
|
||||||
|
CREATE TABLE t1 (pk int PRIMARY KEY, c varchar(32));
|
||||||
|
INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
|
||||||
|
ANALYZE TABLE t1;
|
||||||
|
Table Op Msg_type Msg_text
|
||||||
|
test.t1 analyze status Engine-independent statistics collected
|
||||||
|
test.t1 analyze status OK
|
||||||
|
SELECT * FROM t1;
|
||||||
|
pk c
|
||||||
|
1 foo
|
||||||
|
2 bar
|
||||||
|
SELECT * FROM mysql.column_stats;
|
||||||
|
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
|
||||||
|
test t1 pk 1 2 0.0000 4.0000 1.0000 0 NULL NULL
|
||||||
|
test t1 c bar foo 0.0000 3.0000 1.0000 0 NULL NULL
|
||||||
|
CREATE OR REPLACE TABLE t1 (pk int PRIMARY KEY, a char(7));
|
||||||
|
SELECT * FROM t1;
|
||||||
|
pk a
|
||||||
|
SELECT * FROM mysql.column_stats;
|
||||||
|
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
|
||||||
|
DROP TABLE t1;
|
||||||
|
set use_stat_tables=@save_use_stat_tables;
|
||||||
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
|
set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
|
||||||
SET SESSION STORAGE_ENGINE=DEFAULT;
|
SET SESSION STORAGE_ENGINE=DEFAULT;
|
||||||
|
@ -336,3 +336,23 @@ SELECT pk FROM t1;
|
|||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
|
||||||
set use_stat_tables=@save_use_stat_tables;
|
set use_stat_tables=@save_use_stat_tables;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-16760: CREATE OR REPLACE TABLE after ANALYZE TABLE
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
SET use_stat_tables= PREFERABLY;
|
||||||
|
|
||||||
|
CREATE TABLE t1 (pk int PRIMARY KEY, c varchar(32));
|
||||||
|
INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
|
||||||
|
ANALYZE TABLE t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
SELECT * FROM mysql.column_stats;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TABLE t1 (pk int PRIMARY KEY, a char(7));
|
||||||
|
SELECT * FROM t1;
|
||||||
|
SELECT * FROM mysql.column_stats;
|
||||||
|
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
set use_stat_tables=@save_use_stat_tables;
|
||||||
|
@ -4762,6 +4762,10 @@ int create_table_impl(THD *thd,
|
|||||||
{
|
{
|
||||||
if (create_info->options & HA_LEX_CREATE_REPLACE)
|
if (create_info->options & HA_LEX_CREATE_REPLACE)
|
||||||
{
|
{
|
||||||
|
LEX_STRING db_name= {(char *) db, strlen(db)};
|
||||||
|
LEX_STRING tab_name= {(char *) table_name, strlen(table_name)};
|
||||||
|
(void) delete_statistics_for_table(thd, &db_name, &tab_name);
|
||||||
|
|
||||||
TABLE_LIST table_list;
|
TABLE_LIST table_list;
|
||||||
table_list.init_one_table(db, strlen(db), table_name,
|
table_list.init_one_table(db, strlen(db), table_name,
|
||||||
strlen(table_name), table_name,
|
strlen(table_name), table_name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user