revision-id: 0896d7ebc3698f898bd66544bbc0ba6e4a4fbe0e (mariadb-10.1.34-25-g0896d7ebc36) parent(s): 312de43f40e221096b5565f6f4999eaadae09ef4 ada54101a7185782657813c553907f61f2a35faf author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-07-19 12:55:54 +0200 message: Merge branch '10.0' into bb-10.1-merge cmake/os/Windows.cmake | 2 +- mysql-test/r/derived.result | 33 ++++++++++++ mysql-test/r/join.result | 40 +++++++++++++++ mysql-test/r/join_cache.result | 33 ++++++++++++ mysql-test/r/stat_tables.result | 60 ++++++++++++++++++++++ mysql-test/r/stat_tables_innodb.result | 60 ++++++++++++++++++++++ mysql-test/r/subselect_sj2_mat.result | 51 ++++++++++++++++++ .../suite/binlog/include/check_binlog_size.inc | 31 +++++++++++ .../suite/binlog/r/binlog_tmp_table_row.result | 7 +++ .../suite/binlog/t/binlog_tmp_table_row.test | 30 +++++++++++ mysql-test/suite/vcol/t/vcol_misc.test | 2 + mysql-test/t/derived.test | 21 ++++++++ mysql-test/t/join.test | 53 +++++++++++++++++++ mysql-test/t/join_cache.test | 32 +++++++++++- mysql-test/t/stat_tables.test | 50 ++++++++++++++++++ mysql-test/t/subselect_sj2_mat.test | 49 ++++++++++++++++++ mysql-test/valgrind.supp | 13 +++++ scripts/mysql_install_db.sh | 5 ++ sql/log.cc | 11 ++-- sql/mysqld.cc | 7 ++- sql/opt_subselect.cc | 3 +- sql/sql_base.cc | 12 +++-- sql/sql_parse.cc | 3 ++ sql/sql_select.cc | 4 +- sql/table.cc | 19 +++++-- storage/xtradb/os/os0file.cc | 41 ++++++++++++++- 26 files changed, 649 insertions(+), 23 deletions(-) diff --cc mysql-test/r/derived.result index 687497ceb7e,889518343c0..6f786e34a9a --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@@ -1077,49 -1079,36 +1078,81 @@@ drop procedure pr; drop view v1; drop table t1; + set @@join_cache_level= @save_join_cache_level; + # + # MDEV-16307: Incorrect results when using BNLH join instead of BNL join with views + # + CREATE TABLE t1 (c1 text, c2 int); + INSERT INTO t1 VALUES ('a',1), ('c',3), ('g',7), ('d',4), ('c',3); + CREATE TABLE t2 (c1 text, c2 int); + INSERT INTO t2 VALUES ('b',2), ('c',3); + CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; + explain SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + id select_type table type possible_keys key key_len ref rows Extra + 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 + 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) + 2 DERIVED t1 ALL NULL NULL NULL NULL 5 + SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + c1 c2 c1 c2 + c 3 c 3 + c 3 c 3 + set @save_join_cache_level= @@join_cache_level; + set @@join_cache_level=4; + explain SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + id select_type table type possible_keys key key_len ref rows Extra + 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where + 1 PRIMARY <derived2> hash_ALL NULL #hash#$hj 3 test.t2.c1 5 Using where; Using join buffer (flat, BNLH join) + 2 DERIVED t1 ALL NULL NULL NULL NULL 5 + SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + c1 c2 c1 c2 + c 3 c 3 + c 3 c 3 + drop table t1,t2; + drop view v1; + set @@join_cache_level= @save_join_cache_level; # end of 5.5 +# +# Start of 10.1 tests +# +# +# MDEV-8747 Wrong result for SELECT..WHERE derived_table_column='a' AND derived_table_column<>_latin1'A' COLLATE latin1_bin +# +CREATE TABLE t1 (a VARCHAR(10)); +INSERT INTO t1 VALUES ('a'),('A'); +SELECT * FROM t1 WHERE a='a' AND a <> _latin1'A' COLLATE latin1_bin; +a +a +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='a' AND a <> _latin1'A' COLLATE latin1_bin; +a +a +DROP TABLE t1; +CREATE TABLE t1 (a ENUM('5','6')); +INSERT INTO t1 VALUES ('5'),('6'); +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5'; +a +5 +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a=1; +a +5 +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5' AND a=1; +a +5 +DROP TABLE t1; +# +# MDEV-8749 Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number2 +# +CREATE TABLE t1 (a ENUM('5','6')); +INSERT INTO t1 VALUES ('5'),('6'); +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5'; +a +5 +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a=1; +a +5 +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5' AND a=1; +a +5 +DROP TABLE t1; +# +# End of 10.1 tests +# diff --cc mysql-test/r/stat_tables.result index 279c09ff44f,c1457d5e91a..ceadb61feea --- a/mysql-test/r/stat_tables.result +++ b/mysql-test/r/stat_tables.result @@@ -516,73 -516,64 +516,133 @@@ use test drop database db1; drop database db2; drop table t1; + # + # MDEV-16552: [10.0] ASAN global-buffer-overflow in is_stat_table / statistics_for_tables_is_needed + # + SET use_stat_tables = PREFERABLY; + SELECT CONVERT_TZ( '1991-09-20 10:11:02', '+00:00', 'GMT' ); + CONVERT_TZ( '1991-09-20 10:11:02', '+00:00', 'GMT' ) + NULL + set use_stat_tables=@save_use_stat_tables; + # + # MDEV-16757: manual addition of min/max statistics for BLOB + # + SET use_stat_tables= PREFERABLY; + CREATE TABLE t1 (pk INT PRIMARY KEY, t TEXT); + 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 Warning Engine-independent statistics are not collected for column 't' + test.t1 analyze status OK + 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 t NULL NULL 0.0000 3.0000 NULL NULL NULL NULL + DELETE FROM mysql.column_stats + WHERE db_name='test' AND table_name='t1' AND column_name='t'; + INSERT INTO mysql.column_stats VALUES + ('test','t1','t','bar','foo', 0.0, 3.0, 1.0, 0, NULL, NULL); + 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 t bar foo 0.0000 3.0000 1.0000 0 NULL NULL + SELECT pk FROM t1; + pk + 1 + 2 + DROP TABLE t1; + 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; +# +# MDEV-16757: manual addition of min/max statistics for BLOB +# +SET use_stat_tables= PREFERABLY; +CREATE TABLE t1 (pk INT PRIMARY KEY, t TEXT); +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 Warning Engine-independent statistics are not collected for column 't' +test.t1 analyze status OK +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 +DELETE FROM mysql.column_stats +WHERE db_name='test' AND table_name='t1' AND column_name='t'; +INSERT INTO mysql.column_stats VALUES +('test','t1','t','bar','foo', 0.0, 3.0, 1.0, 0, NULL, NULL); +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 t bar foo 0.0000 3.0000 1.0000 0 NULL NULL +SELECT pk FROM t1; +pk +1 +2 +DROP TABLE t1; +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; +# +# MDEV-16711:CREATE OR REPLACE TABLE introducing BLOB column +# +SET use_stat_tables= PREFERABLY; +CREATE TABLE t1 (pk INT PRIMARY KEY, t CHAR(60)); +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 +CREATE OR REPLACE TABLE t1 (pk INT PRIMARY KEY, t TEXT); +SELECT MAX(pk) FROM t1; +MAX(pk) +NULL +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; diff --cc mysql-test/r/stat_tables_innodb.result index 1604c413743,2ac868e9341..c5e7309861c --- a/mysql-test/r/stat_tables_innodb.result +++ b/mysql-test/r/stat_tables_innodb.result @@@ -543,75 -543,66 +543,135 @@@ use test drop database db1; drop database db2; drop table t1; + # + # MDEV-16552: [10.0] ASAN global-buffer-overflow in is_stat_table / statistics_for_tables_is_needed + # + SET use_stat_tables = PREFERABLY; + SELECT CONVERT_TZ( '1991-09-20 10:11:02', '+00:00', 'GMT' ); + CONVERT_TZ( '1991-09-20 10:11:02', '+00:00', 'GMT' ) + NULL + set use_stat_tables=@save_use_stat_tables; + # + # MDEV-16757: manual addition of min/max statistics for BLOB + # + SET use_stat_tables= PREFERABLY; + CREATE TABLE t1 (pk INT PRIMARY KEY, t TEXT); + 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 Warning Engine-independent statistics are not collected for column 't' + test.t1 analyze status OK + 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 t NULL NULL 0.0000 3.0000 NULL NULL NULL NULL + DELETE FROM mysql.column_stats + WHERE db_name='test' AND table_name='t1' AND column_name='t'; + INSERT INTO mysql.column_stats VALUES + ('test','t1','t','bar','foo', 0.0, 3.0, 1.0, 0, NULL, NULL); + 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 t bar foo 0.0000 3.0000 1.0000 0 NULL NULL + SELECT pk FROM t1; + pk + 1 + 2 + DROP TABLE t1; + 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; +# +# MDEV-16757: manual addition of min/max statistics for BLOB +# +SET use_stat_tables= PREFERABLY; +CREATE TABLE t1 (pk INT PRIMARY KEY, t TEXT); +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 Warning Engine-independent statistics are not collected for column 't' +test.t1 analyze status OK +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 +DELETE FROM mysql.column_stats +WHERE db_name='test' AND table_name='t1' AND column_name='t'; +INSERT INTO mysql.column_stats VALUES +('test','t1','t','bar','foo', 0.0, 3.0, 1.0, 0, NULL, NULL); +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 t bar foo 0.0000 3.0000 1.0000 0 NULL NULL +SELECT pk FROM t1; +pk +1 +2 +DROP TABLE t1; +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; +# +# MDEV-16711:CREATE OR REPLACE TABLE introducing BLOB column +# +SET use_stat_tables= PREFERABLY; +CREATE TABLE t1 (pk INT PRIMARY KEY, t CHAR(60)); +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 +CREATE OR REPLACE TABLE t1 (pk INT PRIMARY KEY, t TEXT); +SELECT MAX(pk) FROM t1; +MAX(pk) +NULL +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; SET SESSION STORAGE_ENGINE=DEFAULT; diff --cc mysql-test/t/derived.test index b0415cf3b04,eeaf94adcee..778d141b80f --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@@ -935,39 -936,25 +936,59 @@@ call pr(2) drop procedure pr; drop view v1; drop table t1; + set @@join_cache_level= @save_join_cache_level; + --echo # + --echo # MDEV-16307: Incorrect results when using BNLH join instead of BNL join with views + --echo # + + CREATE TABLE t1 (c1 text, c2 int); + INSERT INTO t1 VALUES ('a',1), ('c',3), ('g',7), ('d',4), ('c',3); + CREATE TABLE t2 (c1 text, c2 int); + INSERT INTO t2 VALUES ('b',2), ('c',3); + CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; + + explain SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + set @save_join_cache_level= @@join_cache_level; + set @@join_cache_level=4; + explain SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + SELECT v1.c1, v1.c2, t2.c1, t2.c2 FROM v1, t2 WHERE v1.c1=t2.c1; + drop table t1,t2; + drop view v1; + set @@join_cache_level= @save_join_cache_level; --echo # end of 5.5 + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-8747 Wrong result for SELECT..WHERE derived_table_column='a' AND derived_table_column<>_latin1'A' COLLATE latin1_bin +--echo # +CREATE TABLE t1 (a VARCHAR(10)); +INSERT INTO t1 VALUES ('a'),('A'); +SELECT * FROM t1 WHERE a='a' AND a <> _latin1'A' COLLATE latin1_bin; +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='a' AND a <> _latin1'A' COLLATE latin1_bin; +DROP TABLE t1; + +CREATE TABLE t1 (a ENUM('5','6')); +INSERT INTO t1 VALUES ('5'),('6'); +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5'; +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a=1; +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5' AND a=1; +DROP TABLE t1; + +--echo # +--echo # MDEV-8749 Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number2 +--echo # +CREATE TABLE t1 (a ENUM('5','6')); +INSERT INTO t1 VALUES ('5'),('6'); +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5'; +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a=1; +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5' AND a=1; +DROP TABLE t1; + +--echo # +--echo # End of 10.1 tests +--echo # diff --cc mysql-test/t/stat_tables.test index 51c9995b6fa,d69b00618ea..2c9c1eca7d3 --- a/mysql-test/t/stat_tables.test +++ b/mysql-test/t/stat_tables.test @@@ -305,66 -305,54 +305,116 @@@ drop database db1 drop database db2; drop table t1; + --echo # + --echo # MDEV-16552: [10.0] ASAN global-buffer-overflow in is_stat_table / statistics_for_tables_is_needed + --echo # + + SET use_stat_tables = PREFERABLY; + SELECT CONVERT_TZ( '1991-09-20 10:11:02', '+00:00', 'GMT' ); + set use_stat_tables=@save_use_stat_tables; + + --echo # + --echo # MDEV-16757: manual addition of min/max statistics for BLOB + --echo # + + SET use_stat_tables= PREFERABLY; + + CREATE TABLE t1 (pk INT PRIMARY KEY, t TEXT); + INSERT INTO t1 VALUES (1,'foo'),(2,'bar'); + ANALYZE TABLE t1; + --sorted_result + SELECT * FROM mysql.column_stats; + DELETE FROM mysql.column_stats + WHERE db_name='test' AND table_name='t1' AND column_name='t'; + INSERT INTO mysql.column_stats VALUES + ('test','t1','t','bar','foo', 0.0, 3.0, 1.0, 0, NULL, NULL); + --sorted_result + SELECT * FROM mysql.column_stats; + + SELECT pk FROM t1; + + DROP TABLE t1; + + 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; + +--echo # +--echo # MDEV-16757: manual addition of min/max statistics for BLOB +--echo # + +SET use_stat_tables= PREFERABLY; + +CREATE TABLE t1 (pk INT PRIMARY KEY, t TEXT); +INSERT INTO t1 VALUES (1,'foo'),(2,'bar'); +ANALYZE TABLE t1; +--sorted_result +SELECT * FROM mysql.column_stats; +DELETE FROM mysql.column_stats + WHERE db_name='test' AND table_name='t1' AND column_name='t'; +INSERT INTO mysql.column_stats VALUES + ('test','t1','t','bar','foo', 0.0, 3.0, 1.0, 0, NULL, NULL); +--sorted_result +SELECT * FROM mysql.column_stats; + +SELECT pk FROM t1; + +DROP TABLE t1; + +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; + + +--echo # +--echo # MDEV-16711:CREATE OR REPLACE TABLE introducing BLOB column +--echo # + +SET use_stat_tables= PREFERABLY; + +CREATE TABLE t1 (pk INT PRIMARY KEY, t CHAR(60)); +INSERT INTO t1 VALUES (1,'foo'),(2,'bar'); +ANALYZE TABLE t1; +CREATE OR REPLACE TABLE t1 (pk INT PRIMARY KEY, t TEXT); + +SELECT MAX(pk) FROM t1; + +DROP TABLE t1; + +set use_stat_tables=@save_use_stat_tables; diff --cc sql/mysqld.cc index 5f954f7576d,75d6cca7fda..0f5147c8cf1 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@@ -5889,14 -5497,10 +5894,14 @@@ int mysqld_main(int argc, char **argv (char*) "" : mysqld_unix_port), mysqld_port, MYSQL_COMPILATION_COMMENT); + #ifndef _WIN32 - /* Only close stdin if it was open initinally. */ - if (please_close_stdin) + // try to keep fd=0 busy - if (!freopen("/dev/null", "r", stdin)) ++ if (please_close_stdin && !freopen("/dev/null", "r", stdin)) + { + // fall back on failure fclose(stdin); + } #endif #if defined(_WIN32) && !defined(EMBEDDED_LIBRARY) diff --cc sql/sql_base.cc index c2bf37a1064,1ed57a051d8..2a9b409dff5 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@@ -7451,7 -7405,7 +7452,7 @@@ store_natural_using_join_columns(THD *t nj_col_1= it_1.get_natural_column_ref(); if (nj_col_1->is_common) { - natural_using_join->join_columns->push_back(nj_col_1, thd->mem_root); - join_columns->push_back(nj_col_1); ++ join_columns->push_back(nj_col_1, thd->mem_root); /* Reset the common columns for the next call to mark_common_columns. */ nj_col_1->is_common= FALSE; } @@@ -7505,7 -7459,8 +7506,8 @@@ } if (non_join_columns->elements > 0) - natural_using_join->join_columns->append(non_join_columns); - join_columns->concat(non_join_columns); ++ join_columns->append(non_join_columns); + natural_using_join->join_columns= join_columns; natural_using_join->is_join_columns_complete= TRUE; result= FALSE;