From 0739179857699d68758ff2e56e9414735546ded6 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Tue, 8 Aug 2017 21:13:45 +0530 Subject: [PATCH 1/5] MDEV-13458: Wrong result for aggregate function with distinct clause when the value for tmp_table_size is small Fixed by making sure that the sort buffer would have atleast MERGEBUFF2 keys. Also fixed MDEV-13457 by making sure that an empty tree is never dumped to the disk --- mysql-test/r/count_distinct.result | 25 +++++++++++++++++++++++++ mysql-test/t/count_distinct.test | 29 +++++++++++++++++++++++++++++ sql/sql_class.h | 2 +- sql/uniques.cc | 12 ++++++++---- 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/count_distinct.result b/mysql-test/r/count_distinct.result index d55a232c715..760b2710586 100644 --- a/mysql-test/r/count_distinct.result +++ b/mysql-test/r/count_distinct.result @@ -106,3 +106,28 @@ count(distinct user_id) 17 drop table t1; set @@tmp_table_size = default; +create table t1 ( +a VARCHAR(1020), +b int +); +insert into t1 values +( 0 , 1 ), +( 1 , 2 ), +( 2 , 3 ), +( 3 , 4 ), +( 4 , 5 ), +( 5 , 6 ), +( 6 , 7 ), +( 7 , 8 ), +( 8 , 9 ), +( 9 , 10 ), +( 0 , 11 ), +( 1 , 12 ), +( 2 , 13 ), +( 3 , 14 ); +set @@tmp_table_size=1024; +select count(distinct a) from t1; +count(distinct a) +10 +drop table t1; +set @@tmp_table_size = default; diff --git a/mysql-test/t/count_distinct.test b/mysql-test/t/count_distinct.test index a00574b6cba..86045e862e7 100644 --- a/mysql-test/t/count_distinct.test +++ b/mysql-test/t/count_distinct.test @@ -120,6 +120,35 @@ select count(distinct user_id) from t1; drop table t1; set @@tmp_table_size = default; +# +# MDEV-13457: Wrong result for aggregate function with distinct clause when the value for +# tmp_table_size is small +# + +create table t1 ( +a VARCHAR(1020), +b int +); +insert into t1 values +( 0 , 1 ), +( 1 , 2 ), +( 2 , 3 ), +( 3 , 4 ), +( 4 , 5 ), +( 5 , 6 ), +( 6 , 7 ), +( 7 , 8 ), +( 8 , 9 ), +( 9 , 10 ), +( 0 , 11 ), +( 1 , 12 ), +( 2 , 13 ), +( 3 , 14 ); +set @@tmp_table_size=1024; +select count(distinct a) from t1; +drop table t1; +set @@tmp_table_size = default; + # # End of 5.5 tests # diff --git a/sql/sql_class.h b/sql/sql_class.h index 5dd7cd18a5d..f4be996c9a9 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3919,7 +3919,7 @@ public: { DBUG_ENTER("unique_add"); DBUG_PRINT("info", ("tree %u - %lu", tree.elements_in_tree, max_elements)); - if (!(tree.flag & TREE_ONLY_DUPS) && + if (!(tree.flag & TREE_ONLY_DUPS) && tree.elements_in_tree >= max_elements && flush()) DBUG_RETURN(1); DBUG_RETURN(!tree_insert(&tree, ptr, 0, tree.custom_arg)); diff --git a/sql/uniques.cc b/sql/uniques.cc index 8b7da7e6e52..89ab4682829 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -96,6 +96,9 @@ Unique::Unique(qsort_cmp2 comp_func, void * comp_func_fixed_arg, */ max_elements= (ulong) (max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+size)); + if (!max_elements) + max_elements= 1; + (void) open_cached_file(&file, mysql_tmpdir,TEMP_PREFIX, DISK_BUFFER_SIZE, MYF(MY_WME)); } @@ -608,10 +611,11 @@ bool Unique::walk(TABLE *table, tree_walk_action action, void *walk_action_arg) if (flush_io_cache(&file) || reinit_io_cache(&file, READ_CACHE, 0L, 0, 0)) return 1; /* - merge_buffer must fit at least MERGEBUFF2 keys, because - merge_index() can merge that many BUFFPEKs at once. + merge_buffer must fit at least MERGEBUFF2 + 1 keys, because + merge_index() can merge that many BUFFPEKs at once. The extra space for one key + is needed when a piece of merge buffer is re-read, see merge_walk() */ - size_t buff_sz= max(MERGEBUFF2, max_in_memory_size/full_size+1) * full_size; + size_t buff_sz= max(MERGEBUFF2+1, max_in_memory_size/full_size+1) * full_size; if (!(merge_buffer = (uchar *)my_malloc(buff_sz, MYF(MY_WME)))) return 1; if (buff_sz < (ulong) (full_size * (file_ptrs.elements + 1))) @@ -673,7 +677,7 @@ bool Unique::merge(TABLE *table, uchar *buff, bool without_last_merge) full_size; sort_param.min_dupl_count= min_dupl_count; sort_param.res_length= 0; - sort_param.keys= (uint) (max_in_memory_size / sort_param.sort_length); + sort_param.keys= (uint) max((max_in_memory_size / sort_param.sort_length), MERGEBUFF2); sort_param.not_killable= 1; sort_param.unique_buff= buff + (sort_param.keys * sort_param.sort_length); From e866e4cdbe974a83d4a4ee474d28f61e7082700f Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Tue, 15 Aug 2017 20:10:04 +0300 Subject: [PATCH 2/5] MTR's internal check of main.log_tables-big failed The test wasn't restoring log_output properly. Also added output of query_time in case of wrong result, to investigate the failure described in MDEV-13408 --- mysql-test/r/log_tables-big.result | 9 +++++---- mysql-test/t/log_tables-big.test | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/log_tables-big.result b/mysql-test/r/log_tables-big.result index 1e189a7726f..4435d6d2723 100644 --- a/mysql-test/r/log_tables-big.result +++ b/mysql-test/r/log_tables-big.result @@ -1,3 +1,4 @@ +set @log_output.saved = @@global.log_output; set @@global.log_output = 'TABLE'; set session long_query_time=10; select get_lock('bug27638', 1); @@ -7,25 +8,25 @@ set session long_query_time=1; select get_lock('bug27638', 2); get_lock('bug27638', 2) 0 -select if (query_time >= '00:00:01', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log +select if (query_time >= '00:00:01', 'OK', concat('WRONG: ',query_time)) as qt, sql_text from mysql.slow_log where sql_text = 'select get_lock(\'bug27638\', 2)'; qt sql_text OK select get_lock('bug27638', 2) select get_lock('bug27638', 60); get_lock('bug27638', 60) 0 -select if (query_time >= '00:00:59', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log +select if (query_time >= '00:00:59', 'OK', concat('WRONG: ',query_time)) as qt, sql_text from mysql.slow_log where sql_text = 'select get_lock(\'bug27638\', 60)'; qt sql_text OK select get_lock('bug27638', 60) select get_lock('bug27638', 101); get_lock('bug27638', 101) 0 -select if (query_time >= '00:01:40', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log +select if (query_time >= '00:01:40', 'OK', concat('WRONG: ',query_time)) as qt, sql_text from mysql.slow_log where sql_text = 'select get_lock(\'bug27638\', 101)'; qt sql_text OK select get_lock('bug27638', 101) select release_lock('bug27638'); release_lock('bug27638') 1 -set @@global.log_output=default; +set @@global.log_output = @log_output.saved; diff --git a/mysql-test/t/log_tables-big.test b/mysql-test/t/log_tables-big.test index 8936a163d73..fa8810ecd3b 100644 --- a/mysql-test/t/log_tables-big.test +++ b/mysql-test/t/log_tables-big.test @@ -7,6 +7,7 @@ # check that CSV engine was compiled in --source include/have_csv.inc +set @log_output.saved = @@global.log_output; set @@global.log_output = 'TABLE'; connect (con1,localhost,root,,); @@ -21,13 +22,13 @@ select get_lock('bug27638', 1); connection con2; set session long_query_time=1; select get_lock('bug27638', 2); -select if (query_time >= '00:00:01', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log +select if (query_time >= '00:00:01', 'OK', concat('WRONG: ',query_time)) as qt, sql_text from mysql.slow_log where sql_text = 'select get_lock(\'bug27638\', 2)'; select get_lock('bug27638', 60); -select if (query_time >= '00:00:59', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log +select if (query_time >= '00:00:59', 'OK', concat('WRONG: ',query_time)) as qt, sql_text from mysql.slow_log where sql_text = 'select get_lock(\'bug27638\', 60)'; select get_lock('bug27638', 101); -select if (query_time >= '00:01:40', 'OK', 'WRONG') as qt, sql_text from mysql.slow_log +select if (query_time >= '00:01:40', 'OK', concat('WRONG: ',query_time)) as qt, sql_text from mysql.slow_log where sql_text = 'select get_lock(\'bug27638\', 101)'; connection con1; select release_lock('bug27638'); @@ -36,4 +37,4 @@ connection default; disconnect con1; disconnect con2; -set @@global.log_output=default; +set @@global.log_output = @log_output.saved; From bcc1ba921829dc8b09bcbfbc5e5a916d6f1d2ca0 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 16 Aug 2017 19:18:39 +0200 Subject: [PATCH 3/5] MDEV-11240: Server crashes in check_view_single_update or Assertion `derived->table' failed in mysql_derived_merge_for_insert Before "merge" view shoud be inited to maintaing transitive attributes like "multitable". --- mysql-test/r/view.result | 3 --- mysql-test/t/view.test | 5 +---- sql/sql_derived.cc | 4 ++-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 0f8e9999730..c1f76ba58a4 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -5626,9 +5626,6 @@ CREATE TABLE t3 (a INT); CREATE ALGORITHM = MERGE VIEW v1 AS SELECT t2.a FROM t3 AS t1, t3 AS t2; CREATE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM v1; PREPARE stmt FROM 'REPLACE INTO v2 SELECT a FROM t3'; -EXECUTE stmt; -ERROR HY000: Can not insert into join view 'test.v2' without fields list -EXECUTE stmt; ERROR HY000: Can not insert into join view 'test.v2' without fields list drop view v1,v2; drop table t3; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 659327eebb1..79991f89683 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -5573,11 +5573,8 @@ drop table t1,t2,t3; CREATE TABLE t3 (a INT); CREATE ALGORITHM = MERGE VIEW v1 AS SELECT t2.a FROM t3 AS t1, t3 AS t2; CREATE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM v1; +--error ER_VIEW_NO_INSERT_FIELD_LIST PREPARE stmt FROM 'REPLACE INTO v2 SELECT a FROM t3'; ---error ER_VIEW_NO_INSERT_FIELD_LIST -EXECUTE stmt; ---error ER_VIEW_NO_INSERT_FIELD_LIST -EXECUTE stmt; drop view v1,v2; drop table t3; diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 493f0eccc8c..6cd4547aaf9 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -510,6 +510,8 @@ bool mysql_derived_merge_for_insert(THD *thd, LEX *lex, TABLE_LIST *derived) DBUG_ENTER("mysql_derived_merge_for_insert"); if (derived->merged_for_insert) DBUG_RETURN(FALSE); + if (derived->init_derived(thd, FALSE)) + DBUG_RETURN(TRUE); if (derived->is_materialized_derived()) DBUG_RETURN(mysql_derived_prepare(thd, lex, derived)); if ((thd->lex->sql_command == SQLCOM_UPDATE_MULTI || @@ -526,8 +528,6 @@ bool mysql_derived_merge_for_insert(THD *thd, LEX *lex, TABLE_LIST *derived) derived->merged_for_insert= TRUE; } } - else - derived->table= derived->merge_underlying_list->table; DBUG_RETURN(FALSE); } From d947d1bf6e1ebd20c0142832bb2372bf5a5bf6bf Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Fri, 18 Aug 2017 13:35:40 +0300 Subject: [PATCH 4/5] Do not stop repeating a test even if some executions are skipped --- mysql-test/mysql-test-run.pl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 5beb2956638..7bd86e66575 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -738,8 +738,7 @@ sub run_test_server ($$$) { # Repeat test $opt_repeat number of times my $repeat= $result->{repeat} || 1; - # Don't repeat if test was skipped - if ($repeat < $opt_repeat && $result->{'result'} ne 'MTR_RES_SKIPPED') + if ($repeat < $opt_repeat) { $result->{retries}= 0; $result->{rep_failures}++ if $result->{failures}; From f534eef79414f0cbf9b0404146e1076a6df6b45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Tue, 19 Sep 2017 00:25:34 +0300 Subject: [PATCH 5/5] 5.5.57-38.9 --- storage/xtradb/include/univ.i | 2 +- storage/xtradb/trx/trx0sys.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/xtradb/include/univ.i b/storage/xtradb/include/univ.i index a7475bbf396..12c3c833e33 100644 --- a/storage/xtradb/include/univ.i +++ b/storage/xtradb/include/univ.i @@ -64,7 +64,7 @@ component, i.e. we show M.N.P as M.N */ (INNODB_VERSION_MAJOR << 8 | INNODB_VERSION_MINOR) #ifndef PERCONA_INNODB_VERSION -#define PERCONA_INNODB_VERSION 38.8 +#define PERCONA_INNODB_VERSION 38.9 #endif #define INNODB_VERSION_STR MYSQL_SERVER_VERSION diff --git a/storage/xtradb/trx/trx0sys.c b/storage/xtradb/trx/trx0sys.c index 6b230a296c0..193cb9055ec 100644 --- a/storage/xtradb/trx/trx0sys.c +++ b/storage/xtradb/trx/trx0sys.c @@ -730,7 +730,7 @@ trx_sys_doublewrite_init_or_restore_pages( TRUE, read_buf, zip_size))) { fprintf(stderr, - "InnoDB: Warning: database page" + "InnoDB: Database page" " corruption or a failed\n" "InnoDB: file read of" " space %lu page %lu.\n"