From cba2ac6ef10304047f7a7941e6c8912573ebc3c6 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 22 Dec 2016 13:06:44 +0100 Subject: [PATCH 01/97] 5.5.53-38.5 --- storage/xtradb/include/univ.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/xtradb/include/univ.i b/storage/xtradb/include/univ.i index cc589166f8d..d198fbf021b 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.3 +#define PERCONA_INNODB_VERSION 38.5 #endif #define INNODB_VERSION_STR MYSQL_SERVER_VERSION From 9181a561a68d9b18331cc4c0a9b9fdc704edb300 Mon Sep 17 00:00:00 2001 From: Balasubramanian Kandasamy Date: Mon, 27 Feb 2017 17:20:51 +0530 Subject: [PATCH 02/97] Raise version number after cloning 5.5.55 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index bc0b19220b6..ade2e129c54 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=55 +MYSQL_VERSION_PATCH=56 MYSQL_VERSION_EXTRA= From e619295e1b480a24ee9740641ce69b8a412e1fc9 Mon Sep 17 00:00:00 2001 From: Sujatha Sivakumar Date: Tue, 28 Feb 2017 10:00:51 +0530 Subject: [PATCH 03/97] Bug#24901077: RESET SLAVE ALL DOES NOT ALWAYS RESET SLAVE Description: ============ If you have a relay log index file that has ended up with some relay log files that do not exists, then RESET SLAVE ALL is not enough to get back to a clean state. Analysis: ========= In the bug scenario slave server is in stopped state and some of the relay logs got deleted but the relay log index file is not updated. During slave server restart replication initialization fails as some of the required relay logs are missing. User executes RESET SLAVE/RESET SLAVE ALL command to start a clean slave. As per the documentation RESET SLAVE command clears the master info and relay log info repositories, deletes all the relay log files, and starts a new relay log file. But in a scenario where the slave server's Relay_log_info object is not initialized slave will not purge the existing relay logs. Hence the index file still remains in a bad state. Users will not be able to start the slave unless these files are cleared. Fix: === RESET SLAVE/RESET SLAVE ALL commands should do the cleanup even in a scenario where Relay_log_info object initialization failed. Backported a flag named 'error_on_rli_init_info' which is required to identify slave's Relay_log_info object initialization failure. This flag exists in MySQL-5.6 onwards as part of BUG#14021292 fix. During RESET SLAVE/RESET SLAVE ALL execution this flag indicates the Relay_log_info initialization failure. In such a case open the relay log index/relay log files and do the required clean up. --- .../suite/rpl/r/rpl_reset_slave_fail.result | 29 ++++++ .../suite/rpl/t/rpl_reset_slave_fail.test | 91 +++++++++++++++++++ sql/rpl_mi.cc | 3 +- sql/rpl_rli.cc | 50 ++++++++-- sql/rpl_rli.h | 11 ++- sql/slave.cc | 4 +- sql/sql_repl.cc | 3 +- 7 files changed, 176 insertions(+), 15 deletions(-) create mode 100644 mysql-test/suite/rpl/r/rpl_reset_slave_fail.result create mode 100644 mysql-test/suite/rpl/t/rpl_reset_slave_fail.test diff --git a/mysql-test/suite/rpl/r/rpl_reset_slave_fail.result b/mysql-test/suite/rpl/r/rpl_reset_slave_fail.result new file mode 100644 index 00000000000..6b60e021778 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_reset_slave_fail.result @@ -0,0 +1,29 @@ +include/master-slave.inc +[connection master] +CREATE TABLE t1 (c1 INT); +INSERT INTO t1 (c1) VALUES (1); +include/stop_slave_sql.inc +FLUSH LOGS; +FLUSH LOGS; +INSERT INTO t1 (c1) VALUES (2); +include/sync_slave_io_with_master.inc +call mtr.add_suppression("File '.*slave-relay-bin."); +call mtr.add_suppression("Could not open log file"); +call mtr.add_suppression("Failed to open the relay log"); +call mtr.add_suppression("Failed to initialize the master info structure"); +include/rpl_stop_server.inc [server_number=2] +# Removing file(s) +include/rpl_start_server.inc [server_number=2] +START SLAVE; +ERROR HY000: Could not initialize master info structure; more error messages can be found in the MySQL error log +START SLAVE; +ERROR HY000: Could not initialize master info structure; more error messages can be found in the MySQL error log +RESET SLAVE; +DROP TABLE t1; +START SLAVE UNTIL MASTER_LOG_FILE= 'MASTER_LOG_FILE', MASTER_LOG_POS= MASTER_LOG_POS;; +include/wait_for_slave_sql_to_stop.inc +include/stop_slave_io.inc +include/start_slave.inc +include/diff_tables.inc [master:t1, slave:t1] +DROP TABLE t1; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_reset_slave_fail.test b/mysql-test/suite/rpl/t/rpl_reset_slave_fail.test new file mode 100644 index 00000000000..021dc76d50c --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_reset_slave_fail.test @@ -0,0 +1,91 @@ +############################################################################### +# Bug#24901077: RESET SLAVE ALL DOES NOT ALWAYS RESET SLAVE +# +# Problem: +# ======= +# If you have a relay log index file that has ended up with +# some relay log files that do not exists, then RESET SLAVE +# ALL is not enough to get back to a clean state. +############################################################################### +# Remove all slave-relay-bin.0* files (do not remove slave-relay-bin.index) +# During server restart rli initialization will fail as there are no +# relay logs. In case of bug RESET SLAVE will not do the required clean up +# as rli is not inited and subsequent START SLAVE will fail. +# Disable "Warning 1612 Being purged log ./slave-relay-bin.0* was not found" +# because it is different on Unix and Windows systems. + +--source include/have_binlog_format_mixed.inc +--source include/master-slave.inc + +--connection master +CREATE TABLE t1 (c1 INT); +INSERT INTO t1 (c1) VALUES (1); +--sync_slave_with_master + +--connection slave +--source include/stop_slave_sql.inc +--let $MYSQLD_SLAVE_DATADIR= `select @@datadir` + +--connection master +# Generate more relay logs on slave. +FLUSH LOGS; +FLUSH LOGS; +INSERT INTO t1 (c1) VALUES (2); + +--source include/sync_slave_io_with_master.inc +call mtr.add_suppression("File '.*slave-relay-bin."); +call mtr.add_suppression("Could not open log file"); +call mtr.add_suppression("Failed to open the relay log"); +call mtr.add_suppression("Failed to initialize the master info structure"); + +# Stop slave +--let $rpl_server_number= 2 +--source include/rpl_stop_server.inc + +# Delete file(s) +--echo # Removing $remove_pattern file(s) +--let $remove_pattern= slave-relay-bin.0* +--remove_files_wildcard $MYSQLD_SLAVE_DATADIR $remove_pattern + +# Start slave +--let $rpl_server_number= 2 +--source include/rpl_start_server.inc + +# Start slave must fail because of the removed file(s). +--error ER_MASTER_INFO +START SLAVE; + +# Try a second time, it must fail again. +--error ER_MASTER_INFO +START SLAVE; + +# Retrieve master executed position before reset slave. +--let $master_exec_file= query_get_value("SHOW SLAVE STATUS", Relay_Master_Log_File, 1) +--let $master_exec_pos= query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1) + +# Reset slave. +# Disable "Warning 1612 Being purged log ./slave-relay-bin.0* was not found" +# because it is different on Unix and Windows systems. +--disable_warnings +RESET SLAVE; +--enable_warnings +DROP TABLE t1; +--replace_result $master_exec_file MASTER_LOG_FILE $master_exec_pos MASTER_LOG_POS +--eval START SLAVE UNTIL MASTER_LOG_FILE= '$master_exec_file', MASTER_LOG_POS= $master_exec_pos; +--source include/wait_for_slave_sql_to_stop.inc +--source include/stop_slave_io.inc + +# Start slave. +--source include/start_slave.inc + +--connection master +--sync_slave_with_master +# Check consistency. +--let $diff_tables= master:t1, slave:t1 +--source include/diff_tables.inc + +# Cleanup +--connection master +DROP TABLE t1; +--sync_slave_with_master +--source include/rpl_end.inc diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index ee5caced11a..a78b31cbaed 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -551,7 +551,6 @@ void end_master_info(Master_info* mi) if (!mi->inited) DBUG_VOID_RETURN; - end_relay_log_info(&mi->rli); if (mi->fd >= 0) { end_io_cache(&mi->file); diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index e4f2e4fd382..65ab264e1f3 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,7 +41,8 @@ Relay_log_info::Relay_log_info(bool is_slave_recovery) no_storage(FALSE), replicate_same_server_id(::replicate_same_server_id), info_fd(-1), cur_log_fd(-1), relay_log(&sync_relaylog_period), sync_counter(0), is_relay_log_recovery(is_slave_recovery), - save_temporary_tables(0), cur_log_old_open_count(0), group_relay_log_pos(0), + save_temporary_tables(0), cur_log_old_open_count(0), + error_on_rli_init_info(false), group_relay_log_pos(0), event_relay_log_pos(0), #if HAVE_purify is_fake(FALSE), @@ -108,7 +109,7 @@ int init_relay_log_info(Relay_log_info* rli, const char* info_fname) { char fname[FN_REFLEN+128]; - int info_fd; + int info_fd= -1; const char* msg = 0; int error = 0; DBUG_ENTER("init_relay_log_info"); @@ -118,6 +119,8 @@ int init_relay_log_info(Relay_log_info* rli, DBUG_RETURN(0); fn_format(fname, info_fname, mysql_data_home, "", 4+32); mysql_mutex_lock(&rli->data_lock); + if (rli->error_on_rli_init_info) + goto err; info_fd = rli->info_fd; rli->cur_log_fd = -1; rli->slave_skip_counter=0; @@ -351,11 +354,14 @@ Failed to open the existing relay log info file '%s' (errno %d)", goto err; } rli->inited= 1; + rli->error_on_rli_init_info= false; mysql_mutex_unlock(&rli->data_lock); DBUG_RETURN(error); err: - sql_print_error("%s", msg); + rli->error_on_rli_init_info= true; + if (msg) + sql_print_error("%s", msg); end_io_cache(&rli->info_file); if (info_fd >= 0) mysql_file_close(info_fd, MYF(0)); @@ -942,6 +948,8 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, const char** errmsg) { int error=0; + const char *ln; + char name_buf[FN_REFLEN]; DBUG_ENTER("purge_relay_logs"); /* @@ -968,12 +976,34 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, if (!rli->inited) { DBUG_PRINT("info", ("rli->inited == 0")); - DBUG_RETURN(0); + if (rli->error_on_rli_init_info) + { + ln= rli->relay_log.generate_name(opt_relay_logname, "-relay-bin", + 1, name_buf); + + if (rli->relay_log.open_index_file(opt_relaylog_index_name, ln, TRUE)) + { + sql_print_error("Unable to purge relay log files. Failed to open relay " + "log index file:%s.", rli->relay_log.get_index_fname()); + DBUG_RETURN(1); + } + if (rli->relay_log.open(ln, LOG_BIN, 0, SEQ_READ_APPEND, 0, + (max_relay_log_size ? max_relay_log_size : + max_binlog_size), 1, TRUE)) + { + sql_print_error("Unable to purge relay log files. Failed to open relay " + "log file:%s.", rli->relay_log.get_log_fname()); + DBUG_RETURN(1); + } + } + else + DBUG_RETURN(0); + } + else + { + DBUG_ASSERT(rli->slave_running == 0); + DBUG_ASSERT(rli->mi->slave_running == 0); } - - DBUG_ASSERT(rli->slave_running == 0); - DBUG_ASSERT(rli->mi->slave_running == 0); - rli->slave_skip_counter=0; mysql_mutex_lock(&rli->data_lock); @@ -1013,6 +1043,8 @@ int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset, rli->group_relay_log_pos, 0 /* do not need data lock */, errmsg, 0); + if (!rli->inited && rli->error_on_rli_init_info) + rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT); err: #ifndef DBUG_OFF char buf[22]; diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index dceeec9e777..89865a9f55c 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -153,7 +153,14 @@ public: a different log under our feet */ uint32 cur_log_old_open_count; - + + /* + If on init_info() call error_on_rli_init_info is true that means + that previous call to init_info() terminated with an error, RESET + SLAVE must be executed and the problem fixed manually. + */ + bool error_on_rli_init_info; + /* Let's call a group (of events) : - a transaction diff --git a/sql/slave.cc b/sql/slave.cc index acf68e231f3..1e641ac6d7e 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -881,6 +881,7 @@ void close_active_mi() if (active_mi) { end_master_info(active_mi); + end_relay_log_info(&active_mi->rli); delete active_mi; active_mi= 0; } @@ -4165,6 +4166,7 @@ void end_relay_log_info(Relay_log_info* rli) { DBUG_ENTER("end_relay_log_info"); + rli->error_on_rli_init_info= false; if (!rli->inited) DBUG_VOID_RETURN; if (rli->info_fd >= 0) diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 8bbb8c52d95..ecbeff87a61 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1313,6 +1313,7 @@ int reset_slave(THD *thd, Master_info* mi) // close master_info_file, relay_log_info_file, set mi->inited=rli->inited=0 end_master_info(mi); + end_relay_log_info(&mi->rli); // and delete these two files fn_format(fname, master_info_file, mysql_data_home, "", 4+32); if (mysql_file_stat(key_file_master_info, fname, &stat_area, MYF(0)) && From af84921d263b8bb1d1a06989794db07394f94e21 Mon Sep 17 00:00:00 2001 From: Karthik Kamath Date: Thu, 9 Mar 2017 14:57:20 +0530 Subject: [PATCH 04/97] BUG#24807826: UINT3KORR SHOULD STOP READING FOUR INSTEAD OF THREE BYTES ON X86 Analysis: ========= The macro uint3korr reads 4 bytes of data instead of 3 on on x86 machines. Multiple definitions were created for this macro for optimization in WIN32. The idea was to optimize reading of 3 byte ints by reading an ordinary int and masking away the unused byte. However this is an undefined behavior. It will be an issue unless users are aware of allocating an extra byte for using this macro. Fix: ==== Removing the definition which reads 4 bytes of data. The only definition of this macro would now read just 3 bytes of data thus prohibiting the usage of an extra byte. Note: ===== This is a backport of Patches #5 and #6 for Bug#17922198. --- include/my_global.h | 12 +----------- sql/net_serv.cc | 15 ++++++--------- sql/records.cc | 5 ++--- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index 0d43964234b..695884cb6c6 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1064,19 +1064,9 @@ typedef char my_bool; /* Small bool */ ((uint32) (uchar) (A)[0]))) #define sint4korr(A) (*((long *) (A))) #define uint2korr(A) (*((uint16 *) (A))) -#if defined(HAVE_purify) && !defined(_WIN32) #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ (((uint32) ((uchar) (A)[1])) << 8) +\ (((uint32) ((uchar) (A)[2])) << 16)) -#else -/* - ATTENTION ! - - Please, note, uint3korr reads 4 bytes (not 3) ! - It means, that you have to provide enough allocated space ! -*/ -#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF) -#endif /* HAVE_purify && !_WIN32 */ #define uint4korr(A) (*((uint32 *) (A))) #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ (((uint32) ((uchar) (A)[1])) << 8) +\ diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 9c0c84bb292..b2c36f7c29c 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -179,12 +179,10 @@ my_bool net_realloc(NET *net, size_t length) pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); /* We must allocate some extra bytes for the end 0 and to be able to - read big compressed blocks + 1 safety byte since uint3korr() in - my_real_read() may actually read 4 bytes depending on build flags and - platform. + read big compressed blocks in my_real_read(). */ if (!(buff= (uchar*) my_realloc((char*) net->buff, pkt_length + - NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, + NET_HEADER_SIZE + COMP_HEADER_SIZE, MYF(MY_WME)))) { /* @todo: 1 and 2 codes are identical. */ @@ -951,12 +949,11 @@ my_real_read(NET *net, size_t *complen) if (net->compress) { /* - The following uint3korr() may read 4 bytes, so make sure we don't - read unallocated or uninitialized memory. The right-hand expression - must match the size of the buffer allocated in net_realloc(). + The right-hand expression must match the size of the buffer + allocated in net_realloc(). */ DBUG_ASSERT(net->where_b + NET_HEADER_SIZE + sizeof(uint32) <= - net->max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1); + net->max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE); /* If the packet is compressed then complen > 0 and contains the number of bytes in the uncompressed packet diff --git a/sql/records.cc b/sql/records.cc index 7f74b84b2d7..ae7ec74c17d 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -589,10 +589,9 @@ static int init_rr_cache(THD *thd, READ_RECORD *info) rec_cache_size= info->cache_records*info->reclength; info->rec_cache_size= info->cache_records*info->ref_length; - // We have to allocate one more byte to use uint3korr (see comments for it) if (info->cache_records <= 2 || !(info->cache=(uchar*) my_malloc_lock(rec_cache_size+info->cache_records* - info->struct_length+1, + info->struct_length, MYF(0)))) DBUG_RETURN(1); #ifdef HAVE_purify From ec2a6b6035ed842e39bcecc2c62c39758bda02fb Mon Sep 17 00:00:00 2001 From: Terje Rosten Date: Wed, 8 Mar 2017 08:29:02 +0100 Subject: [PATCH 05/97] BUG#25364806 MYSQLD_SAFE FAILING TO START IF DATADIR GIVEN IS NOT ABSOLUTE PATH mysqld_safe is working on real files, however passing these file paths as is to mysqld as options gives different meaning when paths are relative. mysqld_safe uses current working directory as basedir for relative paths, while mysqld uses $datadir as basedir. --- scripts/mysqld_safe.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 7116211f8e6..32f489f2a09 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -24,7 +24,9 @@ want_syslog=0 syslog_tag= user='@MYSQLD_USER@' pid_file= +pid_file_append= err_log= +err_log_append= syslog_tag_mysqld=mysqld syslog_tag_mysqld_safe=mysqld_safe @@ -582,15 +584,17 @@ then err_log="$err_log".err fi + err_log_append="$err_log" case "$err_log" in /* ) ;; * ) err_log="$DATADIR/$err_log" ;; esac else err_log=$DATADIR/`@HOSTNAME@`.err + err_log_append=`@HOSTNAME@`.err fi - append_arg_to_args "--log-error=$err_log" + append_arg_to_args "--log-error=$err_log_append" if [ $want_syslog -eq 1 ] then @@ -700,13 +704,15 @@ fi if test -z "$pid_file" then pid_file="$DATADIR/`@HOSTNAME@`.pid" + pid_file_append="`@HOSTNAME@`.pid" else + pid_file_append="$pid_file" case "$pid_file" in /* ) ;; * ) pid_file="$DATADIR/$pid_file" ;; esac fi -append_arg_to_args "--pid-file=$pid_file" +append_arg_to_args "--pid-file=$pid_file_append" if test -n "$mysql_unix_port" then From 2531c8dcd152bedeeebfe07d5e4a29bd84357c27 Mon Sep 17 00:00:00 2001 From: Ramil Kalimullin Date: Fri, 10 Mar 2017 01:19:50 +0400 Subject: [PATCH 06/97] BUG#25575605: SETTING --SSL-MODE=REQUIRED SENDS CREDENTIALS BEFORE VERIFYING SSL CONNECTION MYSQL_OPT_SSL_MODE option introduced. It is set in case of --ssl-mode=REQUIRED and permits only SSL connection. --- client/client_priv.h | 34 +++++++++++++----- client/mysql.cc | 6 ++-- client/mysql_upgrade.c | 6 ++-- client/mysqladmin.cc | 6 ++-- client/mysqlcheck.c | 4 +-- client/mysqldump.c | 4 +-- client/mysqlimport.c | 4 +-- client/mysqlshow.c | 4 +-- client/mysqlslap.c | 5 +-- client/mysqltest.cc | 6 ++-- include/mysql.h | 9 +++-- include/mysql.h.pp | 6 +++- include/sql_common.h | 3 +- include/sslopt-case.h | 4 +-- include/sslopt-vars.h | 6 ++-- mysql-test/r/ssl_mode.result | 6 ++-- mysql-test/r/ssl_mode_no_ssl.result | 22 ++++++------ sql-common/client.c | 54 +++++++++++++++++++++++++++-- 18 files changed, 134 insertions(+), 55 deletions(-) diff --git a/client/client_priv.h b/client/client_priv.h index e53ced7e790..fb83ce9cc8b 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -115,13 +115,15 @@ enum options_client /** Wrapper for mysql_real_connect() that checks if SSL connection is establised. - The function calls mysql_real_connect() first, then if given ssl_required==TRUE - argument (i.e. --ssl-mode=REQUIRED option used) checks current SSL chiper to - ensure that SSL is used for current connection. - Otherwise it returns NULL and sets errno to CR_SSL_CONNECTION_ERROR. + The function calls mysql_real_connect() first. Then, if the ssl_required + argument is TRUE (i.e., the --ssl-mode=REQUIRED option was specified), it + checks the current SSL cipher to ensure that SSL is used for the current + connection. Otherwise, it returns NULL and sets errno to + CR_SSL_CONNECTION_ERROR. - All clients (except mysqlbinlog which disregards SSL options) use this function - instead of mysql_real_connect() to handle --ssl-mode=REQUIRED option. + All clients (except mysqlbinlog, which disregards SSL options) use this + function instead of mysql_real_connect() to handle the --ssl-mode=REQUIRED + option. */ MYSQL *mysql_connect_ssl_check(MYSQL *mysql_arg, const char *host, const char *user, const char *passwd, @@ -129,8 +131,22 @@ MYSQL *mysql_connect_ssl_check(MYSQL *mysql_arg, const char *host, const char *unix_socket, ulong client_flag, my_bool ssl_required __attribute__((unused))) { - MYSQL *mysql= mysql_real_connect(mysql_arg, host, user, passwd, db, port, - unix_socket, client_flag); + MYSQL *mysql; + +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) + enum mysql_ssl_mode opt_ssl_mode= SSL_MODE_REQUIRED; + if (ssl_required && + mysql_options(mysql_arg, MYSQL_OPT_SSL_MODE, (char *) &opt_ssl_mode)) + { + NET *net= &mysql_arg->net; + net->last_errno= CR_SSL_CONNECTION_ERROR; + strmov(net->last_error, "Client library doesn't support MYSQL_SSL_REQUIRED option"); + strmov(net->sqlstate, "HY000"); + return NULL; + } +#endif + mysql= mysql_real_connect(mysql_arg, host, user, passwd, db, port, + unix_socket, client_flag); #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) if (mysql && /* connection established. */ ssl_required && /* --ssl-mode=REQUIRED. */ diff --git a/client/mysql.cc b/client/mysql.cc index cdc2ab0d6e0..2269563814c 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1318,7 +1318,7 @@ sig_handler handle_sigint(int sig) kill_mysql= mysql_init(kill_mysql); if (!mysql_connect_ssl_check(kill_mysql, current_host, current_user, opt_password, "", opt_mysql_port, opt_mysql_unix_port, 0, - opt_ssl_required)) + opt_ssl_mode == SSL_MODE_REQUIRED)) { tee_fprintf(stdout, "Ctrl-C -- sorry, cannot connect to server to kill query, giving up ...\n"); goto err; @@ -4461,7 +4461,7 @@ sql_real_connect(char *host,char *database,char *user,char *password, if (!mysql_connect_ssl_check(&mysql, host, user, password, database, opt_mysql_port, opt_mysql_unix_port, connect_flag | CLIENT_MULTI_STATEMENTS, - opt_ssl_required)) + opt_ssl_mode == SSL_MODE_REQUIRED)) { if (!silent || (mysql_errno(&mysql) != CR_CONN_HOST_ERROR && diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 507df6f7843..be0af089027 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -387,9 +387,11 @@ static int run_tool(char *tool_path, DYNAMIC_STRING *ds_res, ...) va_end(args); +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) /* If given --ssl-mode=REQUIRED propagate it to the tool. */ - if (opt_ssl_required) + if (opt_ssl_mode == SSL_MODE_REQUIRED) dynstr_append(&ds_cmdline, "--ssl-mode=REQUIRED"); +#endif #ifdef __WIN__ dynstr_append(&ds_cmdline, "\""); diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index c03b37ab165..ae9db85b917 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -519,8 +519,8 @@ static my_bool sql_connect(MYSQL *mysql, uint wait) for (;;) { if (mysql_connect_ssl_check(mysql, host, user, opt_password, NullS, - tcp_port, unix_port, - CLIENT_REMEMBER_OPTIONS, opt_ssl_required)) + tcp_port, unix_port, CLIENT_REMEMBER_OPTIONS, + opt_ssl_mode == SSL_MODE_REQUIRED)) { mysql->reconnect= 1; if (info) diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 55b941e7f1a..7822460e341 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -907,7 +907,7 @@ static int dbConnect(char *host, char *user, char *passwd) if (!(sock = mysql_connect_ssl_check(&mysql_connection, host, user, passwd, NULL, opt_mysql_port, opt_mysql_unix_port, 0, - opt_ssl_required))) + opt_ssl_mode == SSL_MODE_REQUIRED))) { DBerror(&mysql_connection, "when trying to connect"); return 1; diff --git a/client/mysqldump.c b/client/mysqldump.c index 00265def489..fcd29e26fe3 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1501,7 +1501,7 @@ static int connect_to_db(char *host, char *user,char *passwd) if (!(mysql= mysql_connect_ssl_check(&mysql_connection, host, user, passwd, NULL, opt_mysql_port, opt_mysql_unix_port, 0, - opt_ssl_required))) + opt_ssl_mode == SSL_MODE_REQUIRED))) { DB_error(&mysql_connection, "when trying to connect"); DBUG_RETURN(1); diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 5841c0b855a..bab43356bc7 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -463,7 +463,7 @@ static MYSQL *db_connect(char *host, char *database, mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset); if (!(mysql_connect_ssl_check(mysql, host, user, passwd, database, opt_mysql_port, opt_mysql_unix_port, - 0, opt_ssl_required))) + 0, opt_ssl_mode == SSL_MODE_REQUIRED))) { ignore_errors=0; /* NO RETURN FROM db_error */ db_error(mysql); diff --git a/client/mysqlshow.c b/client/mysqlshow.c index d0390ec443b..bd7a37f93b4 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -142,7 +142,7 @@ int main(int argc, char **argv) if (!(mysql_connect_ssl_check(&mysql, host, user, opt_password, (first_argument_uses_wildcards) ? "" : argv[0], opt_mysql_port, opt_mysql_unix_port, - 0, opt_ssl_required))) + 0, opt_ssl_mode == SSL_MODE_REQUIRED))) { fprintf(stderr,"%s: %s\n",my_progname,mysql_error(&mysql)); exit(1); diff --git a/client/mysqlslap.c b/client/mysqlslap.c index eb2b577948c..aa312339e87 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -357,7 +357,8 @@ int main(int argc, char **argv) { if (!(mysql_connect_ssl_check(&mysql, host, user, opt_password, NULL, opt_mysql_port, opt_mysql_unix_port, - connect_flags, opt_ssl_required))) + connect_flags, + opt_ssl_mode == SSL_MODE_REQUIRED))) { fprintf(stderr,"%s: Error when connecting to server: %s\n", my_progname,mysql_error(&mysql)); diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 79d448cf811..e5f9b11fe76 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -5283,7 +5283,7 @@ void safe_connect(MYSQL* mysql, const char *name, const char *host, host, port, sock, user, name, failed_attempts); while(!mysql_connect_ssl_check(mysql, host,user, pass, db, port, sock, CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS, - opt_ssl_required)) + opt_ssl_mode == SSL_MODE_REQUIRED)) { /* Connect failed @@ -5385,7 +5385,7 @@ int connect_n_handle_errors(struct st_command *command, while (!mysql_connect_ssl_check(con, host, user, pass, db, port, sock ? sock: 0, CLIENT_MULTI_STATEMENTS, - opt_ssl_required)) + opt_ssl_mode == SSL_MODE_REQUIRED)) { /* If we have used up all our connections check whether this diff --git a/include/mysql.h b/include/mysql.h index da29cb342cc..7ebf2f725a2 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -167,7 +167,7 @@ enum mysql_option MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, - MYSQL_ENABLE_CLEARTEXT_PLUGIN + MYSQL_ENABLE_CLEARTEXT_PLUGIN, MYSQL_OPT_SSL_MODE }; /** @@ -224,6 +224,11 @@ enum mysql_protocol_type MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY }; +enum mysql_ssl_mode +{ + SSL_MODE_REQUIRED= 3 +}; + typedef struct character_set { unsigned int number; /* character set number */ diff --git a/include/mysql.h.pp b/include/mysql.h.pp index c2c5ba35044..0f292d921ee 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -263,7 +263,7 @@ enum mysql_option MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, - MYSQL_ENABLE_CLEARTEXT_PLUGIN + MYSQL_ENABLE_CLEARTEXT_PLUGIN, MYSQL_OPT_SSL_MODE }; struct st_mysql_options_extention; struct st_mysql_options { @@ -307,6 +307,10 @@ enum mysql_protocol_type MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY }; +enum mysql_ssl_mode +{ + SSL_MODE_REQUIRED= 3 +}; typedef struct character_set { unsigned int number; diff --git a/include/sql_common.h b/include/sql_common.h index a2ea3ac45e7..05bbb5a4f53 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -1,7 +1,7 @@ #ifndef SQL_COMMON_INCLUDED #define SQL_COMMON_INCLUDED -/* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ struct st_mysql_options_extention { char *plugin_dir; char *default_auth; my_bool enable_cleartext_plugin; + unsigned int ssl_mode; }; typedef struct st_mysql_methods diff --git a/include/sslopt-case.h b/include/sslopt-case.h index 57702b3b352..0fddafc4fa9 100644 --- a/include/sslopt-case.h +++ b/include/sslopt-case.h @@ -1,7 +1,7 @@ #ifndef SSLOPT_CASE_INCLUDED #define SSLOPT_CASE_INCLUDED -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,7 +38,7 @@ exit(1); } else - opt_ssl_required= 1; + opt_ssl_mode= SSL_MODE_REQUIRED; break; #endif /* MYSQL_CLIENT */ #endif diff --git a/include/sslopt-vars.h b/include/sslopt-vars.h index 6c9bd4296ef..a037538f693 100644 --- a/include/sslopt-vars.h +++ b/include/sslopt-vars.h @@ -1,7 +1,7 @@ #ifndef SSLOPT_VARS_INCLUDED #define SSLOPT_VARS_INCLUDED -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,11 +31,11 @@ SSL_STATIC char *opt_ssl_key = 0; #ifdef MYSQL_CLIENT SSL_STATIC my_bool opt_ssl_verify_server_cert= 0; -SSL_STATIC my_bool opt_ssl_required= 0; +SSL_STATIC uint opt_ssl_mode= 0; #endif /* MYSQL_CLIENT */ #else /* HAVE_OPENSSL */ -#define opt_ssl_required 0 +#define opt_ssl_mode 0 #endif /* HAVE_OPENSSL */ #endif /* SSLOPT_VARS_INCLUDED */ diff --git a/mysql-test/r/ssl_mode.result b/mysql-test/r/ssl_mode.result index 38fc4e1dca2..c02a50bdcbd 100644 --- a/mysql-test/r/ssl_mode.result +++ b/mysql-test/r/ssl_mode.result @@ -37,8 +37,8 @@ DROP TABLE t1; # mysql Unknown value to --ssl-mode: ''. Use --ssl-mode=REQUIRED Unknown value to --ssl-mode: 'DERIUQER'. Use --ssl-mode=REQUIRED -ERROR 2026 (HY000): --ssl-mode=REQUIRED option forbids non SSL connections -ERROR 2026 (HY000): --ssl-mode=REQUIRED option forbids non SSL connections -ERROR 2026 (HY000): --ssl-mode=REQUIRED option forbids non SSL connections +ERROR 2026 (HY000): SSL connection error: Client is not configured to use SSL +ERROR 2026 (HY000): SSL connection error: Client is not configured to use SSL +ERROR 2026 (HY000): SSL connection error: Client is not configured to use SSL End of tests diff --git a/mysql-test/r/ssl_mode_no_ssl.result b/mysql-test/r/ssl_mode_no_ssl.result index 409b7a0fa1b..831bb3b71ab 100644 --- a/mysql-test/r/ssl_mode_no_ssl.result +++ b/mysql-test/r/ssl_mode_no_ssl.result @@ -1,22 +1,22 @@ # negative client tests # mysql -ERROR 2026 (HY000): --ssl-mode=REQUIRED option forbids non SSL connections -ERROR 2026 (HY000): --ssl-mode=REQUIRED option forbids non SSL connections -ERROR 2026 (HY000): --ssl-mode=REQUIRED option forbids non SSL connections -ERROR 2026 (HY000): --ssl-mode=REQUIRED option forbids non SSL connections +ERROR 2026 (HY000): SSL connection error: Server doesn't support SSL +ERROR 2026 (HY000): SSL connection error: Server doesn't support SSL +ERROR 2026 (HY000): SSL connection error: Server doesn't support SSL +ERROR 2026 (HY000): SSL connection error: Server doesn't support SSL # mysqldump -mysqldump: Got error: 2026: --ssl-mode=REQUIRED option forbids non SSL connections when trying to connect +mysqldump: Got error: 2026: SSL connection error: Server doesn't support SSL when trying to connect # mysqladmin -mysqladmin: error: '--ssl-mode=REQUIRED option forbids non SSL connections' +mysqladmin: error: 'SSL connection error: Server doesn't support SSL' # mysqlcheck -mysqlcheck: Got error: 2026: --ssl-mode=REQUIRED option forbids non SSL connections when trying to connect +mysqlcheck: Got error: 2026: SSL connection error: Server doesn't support SSL when trying to connect # mysqlimport -mysqlimport: Error: 2026 --ssl-mode=REQUIRED option forbids non SSL connections +mysqlimport: Error: 2026 SSL connection error: Server doesn't support SSL # mysqlshow -mysqlshow: --ssl-mode=REQUIRED option forbids non SSL connections +mysqlshow: SSL connection error: Server doesn't support SSL # mysqlslap -mysqlslap: Error when connecting to server: --ssl-mode=REQUIRED option forbids non SSL connections +mysqlslap: Error when connecting to server: SSL connection error: Server doesn't support SSL # mysqltest -mysqltest: Could not open connection 'default': 2026 --ssl-mode=REQUIRED option forbids non SSL connections +mysqltest: Could not open connection 'default': 2026 SSL connection error: Server doesn't support SSL End of tests diff --git a/sql-common/client.c b/sql-common/client.c index 3a6e205d384..759d95117cb 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1137,7 +1137,7 @@ static const char *default_options[]= "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name", "multi-results", "multi-statements", "multi-queries", "secure-auth", "report-data-truncation", "plugin-dir", "default-auth", - "enable-cleartext-plugin", + "enable-cleartext-plugin", "ssl-mode", NullS }; enum option_id { @@ -1149,7 +1149,7 @@ enum option_id { OPT_ssl_cipher, OPT_max_allowed_packet, OPT_protocol, OPT_shared_memory_base_name, OPT_multi_results, OPT_multi_statements, OPT_multi_queries, OPT_secure_auth, OPT_report_data_truncation, OPT_plugin_dir, OPT_default_auth, - OPT_enable_cleartext_plugin, + OPT_enable_cleartext_plugin, OPT_ssl_mode, OPT_keep_this_one_last }; @@ -1338,12 +1338,26 @@ void mysql_read_default_options(struct st_mysql_options *options, my_free(options->ssl_cipher); options->ssl_cipher= my_strdup(opt_arg, MYF(MY_WME)); break; + case OPT_ssl_mode: + if (opt_arg && + !my_strcasecmp(&my_charset_latin1, opt_arg, "required")) + { + ENSURE_EXTENSIONS_PRESENT(options); + options->extension->ssl_mode= SSL_MODE_REQUIRED; + } + else + { + fprintf(stderr, "Unknown option to ssl-mode: %s\n", opt_arg); + exit(1); + } + break; #else case OPT_ssl_key: case OPT_ssl_cert: case OPT_ssl_ca: case OPT_ssl_capath: case OPT_ssl_cipher: + case OPT_ssl_mode: break; #endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ case OPT_character_sets_dir: @@ -1850,6 +1864,10 @@ mysql_ssl_free(MYSQL *mysql __attribute__((unused))) mysql->options.ssl_capath = 0; mysql->options.ssl_cipher= 0; mysql->options.use_ssl = FALSE; + if (mysql->options.extension) + { + mysql->options.extension->ssl_mode= 0; + } mysql->connector_fd = 0; DBUG_VOID_RETURN; } @@ -2596,6 +2614,31 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, end= buff+5; } #ifdef HAVE_OPENSSL + /* + If SSL connection is required we'll: + 1. check if the server supports SSL; + 2. check if the client is properly configured; + 3. try to use SSL no matter the other options given. + */ + if (mysql->options.extension && + mysql->options.extension->ssl_mode == SSL_MODE_REQUIRED) + { + if (!(mysql->server_capabilities & CLIENT_SSL)) + { + set_mysql_extended_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate, + ER(CR_SSL_CONNECTION_ERROR), + "Server doesn't support SSL"); + goto error; + } + if (!mysql->options.use_ssl) + { + set_mysql_extended_error(mysql, CR_SSL_CONNECTION_ERROR, unknown_sqlstate, + ER(CR_SSL_CONNECTION_ERROR), + "Client is not configured to use SSL"); + goto error; + } + mysql->client_flag|= CLIENT_SSL; + } if (mysql->client_flag & CLIENT_SSL) { /* Do the SSL layering. */ @@ -4242,6 +4285,13 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) mysql->options.extension->enable_cleartext_plugin= (*(my_bool*) arg) ? TRUE : FALSE; break; + case MYSQL_OPT_SSL_MODE: + if (*(uint *) arg == SSL_MODE_REQUIRED) + { + ENSURE_EXTENSIONS_PRESENT(&mysql->options); + mysql->options.extension->ssl_mode= SSL_MODE_REQUIRED; + } + break; default: DBUG_RETURN(1); } From fc4c53c28899abf5547e0e0a89b4d91645250895 Mon Sep 17 00:00:00 2001 From: Karthik Kamath Date: Fri, 10 Mar 2017 22:34:38 +0530 Subject: [PATCH 07/97] BUG#24807826: UINT3KORR SHOULD STOP READING FOUR INSTEAD OF THREE BYTES ON X86 Post push fix for resolving main.archive test failure in valgrind. --- sql/records.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/records.cc b/sql/records.cc index ae7ec74c17d..14a4390b229 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -596,7 +596,7 @@ static int init_rr_cache(THD *thd, READ_RECORD *info) DBUG_RETURN(1); #ifdef HAVE_purify // Avoid warnings in qsort - bzero(info->cache,rec_cache_size+info->cache_records* info->struct_length+1); + bzero(info->cache,rec_cache_size+info->cache_records* info->struct_length); #endif DBUG_PRINT("info",("Allocated buffert for %d records",info->cache_records)); info->read_positions=info->cache+rec_cache_size; From 8ea859d3007334065496b78dd8dd57e51c296a55 Mon Sep 17 00:00:00 2001 From: Ramil Kalimullin Date: Mon, 13 Mar 2017 17:01:59 +0400 Subject: [PATCH 08/97] BUG#25575605: SETTING --SSL-MODE=REQUIRED SENDS CREDENTIALS BEFORE VERIFYING SSL CONNECTION Changed MYSQL_OPT_SSL_MODE to be the same as in 5.6 (ABI compatibility). --- include/mysql.h | 4 +++- include/mysql.h.pp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index 7ebf2f725a2..3a27ab4128c 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -167,7 +167,9 @@ enum mysql_option MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, - MYSQL_ENABLE_CLEARTEXT_PLUGIN, MYSQL_OPT_SSL_MODE + MYSQL_ENABLE_CLEARTEXT_PLUGIN, + /* Set MYSQL_OPT_SSL_MODE to be the same as in 5.6 (ABI compatibility). */ + MYSQL_OPT_SSL_MODE= 38 }; /** diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 0f292d921ee..774bf2d0301 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -263,7 +263,8 @@ enum mysql_option MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, - MYSQL_ENABLE_CLEARTEXT_PLUGIN, MYSQL_OPT_SSL_MODE + MYSQL_ENABLE_CLEARTEXT_PLUGIN, + MYSQL_OPT_SSL_MODE= 38 }; struct st_mysql_options_extention; struct st_mysql_options { From d8328690d99aadad5c121da4eee05e940cddb8bb Mon Sep 17 00:00:00 2001 From: Kailasnath Nagarkar Date: Wed, 15 Mar 2017 16:45:21 +0530 Subject: [PATCH 09/97] Bug #25447551: HANDLE_FATAL_SIGNAL (SIG=11) IN FT_BOOLEAN_CHECK_SYNTAX_STRING ISSUE: my_isalnum macro used for checking if character is alphanumeric dereferences uninitialized pointer in default character set structure resulting in server exiting abnormally. FIX: Used standard isalnum function instead of macro my_isalnum. --- storage/myisam/ft_parser.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/storage/myisam/ft_parser.c b/storage/myisam/ft_parser.c index 4d5899107c2..bbb85e8b68b 100644 --- a/storage/myisam/ft_parser.c +++ b/storage/myisam/ft_parser.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ /* Written by Sergei A. Golubchik, who has a shared copyright to this code */ #include "ftdefs.h" +#include "ctype.h" typedef struct st_ft_docstat { FT_WORD *list; @@ -89,7 +90,7 @@ my_bool ft_boolean_check_syntax_string(const uchar *str) for (i=0; i 127 || my_isalnum(default_charset_info, str[i])) + if ((unsigned char)(str[i]) > 127 || isalnum(str[i])) return 1; for (j=0; j Date: Fri, 17 Mar 2017 08:41:31 +0100 Subject: [PATCH 10/97] Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY While writing comments if database object names has a new line character, then next line is considered a command, rather than a comment. This patch fixes the way comments are constructed in mysqldump. --- client/mysqldump.c | 54 +++++++++++++++++++++++------- mysql-test/r/mysqldump.result | 63 +++++++++++++++++++++++++++++++++++ mysql-test/t/mysqldump.test | 50 +++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 12 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index fcd29e26fe3..2775769fe52 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -549,6 +549,7 @@ static int dump_tablespaces_for_databases(char** databases); static int dump_tablespaces(char* ts_where); static void print_comment(FILE *sql_file, my_bool is_error, const char *format, ...); +static const char* fix_identifier_with_newline(char*); /* @@ -649,7 +650,7 @@ static void write_header(FILE *sql_file, char *db_name) MACHINE_TYPE); print_comment(sql_file, 0, "-- Host: %s Database: %s\n", current_host ? current_host : "localhost", - db_name ? db_name : ""); + db_name ? fix_identifier_with_newline(db_name) : ""); print_comment(sql_file, 0, "-- ------------------------------------------------------\n" ); @@ -1981,6 +1982,30 @@ static void print_comment(FILE *sql_file, my_bool is_error, const char *format, print_xml_comment(sql_file, strlen(comment_buff), comment_buff); } +/* + This function accepts object names and prefixes -- wherever \n + character is found. + + @param[in] object_name + + @return + @retval fixed object name. +*/ + +static const char* fix_identifier_with_newline(char* object_name) +{ + static char buff[COMMENT_LENGTH]= {0}; + char *ptr= buff; + memset(buff, 0, 255); + while(*object_name) + { + *ptr++ = *object_name; + if (*object_name == '\n') + ptr= strmov(ptr, "-- "); + object_name++; + } + return buff; +} /* create_delimiter @@ -2049,7 +2074,8 @@ static uint dump_events_for_db(char *db) /* nice comments */ print_comment(sql_file, 0, - "\n--\n-- Dumping events for database '%s'\n--\n", db); + "\n--\n-- Dumping events for database '%s'\n--\n", + fix_identifier_with_newline(db)); /* not using "mysql_query_with_error_report" because we may have not @@ -2266,7 +2292,8 @@ static uint dump_routines_for_db(char *db) /* nice comments */ print_comment(sql_file, 0, - "\n--\n-- Dumping routines for database '%s'\n--\n", db); + "\n--\n-- Dumping routines for database '%s'\n--\n", + fix_identifier_with_newline(db)); /* not using "mysql_query_with_error_report" because we may have not @@ -2325,7 +2352,7 @@ static uint dump_routines_for_db(char *db) query_buff); print_comment(sql_file, 1, "-- does %s have permissions on mysql.proc?\n\n", - current_user); + fix_identifier_with_newline(current_user)); maybe_die(EX_MYSQLERR,"%s has insufficent privileges to %s!", current_user, query_buff); } else if (strlen(row[2])) @@ -2539,11 +2566,11 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (strcmp (table_type, "VIEW") == 0) /* view */ print_comment(sql_file, 0, "\n--\n-- Temporary table structure for view %s\n--\n\n", - result_table); + fix_identifier_with_newline(result_table)); else print_comment(sql_file, 0, "\n--\n-- Table structure for table %s\n--\n\n", - result_table); + fix_identifier_with_newline(result_table)); if (opt_drop) { @@ -2785,7 +2812,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, print_comment(sql_file, 0, "\n--\n-- Table structure for table %s\n--\n\n", - result_table); + fix_identifier_with_newline(result_table)); if (opt_drop) fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", result_table); if (!opt_xml) @@ -3490,21 +3517,23 @@ static void dump_table(char *table, char *db) { print_comment(md_result_file, 0, "\n--\n-- Dumping data for table %s\n--\n", - result_table); + fix_identifier_with_newline(result_table)); dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * FROM "); dynstr_append_checked(&query_string, result_table); if (where) { - print_comment(md_result_file, 0, "-- WHERE: %s\n", where); + print_comment(md_result_file, 0, "-- WHERE: %s\n", + fix_identifier_with_newline(where)); dynstr_append_checked(&query_string, " WHERE "); dynstr_append_checked(&query_string, where); } if (order_by) { - print_comment(md_result_file, 0, "-- ORDER BY: %s\n", order_by); + print_comment(md_result_file, 0, "-- ORDER BY: %s\n", + fix_identifier_with_newline(order_by)); dynstr_append_checked(&query_string, " ORDER BY "); dynstr_append_checked(&query_string, order_by); @@ -4275,7 +4304,8 @@ static int init_dumping(char *database, int init_func(char*)) char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted); print_comment(md_result_file, 0, - "\n--\n-- Current Database: %s\n--\n", qdatabase); + "\n--\n-- Current Database: %s\n--\n", + fix_identifier_with_newline(qdatabase)); /* Call the view or table specific function */ init_func(qdatabase); @@ -5281,7 +5311,7 @@ static my_bool get_view_structure(char *table, char* db) print_comment(sql_file, 0, "\n--\n-- Final view structure for view %s\n--\n\n", - result_table); + fix_identifier_with_newline(result_table)); /* Table might not exist if this view was dumped with --tab. */ fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n", opt_quoted_table); diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index c578f9e8df6..24746a3a51d 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -5283,3 +5283,66 @@ a DROP TABLE t1; DROP TABLE t2; DROP DATABASE db_20772273; +# +# Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY +# +CREATE DATABASE bug25717383; +use bug25717383; +CREATE TABLE `tab +one` (a int); +CREATE VIEW `view +one` as SELECT * FROM `tab +one`; +CREATE PROCEDURE `proc +one`() SELECT * from `tab +one`; +CREATE TEMPORARY TABLE `temp +one` (id INT); +CREATE TRIGGER `trig +one` BEFORE INSERT ON `tab +one` FOR EACH ROW SET NEW.a = 1; +CREATE EVENT `event +one` ON SCHEDULE AT '2030-01-01 00:00:00' DO SET @a=5; +SHOW TABLES FROM bug25717383; +Tables_in_bug25717383 +tab +one +view +one +SHOW TRIGGERS FROM bug25717383; +Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation +trig +one INSERT tab +one SET NEW.a = 1 BEFORE NULL root@localhost utf8 utf8_general_ci latin1_swedish_ci +SHOW EVENTS FROM bug25717383; +Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation +bug25717383 event +one root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL ENABLED 1 utf8 utf8_general_ci latin1_swedish_ci +SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE' + ORDER BY ROUTINE_NAME; +ROUTINE_NAME +proc +one +SHOW TABLES FROM bug25717383; +Tables_in_bug25717383 +tab +one +view +one +SHOW TRIGGERS FROM bug25717383; +Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation +trig +one INSERT tab +one SET NEW.a = 1 BEFORE NULL root@localhost utf8 utf8_general_ci latin1_swedish_ci +SHOW EVENTS FROM bug25717383; +Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation +bug25717383 event +one root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL ENABLED 1 utf8 utf8_general_ci latin1_swedish_ci +SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE' + ORDER BY ROUTINE_NAME; +ROUTINE_NAME +proc +one +DROP DATABASE bug25717383; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 11d766c3293..da958f83c48 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2425,3 +2425,53 @@ SELECT * FROM t2; DROP TABLE t1; DROP TABLE t2; DROP DATABASE db_20772273; + +--echo # +--echo # Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY +--echo # + + +CREATE DATABASE bug25717383; +use bug25717383; + +CREATE TABLE `tab +one` (a int); +CREATE VIEW `view +one` as SELECT * FROM `tab +one`; + +CREATE PROCEDURE `proc +one`() SELECT * from `tab +one`; + +CREATE TEMPORARY TABLE `temp +one` (id INT); + +CREATE TRIGGER `trig +one` BEFORE INSERT ON `tab +one` FOR EACH ROW SET NEW.a = 1; + +CREATE EVENT `event +one` ON SCHEDULE AT '2030-01-01 00:00:00' DO SET @a=5; + +SHOW TABLES FROM bug25717383; +SHOW TRIGGERS FROM bug25717383; +--replace_column 6 # +SHOW EVENTS FROM bug25717383; + +SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES + WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE' + ORDER BY ROUTINE_NAME; + +--exec $MYSQL_DUMP --triggers --events --routines --add-drop-database --databases bug25717383 > $MYSQLTEST_VARDIR/tmp/bug25717383.sql + +SHOW TABLES FROM bug25717383; +SHOW TRIGGERS FROM bug25717383; +--replace_column 6 # +SHOW EVENTS FROM bug25717383; + +SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES + WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE' + ORDER BY ROUTINE_NAME; + +DROP DATABASE bug25717383; From 741305b3a4a15b8957926f24300ea0b7da8d04bd Mon Sep 17 00:00:00 2001 From: "mysql-builder@oracle.com" <> Date: Thu, 23 Mar 2017 22:57:25 +0530 Subject: [PATCH 11/97] From 5d4cfb30e517e861defd9728e88f37ef6072becb Mon Sep 17 00:00:00 2001 From: Terje Rosten Date: Tue, 28 Mar 2017 13:22:32 +0200 Subject: [PATCH 12/97] BUG#25719975 SHEBANG HARD CODED AS /USR/BIN/PERL IN SCRIPTS, BREAKS ON FREEBSD Use cmake variable to adjust shebang to platform. --- scripts/CMakeLists.txt | 9 ++++++++- scripts/dheadgen.pl | 8 +------- scripts/mysql_config.pl.in | 4 ++-- scripts/mysql_convert_table_format.sh | 5 ++--- scripts/mysql_find_rows.sh | 5 ++--- scripts/mysql_fix_extensions.sh | 5 ++--- scripts/mysql_install_db.pl.in | 4 ++-- scripts/mysql_secure_installation.pl.in | 4 ++-- scripts/mysql_setpermission.sh | 5 ++--- scripts/mysql_zap.sh | 5 ++--- scripts/mysqlaccess.conf | 0 scripts/mysqlaccess.sh | 4 ++-- scripts/mysqld_multi.sh | 4 ++-- scripts/mysqldumpslow.sh | 5 ++--- scripts/mysqlhotcopy.sh | 4 ++-- 15 files changed, 33 insertions(+), 38 deletions(-) mode change 100755 => 100644 scripts/dheadgen.pl mode change 100755 => 100644 scripts/mysql_secure_installation.pl.in mode change 100755 => 100644 scripts/mysqlaccess.conf diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 920b6854334..d0fdf76ce9e 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -104,6 +104,13 @@ ELSE() "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") ENDIF() + +IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + SET (PERL_PATH "/usr/local/bin/perl") +ELSE() + SET (PERL_PATH "/usr/bin/perl") +ENDIF() + IF(UNIX) # SHELL_PATH, FIND_PROC, CHECK_PID are used by mysqld_safe IF(CMAKE_SYSTEM_NAME MATCHES "SunOS") diff --git a/scripts/dheadgen.pl b/scripts/dheadgen.pl old mode 100755 new mode 100644 index c42bd49b32e..69ece2e7c81 --- a/scripts/dheadgen.pl +++ b/scripts/dheadgen.pl @@ -1,10 +1,4 @@ -#!/usr/bin/perl -w - -# -# Copyright (c) 2008, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. -# - +# Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: diff --git a/scripts/mysql_config.pl.in b/scripts/mysql_config.pl.in index bced4a16360..edd258d5771 100644 --- a/scripts/mysql_config.pl.in +++ b/scripts/mysql_config.pl.in @@ -1,7 +1,7 @@ -#!/usr/bin/perl +#!@PERL_PATH@ # -*- cperl -*- # -# Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/mysql_convert_table_format.sh b/scripts/mysql_convert_table_format.sh index 2e5b5c11ab5..869a25c152b 100644 --- a/scripts/mysql_convert_table_format.sh +++ b/scripts/mysql_convert_table_format.sh @@ -1,6 +1,5 @@ -#!/usr/bin/perl -# Copyright (c) 2000-2002, 2006, 2007 MySQL AB, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. +#!@PERL_PATH@ +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/mysql_find_rows.sh b/scripts/mysql_find_rows.sh index 48c4915ae00..20c3e2c3106 100644 --- a/scripts/mysql_find_rows.sh +++ b/scripts/mysql_find_rows.sh @@ -1,6 +1,5 @@ -#!/usr/bin/perl -# Copyright (c) 2000, 2004, 2006 MySQL AB, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. +#!@PERL_PATH@ +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/mysql_fix_extensions.sh b/scripts/mysql_fix_extensions.sh index 2a50bfe22bb..7aa07209d4d 100644 --- a/scripts/mysql_fix_extensions.sh +++ b/scripts/mysql_fix_extensions.sh @@ -1,7 +1,6 @@ -#!/usr/bin/perl +#!@PERL_PATH@ -# Copyright (c) 2001 MySQL AB, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. +# Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public diff --git a/scripts/mysql_install_db.pl.in b/scripts/mysql_install_db.pl.in index 5f6bcabd518..760c7df887e 100644 --- a/scripts/mysql_install_db.pl.in +++ b/scripts/mysql_install_db.pl.in @@ -1,7 +1,7 @@ -#!/usr/bin/perl +#!@PERL_PATH@ # -*- cperl -*- # -# Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/mysql_secure_installation.pl.in b/scripts/mysql_secure_installation.pl.in old mode 100755 new mode 100644 index 278fffe7322..09f2e20b6a3 --- a/scripts/mysql_secure_installation.pl.in +++ b/scripts/mysql_secure_installation.pl.in @@ -1,7 +1,7 @@ -#!/usr/bin/perl +#!@PERL_PATH@ # -*- cperl -*- # -# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/mysql_setpermission.sh b/scripts/mysql_setpermission.sh index 48f0b09b566..4416551eadd 100644 --- a/scripts/mysql_setpermission.sh +++ b/scripts/mysql_setpermission.sh @@ -1,8 +1,7 @@ -#!/usr/bin/perl +#!@PERL_PATH@ ## Emacs, this is -*- perl -*- mode? :-) -# Copyright (c) 2000, 2007 MySQL AB, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public diff --git a/scripts/mysql_zap.sh b/scripts/mysql_zap.sh index a9c3e7a7f5a..725a4e247a4 100644 --- a/scripts/mysql_zap.sh +++ b/scripts/mysql_zap.sh @@ -1,6 +1,5 @@ -#!/usr/bin/perl -# Copyright (c) 2000-2002, 2004, 2006 MySQL AB, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. +#!@PERL_PATH@ +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/scripts/mysqlaccess.conf b/scripts/mysqlaccess.conf old mode 100755 new mode 100644 diff --git a/scripts/mysqlaccess.sh b/scripts/mysqlaccess.sh index 4ca3b2d3686..03810e95b72 100644 --- a/scripts/mysqlaccess.sh +++ b/scripts/mysqlaccess.sh @@ -1,6 +1,6 @@ -#!/usr/bin/perl +#!@PERL_PATH@ -# Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public diff --git a/scripts/mysqld_multi.sh b/scripts/mysqld_multi.sh index d9ea6a117d2..a00704b6085 100644 --- a/scripts/mysqld_multi.sh +++ b/scripts/mysqld_multi.sh @@ -1,6 +1,6 @@ -#!/usr/bin/perl +#!@PERL_PATH@ -# Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public diff --git a/scripts/mysqldumpslow.sh b/scripts/mysqldumpslow.sh index 94665f345f4..78040aac320 100644 --- a/scripts/mysqldumpslow.sh +++ b/scripts/mysqldumpslow.sh @@ -1,7 +1,6 @@ -#!/usr/bin/perl +#!@PERL_PATH@ -# Copyright (c) 2000-2002, 2005-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc. -# Use is subject to license terms. +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public diff --git a/scripts/mysqlhotcopy.sh b/scripts/mysqlhotcopy.sh index a7f465dc891..2dc3a33c25d 100644 --- a/scripts/mysqlhotcopy.sh +++ b/scripts/mysqlhotcopy.sh @@ -1,6 +1,6 @@ -#!/usr/bin/perl +#!@PERL_PATH@ -# Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public From 3c6c0ebc6a31835260d07463d581b9715776812f Mon Sep 17 00:00:00 2001 From: Nisha Gopalakrishnan Date: Mon, 9 Jan 2017 20:09:57 +0530 Subject: [PATCH 13/97] BUG#25250768: WRITING ON A READ_ONLY=ON SERVER WITHOUT SUPER PRIVILEGE. Backport from mysql-5.7 to mysql-5.5 and mysql-5.6. BUG#13969578: TEMPORARY TABLE IN A DATABASE ON A READ-ONLY INSTANCE CAN BE OVERWRITTEN Analysis: ======== Creation or modification of a persistent table by a non-super user is NOT ALLOWED in read_only mode. Only TEMPORARY tables are allowed to be created or modified in read_only mode. But the creation of a persistent table was being allowed when a temporary table of the same name existed. The routine which denies updating a non-temporary table in a read_only mode does not handle the case of creation of a regular table when a temporary table of the same exists. Fix: === Handled the condition where an attempt is made to create a persistent table having the same name as that of the temporary table. Hence the creation of a persistent table by a non-super user when a temporary table of the same exists is denied under read_only mode. --- sql/sql_parse.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 86763b6e3de..82ab76b2e1c 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -822,14 +822,18 @@ static my_bool deny_updates_if_read_only_option(THD *thd, (lex->sql_command == SQLCOM_CREATE_TABLE) && (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE); + const my_bool create_real_tables= + (lex->sql_command == SQLCOM_CREATE_TABLE) && + !(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE); + const my_bool drop_temp_tables= (lex->sql_command == SQLCOM_DROP_TABLE) && lex->drop_temporary; const my_bool update_real_tables= - some_non_temp_table_to_be_updated(thd, all_tables) && - !(create_temp_tables || drop_temp_tables); - + ((create_real_tables || + some_non_temp_table_to_be_updated(thd, all_tables)) && + !(create_temp_tables || drop_temp_tables)); const my_bool create_or_drop_databases= (lex->sql_command == SQLCOM_CREATE_DB) || From 07fb7b9c3d3ab403f110b6e52fa2d70e95bb6ded Mon Sep 17 00:00:00 2001 From: "mysql-builder@oracle.com" <> Date: Mon, 10 Apr 2017 08:51:28 +0530 Subject: [PATCH 14/97] From 788fb5bf678e2854fd2936cf6ac8d8f46f7c90c4 Mon Sep 17 00:00:00 2001 From: Shishir Jaiswal Date: Mon, 17 Apr 2017 12:04:14 +0530 Subject: [PATCH 15/97] Bug#25043674 - MYSQLACCESS SCRIPT LOADS AND EXECUTES CODE FROM THE CURRENT DIRECTORY DESCRIPTION =========== When 'mysqlaccess' tool is run, it reads (and executes) the content of its configuration file 'mysqlaccess.conf' from the current directory. This is not a recommended behaviour as someone with ill intentions can insert malicious instructions into this file which could be executed whenever this tool is run. ANALYSIS ======== The configuration file is presently looked for, in the following folders (in given order): 1. Current directory 2. SYSCONFDIR //This gets expanded 3. /etc/ Owing to the reasons mentioned above, we should not permit the file to be in the current directory. Since the other two folders are assumed to be accessible only to authorized people, the config file is safe to be read from there. FIX === Modified the script so that it looks for the config file now in the following two folders (in the given order): 1. SYSCONFDIR 2. /etc/ If it's absent from above locations but present in current directory, an error is thrown asking the user to move the file to one of the above locations and retry. NOTE ==== The location paths and their precedence are not documented for this tool. It needs to be noted as part of the associated documentation. --- mysql-test/mysql-test-run.pl | 13 ++++++++++++- scripts/mysqlaccess.sh | 15 +++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 86d37a56835..2ca5c83e3f4 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl # -*- cperl -*- -# Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -2454,6 +2454,17 @@ sub environment_setup { "$basedir/storage/myisam/myisampack", "$basedir/myisam/myisampack")); + # ---------------------------------------------------- + # mysqlaccess + # ---------------------------------------------------- + my $mysqlaccess= + mtr_pl_maybe_exists("$bindir/scripts/mysqlaccess") || + mtr_pl_maybe_exists("$path_client_bindir/mysqlaccess"); + if ($mysqlaccess) + { + $ENV{'MYSQLACCESS'}= $mysqlaccess; + } + # ---------------------------------------------------- # mysqlhotcopy # ---------------------------------------------------- diff --git a/scripts/mysqlaccess.sh b/scripts/mysqlaccess.sh index 03810e95b72..85112a59ee4 100644 --- a/scripts/mysqlaccess.sh +++ b/scripts/mysqlaccess.sh @@ -477,15 +477,22 @@ MySQLaccess::Report::Print_Header(); # ***************************** # Read configuration-file MySQLaccess::Debug::Print(1, "Reading configuration file..."); - if (-f "./$script_conf") { - require "./$script_conf"; - } - elsif (-f "@sysconfdir@/$script_conf") { + if (-f "@sysconfdir@/$script_conf") { + print "Configuration file '$script_conf' is found in '@sysconfdir@/'\n"; require "@sysconfdir@/$script_conf"; } elsif (-f "/etc/$script_conf") { + print "Configuration file '$script_conf' is found in '/etc/'\n"; require "/etc/$script_conf"; } + elsif (-f "./$script_conf") { + print "\nERROR! Configuration file '$script_conf' is found in the current "; + print "directory.\nThe permissible locations for this file are either "; + print "@sysconfdir@/ or /etc/\n"; + print "Please move it to one of these locations and retry.\n\n"; + exit 0; + } + # **************************** # Read in all parameters From 8fab3ea01ff84b700d4686f9380c52cb30af7dc2 Mon Sep 17 00:00:00 2001 From: Balasubramanian Kandasamy Date: Tue, 25 Apr 2017 13:12:30 +0530 Subject: [PATCH 16/97] Added plugins for commercial docker rpm builds --- packaging/rpm-docker/mysql.spec.in | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packaging/rpm-docker/mysql.spec.in b/packaging/rpm-docker/mysql.spec.in index 5d35fb0a410..c5b7c664f59 100644 --- a/packaging/rpm-docker/mysql.spec.in +++ b/packaging/rpm-docker/mysql.spec.in @@ -1,4 +1,4 @@ -# Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -195,6 +195,9 @@ done rm -f %{buildroot}%{_datadir}/mysql/{mysql.server,mysqld_multi.server,mysql-log-rotate,binary-configure} rm -f %{buildroot}%{_datadir}/mysql/{*.ini,*.cnf} +# Remove files pages we explicitly do not want to package +rm -rf %{buildroot}%{_infodir}/mysql.info* + %check %if 0%{?runselftest} pushd release @@ -271,6 +274,13 @@ rm -r $(readlink var) var %attr(644, root, root) %{_datadir}/mysql/mysql_system_tables_data.sql %attr(644, root, root) %{_datadir}/mysql/mysql_test_data_timezone.sql %attr(644, root, root) %{_datadir}/mysql/magic + +%if 0%{?commercial} +%attr(755, root, root) %{_libdir}/mysql/plugin/audit_log.so +%attr(755, root, root) %{_libdir}/mysql/plugin/authentication_pam.so +%attr(755, root, root) %{_libdir}/mysql/plugin/thread_pool.so +%endif + %dir %attr(750, mysql, mysql) /var/lib/mysql %dir %attr(755, mysql, mysql) /var/run/mysqld %dir %attr(750, mysql, mysql) /var/lib/mysql-files From c49b2707868d27c67e90c3844d570a97c573b9e5 Mon Sep 17 00:00:00 2001 From: Harin Vadodaria Date: Thu, 27 Apr 2017 07:41:27 +0200 Subject: [PATCH 17/97] Bug#25942414: SSL VARIABLES USAGE WHEN LIBMYSQL IS COMPILED WITH WITH_SSL=NO Description: If libmysql is compiled with WITH_SSL=NO, --ssl-* are not useful. Solution: 1. Restricted WITH_SSL to values : bundled | yes | system 2. Made "bundled" as default value for WITH_SSL. Also, not specifying WITH_SSL or even specifying WITH_SSL=no will be treated as/converted to WITH_SSL=bundled. Reviewed-By: Tor Didriksen Reviewed-By: Georgi Kodinov --- .../build_configurations/mysql_release.cmake | 4 +-- cmake/ssl.cmake | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cmake/build_configurations/mysql_release.cmake b/cmake/build_configurations/mysql_release.cmake index b0d3de10299..7d54e2aec77 100644 --- a/cmake/build_configurations/mysql_release.cmake +++ b/cmake/build_configurations/mysql_release.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -169,7 +169,6 @@ IF(UNIX) SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "+O2 ${COMMON_CXX_FLAGS}") ENDIF() ENDIF() - SET(WITH_SSL no) ENDIF() # Linux flags @@ -185,7 +184,6 @@ IF(UNIX) SET(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS}") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -unroll2 -ip ${COMMON_C_FLAGS}") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -unroll2 -ip ${COMMON_CXX_FLAGS}") - SET(WITH_SSL no) ENDIF() ENDIF() diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index 32b735410b7..f11c18a1bc8 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -11,10 +11,16 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +SET(WITH_SSL_DOC "bundled (use yassl)") +SET(WITH_SSL_DOC + "${WITH_SSL_DOC}, yes (prefer os library if present, otherwise use bundled)") +SET(WITH_SSL_DOC + "${WITH_SSL_DOC}, system (use os library)") MACRO (CHANGE_SSL_SETTINGS string) - SET(WITH_SSL ${string} CACHE STRING "Options are : no, bundled, yes (prefer os library if present otherwise use bundled), system (use os library)" FORCE) + SET(WITH_SSL ${string} CACHE STRING ${WITH_SSL_DOC} FORCE) ENDMACRO() MACRO (MYSQL_USE_BUNDLED_SSL) @@ -50,14 +56,12 @@ ENDMACRO() # MYSQL_CHECK_SSL # # Provides the following configure options: -# WITH_SSL=[yes|no|bundled] +# WITH_SSL=[bundled|yes|system] MACRO (MYSQL_CHECK_SSL) IF(NOT WITH_SSL) - IF(WIN32) CHANGE_SSL_SETTINGS("bundled") - ELSE() - CHANGE_SSL_SETTINGS("no") - ENDIF() + MESSAGE(STATUS "Found WITH_SSL set to no. " + "Changing it to bundled") ENDIF() IF(WITH_SSL STREQUAL "bundled") @@ -80,11 +84,12 @@ MACRO (MYSQL_CHECK_SSL) CHANGE_SSL_SETTINGS("system") ELSE() IF(WITH_SSL STREQUAL "system") - MESSAGE(SEND_ERROR "Cannot find appropriate system libraries for SSL. Use WITH_SSL=bundled to enable SSL support") + MESSAGE(SEND_ERROR "Cannot find appropriate system libraries for SSL. Use WITH_SSL=bundled to enable SSL support") ENDIF() MYSQL_USE_BUNDLED_SSL() ENDIF() - ELSEIF(NOT WITH_SSL STREQUAL "no") - MESSAGE(SEND_ERROR "Wrong option for WITH_SSL. Valid values are : yes, no, bundled") + ELSE() + MESSAGE(SEND_ERROR "Wrong option for WITH_SSL. " + "Valid options are : ${WITH_SSL_DOC}") ENDIF() ENDMACRO() From c230d3af1dec914580b9c0d9051725a0aa40fdf5 Mon Sep 17 00:00:00 2001 From: Balasubramanian Kandasamy Date: Mon, 27 Feb 2017 17:20:51 +0530 Subject: [PATCH 18/97] Raise version number after cloning 5.5.55 (cherry picked from commit 7df8dc750c26ead87c643f87dccba28a66cf3c9b) --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index bc0b19220b6..ade2e129c54 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=55 +MYSQL_VERSION_PATCH=56 MYSQL_VERSION_EXTRA= From ad88f2a7b5c5827cb1ba78eee3497fb851b37a9f Mon Sep 17 00:00:00 2001 From: Harin Vadodaria Date: Thu, 27 Apr 2017 07:41:27 +0200 Subject: [PATCH 19/97] Bug#25942414: SSL VARIABLES USAGE WHEN LIBMYSQL IS COMPILED WITH WITH_SSL=NO Description: If libmysql is compiled with WITH_SSL=NO, --ssl-* are not useful. Solution: 1. Restricted WITH_SSL to values : bundled | yes | system 2. Made "bundled" as default value for WITH_SSL. Also, not specifying WITH_SSL or even specifying WITH_SSL=no will be treated as/converted to WITH_SSL=bundled. Reviewed-By: Tor Didriksen Reviewed-By: Georgi Kodinov (cherry picked from commit 3eb2058be34d1a21771fe89ff1a0c08f156899bc) --- .../build_configurations/mysql_release.cmake | 4 +-- cmake/ssl.cmake | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cmake/build_configurations/mysql_release.cmake b/cmake/build_configurations/mysql_release.cmake index b0d3de10299..7d54e2aec77 100644 --- a/cmake/build_configurations/mysql_release.cmake +++ b/cmake/build_configurations/mysql_release.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -169,7 +169,6 @@ IF(UNIX) SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "+O2 ${COMMON_CXX_FLAGS}") ENDIF() ENDIF() - SET(WITH_SSL no) ENDIF() # Linux flags @@ -185,7 +184,6 @@ IF(UNIX) SET(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS}") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -unroll2 -ip ${COMMON_C_FLAGS}") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -unroll2 -ip ${COMMON_CXX_FLAGS}") - SET(WITH_SSL no) ENDIF() ENDIF() diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index 32b735410b7..f11c18a1bc8 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -11,10 +11,16 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +SET(WITH_SSL_DOC "bundled (use yassl)") +SET(WITH_SSL_DOC + "${WITH_SSL_DOC}, yes (prefer os library if present, otherwise use bundled)") +SET(WITH_SSL_DOC + "${WITH_SSL_DOC}, system (use os library)") MACRO (CHANGE_SSL_SETTINGS string) - SET(WITH_SSL ${string} CACHE STRING "Options are : no, bundled, yes (prefer os library if present otherwise use bundled), system (use os library)" FORCE) + SET(WITH_SSL ${string} CACHE STRING ${WITH_SSL_DOC} FORCE) ENDMACRO() MACRO (MYSQL_USE_BUNDLED_SSL) @@ -50,14 +56,12 @@ ENDMACRO() # MYSQL_CHECK_SSL # # Provides the following configure options: -# WITH_SSL=[yes|no|bundled] +# WITH_SSL=[bundled|yes|system] MACRO (MYSQL_CHECK_SSL) IF(NOT WITH_SSL) - IF(WIN32) CHANGE_SSL_SETTINGS("bundled") - ELSE() - CHANGE_SSL_SETTINGS("no") - ENDIF() + MESSAGE(STATUS "Found WITH_SSL set to no. " + "Changing it to bundled") ENDIF() IF(WITH_SSL STREQUAL "bundled") @@ -80,11 +84,12 @@ MACRO (MYSQL_CHECK_SSL) CHANGE_SSL_SETTINGS("system") ELSE() IF(WITH_SSL STREQUAL "system") - MESSAGE(SEND_ERROR "Cannot find appropriate system libraries for SSL. Use WITH_SSL=bundled to enable SSL support") + MESSAGE(SEND_ERROR "Cannot find appropriate system libraries for SSL. Use WITH_SSL=bundled to enable SSL support") ENDIF() MYSQL_USE_BUNDLED_SSL() ENDIF() - ELSEIF(NOT WITH_SSL STREQUAL "no") - MESSAGE(SEND_ERROR "Wrong option for WITH_SSL. Valid values are : yes, no, bundled") + ELSE() + MESSAGE(SEND_ERROR "Wrong option for WITH_SSL. " + "Valid options are : ${WITH_SSL_DOC}") ENDIF() ENDMACRO() From 80080eb389274ba69317a6c2019d5e8e23728b41 Mon Sep 17 00:00:00 2001 From: Balasubramanian Kandasamy Date: Thu, 27 Apr 2017 12:27:52 +0530 Subject: [PATCH 20/97] Raise version number after cloning 5.5.56 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ade2e129c54..68358acf754 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=56 +MYSQL_VERSION_PATCH=57 MYSQL_VERSION_EXTRA= From 14fca28ea44dabf62e75e2aa9a90d71bd7be45c0 Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Tue, 2 May 2017 19:11:21 -0400 Subject: [PATCH 21/97] bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ade2e129c54..68358acf754 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=56 +MYSQL_VERSION_PATCH=57 MYSQL_VERSION_EXTRA= From 756b00d80a46668d5a93ff927e13b5aea1c7d477 Mon Sep 17 00:00:00 2001 From: Anushree Prakash B Date: Wed, 3 May 2017 15:16:08 +0000 Subject: [PATCH 22/97] Bug#25340722 - PRINT BINARY DATA AS HEX IN THE MYSQL CLIENT (CONTRIBUTION) DESCRIPTION: ============ Binary data should be printed as hex in the mysql client when the option binary-as-hex is enabled. ANALYSIS: ========= The fix deals only with mysql command line client. It does not change, at all, the data sent to the applications. Printing binary data as hex also allows to use the output in the where clause of the query. FIX: ==== A new option 'binary-as-hex' is introduced to print the binary contents as hex in the mysql client. The option is disabled by default. When the option is enabled, we convert the binary data to hex before printing the contents irrespective of whether it is in tabular, xml or html format. --- client/mysql.cc | 88 ++++++++++++++++++---- mysql-test/r/binary_to_hex.result | 117 ++++++++++++++++++++++++++++++ mysql-test/t/binary_to_hex.test | 76 +++++++++++++++++++ 3 files changed, 268 insertions(+), 13 deletions(-) create mode 100644 mysql-test/r/binary_to_hex.result create mode 100644 mysql-test/t/binary_to_hex.test diff --git a/client/mysql.cc b/client/mysql.cc index 2269563814c..6e6dc4971ac 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -142,7 +142,7 @@ static my_bool ignore_errors=0,wait_flag=0,quick=0, default_pager_set= 0, opt_sigint_ignore= 0, auto_vertical_output= 0, show_warnings= 0, executing_query= 0, interrupted_query= 0, - ignore_spaces= 0; + ignore_spaces= 0, opt_binhex= 0; static my_bool debug_info_flag, debug_check_flag; static my_bool column_types_flag; static my_bool preserve_comments= 0; @@ -1392,6 +1392,8 @@ static struct my_option my_long_options[] = {"batch", 'B', "Don't use history file. Disable interactive behavior. (Enables --silent.)", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"binary-as-hex", 'b', "Print binary data as hex", &opt_binhex, &opt_binhex, + 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"character-sets-dir", OPT_CHARSETS_DIR, "Directory for character set files.", &charsets_dir, &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -3101,7 +3103,8 @@ com_go(String *buffer,char *line __attribute__((unused))) print_table_data_html(result); else if (opt_xml) print_table_data_xml(result); - else if (vertical || (auto_vertical_output && (terminal_width < get_result_width(result)))) + else if (vertical || (auto_vertical_output && + (terminal_width < get_result_width(result)))) print_table_data_vertically(result); else if (opt_silent && verbose <= 2 && !output_tables) print_tab_data(result); @@ -3320,6 +3323,41 @@ print_field_types(MYSQL_RES *result) } +/* Used to determine if we should invoke print_as_hex for this field */ + +static bool +is_binary_field(MYSQL_FIELD *field) +{ + if ((field->charsetnr == 63) && + (field->type == MYSQL_TYPE_BIT || + field->type == MYSQL_TYPE_BLOB || + field->type == MYSQL_TYPE_LONG_BLOB || + field->type == MYSQL_TYPE_MEDIUM_BLOB || + field->type == MYSQL_TYPE_TINY_BLOB || + field->type == MYSQL_TYPE_VAR_STRING || + field->type == MYSQL_TYPE_STRING || + field->type == MYSQL_TYPE_VARCHAR || + field->type == MYSQL_TYPE_GEOMETRY)) + return 1; + return 0; +} + + +/* Print binary value as hex literal (0x ...) */ + +static void +print_as_hex(FILE *output_file, const char *str, ulong len, ulong total_bytes_to_send) +{ + const char *ptr= str, *end= ptr+len; + ulong i; + fprintf(output_file, "0x"); + for(; ptr < end; ptr++) + fprintf(output_file, "%02X", *((uchar*)ptr)); + for (i= 2*len+2; i < total_bytes_to_send; i++) + tee_putc((int)' ', output_file); +} + + static void print_table_data(MYSQL_RES *result) { @@ -3346,6 +3384,8 @@ print_table_data(MYSQL_RES *result) length=max(length,field->max_length); if (length < 4 && !IS_NOT_NULL(field->flags)) length=4; // Room for "NULL" + if (opt_binhex && is_binary_field(field)) + length= 2 + length * 2; field->max_length=length; separator.fill(separator.length()+length+2,'-'); separator.append('+'); @@ -3415,7 +3455,9 @@ print_table_data(MYSQL_RES *result) visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length); extra_padding= data_length - visible_length; - if (field_max_length > MAX_COLUMN_LENGTH) + if (opt_binhex && is_binary_field(field)) + print_as_hex(PAGER, cur[off], lengths[off], field_max_length); + else if (field_max_length > MAX_COLUMN_LENGTH) tee_print_sized_data(buffer, data_length, MAX_COLUMN_LENGTH+extra_padding, FALSE); else { @@ -3548,11 +3590,15 @@ print_table_data_html(MYSQL_RES *result) if (interrupted_query) break; ulong *lengths=mysql_fetch_lengths(result); + field= mysql_fetch_fields(result); (void) tee_fputs("", PAGER); for (uint i=0; i < mysql_num_fields(result); i++) { (void) tee_fputs("", PAGER); - xmlencode_print(cur[i], lengths[i]); + if (opt_binhex && is_binary_field(&field[i])) + print_as_hex(PAGER, cur[i], lengths[i], lengths[i]); + else + xmlencode_print(cur[i], lengths[i]); (void) tee_fputs("", PAGER); } (void) tee_fputs("", PAGER); @@ -3588,7 +3634,10 @@ print_table_data_xml(MYSQL_RES *result) if (cur[i]) { tee_fprintf(PAGER, "\">"); - xmlencode_print(cur[i], lengths[i]); + if (opt_binhex && is_binary_field(&fields[i])) + print_as_hex(PAGER, cur[i], lengths[i], lengths[i]); + else + xmlencode_print(cur[i], lengths[i]); tee_fprintf(PAGER, "\n"); } else @@ -3635,23 +3684,28 @@ print_table_data_vertically(MYSQL_RES *result) { unsigned int i; const char *p; - + if (opt_binhex && is_binary_field(field)) + fprintf(PAGER, "0x"); for (i= 0, p= cur[off]; i < lengths[off]; i+= 1, p+= 1) { - if (*p == '\0') - tee_putc((int)' ', PAGER); + if (opt_binhex && is_binary_field(field)) + fprintf(PAGER, "%02X", *((uchar*)p)); else - tee_putc((int)*p, PAGER); + { + if (*p == '\0') + tee_putc((int)' ', PAGER); + else + tee_putc((int)*p, PAGER); + } } tee_putc('\n', PAGER); } - else + else tee_fprintf(PAGER, "NULL\n"); } } } - /* print_warnings should be called right after executing a statement */ static void print_warnings() @@ -3788,11 +3842,19 @@ print_tab_data(MYSQL_RES *result) while ((cur = mysql_fetch_row(result))) { lengths=mysql_fetch_lengths(result); - safe_put_field(cur[0],lengths[0]); + field= mysql_fetch_fields(result); + if (opt_binhex && is_binary_field(&field[0])) + print_as_hex(PAGER, cur[0], lengths[0], lengths[0]); + else + safe_put_field(cur[0],lengths[0]); + for (uint off=1 ; off < mysql_num_fields(result); off++) { (void) tee_fputs("\t", PAGER); - safe_put_field(cur[off], lengths[off]); + if (opt_binhex && field && is_binary_field(&field[off])) + print_as_hex(PAGER, cur[off], lengths[off], lengths[off]); + else + safe_put_field(cur[off], lengths[off]); } (void) tee_fputs("\n", PAGER); } diff --git a/mysql-test/r/binary_to_hex.result b/mysql-test/r/binary_to_hex.result new file mode 100644 index 00000000000..a6b68834da8 --- /dev/null +++ b/mysql-test/r/binary_to_hex.result @@ -0,0 +1,117 @@ +USE test; +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1 (c1 TINYBLOB, +c2 BLOB, +c3 MEDIUMBLOB, +c4 LONGBLOB, +c5 TEXT, +c6 BIT(1), +c7 CHAR, +c8 VARCHAR(10), +c9 GEOMETRY) CHARACTER SET = binary; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` tinyblob, + `c2` blob, + `c3` mediumblob, + `c4` longblob, + `c5` blob, + `c6` bit(1) DEFAULT NULL, + `c7` binary(1) DEFAULT NULL, + `c8` varbinary(10) DEFAULT NULL, + `c9` geometry DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=binary +INSERT INTO t1 VALUES ('tinyblob-text readable', 'blob-text readable', +'mediumblob-text readable', 'longblob-text readable', +'text readable', b'1', 'c', 'variable', +POINT(1, 1)); +CREATE TABLE t2(id int, `col1` binary(10),`col2` blob); +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `id` int(11) DEFAULT NULL, + `col1` binary(10) DEFAULT NULL, + `col2` blob +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t2 VALUES (1, X'AB1234', X'123ABC'), (2, X'DE1234', X'123DEF'); +#Print the table contents when binary-as-hex option is off. +SELECT * FROM t1; +c1 c2 c3 c4 c5 c6 c7 c8 c9 +tinyblob-text readable blob-text readable mediumblob-text readable longblob-text readable text readable # c variable # +SELECT * FROM t2; +id col1 col2 +1 # # +2 # # +#Print the table contents after turning on the binary-as-hex option + +#Print the table contents in tab format + +c1 c2 c3 c4 c5 c6 c7 c8 c9 +0x74696E79626C6F622D74657874207265616461626C65 0x626C6F622D74657874207265616461626C65 0x6D656469756D626C6F622D74657874207265616461626C65 0x6C6F6E67626C6F622D74657874207265616461626C65 0x74657874207265616461626C65 0x01 0x63 0x7661726961626C65 0x000000000101000000000000000000F03F000000000000F03F +id col1 col2 +1 0xAB123400000000000000 0x123ABC +2 0xDE123400000000000000 0x123DEF + +#Print the table contents in table format + ++------------------------------------------------+----------------------------------------+----------------------------------------------------+------------------------------------------------+------------------------------+------------+------------+--------------------+------------------------------------------------------+ +| c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | ++------------------------------------------------+----------------------------------------+----------------------------------------------------+------------------------------------------------+------------------------------+------------+------------+--------------------+------------------------------------------------------+ +| 0x74696E79626C6F622D74657874207265616461626C65 | 0x626C6F622D74657874207265616461626C65 | 0x6D656469756D626C6F622D74657874207265616461626C65 | 0x6C6F6E67626C6F622D74657874207265616461626C65 | 0x74657874207265616461626C65 | 0x01 | 0x63 | 0x7661726961626C65 | 0x000000000101000000000000000000F03F000000000000F03F | ++------------------------------------------------+----------------------------------------+----------------------------------------------------+------------------------------------------------+------------------------------+------------+------------+--------------------+------------------------------------------------------+ ++------+------------------------+------------+ +| id | col1 | col2 | ++------+------------------------+------------+ +| 1 | 0xAB123400000000000000 | 0x123ABC | ++------+------------------------+------------+ + +#Print the table contents vertically + +*************************** 1. row *************************** +c1: 0x74696E79626C6F622D74657874207265616461626C65 +c2: 0x626C6F622D74657874207265616461626C65 +c3: 0x6D656469756D626C6F622D74657874207265616461626C65 +c4: 0x6C6F6E67626C6F622D74657874207265616461626C65 +c5: 0x74657874207265616461626C65 +c6: 0x01 +c7: 0x63 +c8: 0x7661726961626C65 +c9: 0x000000000101000000000000000000F03F000000000000F03F + +#Print the table contents in xml format + + + + + + 0x74696E79626C6F622D74657874207265616461626C65 + 0x626C6F622D74657874207265616461626C65 + 0x6D656469756D626C6F622D74657874207265616461626C65 + 0x6C6F6E67626C6F622D74657874207265616461626C65 + 0x74657874207265616461626C65 + 0x01 + 0x63 + 0x7661726961626C65 + 0x000000000101000000000000000000F03F000000000000F03F + + + + + + + 1 + 0xAB123400000000000000 + 0x123ABC + + + + 2 + 0xDE123400000000000000 + 0x123DEF + + + +#Print the table contents in html format + +
c1c2c3c4c5c6c7c8c9
0x74696E79626C6F622D74657874207265616461626C650x626C6F622D74657874207265616461626C650x6D656469756D626C6F622D74657874207265616461626C650x6C6F6E67626C6F622D74657874207265616461626C650x74657874207265616461626C650x010x630x7661726961626C650x000000000101000000000000000000F03F000000000000F03F
idcol1col2
10xAB1234000000000000000x123ABC
20xDE1234000000000000000x123DEF
DROP TABLE t1, t2; diff --git a/mysql-test/t/binary_to_hex.test b/mysql-test/t/binary_to_hex.test new file mode 100644 index 00000000000..8312a246d0c --- /dev/null +++ b/mysql-test/t/binary_to_hex.test @@ -0,0 +1,76 @@ +# === Purpose === +# The purpose of this test case is to make +# sure that the binary data in tables is printed +# as hex when the option binary-as-hex is enabled. +# +# === Related bugs and/or worklogs === +# Bug #25340722 - PRINT BINARY DATA AS HEX IN THE MYSQL +# CLIENT (CONTRIBUTION) +# + +# Save the initial number of concurrent sessions +--source include/count_sessions.inc +--source include/not_embedded.inc + +USE test; +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +CREATE TABLE t1 (c1 TINYBLOB, + c2 BLOB, + c3 MEDIUMBLOB, + c4 LONGBLOB, + c5 TEXT, + c6 BIT(1), + c7 CHAR, + c8 VARCHAR(10), + c9 GEOMETRY) CHARACTER SET = binary; + +SHOW CREATE TABLE t1; + +INSERT INTO t1 VALUES ('tinyblob-text readable', 'blob-text readable', + 'mediumblob-text readable', 'longblob-text readable', + 'text readable', b'1', 'c', 'variable', + POINT(1, 1)); + +CREATE TABLE t2(id int, `col1` binary(10),`col2` blob); + +SHOW CREATE TABLE t2; + +INSERT INTO t2 VALUES (1, X'AB1234', X'123ABC'), (2, X'DE1234', X'123DEF'); + +--echo #Print the table contents when binary-as-hex option is off. +--replace_column 6 # 9 # +SELECT * FROM t1; + +--replace_column 2 # 3 # +SELECT * FROM t2; + +--echo #Print the table contents after turning on the binary-as-hex option +--echo +--echo #Print the table contents in tab format +--echo +--exec $MYSQL test --binary-as-hex -e "SELECT * FROM t1; SELECT * FROM t2;" +--echo +--echo #Print the table contents in table format +--echo +--exec $MYSQL test --binary-as-hex --table -e "SELECT * FROM t1; SELECT * FROM t2 WHERE col2=0x123ABC;" +--echo +--echo #Print the table contents vertically +--echo +--exec $MYSQL test --binary-as-hex --vertical -e "SELECT * FROM t1;" +--echo +--echo #Print the table contents in xml format +--echo +--exec $MYSQL test --binary-as-hex --xml -e "SELECT * FROM t1; SELECT * FROM t2;" +--echo +--echo #Print the table contents in html format +--echo +--exec $MYSQL test --binary-as-hex --html -e "SELECT * FROM t1; SELECT * FROM t2;" + +#Cleanup +DROP TABLE t1, t2; + +# Wait till all disconnects are completed + --source include/wait_until_count_sessions.inc From 67bec60c726ee25e5c4a82709397c65c4e768e3e Mon Sep 17 00:00:00 2001 From: Balasubramanian Kandasamy Date: Thu, 4 May 2017 16:05:04 +0530 Subject: [PATCH 23/97] Bug#25998285 - ADD MYSQLADMIN DOCKER/MINIMAL SERVER BUILDS - mysqladmin is needed by InnoDB Cluster, add tool to docker/minimal package. --- packaging/rpm-docker/mysql.spec.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/rpm-docker/mysql.spec.in b/packaging/rpm-docker/mysql.spec.in index c5b7c664f59..497ae395577 100644 --- a/packaging/rpm-docker/mysql.spec.in +++ b/packaging/rpm-docker/mysql.spec.in @@ -177,7 +177,7 @@ for f in msql2mysql mysqlaccess mysqlaccess.conf mysqlbug mysql_convert_table_fo rm -f %{buildroot}%{_bindir}/$f done -for f in innochecksum myisamchk myisam_ftdump myisamlog myisampack mysqladmin \ +for f in innochecksum myisamchk myisam_ftdump myisamlog myisampack \ mysqlbinlog mysqlcheck mysql_client_test mysql_config_editor \ mysqld_multi mysqld_safe mysqldumpslow mysql_embedded mysqlimport \ mysql_plugin mysql_secure_installation mysqlshow mysqlslap mysqltest \ @@ -231,6 +231,7 @@ rm -r $(readlink var) var %dir %{_sysconfdir}/my.cnf.d %attr(755, root, root) %{_sbindir}/mysqld %attr(755, root, root) %{_bindir}/mysql +%attr(755, root, root) %{_bindir}/mysqladmin %attr(755, root, root) %{_bindir}/mysqldump %attr(755, root, root) %{_bindir}/mysql_config %attr(755, root, root) %{_bindir}/mysql_install_db From 15f9931f6d2b0eb4006fdc42072c2905fd67c1aa Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 4 May 2017 22:45:32 -0700 Subject: [PATCH 24/97] Fixed the bug mdev-12673. This patch corrects the fix for the bug mdev-10693. It is critical for the function get_best_combination() not to call create_ref_for_key() for constant tables. This bug could manifest itself only in multi-table subqueries where one of the tables is accessed by a constant primary key. --- mysql-test/r/subselect_mat_cost_bugs.result | 42 +++++++++++++++++++++ mysql-test/t/subselect_mat_cost_bugs.test | 39 +++++++++++++++++++ sql/sql_select.cc | 12 +++--- 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/subselect_mat_cost_bugs.result b/mysql-test/r/subselect_mat_cost_bugs.result index 24640154c59..9bfd5bd67b5 100644 --- a/mysql-test/r/subselect_mat_cost_bugs.result +++ b/mysql-test/r/subselect_mat_cost_bugs.result @@ -400,3 +400,45 @@ id select_type table type possible_keys key key_len ref rows Extra select * from t1 where c1 = 'a2' and (c1, c2) not in (select * from t2); c1 c2 drop table t1, t2; +# +# MDEV-12673: cost-based choice between materialization and in-to-exists +# +CREATE TABLE t1 ( +pk1 int, a1 varchar(3), b1 varchar(3), PRIMARY KEY (pk1), KEY(a1), KEY(b1) +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,'foo','bar'),(2,'bar','foo'); +CREATE TABLE t2 (pk2 INT PRIMARY KEY, a2 VARCHAR(3), KEY(a2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,'abc'),(2,'xyz'),(3,'foo'); +SELECT 'qux' IN ( SELECT a1 FROM t1 INNER JOIN t2 WHERE a2 = b1 AND pk2 = 3 ); +'qux' IN ( SELECT a1 FROM t1 INNER JOIN t2 WHERE a2 = b1 AND pk2 = 3 ) +0 +SELECT 'bar' IN ( SELECT a1 FROM t1 INNER JOIN t2 WHERE a2 = b1 AND pk2 = 3 ); +'bar' IN ( SELECT a1 FROM t1 INNER JOIN t2 WHERE a2 = b1 AND pk2 = 3 ) +1 +EXPLAIN +SELECT 'bar' IN ( SELECT a1 FROM t1 INNER JOIN t2 WHERE a2 = b1 AND pk2 = 3 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used +2 SUBQUERY t2 const PRIMARY,a2 PRIMARY 4 const 1 +2 SUBQUERY t1 ref a1,b1 b1 6 const 1 Using where +DROP TABLE t1,t2; +CREATE TABLE t1 (i1 INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 (i2 int, c2 varchar(3), KEY(i2,c2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,'abc'),(2,'foo'); +CREATE TABLE t3 (pk3 int PRIMARY KEY, c3 varchar(3)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (1,'foo'),(2,'bar'); +SELECT * FROM t1 WHERE i1 NOT IN ( +SELECT i2 FROM t2 RIGHT JOIN t3 ON (c3 = c2) WHERE pk3 = i1 +); +i1 +1 +EXPLAIN +SELECT * FROM t1 WHERE i1 NOT IN ( +SELECT i2 FROM t2 RIGHT JOIN t3 ON (c3 = c2) WHERE pk3 = i1 +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +2 DEPENDENT SUBQUERY t3 const PRIMARY PRIMARY 4 const 1 +2 DEPENDENT SUBQUERY t2 index NULL i2 11 NULL 2 Using where; Using index +DROP TABLE t1,t2,t3; diff --git a/mysql-test/t/subselect_mat_cost_bugs.test b/mysql-test/t/subselect_mat_cost_bugs.test index 8205e94b203..316ac707bef 100644 --- a/mysql-test/t/subselect_mat_cost_bugs.test +++ b/mysql-test/t/subselect_mat_cost_bugs.test @@ -424,3 +424,42 @@ explain select * from t1 where c1 = 'a2' and (c1, c2) not in (select * from t2); select * from t1 where c1 = 'a2' and (c1, c2) not in (select * from t2); drop table t1, t2; + +--echo # +--echo # MDEV-12673: cost-based choice between materialization and in-to-exists +--echo # + +CREATE TABLE t1 ( + pk1 int, a1 varchar(3), b1 varchar(3), PRIMARY KEY (pk1), KEY(a1), KEY(b1) +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,'foo','bar'),(2,'bar','foo'); + +CREATE TABLE t2 (pk2 INT PRIMARY KEY, a2 VARCHAR(3), KEY(a2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,'abc'),(2,'xyz'),(3,'foo'); + +SELECT 'qux' IN ( SELECT a1 FROM t1 INNER JOIN t2 WHERE a2 = b1 AND pk2 = 3 ); +SELECT 'bar' IN ( SELECT a1 FROM t1 INNER JOIN t2 WHERE a2 = b1 AND pk2 = 3 ); +EXPLAIN +SELECT 'bar' IN ( SELECT a1 FROM t1 INNER JOIN t2 WHERE a2 = b1 AND pk2 = 3 ); + +DROP TABLE t1,t2; + +CREATE TABLE t1 (i1 INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1); + +CREATE TABLE t2 (i2 int, c2 varchar(3), KEY(i2,c2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,'abc'),(2,'foo'); + +CREATE TABLE t3 (pk3 int PRIMARY KEY, c3 varchar(3)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (1,'foo'),(2,'bar'); + +SELECT * FROM t1 WHERE i1 NOT IN ( + SELECT i2 FROM t2 RIGHT JOIN t3 ON (c3 = c2) WHERE pk3 = i1 +); + +EXPLAIN +SELECT * FROM t1 WHERE i1 NOT IN ( + SELECT i2 FROM t2 RIGHT JOIN t3 ON (c3 = c2) WHERE pk3 = i1 +); + +DROP TABLE t1,t2,t3; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c5f2a83fc01..09e6ece7807 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7844,12 +7844,14 @@ get_best_combination(JOIN *join) { if (j->bush_children) j= j->bush_children->start; - + used_tables|= j->table->map; - if ((keyuse= join->best_positions[tablenr].key) && - create_ref_for_key(join, j, keyuse, TRUE, used_tables)) - DBUG_RETURN(TRUE); // Something went wrong - + if (j->type != JT_CONST && j->type != JT_SYSTEM) + { + if ((keyuse= join->best_positions[tablenr].key) && + create_ref_for_key(join, j, keyuse, TRUE, used_tables)) + DBUG_RETURN(TRUE); // Something went wrong + } if (j->last_leaf_in_bush) j= j->bush_root_tab; } From 6b97fe067db1b1d8e8dee56508e6d78a36e92481 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 9 May 2017 00:41:45 -0700 Subject: [PATCH 25/97] Fixed the bugs mdev-12670 and mdev-12675. The code that blocked conversion of a IN subselect pedicate to a semi-join if it occurred in the ON expression of an outer join did not do it correctly. As a result, the conversion was blocked for IN subselect predicates encountered in ON expressions of INNER joins or in WHERE conditions of mergeable views / derived tables. This patch fixes this problem. --- mysql-test/r/derived_view.result | 38 ++++++++++++ mysql-test/r/limit_rows_examined.result | 5 +- mysql-test/r/subselect_sj.result | 41 ++++++++++++- mysql-test/r/subselect_sj_jcl6.result | 41 ++++++++++++- mysql-test/t/derived_view.test | 30 +++++++++ mysql-test/t/subselect_sj.test | 32 ++++++++++ sql/item_subselect.cc | 2 +- sql/item_subselect.h | 10 ++- sql/opt_subselect.cc | 81 ++++++++++++++++++++++++- 9 files changed, 269 insertions(+), 11 deletions(-) diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result index d993086299e..8af8db15319 100644 --- a/mysql-test/r/derived_view.result +++ b/mysql-test/r/derived_view.result @@ -2579,5 +2579,43 @@ Handler_read_rnd_deleted 0 Handler_read_rnd_next 27 deallocate prepare stmt1; drop table t1,t2; +# +# Bug mdev-12670: mergeable derived / view with subqueries +# subject to semi-join optimizations +# (actually this is a 5.3 bug.) +# +create table t1 (a int) engine=myisam; +insert into t1 values (5),(3),(2),(7),(2),(5),(1); +create table t2 (b int, index idx(b)) engine=myisam; +insert into t2 values (2),(3),(2),(1),(3),(4); +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +analyze table t1,t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +explain select a from t1 where a in (select b from t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where +1 PRIMARY t2 ref idx idx 5 test.t1.a 140 Using index; FirstMatch(t1) +explain select * from (select a from t1 where a in (select b from t2)) t; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t2 ref idx idx 5 test.t1.a 140 Using index; FirstMatch(t1) +create view v1 as select a from t1 where a in (select b from t2); +explain select * from v1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where +1 SIMPLE t2 ref idx idx 5 test.t1.a 140 Using index; FirstMatch(t1) +drop view v1; +drop table t1,t2; set optimizer_switch=@exit_optimizer_switch; set join_cache_level=@exit_join_cache_level; diff --git a/mysql-test/r/limit_rows_examined.result b/mysql-test/r/limit_rows_examined.result index a51798a5883..4e13e04f961 100644 --- a/mysql-test/r/limit_rows_examined.result +++ b/mysql-test/r/limit_rows_examined.result @@ -426,7 +426,7 @@ c1 bb cc Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 18 rows, which exceeds LIMIT ROWS EXAMINED (16). The query result may be incomplete. +Warning 1931 Query execution was interrupted. The query examined at least 17 rows, which exceeds LIMIT ROWS EXAMINED (16). The query result may be incomplete. select * from v1 LIMIT ROWS EXAMINED 11; c1 bb @@ -439,7 +439,8 @@ from (select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp LIMIT ROWS EXAMINED 11; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 +1 SIMPLE eq_ref distinct_key distinct_key 2 func 1 3 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where select * from (select * from t1 diff --git a/mysql-test/r/subselect_sj.result b/mysql-test/r/subselect_sj.result index 50a70a6614a..c14b82f274e 100644 --- a/mysql-test/r/subselect_sj.result +++ b/mysql-test/r/subselect_sj.result @@ -1650,9 +1650,9 @@ CREATE VIEW v1 AS SELECT 1; EXPLAIN SELECT * FROM t1 INNER JOIN t2 ON t2.a != 0 AND t2.a IN (SELECT * FROM v1); id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY system NULL NULL NULL NULL 1 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -2 MATERIALIZED system NULL NULL NULL NULL 1 3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used SELECT * FROM t1 INNER JOIN t2 ON t2.a != 0 AND t2.a IN (SELECT * FROM v1); a a @@ -3060,4 +3060,43 @@ project_number aaa drop table t1, t2, t3; set optimizer_switch= @tmp_mdev6859; +# +# MDEV-12675: subquery subject to semi-join optimizations +# in ON expression of INNER JOIN +# +set @tmp_mdev12675=@@optimizer_switch; +set optimizer_switch=default; +create table t1 (a int) engine=myisam; +insert into t1 values (5),(3),(2),(7),(2),(5),(1); +create table t2 (b int, index idx(b)) engine=myisam; +insert into t2 values (2),(3),(2),(1),(3),(4); +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +analyze table t1,t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +explain +select a from t1, t2 where b between 1 and 2 and a in (select b from t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where +1 PRIMARY t2 ref idx idx 5 test.t1.a 256 Using index; FirstMatch(t1) +1 PRIMARY t2 range idx idx 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +explain +select a from t1 join t2 on b between 1 and 2 and a in (select b from t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where +1 PRIMARY t2 ref idx idx 5 test.t1.a 256 Using index; FirstMatch(t1) +1 PRIMARY t2 range idx idx 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +drop table t1,t2; +set optimizer_switch= @tmp_mdev12675; set optimizer_switch=@subselect_sj_tmp; diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result index ccf348fa311..33fd4c519ff 100644 --- a/mysql-test/r/subselect_sj_jcl6.result +++ b/mysql-test/r/subselect_sj_jcl6.result @@ -1663,9 +1663,9 @@ CREATE VIEW v1 AS SELECT 1; EXPLAIN SELECT * FROM t1 INNER JOIN t2 ON t2.a != 0 AND t2.a IN (SELECT * FROM v1); id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY system NULL NULL NULL NULL 1 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -2 MATERIALIZED system NULL NULL NULL NULL 1 3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used SELECT * FROM t1 INNER JOIN t2 ON t2.a != 0 AND t2.a IN (SELECT * FROM v1); a a @@ -3074,6 +3074,45 @@ project_number aaa drop table t1, t2, t3; set optimizer_switch= @tmp_mdev6859; +# +# MDEV-12675: subquery subject to semi-join optimizations +# in ON expression of INNER JOIN +# +set @tmp_mdev12675=@@optimizer_switch; +set optimizer_switch=default; +create table t1 (a int) engine=myisam; +insert into t1 values (5),(3),(2),(7),(2),(5),(1); +create table t2 (b int, index idx(b)) engine=myisam; +insert into t2 values (2),(3),(2),(1),(3),(4); +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +analyze table t1,t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +explain +select a from t1, t2 where b between 1 and 2 and a in (select b from t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where +1 PRIMARY t2 ref idx idx 5 test.t1.a 256 Using index; FirstMatch(t1) +1 PRIMARY t2 range idx idx 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +explain +select a from t1 join t2 on b between 1 and 2 and a in (select b from t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 Using where +1 PRIMARY t2 ref idx idx 5 test.t1.a 256 Using index; FirstMatch(t1) +1 PRIMARY t2 range idx idx 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +drop table t1,t2; +set optimizer_switch= @tmp_mdev12675; set optimizer_switch=@subselect_sj_tmp; # # BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off diff --git a/mysql-test/t/derived_view.test b/mysql-test/t/derived_view.test index d017f847af9..cdddaf8f9d8 100644 --- a/mysql-test/t/derived_view.test +++ b/mysql-test/t/derived_view.test @@ -1881,6 +1881,36 @@ deallocate prepare stmt1; drop table t1,t2; +--echo # +--echo # Bug mdev-12670: mergeable derived / view with subqueries +--echo # subject to semi-join optimizations +--echo # (actually this is a 5.3 bug.) +--echo # + +create table t1 (a int) engine=myisam; +insert into t1 values (5),(3),(2),(7),(2),(5),(1); +create table t2 (b int, index idx(b)) engine=myisam; +insert into t2 values (2),(3),(2),(1),(3),(4); +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +analyze table t1,t2; + +explain select a from t1 where a in (select b from t2); +explain select * from (select a from t1 where a in (select b from t2)) t; +create view v1 as select a from t1 where a in (select b from t2); +explain select * from v1; + +drop view v1; +drop table t1,t2; + # The following command must be the last one the file set optimizer_switch=@exit_optimizer_switch; set join_cache_level=@exit_join_cache_level; diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test index 51bed53be17..5e9a2c88f22 100644 --- a/mysql-test/t/subselect_sj.test +++ b/mysql-test/t/subselect_sj.test @@ -2769,5 +2769,37 @@ WHERE ( SELECT z.country drop table t1, t2, t3; set optimizer_switch= @tmp_mdev6859; +--echo # +--echo # MDEV-12675: subquery subject to semi-join optimizations +--echo # in ON expression of INNER JOIN +--echo # + +set @tmp_mdev12675=@@optimizer_switch; +set optimizer_switch=default; +create table t1 (a int) engine=myisam; +insert into t1 values (5),(3),(2),(7),(2),(5),(1); +create table t2 (b int, index idx(b)) engine=myisam; +insert into t2 values (2),(3),(2),(1),(3),(4); +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +insert into t2 select b+10 from t2; +analyze table t1,t2; + +explain +select a from t1, t2 where b between 1 and 2 and a in (select b from t2); +explain +select a from t1 join t2 on b between 1 and 2 and a in (select b from t2); + +drop table t1,t2; +set optimizer_switch= @tmp_mdev12675; + # The following command must be the last one the file set optimizer_switch=@subselect_sj_tmp; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 78dcfc4215c..12337ec2b1c 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1366,7 +1366,7 @@ Item_in_subselect::Item_in_subselect(Item * left_exp, Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE), in_strategy(SUBS_NOT_TRANSFORMED), optimizer(0), pushed_cond_guards(NULL), emb_on_expr_nest(NULL), - is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE), + do_not_convert_to_sj(FALSE), is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE), is_flattenable_semijoin(FALSE), is_registered_semijoin(FALSE), upper_item(0) diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 2f166c83e8f..75822ff8c6b 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -466,6 +466,8 @@ public: NULL - for all other locations */ TABLE_LIST *emb_on_expr_nest; + /* May be TRUE only for the candidates to semi-join conversion */ + bool do_not_convert_to_sj; /* Types of left_expr and subquery's select list allow to perform subquery materialization. Currently, we set this to FALSE when it as well could @@ -554,9 +556,9 @@ public: Item_in_subselect() :Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE), abort_on_null(0), in_strategy(SUBS_NOT_TRANSFORMED), optimizer(0), - pushed_cond_guards(NULL), func(NULL), emb_on_expr_nest(NULL), - is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE), - upper_item(0) + pushed_cond_guards(NULL), func(NULL), emb_on_expr_nest(NULL), + do_not_convert_to_sj(FALSE), is_jtbm_merged(FALSE), + is_jtbm_const_tab(FALSE), upper_item(0) {} void cleanup(); subs_type substype() { return IN_SUBS; } @@ -617,6 +619,8 @@ public: emb_on_expr_nest= embedding; } + void block_conversion_to_sj () { do_not_convert_to_sj= TRUE; } + bool test_strategy(uchar strategy) { return test(in_strategy & strategy); } diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 5137d8a0986..645afa6744a 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -678,6 +678,7 @@ int check_and_do_in_subquery_rewrites(JOIN *join) !((join->select_options | // 10 select_lex->outer_select()->join->select_options) // 10 & SELECT_STRAIGHT_JOIN)) // 10 + { DBUG_PRINT("info", ("Subquery is semi-join conversion candidate")); @@ -1000,6 +1001,25 @@ bool check_for_outer_joins(List *join_list) } +void find_and_block_conversion_to_sj(Item *to_find, + List_iterator_fast &li) +{ + if (to_find->type() != Item::SUBSELECT_ITEM || + ((Item_subselect *) to_find)->substype() != Item_subselect::IN_SUBS) + return; + Item_in_subselect *in_subq; + li.rewind(); + while ((in_subq= li++)) + { + if (in_subq == to_find) + { + in_subq->block_conversion_to_sj(); + return; + } + } +} + + /* Convert semi-join subquery predicates into semi-join join nests @@ -1052,7 +1072,6 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) Query_arena *arena, backup; Item_in_subselect *in_subq; THD *thd= join->thd; - List_iterator ti(join->select_lex->leaf_tables); DBUG_ENTER("convert_join_subqueries_to_semijoins"); if (join->select_lex->sj_subselects.is_empty()) @@ -1070,6 +1089,60 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) subq_sel->update_used_tables(); } + /* + Check all candidates to semi-join conversion that occur + in ON expressions of outer join. Set the flag blocking + this conversion for them. + */ + TABLE_LIST *tbl; + List_iterator ti(join->select_lex->leaf_tables); + while ((tbl= ti++)) + { + TABLE_LIST *embedded; + TABLE_LIST *embedding= tbl; + do + { + embedded= embedding; + if (test(embedded->outer_join)) + { + Item *cond= embedded->on_expr; + if (!cond) + ; + else if (cond->type() != Item::COND_ITEM) + find_and_block_conversion_to_sj(cond, li); + else if (((Item_cond*) cond)->functype() == + Item_func::COND_AND_FUNC) + { + Item *item; + List_iterator it(*(((Item_cond*) cond)->argument_list())); + while ((item= it++)) + { + find_and_block_conversion_to_sj(item, li); + } + } + } + embedding= embedded->embedding; + } + while (embedding && + embedding->nested_join->join_list.head() == embedded); + } + + /* + Block conversion to semi-joins for those candidates that + are encountered in the WHERE condition of the multi-table view + with CHECK OPTION if this view is used in UPDATE/DELETE. + (This limitation can be, probably, easily lifted.) + */ + li.rewind(); + while ((in_subq= li++)) + { + if (in_subq->emb_on_expr_nest != NO_JOIN_NEST && + in_subq->emb_on_expr_nest->effective_with_check) + { + in_subq->block_conversion_to_sj(); + } + } + li.rewind(); /* First, convert child join's subqueries. We proceed bottom-up here */ while ((in_subq= li++)) @@ -1088,8 +1161,10 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) if (convert_join_subqueries_to_semijoins(child_join)) DBUG_RETURN(TRUE); + + in_subq->sj_convert_priority= - test(in_subq->emb_on_expr_nest != NO_JOIN_NEST) * MAX_TABLES * 2 + + test(in_subq->do_not_convert_to_sj) * MAX_TABLES * 2 + in_subq->is_correlated * MAX_TABLES + child_join->outer_tables; } @@ -1122,7 +1197,7 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) bool remove_item= TRUE; /* Stop processing if we've reached a subquery that's attached to the ON clause */ - if (in_subq->emb_on_expr_nest != NO_JOIN_NEST) + if (in_subq->do_not_convert_to_sj) break; if (in_subq->is_flattenable_semijoin) From b615c3dff885b1ce44fa2275aec8f04c8963ea75 Mon Sep 17 00:00:00 2001 From: Nisha Gopalakrishnan Date: Fri, 12 May 2017 09:47:48 +0530 Subject: [PATCH 26/97] BUG#25451091:CREATE TABLE DATA DIRECTORY / INDEX DIRECTORY SYMLINK CHECK RACE CONDITIONS ANALYSIS: ========= A potential defect exists in the handling of CREATE TABLE .. DATA DIRECTORY/ INDEX DIRECTORY which gives way to the user to gain access to another user table or a system table. FIX: ==== The lstat and fstat output of the target files are now stored which help in determining the identity of the target files thus preventing the unauthorized access to other files. --- include/my_sys.h | 16 ++++++++-- mysys/my_symlink.c | 30 +++++++++++++++++-- storage/myisam/mi_delete_table.c | 6 ++-- storage/myisam/mi_open.c | 50 +++++++++++++++++++++++++------- 4 files changed, 83 insertions(+), 19 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index 472c2ba5ca0..9983ee3319f 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,6 +49,7 @@ typedef struct my_aio_result { #ifdef _WIN32 #include /*for alloca*/ #endif +#include #define MY_INIT(name) { my_progname= name; my_init(); } @@ -491,6 +492,16 @@ typedef struct st_io_cache /* Used when cacheing files */ typedef int (*qsort2_cmp)(const void *, const void *, const void *); +/* + Subset of struct stat fields filled by stat/lstat/fstat that uniquely + identify a file +*/ +typedef struct st_file_id +{ + dev_t st_dev; + ino_t st_ino; +} ST_FILE_ID; + /* defines for mf_iocache */ /* Test if buffer is inited */ @@ -569,8 +580,9 @@ extern File my_create(const char *FileName,int CreateFlags, extern int my_close(File Filedes,myf MyFlags); extern int my_mkdir(const char *dir, int Flags, myf MyFlags); extern int my_readlink(char *to, const char *filename, myf MyFlags); -extern int my_is_symlink(const char *filename); +extern int my_is_symlink(const char *filename, ST_FILE_ID *file_id); extern int my_realpath(char *to, const char *filename, myf MyFlags); +extern int my_is_same_file(File file, const ST_FILE_ID *file_id); extern File my_create_with_symlink(const char *linkname, const char *filename, int createflags, int access_flags, myf MyFlags); diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c index cdb16a7422b..4569fcf7fbf 100644 --- a/mysys/my_symlink.c +++ b/mysys/my_symlink.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -99,11 +99,18 @@ int my_symlink(const char *content, const char *linkname, myf MyFlags) #endif -int my_is_symlink(const char *filename __attribute__((unused))) +int my_is_symlink(const char *filename __attribute__((unused)), + ST_FILE_ID *file_id) { #if defined (HAVE_LSTAT) && defined (S_ISLNK) struct stat stat_buff; - return !lstat(filename, &stat_buff) && S_ISLNK(stat_buff.st_mode); + int result= !lstat(filename, &stat_buff) && S_ISLNK(stat_buff.st_mode); + if (file_id && !result) + { + file_id->st_dev= stat_buff.st_dev; + file_id->st_ino= stat_buff.st_ino; + } + return result; #elif defined (_WIN32) DWORD dwAttr = GetFileAttributes(filename); return (dwAttr != INVALID_FILE_ATTRIBUTES) && @@ -164,3 +171,20 @@ int my_realpath(char *to, const char *filename, myf MyFlags) #endif return 0; } + + +/** + Return non-zero if the file descriptor and a previously lstat-ed file + identified by file_id point to the same file +*/ +int my_is_same_file(File file, const ST_FILE_ID *file_id) +{ + MY_STAT stat_buf; + if (my_fstat(file, &stat_buf, MYF(0)) == -1) + { + my_errno= errno; + return 0; + } + return (stat_buf.st_dev == file_id->st_dev) + && (stat_buf.st_ino == file_id->st_ino); +} diff --git a/storage/myisam/mi_delete_table.c b/storage/myisam/mi_delete_table.c index b6530334dd2..768b4618928 100644 --- a/storage/myisam/mi_delete_table.c +++ b/storage/myisam/mi_delete_table.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ int mi_delete_table(const char *name) #endif fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_is_symlink(from) && (*myisam_test_invalid_symlink)(from)) + if (my_is_symlink(from, NULL) && (*myisam_test_invalid_symlink)(from)) { /* Symlink is pointing to file in data directory. @@ -44,7 +44,7 @@ int mi_delete_table(const char *name) DBUG_RETURN(my_errno); } fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); - if (my_is_symlink(from) && (*myisam_test_invalid_symlink)(from)) + if (my_is_symlink(from, NULL) && (*myisam_test_invalid_symlink)(from)) { /* Symlink is pointing to file in data directory. diff --git a/storage/myisam/mi_open.c b/storage/myisam/mi_open.c index 93f70a5d340..1f0cc8e2169 100644 --- a/storage/myisam/mi_open.c +++ b/storage/myisam/mi_open.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -78,6 +78,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) ulong rec_per_key_part[HA_MAX_POSSIBLE_KEY*MI_MAX_KEY_SEG]; my_off_t key_root[HA_MAX_POSSIBLE_KEY],key_del[MI_MAX_KEY_BLOCK_SIZE]; ulonglong max_key_file_length, max_data_file_length; + ST_FILE_ID file_id= {0, 0}; DBUG_ENTER("mi_open"); LINT_INIT(m_info); @@ -89,11 +90,15 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) realpath_err= my_realpath(name_buff, fn_format(org_name,name,"",MI_NAME_IEXT,4),MYF(0)); - if (my_is_symlink(org_name) && - (realpath_err || (*myisam_test_invalid_symlink)(name_buff))) + if (my_is_symlink(name_buff, &file_id)) { - my_errno= HA_WRONG_CREATE_OPTION; - DBUG_RETURN (NULL); + if (realpath_err || + (*myisam_test_invalid_symlink)(name_buff) || + my_is_symlink(name_buff, &file_id)) + { + my_errno= HA_WRONG_CREATE_OPTION; + DBUG_RETURN (NULL); + } } mysql_mutex_lock(&THR_LOCK_myisam); @@ -113,17 +118,28 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) my_errno= HA_ERR_CRASHED; goto err; }); + DEBUG_SYNC_C("before_opening_indexfile"); if ((kfile= mysql_file_open(mi_key_file_kfile, name_buff, - (open_mode= O_RDWR) | O_SHARE, MYF(0))) < 0) + (open_mode= O_RDWR) | O_SHARE | O_NOFOLLOW, + MYF(0))) < 0) { if ((errno != EROFS && errno != EACCES) || mode != O_RDONLY || (kfile= mysql_file_open(mi_key_file_kfile, name_buff, - (open_mode= O_RDONLY) | O_SHARE, MYF(0))) < 0) + (open_mode= O_RDONLY) | O_SHARE | O_NOFOLLOW, + MYF(0))) < 0) goto err; } + + if (!my_is_same_file(kfile, &file_id)) + { + mysql_file_close(kfile, MYF(0)); + my_errno= HA_WRONG_CREATE_OPTION; + goto err; + } + share->mode=open_mode; errpos=1; if (mysql_file_read(kfile, share->state.header.file_version, head_length, @@ -1206,14 +1222,16 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name, { char *data_name= share->data_file_name; char real_data_name[FN_REFLEN]; + ST_FILE_ID file_id= {0, 0}; if (org_name) { fn_format(real_data_name,org_name,"",MI_NAME_DEXT,4); - if (my_is_symlink(real_data_name)) + if (my_is_symlink(real_data_name, &file_id)) { if (my_realpath(real_data_name, real_data_name, MYF(0)) || - (*myisam_test_invalid_symlink)(real_data_name)) + (*myisam_test_invalid_symlink)(real_data_name) || + my_is_symlink(real_data_name, &file_id)) { my_errno= HA_WRONG_CREATE_OPTION; return 1; @@ -1221,9 +1239,19 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name, data_name= real_data_name; } } + DEBUG_SYNC_C("before_opening_datafile"); info->dfile= mysql_file_open(mi_key_file_dfile, - data_name, share->mode | O_SHARE, MYF(MY_WME)); - return info->dfile >= 0 ? 0 : 1; + data_name, share->mode | O_SHARE | O_NOFOLLOW, + MYF(MY_WME)); + if (info->dfile < 0) + return 1; + if (org_name && !my_is_same_file(info->dfile, &file_id)) + { + mysql_file_close(info->dfile, MYF(0)); + my_errno= HA_WRONG_CREATE_OPTION; + return 1; + } + return 0; } From 9495e018fbd88d094a71cb054cf468c31ebd6957 Mon Sep 17 00:00:00 2001 From: Sachin Setiya Date: Fri, 12 May 2017 11:09:27 +0530 Subject: [PATCH 27/97] MDEV-11718 Post-fix A better way of finding mysqld --- mysql-test/mysql-test-run.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 0d9626b77e1..1e27f31989f 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -6190,7 +6190,8 @@ sub valgrind_arguments { mtr_add_arg($args, "--num-callers=16"); mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir) if -f "$glob_mysql_test_dir/valgrind.supp"; - my $temp= `ldd $ENV{MTR_BINDIR}/sql/mysqld | grep 'libjemalloc'`; + my $exe_mysqld= find_mysqld($bindir) || ""; + my $temp= `ldd $exe_mysqld | grep 'libjemalloc'`; if ($temp) { mtr_add_arg($args, "--soname-synonyms=somalloc=libjemalloc*"); From af676805109135fba189410e90cd753ff4fc22b5 Mon Sep 17 00:00:00 2001 From: "mysql-builder@oracle.com" <> Date: Sat, 13 May 2017 10:22:46 +0530 Subject: [PATCH 28/97] From e0352fb07961f09ff6481136dc22f3c0db376def Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 15 May 2017 09:51:01 -0700 Subject: [PATCH 29/97] Fixed the bug mdev-7599. At some conditions the function opt_sum_query() can apply MIN/MAX optimizations to to Item_sum objects of a select These optimizations becomes invalid if this select is the subquery of an IN subquery predicate that is converted to a EXISTS subquery. Thus in this case the MIX/MAX optimizations that have been applied in opt_sum_query() must be rolled back. This bug appeared in 5.3 when the code for the cost base choice between materialization and in-to-exists transformation of non-correlated IN subqueries was introduced. Before this code in-to-exists transformations were always performed before the call of opt_sum_query(). --- mysql-test/r/subselect_mat_cost_bugs.result | 43 ++++++++++++++++++++ mysql-test/t/subselect_mat_cost_bugs.test | 44 +++++++++++++++++++++ sql/item_subselect.cc | 21 ++++++++++ sql/item_sum.h | 1 + sql/opt_sum.cc | 9 +++++ sql/sql_lex.cc | 1 + sql/sql_lex.h | 5 +++ 7 files changed, 124 insertions(+) diff --git a/mysql-test/r/subselect_mat_cost_bugs.result b/mysql-test/r/subselect_mat_cost_bugs.result index 9bfd5bd67b5..dba4d049da3 100644 --- a/mysql-test/r/subselect_mat_cost_bugs.result +++ b/mysql-test/r/subselect_mat_cost_bugs.result @@ -379,6 +379,7 @@ drop table t3, t4, t5; # # LP BUG#858038 The result of a query with NOT IN subquery depends on the state of the optimizer switch # +set @optimizer_switch_save= @@optimizer_switch; create table t1 (c1 char(2) not null, c2 char(2)); create table t2 (c3 char(2), c4 char(2)); insert into t1 values ('a1', 'b1'); @@ -400,6 +401,7 @@ id select_type table type possible_keys key key_len ref rows Extra select * from t1 where c1 = 'a2' and (c1, c2) not in (select * from t2); c1 c2 drop table t1, t2; +set optimizer_switch= @optimizer_switch_save; # # MDEV-12673: cost-based choice between materialization and in-to-exists # @@ -442,3 +444,44 @@ id select_type table type possible_keys key key_len ref rows Extra 2 DEPENDENT SUBQUERY t3 const PRIMARY PRIMARY 4 const 1 2 DEPENDENT SUBQUERY t2 index NULL i2 11 NULL 2 Using where; Using index DROP TABLE t1,t2,t3; +# +# MDEV-7599: in-to-exists chosen after min/max optimization +# +set @optimizer_switch_save= @@optimizer_switch; +CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT, c INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,6),(2,4), (8,9); +SELECT * FROM t2 WHERE b != ALL (SELECT MIN(a) FROM t1, t2 WHERE t2.c = t2.b); +b c +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b != ALL (SELECT MIN(a) FROM t1, t2 WHERE t2.c = t2.b); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t1 index NULL a 5 NULL 2 100.00 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where (not(<`test`.`t2`.`b`>((`test`.`t2`.`b`,`test`.`t2`.`b` in ( (select min(`test`.`t1`.`a`) from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`c` = `test`.`t2`.`b`) ), (`test`.`t2`.`b` in on distinct_key where ((`test`.`t2`.`b` = ``.`MIN(a)`)))))))) +set optimizer_switch= 'materialization=off'; +SELECT * FROM t2 WHERE b != ALL (SELECT MIN(a) FROM t1, t2 WHERE t2.c = t2.b); +b c +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b != ALL (SELECT MIN(a) FROM t1, t2 WHERE t2.c = t2.b); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t1 index NULL a 5 NULL 2 100.00 Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where (not(<`test`.`t2`.`b`>((`test`.`t2`.`b`,(select min(`test`.`t1`.`a`) from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`c` = `test`.`t2`.`b`) having trigcond(((`test`.`t2`.`b`) = (min(`test`.`t1`.`a`))))))))) +set optimizer_switch= @optimizer_switch_save; +DROP TABLE t1,t2; +CREATE TABLE t1 (f1 varchar(10)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo'),('bar'); +CREATE TABLE t2 (f2 varchar(10), key(f2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('baz'),('qux'); +CREATE TABLE t3 (f3 varchar(10)) ENGINE=MyISAM; +INSERT INTO t3 VALUES ('abc'),('def'); +SELECT * FROM t1 +WHERE f1 = ALL( SELECT MAX(t2a.f2) +FROM t2 AS t2a INNER JOIN t2 t2b INNER JOIN t3 +ON (f3 = t2b.f2) ); +f1 +DROP TABLE t1,t2,t3; diff --git a/mysql-test/t/subselect_mat_cost_bugs.test b/mysql-test/t/subselect_mat_cost_bugs.test index 316ac707bef..9e3ac603ec6 100644 --- a/mysql-test/t/subselect_mat_cost_bugs.test +++ b/mysql-test/t/subselect_mat_cost_bugs.test @@ -406,6 +406,8 @@ drop table t3, t4, t5; --echo # LP BUG#858038 The result of a query with NOT IN subquery depends on the state of the optimizer switch --echo # +set @optimizer_switch_save= @@optimizer_switch; + create table t1 (c1 char(2) not null, c2 char(2)); create table t2 (c3 char(2), c4 char(2)); @@ -425,6 +427,8 @@ select * from t1 where c1 = 'a2' and (c1, c2) not in (select * from t2); drop table t1, t2; +set optimizer_switch= @optimizer_switch_save; + --echo # --echo # MDEV-12673: cost-based choice between materialization and in-to-exists --echo # @@ -463,3 +467,43 @@ SELECT * FROM t1 WHERE i1 NOT IN ( ); DROP TABLE t1,t2,t3; + +--echo # +--echo # MDEV-7599: in-to-exists chosen after min/max optimization +--echo # + +set @optimizer_switch_save= @@optimizer_switch; + +CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); + +CREATE TABLE t2 (b INT, c INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,6),(2,4), (8,9); + +let $q= +SELECT * FROM t2 WHERE b != ALL (SELECT MIN(a) FROM t1, t2 WHERE t2.c = t2.b); + +eval $q; +eval EXPLAIN EXTENDED $q; +set optimizer_switch= 'materialization=off'; +eval $q; +eval EXPLAIN EXTENDED $q; +set optimizer_switch= @optimizer_switch_save; + +DROP TABLE t1,t2; + +CREATE TABLE t1 (f1 varchar(10)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo'),('bar'); + +CREATE TABLE t2 (f2 varchar(10), key(f2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('baz'),('qux'); + +CREATE TABLE t3 (f3 varchar(10)) ENGINE=MyISAM; +INSERT INTO t3 VALUES ('abc'),('def'); + +SELECT * FROM t1 + WHERE f1 = ALL( SELECT MAX(t2a.f2) + FROM t2 AS t2a INNER JOIN t2 t2b INNER JOIN t3 + ON (f3 = t2b.f2) ); + +DROP TABLE t1,t2,t3; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 12337ec2b1c..e0da946d190 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -2493,6 +2493,27 @@ bool Item_in_subselect::inject_in_to_exists_cond(JOIN *join_arg) DBUG_ENTER("Item_in_subselect::inject_in_to_exists_cond"); DBUG_ASSERT(thd == join_arg->thd); + if (select_lex->min_max_opt_list.elements) + { + /* + MIN/MAX optimizations have been applied to Item_sum objects + of the subquery this subquery predicate in opt_sum_query(). + Injection of new condition invalidates this optimizations. + Thus those optimizations must be rolled back. + */ + List_iterator_fast it(select_lex->min_max_opt_list); + Item_sum *item; + while ((item= it++)) + { + item->clear(); + item->reset_forced_const(); + } + if (where_item) + where_item->update_used_tables(); + if (having_item) + having_item->update_used_tables(); + } + if (where_item) { List *and_args= NULL; diff --git a/sql/item_sum.h b/sql/item_sum.h index 86093f5d4f5..dcc3e494f82 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -454,6 +454,7 @@ public: used_tables_cache= 0; forced_const= TRUE; } + void reset_forced_const() { forced_const= FALSE; } virtual bool const_item() const { return forced_const; } virtual bool const_during_execution() const { return false; } virtual void print(String *str, enum_query_type query_type); diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index aa8b17a2c85..1a8c6be5f41 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -253,6 +253,8 @@ int opt_sum_query(THD *thd, int error= 0; DBUG_ENTER("opt_sum_query"); + thd->lex->current_select->min_max_opt_list.empty(); + if (conds) where_tables= conds->used_tables(); @@ -444,7 +446,14 @@ int opt_sum_query(THD *thd, item_sum->aggregator_clear(); } else + { item_sum->reset_and_add(); + /* + Save a reference to the item for possible rollback + of the min/max optimizations for this select + */ + thd->lex->current_select->min_max_opt_list.push_back(item_sum); + } item_sum->make_const(); recalc_const_item= 1; break; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index fa866bc7008..6611fd43876 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1875,6 +1875,7 @@ void st_select_lex::init_query() leaf_tables_prep.empty(); leaf_tables.empty(); item_list.empty(); + min_max_opt_list.empty(); join= 0; having= prep_having= where= prep_where= 0; olap= UNSPECIFIED_OLAP_TYPE; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index b13befd8dbe..d283085886e 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -766,6 +766,11 @@ public: */ List *ftfunc_list; List ftfunc_list_alloc; + /* + The list of items to which MIN/MAX optimizations of opt_sum_query() + have been applied. Used to rollback those optimizations if it's needed. + */ + List min_max_opt_list; JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */ List top_join_list; /* join list of the top level */ List *join_list; /* list for the currently parsed join */ From 2e1428c0b552f2c80aa4b27edaaab8bde8966b22 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 15 May 2017 13:33:59 +0200 Subject: [PATCH 30/97] MDEV-12799 Buffer overflow with a specially corrupted master.info one can get an invalid heartbeat_period that will trigger a heap overflow. --- sql/rpl_mi.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index 3c5a99121fa..13284308f04 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -401,7 +401,7 @@ file '%s')", fname); mi->connect_retry= (uint) connect_retry; mi->ssl= (my_bool) ssl; mi->ssl_verify_server_cert= ssl_verify_server_cert; - mi->heartbeat_period= master_heartbeat_period; + mi->heartbeat_period= min(SLAVE_MAX_HEARTBEAT_PERIOD, master_heartbeat_period); } DBUG_PRINT("master_info",("log_file_name: %s position: %ld", mi->master_log_name, @@ -518,8 +518,8 @@ int flush_master_info(Master_info* mi, contents of file). But because of number of lines in the first line of file we don't care about this garbage. */ - char heartbeat_buf[sizeof(mi->heartbeat_period) * 4]; // buffer to suffice always - sprintf(heartbeat_buf, "%.3f", mi->heartbeat_period); + char heartbeat_buf[FLOATING_POINT_BUFFER]; + my_fcvt(mi->heartbeat_period, 3, heartbeat_buf, NULL); my_b_seek(file, 0L); my_b_printf(file, "%u\n%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n%s\n%s\n%s\n%s\n%s\n%d\n%s\n%s\n%s\n", From f4ce18b0a6954c01579698d2865e5c3aa8763df7 Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Wed, 26 Apr 2017 12:45:38 +0200 Subject: [PATCH 31/97] Bug #25436469: BUILDS ARE NOT REPRODUCIBLE Backport to 5.5 Current MySQL builds, even on Pushbuild, are not reproducible; they return different results depending on which directory they are built from (and Pushbuild uses several different directories). This is because absolute paths leak into debug information, and even worse, __FILE__. The latter moves code around enough that we've actually seen sysbench changes on the order of 4% in some tests. CMake seemingly insists on using absolute paths, but we can insert our own layer between CMake and GCC to relativize all paths. Also give the right flags to get debug information reproducible and turn off build stamping. This makes the mysqld build 100% bit-for-bit reproducible between runs on my machine, even when run from different directories. --- CMakeLists.txt | 30 +++++++++ scripts/invoke-with-relative-paths.pl | 95 +++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100755 scripts/invoke-with-relative-paths.pl diff --git a/CMakeLists.txt b/CMakeLists.txt index ba5e60f6146..154273576d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,36 @@ IF (ENABLE_GCOV AND NOT WIN32 AND NOT APPLE) SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov") ENDIF() +IF(CMAKE_SYSTEM_NAME MATCHES "Linux") + OPTION(REPRODUCIBLE_BUILD "Take extra pains to make build result independent of build location and time" OFF) +ENDIF() +IF(REPRODUCIBLE_BUILD) + SET(DEBUG_PREFIX_FLAGS + "-fdebug-prefix-map=${CMAKE_SOURCE_DIR}/=./ -fdebug-prefix-map=${CMAKE_CURRENT_BINARY_DIR}=./obj") + + # See if -fdebug-prefix= commands are included in the debug output, + # making the build unreproducible with switches recorded. + # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69821. + EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -g3 -x c -S -fdebug-prefix-map=foo=bar -o - - + INPUT_FILE /dev/null OUTPUT_VARIABLE DEBUG_PREFIX_MAP_RESULT) + IF(DEBUG_PREFIX_MAP_RESULT MATCHES "foo=bar") + SET(DEBUG_PREFIX_FLAGS "${DEBUG_PREFIX_FLAGS} -gno-record-gcc-switches") + ENDIF() + + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_PREFIX_FLAGS}") + SET(CMAKE_C_FLAGS_RELWITHDEBINFO + "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${DEBUG_PREFIX_FLAGS}") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_PREFIX_FLAGS}") + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO + "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${DEBUG_PREFIX_FLAGS}") + + SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--build-id=none") + SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--build-id=none") + + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE + "${CMAKE_SOURCE_DIR}/scripts/invoke-with-relative-paths.pl") +ENDIF() + OPTION(ENABLED_LOCAL_INFILE "If we should should enable LOAD DATA LOCAL by default" ${IF_WIN}) MARK_AS_ADVANCED(ENABLED_LOCAL_INFILE) diff --git a/scripts/invoke-with-relative-paths.pl b/scripts/invoke-with-relative-paths.pl new file mode 100755 index 00000000000..97480330b7f --- /dev/null +++ b/scripts/invoke-with-relative-paths.pl @@ -0,0 +1,95 @@ +#! /usr/bin/perl +# +# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA +# + +# +# Take the given GCC command line and run it with all absolute paths +# changed to relative paths. This makes sure that no part of the build +# path leaks into the .o files, which it normally would through the +# contents of __FILE__. (Debug information is also affected, but that +# is already fixed through -fdebug-prefix-map=.) +# +# A more elegant solution would be -ffile-prefix-map=, but this is +# not currently supported in GCC; see +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70268. +# + +use strict; +use warnings; +use Cwd; + +my $cwd = getcwd(); + +my @newarg = (); +for my $i (0..$#ARGV) { + my $arg = $ARGV[$i]; + if ($arg =~ /-I(.+)$/) { + $arg = '-I' . relativize($1, $cwd); + } elsif ($arg =~ /^\//) { + $arg = relativize($arg, $cwd); + } + push @newarg, $arg; +} + +exec(@newarg); + +# /a/b/c/foo from /a/b/d = ../c/foo +sub relativize { + my ($dir1, $dir2) = @_; + + if ($dir1 !~ /^\//) { + # Not an absolute path. + return $dir1; + } + + if (! -e $dir1) { +# print STDERR "Unknown file/directory $dir1.\n"; + return $dir1; + } + # Resolve symlinks and such, because getcwd() does. + $dir1 = Cwd::abs_path($dir1); + + if ($dir1 =~ /^\/(lib|tmp|usr)/) { + # Not related to our source code. + return $dir1; + } + + if ($dir1 eq $dir2) { + return "."; + } + + my (@dir1_components) = split /\//, $dir1; + my (@dir2_components) = split /\//, $dir2; + + # Remove common leading components. + while (scalar @dir1_components > 0 && scalar @dir2_components > 0 && + $dir1_components[0] eq $dir2_components[0]) { + shift @dir1_components; + shift @dir2_components; + } + + my $ret = ""; + for my $i (0..$#dir2_components) { + $ret .= '../'; + } + $ret .= join('/', @dir1_components); + + # print STDERR "[$dir1] from [$dir2] => [$ret]\n"; + + return $ret; +} + From 3b562dcf6e5423d41d41ef416c18187c3a946d9e Mon Sep 17 00:00:00 2001 From: Shishir Jaiswal Date: Tue, 16 May 2017 13:48:52 +0530 Subject: [PATCH 32/97] Bug#16212207 - LOAD XML INFILE PERFORMANCE WITH INDENTED XML DESCRIPTION =========== LOAD XML INFILE performance becomes painfully slow if the tags' value has any space(s) in between them. They're usually kept intentionally for indentation purpose. ANALYSIS ======== The extra spaces are calling clear_level() many a times which is having overhead of clearing taglist etc. This can be avoided altogether by skipping all such spaces. FIX === Trim all the starting whitespaces from the value before passing it to read_value() --- sql/sql_load.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sql/sql_load.cc b/sql/sql_load.cc index c28c7cdb2db..a2c01c3b8a8 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1989,6 +1989,13 @@ int READ_INFO::read_xml() case '>': /* end tag - read tag value */ in_tag= false; + /* Skip all whitespaces */ + while (' ' == (chr= my_tospace(GET))); + /* + Push the first non-whitespace char back to Stack. This char would be + read in the upcoming call to read_value() + */ + PUSH(chr); chr= read_value('<', &value); if(chr == my_b_EOF) goto found_eof; From 934b8312817d4e8e0387fae0bd9cca3ffafbc7de Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Tue, 16 May 2017 08:24:42 -0700 Subject: [PATCH 33/97] Fixed the bug mdev-7791. When an IN subquery predicate was converted to a semi-join that were materialized and the result of the materialization happened to be the last in the execution plan then any conjunctive condition with RAND() turned out to be lost. Fixed by attaching this condition to the last top base table. --- mysql-test/r/subselect_sj2_mat.result | 23 +++++++++++++++++++++++ mysql-test/t/subselect_sj2_mat.test | 20 ++++++++++++++++++++ sql/sql_select.cc | 18 +++++++++++++----- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/subselect_sj2_mat.result b/mysql-test/r/subselect_sj2_mat.result index 4e75aee24a2..202e6cc4b9e 100644 --- a/mysql-test/r/subselect_sj2_mat.result +++ b/mysql-test/r/subselect_sj2_mat.result @@ -1556,3 +1556,26 @@ i1 DROP TABLE t1,t2,t3; set join_cache_level= @save_join_cache_level; set optimizer_switch=@save_optimizer_switch; +# +# mdev-7791: materialization of a semi-join subquery + +# RAND() in WHERE +# (materialized table is accessed last) +# +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='materialization=on'; +create table t1(i int); +insert into t1 values (1), (2), (3), (7), (9), (10); +create table t2(i int); +insert into t2 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +select * from t1 where (rand() < 0) and i in (select i from t2); +i +explain extended +select * from t1 where (rand() < 0) and i in (select i from t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where +1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 10 100.00 +Warnings: +Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` semi join (`test`.`t2`) where ((rand() < 0)) +drop table t1,t2; +set optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/t/subselect_sj2_mat.test b/mysql-test/t/subselect_sj2_mat.test index 61d9b09edff..0f2892ae2dc 100644 --- a/mysql-test/t/subselect_sj2_mat.test +++ b/mysql-test/t/subselect_sj2_mat.test @@ -263,3 +263,23 @@ DROP TABLE t1,t2,t3; set join_cache_level= @save_join_cache_level; set optimizer_switch=@save_optimizer_switch; +--echo # +--echo # mdev-7791: materialization of a semi-join subquery + +--echo # RAND() in WHERE +--echo # (materialized table is accessed last) +--echo # + +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='materialization=on'; + +create table t1(i int); +insert into t1 values (1), (2), (3), (7), (9), (10); +create table t2(i int); +insert into t2 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); + +select * from t1 where (rand() < 0) and i in (select i from t2); +explain extended +select * from t1 where (rand() < 0) and i in (select i from t2); + +drop table t1,t2; +set optimizer_switch=@save_optimizer_switch; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 09e6ece7807..bad57aeac87 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8761,12 +8761,20 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) /* Step #2: Extract WHERE/ON parts */ + uint i; + for (i= join->top_join_tab_count - 1; i >= join->const_tables; i--) + { + if (!join->join_tab[i].bush_children) + break; + } + uint last_top_base_tab_idx= i; + table_map save_used_tables= 0; used_tables=((select->const_tables=join->const_table_map) | OUTER_REF_TABLE_BIT | RAND_TABLE_BIT); JOIN_TAB *tab; table_map current_map; - uint i= join->const_tables; + i= join->const_tables; for (tab= first_depth_first_tab(join); tab; tab= next_depth_first_tab(join, tab), i++) { @@ -8804,7 +8812,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) Following force including random expression in last table condition. It solve problem with select like SELECT * FROM t1 WHERE rand() > 0.5 */ - if (tab == join->join_tab + join->top_join_tab_count - 1) + if (tab == join->join_tab + last_top_base_tab_idx) current_map|= RAND_TABLE_BIT; used_tables|=current_map; @@ -8843,10 +8851,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) save_used_tables= 0; } else - { - tmp= make_cond_for_table(thd, cond, used_tables, current_map, i, + { + tmp= make_cond_for_table(thd, cond, used_tables, current_map, i, FALSE, FALSE); - } + } /* Add conditions added by add_not_null_conds(). */ if (tab->select_cond) add_cond_and_fix(thd, &tmp, tab->select_cond); From 7e9716310261bce124585cbffd85f3402390ec9d Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 17 May 2017 14:29:13 -0700 Subject: [PATCH 34/97] Fixed the bug mdev-12817/mdev-12820. This patch is a correction of the patch for bug mdev-12670. With the current code handling semi-joins the following must be taken into account. Conversion of an IN subquery predicate into semi-join has to be blocked if the predicate occurs: (a) in the ON expression of an outer join (b) in the ON expression of an inner join embedded directly or indirectly in the inner nest of an outer join. The patch for mdev-12670 blocked conversion to semi-joins only in the case (a), but not in the case (b). This patch blocks the conversion in both cases. --- mysql-test/r/subselect_sj.result | 54 +++++++++++++++++++++++++++ mysql-test/r/subselect_sj_jcl6.result | 54 +++++++++++++++++++++++++++ mysql-test/t/subselect_sj.test | 40 ++++++++++++++++++++ sql/opt_subselect.cc | 21 ++++++++++- 4 files changed, 168 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/subselect_sj.result b/mysql-test/r/subselect_sj.result index c14b82f274e..74384141998 100644 --- a/mysql-test/r/subselect_sj.result +++ b/mysql-test/r/subselect_sj.result @@ -3099,4 +3099,58 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 range idx idx 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) drop table t1,t2; set optimizer_switch= @tmp_mdev12675; +# +# MDEV-12817: subquery NOT subject to semi-join optimizations +# in ON expression of INNER JOIN +# +CREATE TABLE t1 (c1 int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (c2 int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (c3 int) ENGINE=MyISAM; +INSERT INTO t3 VALUES (5),(6); +CREATE TABLE t4 (c4 int) ENGINE=MyISAM; +INSERT INTO t4 VALUES (7),(8); +SELECT c1 +FROM t1 +LEFT JOIN +( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) ) +ON (c1 = c3); +c1 +1 +2 +EXPLAIN EXTENDED SELECT c1 +FROM t1 +LEFT JOIN +( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) ) +ON (c1 = c3); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using where +2 SUBQUERY t4 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`c1` AS `c1` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t3`.`c3` = `test`.`t1`.`c1`) and ((1,(select `test`.`t4`.`c4` from `test`.`t4` where (1 = `test`.`t4`.`c4`)))))) where 1 +# mdev-12820 +SELECT * +FROM t1 +LEFT JOIN +( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 ) +ON (c1 = c2); +c1 c2 c4 +1 NULL NULL +2 NULL NULL +EXPLAIN EXTENDED SELECT * +FROM t1 +LEFT JOIN +( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 ) +ON (c1 = c2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +1 SIMPLE t4 ALL NULL NULL NULL NULL 2 100.00 +3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2`,`test`.`t4`.`c4` AS `c4` from `test`.`t1` left join (`test`.`t2` join `test`.`t4`) on(((`test`.`t2`.`c2` = `test`.`t1`.`c1`) and (`test`.`t1`.`c1`,(select `test`.`t3`.`c3` from `test`.`t3` where ((`test`.`t2`.`c2`) = `test`.`t3`.`c3`))))) where 1 +DROP TABLE t1,t2,t3,t4; set optimizer_switch=@subselect_sj_tmp; diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result index 33fd4c519ff..47dbdd782b5 100644 --- a/mysql-test/r/subselect_sj_jcl6.result +++ b/mysql-test/r/subselect_sj_jcl6.result @@ -3113,6 +3113,60 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 range idx idx 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) drop table t1,t2; set optimizer_switch= @tmp_mdev12675; +# +# MDEV-12817: subquery NOT subject to semi-join optimizations +# in ON expression of INNER JOIN +# +CREATE TABLE t1 (c1 int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (c2 int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (c3 int) ENGINE=MyISAM; +INSERT INTO t3 VALUES (5),(6); +CREATE TABLE t4 (c4 int) ENGINE=MyISAM; +INSERT INTO t4 VALUES (7),(8); +SELECT c1 +FROM t1 +LEFT JOIN +( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) ) +ON (c1 = c3); +c1 +1 +2 +EXPLAIN EXTENDED SELECT c1 +FROM t1 +LEFT JOIN +( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) ) +ON (c1 = c3); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) +2 SUBQUERY t4 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`c1` AS `c1` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t3`.`c3` = `test`.`t1`.`c1`) and ((1,(select `test`.`t4`.`c4` from `test`.`t4` where (1 = `test`.`t4`.`c4`)))))) where 1 +# mdev-12820 +SELECT * +FROM t1 +LEFT JOIN +( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 ) +ON (c1 = c2); +c1 c2 c4 +1 NULL NULL +2 NULL NULL +EXPLAIN EXTENDED SELECT * +FROM t1 +LEFT JOIN +( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 ) +ON (c1 = c2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t4 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join) +3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2`,`test`.`t4`.`c4` AS `c4` from `test`.`t1` left join (`test`.`t2` join `test`.`t4`) on(((`test`.`t2`.`c2` = `test`.`t1`.`c1`) and (`test`.`t1`.`c1`,(select `test`.`t3`.`c3` from `test`.`t3` where ((`test`.`t2`.`c2`) = `test`.`t3`.`c3`))))) where 1 +DROP TABLE t1,t2,t3,t4; set optimizer_switch=@subselect_sj_tmp; # # BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off diff --git a/mysql-test/t/subselect_sj.test b/mysql-test/t/subselect_sj.test index 5e9a2c88f22..acee1a67d63 100644 --- a/mysql-test/t/subselect_sj.test +++ b/mysql-test/t/subselect_sj.test @@ -2801,5 +2801,45 @@ select a from t1 join t2 on b between 1 and 2 and a in (select b from t2); drop table t1,t2; set optimizer_switch= @tmp_mdev12675; +--echo # +--echo # MDEV-12817: subquery NOT subject to semi-join optimizations +--echo # in ON expression of INNER JOIN +--echo # + +CREATE TABLE t1 (c1 int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); + +CREATE TABLE t2 (c2 int) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); + +CREATE TABLE t3 (c3 int) ENGINE=MyISAM; +INSERT INTO t3 VALUES (5),(6); + +CREATE TABLE t4 (c4 int) ENGINE=MyISAM; +INSERT INTO t4 VALUES (7),(8); + +let $q1= +SELECT c1 +FROM t1 +LEFT JOIN +( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) ) +ON (c1 = c3); + +eval $q1; +eval EXPLAIN EXTENDED $q1; + +let $q2= +SELECT * +FROM t1 +LEFT JOIN +( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 ) +ON (c1 = c2); + +--echo # mdev-12820 +eval $q2; +eval EXPLAIN EXTENDED $q2; + +DROP TABLE t1,t2,t3,t4; + # The following command must be the last one the file set optimizer_switch=@subselect_sj_tmp; diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 645afa6744a..84e06fda852 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -1103,7 +1103,26 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) do { embedded= embedding; - if (test(embedded->outer_join)) + bool block_conversion_to_sj= false; + if (embedded->on_expr) + { + /* + Conversion of an IN subquery predicate into semi-join + is blocked now if the predicate occurs: + - in the ON expression of an outer join + - in the ON expression of an inner join embedded directly + or indirectly in the inner nest of an outer join + */ + for (TABLE_LIST *tl= embedded; tl; tl= tl->embedding) + { + if (tl->outer_join) + { + block_conversion_to_sj= true; + break; + } + } + } + if (block_conversion_to_sj) { Item *cond= embedded->on_expr; if (!cond) From efb9f2617bde1654006a99af625859eb509d5448 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 17 May 2017 16:16:54 -0700 Subject: [PATCH 35/97] Fixed the bug mdev-12812. This is another correction of the patch for bug mdev-12670. If a derived table is merged into a select with STRAIGHT_JOIN modifier all IN subquery predicates contained in the specification of the derived table cannot be subject to conversion to semi-joins. --- mysql-test/r/derived_view.result | 21 +++++++++++++++++++++ mysql-test/t/derived_view.test | 20 ++++++++++++++++++++ sql/opt_subselect.cc | 10 ++++++++++ 3 files changed, 51 insertions(+) diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result index 8af8db15319..f7062473a3f 100644 --- a/mysql-test/r/derived_view.result +++ b/mysql-test/r/derived_view.result @@ -2617,5 +2617,26 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref idx idx 5 test.t1.a 140 Using index; FirstMatch(t1) drop view v1; drop table t1,t2; +# +# Bug mdev-12812: mergeable derived / view with subqueries +# NOT subject to semi-join optimizations +# +CREATE TABLE t1 (c1 varchar(3)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo'),('foo'); +CREATE TABLE t2 (c2 varchar(3)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('bar'),('qux'),('foo'); +SELECT STRAIGHT_JOIN * +FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq; +c1 +foo +foo +EXPLAIN EXTENDED SELECT STRAIGHT_JOIN * +FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select straight_join `test`.`t1`.`c1` AS `c1` from `test`.`t1` where (`test`.`t1`.`c1`,(select `test`.`t2`.`c2` from `test`.`t2` where ((`test`.`t1`.`c1`) = `test`.`t2`.`c2`))) +DROP TABLE t1, t2; set optimizer_switch=@exit_optimizer_switch; set join_cache_level=@exit_join_cache_level; diff --git a/mysql-test/t/derived_view.test b/mysql-test/t/derived_view.test index cdddaf8f9d8..07fbe4980a5 100644 --- a/mysql-test/t/derived_view.test +++ b/mysql-test/t/derived_view.test @@ -1911,6 +1911,26 @@ explain select * from v1; drop view v1; drop table t1,t2; +--echo # +--echo # Bug mdev-12812: mergeable derived / view with subqueries +--echo # NOT subject to semi-join optimizations +--echo # + +CREATE TABLE t1 (c1 varchar(3)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo'),('foo'); + +CREATE TABLE t2 (c2 varchar(3)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('bar'),('qux'),('foo'); + +let $q= +SELECT STRAIGHT_JOIN * + FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq; + +eval $q; +eval EXPLAIN EXTENDED $q; + +DROP TABLE t1, t2; + # The following command must be the last one the file set optimizer_switch=@exit_optimizer_switch; set join_cache_level=@exit_join_cache_level; diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 84e06fda852..d8b4de29f47 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -1161,6 +1161,16 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) in_subq->block_conversion_to_sj(); } } + + if (join->select_options & SELECT_STRAIGHT_JOIN) + { + /* Block conversion to semijoins for all candidates */ + li.rewind(); + while ((in_subq= li++)) + { + in_subq->block_conversion_to_sj(); + } + } li.rewind(); /* First, convert child join's subqueries. We proceed bottom-up here */ From b5cdf01404dd352bb9aa7b58cad76f7a500b32d2 Mon Sep 17 00:00:00 2001 From: Sachin Setiya Date: Thu, 18 May 2017 17:13:37 +0530 Subject: [PATCH 36/97] MDEV-11092 Assertion `!writer.checksum_len || writer.remains == 0' failed Problem:- This crash happens because logged stmt is quite big and while writing Annotate_rows_log_event it throws EFBIG error but we ignore this error and do not call cache_data->set_incident(). Solution:- When we normally write Binlog_log_event we check for error EFBIG, but we did do this for Annotate_rows_log_event. We check for this error and call cache_data->set_incident() accordingly. # Conflicts: # sql/log.cc --- mysql-test/suite/rpl/r/rpl_mdev-11092.result | 17 +++++++ mysql-test/suite/rpl/t/rpl_mdev-11092.test | 53 ++++++++++++++++++++ sql/log.cc | 7 +++ 3 files changed, 77 insertions(+) create mode 100644 mysql-test/suite/rpl/r/rpl_mdev-11092.result create mode 100644 mysql-test/suite/rpl/t/rpl_mdev-11092.test diff --git a/mysql-test/suite/rpl/r/rpl_mdev-11092.result b/mysql-test/suite/rpl/r/rpl_mdev-11092.result new file mode 100644 index 00000000000..b2de9e5f573 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_mdev-11092.result @@ -0,0 +1,17 @@ +include/master-slave.inc +[connection master] +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +call mtr.add_suppression("Slave SQL: The incident LOST_EVENTS occured on the master. .*"); +SET GLOBAL max_binlog_cache_size = 4096; +SET GLOBAL binlog_cache_size = 4096; +SET GLOBAL max_binlog_stmt_cache_size = 4096; +SET GLOBAL binlog_stmt_cache_size = 4096; +CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MYISAM; +ERROR HY000: Writing one row to the row-based binary log failed +include/wait_for_slave_sql_error_and_skip.inc [errno=1590] +SET GLOBAL max_binlog_cache_size= ORIGINAL_VALUE; +SET GLOBAL binlog_cache_size= ORIGINAL_VALUE; +SET GLOBAL max_binlog_stmt_cache_size= ORIGINAL_VALUE; +SET GLOBAL binlog_stmt_cache_size= ORIGINAL_VALUE; +DROP TABLE t1; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_mdev-11092.test b/mysql-test/suite/rpl/t/rpl_mdev-11092.test new file mode 100644 index 00000000000..c8b2b7f2ad1 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_mdev-11092.test @@ -0,0 +1,53 @@ +--source include/have_innodb.inc +--source include/master-slave.inc +--source include/not_embedded.inc +--source include/not_windows.inc +--source include/have_binlog_format_row.inc + +######################################################################################## +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +call mtr.add_suppression("Slave SQL: The incident LOST_EVENTS occured on the master. .*"); + +let $old_max_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_cache_size", Value, 1); +let $old_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_cache_size", Value, 1); +let $old_max_binlog_stmt_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_stmt_cache_size", Value, 1); +let $old_binlog_stmt_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_stmt_cache_size", Value, 1); + +SET GLOBAL max_binlog_cache_size = 4096; +SET GLOBAL binlog_cache_size = 4096; +SET GLOBAL max_binlog_stmt_cache_size = 4096; +SET GLOBAL binlog_stmt_cache_size = 4096; +disconnect master; +connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,); + +CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MYISAM; + +let $data = `select concat('"', repeat('a',2000), '"')`; + +connection master; + +--disable_query_log +--error ER_BINLOG_ROW_LOGGING_FAILED +eval INSERT INTO t1 (a, data) VALUES (2, + CONCAT($data, $data, $data, $data, $data, $data)); +--enable_query_log + +# Incident event +# 1590=ER_SLAVE_INCIDENT +--let $slave_sql_errno= 1590 +--source include/wait_for_slave_sql_error_and_skip.inc + +connection master; + +--replace_result $old_max_binlog_cache_size ORIGINAL_VALUE +--eval SET GLOBAL max_binlog_cache_size= $old_max_binlog_cache_size +--replace_result $old_binlog_cache_size ORIGINAL_VALUE +--eval SET GLOBAL binlog_cache_size= $old_binlog_cache_size +--replace_result $old_max_binlog_stmt_cache_size ORIGINAL_VALUE +--eval SET GLOBAL max_binlog_stmt_cache_size= $old_max_binlog_stmt_cache_size +--replace_result $old_binlog_stmt_cache_size ORIGINAL_VALUE +--eval SET GLOBAL binlog_stmt_cache_size= $old_binlog_stmt_cache_size + +DROP TABLE t1; + +--source include/rpl_end.inc diff --git a/sql/log.cc b/sql/log.cc index dc87c39730c..f8c256e645f 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -4887,13 +4887,20 @@ int THD::binlog_write_table_map(TABLE *table, bool is_transactional, IO_CACHE *file= cache_mngr->get_binlog_cache_log(use_trans_cache(this, is_transactional)); + binlog_cache_data *cache_data= + cache_mngr->get_binlog_cache_data(use_trans_cache(this, is_transactional)); + if (with_annotate && *with_annotate) { Annotate_rows_log_event anno(current_thd, is_transactional, false); /* Annotate event should be written not more than once */ *with_annotate= 0; if ((error= anno.write(file))) + { + if (my_errno == EFBIG) + cache_data->set_incident(); DBUG_RETURN(error); + } } if ((error= the_event.write(file))) DBUG_RETURN(error); From 4a846e018d2e31a7c78e45fb40b865246b5abb11 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Thu, 18 May 2017 19:31:44 +0200 Subject: [PATCH 37/97] Make IF clear. --- storage/maria/ma_loghandler.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/storage/maria/ma_loghandler.c b/storage/maria/ma_loghandler.c index bf2205f5a4c..16cd0a09af5 100644 --- a/storage/maria/ma_loghandler.c +++ b/storage/maria/ma_loghandler.c @@ -7814,8 +7814,24 @@ void translog_flush_buffers(TRANSLOG_ADDRESS *lsn, translog_force_current_buffer_to_finish(); translog_buffer_unlock(buffer); } - else if (log_descriptor.bc.buffer->prev_last_lsn != LSN_IMPOSSIBLE) + else { + if (log_descriptor.bc.buffer->last_lsn == LSN_IMPOSSIBLE) + { + /* + In this case both last_lsn & prev_last_lsn are LSN_IMPOSSIBLE + otherwise it will go in the first IF because LSN_IMPOSSIBLE less + then any real LSN and cmp_translog_addr(*lsn, + log_descriptor.bc.buffer->prev_last_lsn) will be TRUE + */ + DBUG_ASSERT(log_descriptor.bc.buffer->prev_last_lsn == + LSN_IMPOSSIBLE); + DBUG_PRINT("info", ("There is no LSNs yet generated => do nothing")); + translog_unlock(); + DBUG_VOID_RETURN; + } + + DBUG_ASSERT(log_descriptor.bc.buffer->prev_last_lsn != LSN_IMPOSSIBLE); /* fix lsn if it was horizon */ *lsn= log_descriptor.bc.buffer->prev_last_lsn; DBUG_PRINT("info", ("LSN to flush fixed to prev last lsn: (%lu,0x%lx)", @@ -7824,13 +7840,6 @@ void translog_flush_buffers(TRANSLOG_ADDRESS *lsn, TRANSLOG_BUFFERS_NO); translog_unlock(); } - else if (log_descriptor.bc.buffer->last_lsn == LSN_IMPOSSIBLE) - { - DBUG_PRINT("info", ("There is no LSNs yet generated => do nothing")); - translog_unlock(); - DBUG_VOID_RETURN; - } - /* flush buffers */ *sent_to_disk= translog_get_sent_to_disk(); if (cmp_translog_addr(*lsn, *sent_to_disk) > 0) From 7d57ba6e28f8dd5f6ab48b0b99d110c2363b576d Mon Sep 17 00:00:00 2001 From: Sachin Setiya Date: Fri, 19 May 2017 13:02:45 +0530 Subject: [PATCH 38/97] MDEV-11092 :- Fix Previous commit of MDEV-11092 --- mysql-test/suite/rpl/t/rpl_mdev-11092.opt | 1 + 1 file changed, 1 insertion(+) create mode 100644 mysql-test/suite/rpl/t/rpl_mdev-11092.opt diff --git a/mysql-test/suite/rpl/t/rpl_mdev-11092.opt b/mysql-test/suite/rpl/t/rpl_mdev-11092.opt new file mode 100644 index 00000000000..7f1d270d29f --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_mdev-11092.opt @@ -0,0 +1 @@ +--binlog_checksum=1 --binlog-annotate-row-events=1 From 20addb05e58fdf822896f490fcaaf2ec5ed4bcb5 Mon Sep 17 00:00:00 2001 From: Ivo Roylev Date: Mon, 22 May 2017 15:52:00 +0300 Subject: [PATCH 39/97] Bug# 25998635: Client does not escape the USE statement When there are quotes in the USE statement, the mysql client does not correctly escape them. The USE statement is processed line by line from the client's parser, and cannot handle multi-line commands as the server. The fix is to escape the USE parameters whenever quotes are used. --- client/mysql.cc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index 6e6dc4971ac..d09499c120a 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -3386,7 +3386,7 @@ print_table_data(MYSQL_RES *result) length=4; // Room for "NULL" if (opt_binhex && is_binary_field(field)) length= 2 + length * 2; - field->max_length=length; + field->max_length=(ulong) length; separator.fill(separator.length()+length+2,'-'); separator.append('+'); } @@ -3453,7 +3453,7 @@ print_table_data(MYSQL_RES *result) many extra padding-characters we should send with the printing function. */ visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length); - extra_padding= data_length - visible_length; + extra_padding= (uint) (data_length - visible_length); if (opt_binhex && is_binary_field(field)) print_as_hex(PAGER, cur[off], lengths[off], field_max_length); @@ -4232,10 +4232,9 @@ com_use(String *buffer __attribute__((unused)), char *line) bzero(buff, sizeof(buff)); /* - In case number of quotes exceed 2, we try to get - the normalized db name. + In case of quotes used, try to get the normalized db name. */ - if (get_quote_count(line) > 2) + if (get_quote_count(line) > 0) { if (normalize_dbname(line, buff, sizeof(buff))) return put_error(&mysql); @@ -4453,11 +4452,13 @@ char *get_arg(char *line, my_bool get_next_arg) static int get_quote_count(const char *line) { - int quote_count; - const char *ptr= line; + int quote_count= 0; + const char *quote= line; - for(quote_count= 0; ptr ++ && *ptr; ptr= strpbrk(ptr, "\"\'`")) - quote_count ++; + while ((quote= strpbrk(quote, "'`\"")) != NULL) { + quote_count++; + quote++; + } return quote_count; } From 8c7e9aab054360ec192ce3cffb2c25aa16e25f10 Mon Sep 17 00:00:00 2001 From: Shishir Jaiswal Date: Tue, 23 May 2017 10:22:33 +0530 Subject: [PATCH 40/97] Bug#16212207 - LOAD XML INFILE PERFORMANCE WITH INDENTED XML Post-push fix for build failure on Linux machine sles11-x86-64bit --- sql/sql_load.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/sql_load.cc b/sql/sql_load.cc index a2c01c3b8a8..6d6dc8b55e8 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -1990,7 +1990,9 @@ int READ_INFO::read_xml() case '>': /* end tag - read tag value */ in_tag= false; /* Skip all whitespaces */ - while (' ' == (chr= my_tospace(GET))); + while (' ' == (chr= my_tospace(GET))) + { + } /* Push the first non-whitespace char back to Stack. This char would be read in the upcoming call to read_value() From 3d8134d2c9b74bc8883ffe2ef59c168361223837 Mon Sep 17 00:00:00 2001 From: Harin Vadodaria Date: Tue, 23 May 2017 07:14:33 +0200 Subject: [PATCH 41/97] Bug#25988681: USE-AFTER-FREE IN MYSQL_STMT_CLOSE() Description: If mysql_stmt_close() encountered error, it recorded error in prepared statement but then frees memory assigned to prepared statement. If mysql_stmt_error() is used to get error information, it will result into use after free. In all cases where mysql_stmt_close() can fail, error would have been set by cli_advanced_command in MYSQL structure. Solution: Don't copy error from MYSQL using set_stmt_errmsg. There is no automated way to test the fix since it is in mysql_stmt_close() which does not expect any reply from server. Reviewed-By: Georgi Kodinov Reviewed-By: Ramil Kalimullin --- libmysql/libmysql.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 6e7134ff97c..d5ab85efa32 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -4678,10 +4678,14 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) mysql->status= MYSQL_STATUS_READY; } int4store(buff, stmt->stmt_id); - if ((rc= stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt))) - { - set_stmt_errmsg(stmt, &mysql->net); - } + /* + If stmt_command failed, it would have already raised + error using set_mysql_error. Caller should use + mysql_error() or mysql_errno() to find out details. + Memory allocated for stmt will be released regardless + of the error. + */ + rc= stmt_command(mysql, COM_STMT_CLOSE, buff, 4, stmt); } } From ba15ff2aaaa208c90fdb996c880af28d2b5a0353 Mon Sep 17 00:00:00 2001 From: "mysql-builder@oracle.com" <> Date: Tue, 23 May 2017 11:24:23 +0300 Subject: [PATCH 42/97] From b8405c853fa30002d164d5fe2b4f8ea8979c09b8 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 22 May 2017 07:09:49 +0200 Subject: [PATCH 43/97] MDEV-11958: LEFT JOIN with stored routine produces incorrect result Added forgoten method of Item_func_sp to make it correctly work with LEFT/RIGHT JOIN. Fixed inconsistency with the null table caches. --- mysql-test/r/join_outer.result | 95 +++++++++++++++++++++++++++++ mysql-test/r/join_outer_jcl6.result | 95 +++++++++++++++++++++++++++++ mysql-test/t/join_outer.test | 82 +++++++++++++++++++++++++ sql/item_func.h | 29 +++++++-- 4 files changed, 297 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 5dbb0f1d8b6..5611b61a7b0 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -2245,4 +2245,99 @@ SELECT * FROM t1 INNER JOIN t2 ON c = b LEFT JOIN t3 ON d = a WHERE b IN (1,2,3) OR b = d; a b c d DROP TABLE t1,t2,t3; +# +# MDEV-11958: LEFT JOIN with stored routine produces incorrect result +# +CREATE TABLE t (x INT); +INSERT INTO t VALUES(1),(NULL); +CREATE FUNCTION f (val INT, ret INT) RETURNS INT DETERMINISTIC RETURN IFNULL(val, ret); +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) +FROM t t1 LEFT JOIN t t2 +ON t1.x = t2.x +WHERE IFNULL(t2.x,0)=0; +x x IFNULL(t2.x,0) f(t2.x,0) +NULL NULL 0 0 +explain extended +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) +FROM t t1 LEFT JOIN t t2 +ON t1.x = t2.x +WHERE IFNULL(t2.x,0)=0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t2`.`x` AS `x`,ifnull(`test`.`t2`.`x`,0) AS `IFNULL(t2.x,0)`,`f`(`test`.`t2`.`x`,0) AS `f(t2.x,0)` from `test`.`t` `t1` left join `test`.`t` `t2` on((`test`.`t2`.`x` = `test`.`t1`.`x`)) where (ifnull(`test`.`t2`.`x`,0) = 0) +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) +FROM t t1 LEFT JOIN t t2 +ON t1.x = t2.x +WHERE f(t2.x,0)=0; +x x IFNULL(t2.x,0) f(t2.x,0) +NULL NULL 0 0 +explain extended +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) +FROM t t1 LEFT JOIN t t2 +ON t1.x = t2.x +WHERE f(t2.x,0)=0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t2`.`x` AS `x`,ifnull(`test`.`t2`.`x`,0) AS `IFNULL(t2.x,0)`,`f`(`test`.`t2`.`x`,0) AS `f(t2.x,0)` from `test`.`t` `t1` left join `test`.`t` `t2` on((`test`.`t2`.`x` = `test`.`t1`.`x`)) where (`f`(`test`.`t2`.`x`,0) = 0) +drop function f; +drop table t; +CREATE TABLE t1 ( +col1 DECIMAL(33,5) NULL DEFAULT NULL, +col2 DECIMAL(33,5) NULL DEFAULT NULL +); +CREATE TABLE t2 ( +col1 DECIMAL(33,5) NULL DEFAULT NULL, +col2 DECIMAL(33,5) NULL DEFAULT NULL, +col3 DECIMAL(33,5) NULL DEFAULT NULL +); +INSERT INTO t1 VALUES (2, 1.1), (2, 2.1); +INSERT INTO t2 VALUES (3, 3.1, 4), (1, 1, NULL); +CREATE FUNCTION f1 ( p_num DECIMAL(45,15), p_return DECIMAL(45,15)) +RETURNS decimal(33,5) +LANGUAGE SQL +DETERMINISTIC +CONTAINS SQL +SQL SECURITY INVOKER +BEGIN +IF p_num IS NULL THEN +RETURN p_return; +ELSE +RETURN p_num; +END IF; +END | +SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE IFNULL(t2.col3,0) = 0; +col1 col1 col3 +2.00000 NULL NULL +2.00000 NULL NULL +EXPLAIN EXTENDED SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE IFNULL(t2.col3,0) = 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`col1` AS `col1`,`test`.`t2`.`col1` AS `col1`,`test`.`t2`.`col3` AS `col3` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`col2` = `test`.`t1`.`col1`)) where (ifnull(`test`.`t2`.`col3`,0) = 0) +SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE f1(t2.col3,0) = 0; +col1 col1 col3 +2.00000 NULL NULL +2.00000 NULL NULL +EXPLAIN EXTENDED SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE f1(t2.col3,0) = 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`col1` AS `col1`,`test`.`t2`.`col1` AS `col1`,`test`.`t2`.`col3` AS `col3` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`col2` = `test`.`t1`.`col1`)) where (`f1`(`test`.`t2`.`col3`,0) = 0) +DROP FUNCTION f1; +DROP TABLE t1,t2; +# end of 5.5 tests SET optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index bdc4be0cb8c..8a1ccc7d5e5 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -2256,6 +2256,101 @@ SELECT * FROM t1 INNER JOIN t2 ON c = b LEFT JOIN t3 ON d = a WHERE b IN (1,2,3) OR b = d; a b c d DROP TABLE t1,t2,t3; +# +# MDEV-11958: LEFT JOIN with stored routine produces incorrect result +# +CREATE TABLE t (x INT); +INSERT INTO t VALUES(1),(NULL); +CREATE FUNCTION f (val INT, ret INT) RETURNS INT DETERMINISTIC RETURN IFNULL(val, ret); +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) +FROM t t1 LEFT JOIN t t2 +ON t1.x = t2.x +WHERE IFNULL(t2.x,0)=0; +x x IFNULL(t2.x,0) f(t2.x,0) +NULL NULL 0 0 +explain extended +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) +FROM t t1 LEFT JOIN t t2 +ON t1.x = t2.x +WHERE IFNULL(t2.x,0)=0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t2`.`x` AS `x`,ifnull(`test`.`t2`.`x`,0) AS `IFNULL(t2.x,0)`,`f`(`test`.`t2`.`x`,0) AS `f(t2.x,0)` from `test`.`t` `t1` left join `test`.`t` `t2` on((`test`.`t2`.`x` = `test`.`t1`.`x`)) where (ifnull(`test`.`t2`.`x`,0) = 0) +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) +FROM t t1 LEFT JOIN t t2 +ON t1.x = t2.x +WHERE f(t2.x,0)=0; +x x IFNULL(t2.x,0) f(t2.x,0) +NULL NULL 0 0 +explain extended +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) +FROM t t1 LEFT JOIN t t2 +ON t1.x = t2.x +WHERE f(t2.x,0)=0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t2`.`x` AS `x`,ifnull(`test`.`t2`.`x`,0) AS `IFNULL(t2.x,0)`,`f`(`test`.`t2`.`x`,0) AS `f(t2.x,0)` from `test`.`t` `t1` left join `test`.`t` `t2` on((`test`.`t2`.`x` = `test`.`t1`.`x`)) where (`f`(`test`.`t2`.`x`,0) = 0) +drop function f; +drop table t; +CREATE TABLE t1 ( +col1 DECIMAL(33,5) NULL DEFAULT NULL, +col2 DECIMAL(33,5) NULL DEFAULT NULL +); +CREATE TABLE t2 ( +col1 DECIMAL(33,5) NULL DEFAULT NULL, +col2 DECIMAL(33,5) NULL DEFAULT NULL, +col3 DECIMAL(33,5) NULL DEFAULT NULL +); +INSERT INTO t1 VALUES (2, 1.1), (2, 2.1); +INSERT INTO t2 VALUES (3, 3.1, 4), (1, 1, NULL); +CREATE FUNCTION f1 ( p_num DECIMAL(45,15), p_return DECIMAL(45,15)) +RETURNS decimal(33,5) +LANGUAGE SQL +DETERMINISTIC +CONTAINS SQL +SQL SECURITY INVOKER +BEGIN +IF p_num IS NULL THEN +RETURN p_return; +ELSE +RETURN p_num; +END IF; +END | +SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE IFNULL(t2.col3,0) = 0; +col1 col1 col3 +2.00000 NULL NULL +2.00000 NULL NULL +EXPLAIN EXTENDED SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE IFNULL(t2.col3,0) = 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`col1` AS `col1`,`test`.`t2`.`col1` AS `col1`,`test`.`t2`.`col3` AS `col3` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`col2` = `test`.`t1`.`col1`)) where (ifnull(`test`.`t2`.`col3`,0) = 0) +SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE f1(t2.col3,0) = 0; +col1 col1 col3 +2.00000 NULL NULL +2.00000 NULL NULL +EXPLAIN EXTENDED SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE f1(t2.col3,0) = 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`col1` AS `col1`,`test`.`t2`.`col1` AS `col1`,`test`.`t2`.`col3` AS `col3` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`col2` = `test`.`t1`.`col1`)) where (`f1`(`test`.`t2`.`col3`,0) = 0) +DROP FUNCTION f1; +DROP TABLE t1,t2; +# end of 5.5 tests SET optimizer_switch=@save_optimizer_switch; set join_cache_level=default; show variables like 'join_cache_level'; diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index 19c5f64de78..9645d8ad82a 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -1801,4 +1801,86 @@ SELECT * FROM t1 INNER JOIN t2 ON c = b LEFT JOIN t3 ON d = a DROP TABLE t1,t2,t3; +--echo # +--echo # MDEV-11958: LEFT JOIN with stored routine produces incorrect result +--echo # + +CREATE TABLE t (x INT); +INSERT INTO t VALUES(1),(NULL); +CREATE FUNCTION f (val INT, ret INT) RETURNS INT DETERMINISTIC RETURN IFNULL(val, ret); + +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) + FROM t t1 LEFT JOIN t t2 + ON t1.x = t2.x + WHERE IFNULL(t2.x,0)=0; +explain extended +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) + FROM t t1 LEFT JOIN t t2 + ON t1.x = t2.x + WHERE IFNULL(t2.x,0)=0; +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) + FROM t t1 LEFT JOIN t t2 + ON t1.x = t2.x + WHERE f(t2.x,0)=0; +explain extended +SELECT t1.x, t2.x, IFNULL(t2.x,0), f(t2.x,0) + FROM t t1 LEFT JOIN t t2 + ON t1.x = t2.x + WHERE f(t2.x,0)=0; + +drop function f; +drop table t; +CREATE TABLE t1 ( + col1 DECIMAL(33,5) NULL DEFAULT NULL, + col2 DECIMAL(33,5) NULL DEFAULT NULL +); + +CREATE TABLE t2 ( + col1 DECIMAL(33,5) NULL DEFAULT NULL, + col2 DECIMAL(33,5) NULL DEFAULT NULL, + col3 DECIMAL(33,5) NULL DEFAULT NULL +); + +INSERT INTO t1 VALUES (2, 1.1), (2, 2.1); +INSERT INTO t2 VALUES (3, 3.1, 4), (1, 1, NULL); + +DELIMITER |; + +CREATE FUNCTION f1 ( p_num DECIMAL(45,15), p_return DECIMAL(45,15)) +RETURNS decimal(33,5) +LANGUAGE SQL +DETERMINISTIC +CONTAINS SQL +SQL SECURITY INVOKER +BEGIN + IF p_num IS NULL THEN + RETURN p_return; + ELSE + RETURN p_num; + END IF; +END | + +DELIMITER ;| + +let $q1= +SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE IFNULL(t2.col3,0) = 0; + +eval $q1; +eval EXPLAIN EXTENDED $q1; + +let $q2= +SELECT t1.col1, t2.col1, t2.col3 +FROM t1 LEFT OUTER JOIN t2 ON t1.col1 = t2.col2 +WHERE f1(t2.col3,0) = 0; +eval $q2; +eval EXPLAIN EXTENDED $q2; + +DROP FUNCTION f1; + +DROP TABLE t1,t2; + +--echo # end of 5.5 tests + SET optimizer_switch=@save_optimizer_switch; diff --git a/sql/item_func.h b/sql/item_func.h index d60801745fe..2157c6b6b6d 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1165,7 +1165,11 @@ public: longlong val_int(); const char *func_name() const { return "coercibility"; } void fix_length_and_dec() { max_length=10; maybe_null= 0; } - table_map not_null_tables() const { return 0; } + bool eval_not_null_tables(uchar *opt_arg) + { + not_null_tables_cache= 0; + return 0; + } }; class Item_func_locate :public Item_int_func @@ -1433,7 +1437,11 @@ public: } void cleanup(); Item_result result_type () const { return udf.result_type(); } - table_map not_null_tables() const { return 0; } + bool eval_not_null_tables(uchar *opt_arg) + { + not_null_tables_cache= 0; + return 0; + } bool is_expensive() { return 1; } virtual void print(String *str, enum_query_type query_type); }; @@ -1889,7 +1897,11 @@ public: bool is_expensive_processor(uchar *arg) { return TRUE; } enum Functype functype() const { return FT_FUNC; } const char *func_name() const { return "match"; } - table_map not_null_tables() const { return 0; } + bool eval_not_null_tables(uchar *opt_arg) + { + not_null_tables_cache= 0; + return 0; + } bool fix_fields(THD *thd, Item **ref); bool eq(const Item *, bool binary_cmp) const; /* The following should be safe, even if we compare doubles */ @@ -2091,6 +2103,11 @@ public: { return TRUE; } + bool eval_not_null_tables(uchar *opt_arg) + { + not_null_tables_cache= 0; + return 0; + } }; @@ -2138,7 +2155,11 @@ public: void fix_length_and_dec(); enum Item_result result_type () const { return last_value->result_type(); } const char *func_name() const { return "last_value"; } - table_map not_null_tables() const { return 0; } + bool eval_not_null_tables(uchar *opt_arg) + { + not_null_tables_cache= 0; + return 0; + } enum_field_types field_type() const { return last_value->field_type(); } bool const_item() const { return 0; } void evaluate_sideeffects(); From c34f2e518a141ac117eaa4d08ca283d4440752b6 Mon Sep 17 00:00:00 2001 From: Sreeharsha Ramanavarapu Date: Wed, 24 May 2017 08:50:05 +0530 Subject: [PATCH 44/97] Bug #24595639: INCORRECT BEHAVIOR IN QUERY WITH UNION AND GROUP BY Issue 1: -------- This problem occurs in the following conditions: 1) A UNION is present in the subquery of select list and handles multiple columns. 2) Query has a GROUP BY. A temporary table is created to handle the UNION. Item_field objects are based on the expressions of the result of the UNION (ie. the fake_select_lex). While checking validity of the columns in the GROUP BY list, the columns of the temporary table are checked in Item_ident::local_column. But the Item_field objects created for the temporary table don't have information like the Name_resolution_context that they belong to or whether they are dependent on an outer query. Since these members are null, incorrect behavior is caused. This can happen when such Item objects are cached to apply the IN-to-EXISTS transform for Item_row. Solution to Issue 1: -------------------- Context information of the first select in the UNION will be assigned to the new Item_field objects. Issue 2: -------- This problem occurs in the following conditions: 1) A UNION is present in the subquery of select list. 2) A column in the UNION's first SELECT refers to a table in the outer-query making it a dependent union. 3) GROUP BY column refers to the outer-referencing column. While resolving the select list with an outer-reference, an Item_outer_ref object is created to handle the outer-query's GROUP BY list. The Item_outer_ref object replaces the Item_field object in the item tree. Item_outer_ref::fix_fields will be called only while fixing the inner references of the outer query. Before resolving the outer-query, an Item_type_holder object needs to be created to handle the UNION. But as explained above, the Item_outer_ref object has not been fixed yet. Having a fixed Item object is a pre-condition for creating an Item_type_holder. Solution to Issue 2: -------------------- Use the reference (real_item()) of an Item_outer_ref object instead of the object itself while creating an Item_type_holder. --- sql/item.cc | 5 ++++- sql/sql_union.cc | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index 34157c33cf4..6f1fdaae398 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1949,6 +1949,9 @@ Item_field::Item_field(Field *f) item_equal(0), no_const_subst(0), have_privileges(0), any_privileges(0) { + if (f->table->pos_in_table_list != NULL) + context= &(f->table->pos_in_table_list->select_lex->context); + set_field(f); /* field_name and table_name should not point to garbage diff --git a/sql/sql_union.cc b/sql/sql_union.cc index d230b903d2c..ca6870dab9c 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -282,6 +282,19 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, Item *item_tmp; while ((item_tmp= it++)) { + /* + If the outer query has a GROUP BY clause, an outer reference to this + query block may have been wrapped in a Item_outer_ref, which has not + been fixed yet. An Item_type_holder must be created based on a fixed + Item, so use the inner Item instead. + */ + DBUG_ASSERT(item_tmp->fixed || + (item_tmp->type() == Item::REF_ITEM && + ((Item_ref *)(item_tmp))->ref_type() == + Item_ref::OUTER_REF)); + if (!item_tmp->fixed) + item_tmp= item_tmp->real_item(); + /* Error's in 'new' will be detected after loop */ types.push_back(new Item_type_holder(thd_arg, item_tmp)); } From fedfba217165f78745001a6f1043d847df3a9510 Mon Sep 17 00:00:00 2001 From: Piotr Obrzut Date: Wed, 24 May 2017 18:09:17 +0200 Subject: [PATCH 45/97] Bug #25658832 VALIDATION CHECK FOR MSVC REDIST NEEDED IN SERVER COMMUNITY MSI Added matching redist prerequisite check to the server msi installer. --- packaging/WiX/create_msi.cmake.in | 3 ++- packaging/WiX/mysql_server.wxs.in | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packaging/WiX/create_msi.cmake.in b/packaging/WiX/create_msi.cmake.in index 8de271fc1cf..95cbbb3d437 100644 --- a/packaging/WiX/create_msi.cmake.in +++ b/packaging/WiX/create_msi.cmake.in @@ -1,4 +1,4 @@ -# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -13,6 +13,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +SET(LINK_STATIC_RUNTIME_LIBRARIES "@LINK_STATIC_RUNTIME_LIBRARIES@") SET(CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@") SET(CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@") SET(CANDLE_EXECUTABLE "@CANDLE_EXECUTABLE@") diff --git a/packaging/WiX/mysql_server.wxs.in b/packaging/WiX/mysql_server.wxs.in index 10b6f892a2e..2092d0ebe3d 100644 --- a/packaging/WiX/mysql_server.wxs.in +++ b/packaging/WiX/mysql_server.wxs.in @@ -2,7 +2,7 @@ xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"> From bb9e547a860432972739e6661d15c52d8c008748 Mon Sep 17 00:00:00 2001 From: Venkatesh Duggirala Date: Wed, 24 May 2017 16:12:57 +0530 Subject: [PATCH 46/97] Bug#18950197 RPL_SEMI_SYNC_UNINSTALL_PLUGIN FAILS BECAUSE RPL_SEMI_SYNC_MASTER_CLIENTS=1 Analysis: Uninstalling rpl_semi_sync_slave on slave will trigger removing the slave logic on Master which will reduce Rpl_semi_sync_master_clients by one number. But it happens asynchronously on Master. Having assert to check this value with zero will have problems on slow pb2 machines. Fix: Change assert into wait_for_status_var condition. --- .../suite/rpl/r/rpl_semi_sync_uninstall_plugin.result | 1 - .../suite/rpl/t/rpl_semi_sync_uninstall_plugin.test | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_semi_sync_uninstall_plugin.result b/mysql-test/suite/rpl/r/rpl_semi_sync_uninstall_plugin.result index bd659e71600..347e6de4dd7 100644 --- a/mysql-test/suite/rpl/r/rpl_semi_sync_uninstall_plugin.result +++ b/mysql-test/suite/rpl/r/rpl_semi_sync_uninstall_plugin.result @@ -28,7 +28,6 @@ include/stop_slave.inc SET GLOBAL rpl_semi_sync_slave_enabled = OFF; include/start_slave.inc UNINSTALL PLUGIN rpl_semi_sync_slave; -include/assert.inc [semi sync master clients should be 0.] UNINSTALL PLUGIN rpl_semi_sync_master; CREATE TABLE t1(i int); INSERT INTO t1 values (3); diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync_uninstall_plugin.test b/mysql-test/suite/rpl/t/rpl_semi_sync_uninstall_plugin.test index 2badd4203cf..a3a3da8b18a 100644 --- a/mysql-test/suite/rpl/t/rpl_semi_sync_uninstall_plugin.test +++ b/mysql-test/suite/rpl/t/rpl_semi_sync_uninstall_plugin.test @@ -125,12 +125,11 @@ SET GLOBAL rpl_semi_sync_slave_enabled = OFF; # Step 4.4: Uninstall semi sync plugin, it should be successful now. UNINSTALL PLUGIN rpl_semi_sync_slave; -# Step 4.5: On Master, check that semi sync slaves are now '0'. +# Step 4.5: On Master, wait until semi sync slaves is '0'. --connection master ---let $master_clients=[show status like "Rpl_semi_sync_master_clients", Value, 1] ---let assert_cond= $master_clients = 0 ---let assert_text= semi sync master clients should be 0. ---source include/assert.inc +--let $status_var= Rpl_semi_sync_master_clients +--let $status_var_value= 0 +--source include/wait_for_status_var.inc # Step 4.6: So uninstalling semi sync plugin should be allowed UNINSTALL PLUGIN rpl_semi_sync_master; From 2cb94aa1b70fa01d9e5c1d8a7625415a0220a3d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 29 May 2017 13:07:23 +0300 Subject: [PATCH 47/97] MDEV-11626 innodb.innodb-change-buffer-recovery fails for xtradb buf_page_get_gen(): Remove the error log messages about page flushing and eviction when innodb_change_buffering_debug=1 is in effect. --- storage/innobase/buf/buf0buf.c | 6 ------ storage/xtradb/buf/buf0buf.c | 6 ------ 2 files changed, 12 deletions(-) diff --git a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c index a5e1c045b7b..80a15ffe0d5 100644 --- a/storage/innobase/buf/buf0buf.c +++ b/storage/innobase/buf/buf0buf.c @@ -2560,14 +2560,8 @@ wait_until_unfixed: } } buf_pool_mutex_exit(buf_pool); - fprintf(stderr, - "innodb_change_buffering_debug evict %u %u\n", - (unsigned) space, (unsigned) offset); return(NULL); } else if (buf_flush_page_try(buf_pool, block)) { - fprintf(stderr, - "innodb_change_buffering_debug flush %u %u\n", - (unsigned) space, (unsigned) offset); guess = block; goto loop; } diff --git a/storage/xtradb/buf/buf0buf.c b/storage/xtradb/buf/buf0buf.c index e68b0526d42..0b0a00cd1ed 100644 --- a/storage/xtradb/buf/buf0buf.c +++ b/storage/xtradb/buf/buf0buf.c @@ -2852,9 +2852,6 @@ wait_until_unfixed: } } //buf_pool_mutex_exit(buf_pool); - fprintf(stderr, - "innodb_change_buffering_debug evict %u %u\n", - (unsigned) space, (unsigned) offset); return(NULL); } else if (UNIV_UNLIKELY(buf_block_get_state(block) @@ -2875,9 +2872,6 @@ wait_until_unfixed: ut_ad(!mutex_own(&buf_pool->LRU_list_mutex)); if (buf_flush_page_try(buf_pool, block)) { - fprintf(stderr, - "innodb_change_buffering_debug flush %u %u\n", - (unsigned) space, (unsigned) offset); guess = block; goto loop; } From 88915a3090d34a02d71b79001addc2fea00016c6 Mon Sep 17 00:00:00 2001 From: Piotr Obrzut Date: Thu, 1 Jun 2017 15:25:04 +0200 Subject: [PATCH 48/97] Bug#26181622 MSI BUILD FAIL DUE TO DUPLICATED FILE ID Fixed generated mysql_server.wxs not to contain duplicates, or too long ids (cherry picked from commit bf47fb74dcc3e84057314817c56e6f8e05af094c) --- packaging/WiX/create_msi.cmake.in | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/packaging/WiX/create_msi.cmake.in b/packaging/WiX/create_msi.cmake.in index 95cbbb3d437..b306c0c70d3 100644 --- a/packaging/WiX/create_msi.cmake.in +++ b/packaging/WiX/create_msi.cmake.in @@ -218,22 +218,37 @@ MACRO(GENERATE_GUID VarName) OUTPUT_STRIP_TRAILING_WHITESPACE) ENDMACRO() -SET(INC_VAR 0) +# Make sure that WIX identifier created from a path matches all the rules: +# - it is shorter than 72 characters +# - doesn't contain reserver characters ('+', '-' and '/') +# ID_SET contains a global list of all identifiers which are too long. +# Every time we use an identifier which is too long we use its index in +# ID_SET to shorten the name. +SET_PROPERTY(GLOBAL PROPERTY ID_SET) MACRO(MAKE_WIX_IDENTIFIER str varname) STRING(REPLACE "/" "." ${varname} "${str}") + STRING(REPLACE "+" "p" ${varname} "${str}") + STRING(REPLACE "-" "m" ${varname} "${str}") STRING(REGEX REPLACE "[^a-zA-Z_0-9.]" "_" ${varname} "${${varname}}") STRING(LENGTH "${${varname}}" len) + # FIXME: the prefix length has to be controlled better # Identifier should be smaller than 72 character - # We have to cut down the length to 70 chars, since we add 2 char prefix + # We have to cut down the length to 40 chars, since we add prefixes # pretty often - IF(len GREATER 70) - STRING(SUBSTRING "${${varname}}" 0 67 shortstr) - MATH(EXPR INC_VAR ${INC_VAR}+1) - SET(${varname} "${shortstr}${INC_VAR}") + IF(len GREATER 40) + STRING(SUBSTRING "${${varname}}" 0 37 shortstr) + GET_PROPERTY(LOCAL_LIST GLOBAL PROPERTY ID_SET) + LIST(FIND LOCAL_LIST "${${varname}}" STRING_ID) + IF(${STRING_ID} EQUAL -1) + LIST(APPEND LOCAL_LIST "${${varname}}") + SET_PROPERTY(GLOBAL PROPERTY ID_SET "${LOCAL_LIST}") + LIST(LENGTH LOCAL_LIST STRING_ID) + MATH(EXPR STRING_ID "${STRING_ID}-1" ) + ENDIF() + SET(${varname} "${shortstr}${STRING_ID}") ENDIF() ENDMACRO() - FUNCTION(TRAVERSE_FILES dir topdir file file_comp dir_root) FILE(RELATIVE_PATH dir_rel ${topdir} ${dir}) IF(dir_rel) From c3e6a032c3acbfc56fb3cc7b38710a24c416ffd0 Mon Sep 17 00:00:00 2001 From: Piotr Obrzut Date: Fri, 2 Jun 2017 19:17:30 +0200 Subject: [PATCH 49/97] Bug#26171638 MYSQL 5.5.57 - MSI COMMUNITY PACKAGES NOT GETTING INSTALLED Temporary revert of the VS2008 redist check. (cherry picked from commit 36ec550fe5fa6b2a997cb39d3b9e33988f525c96) --- packaging/WiX/create_msi.cmake.in | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/packaging/WiX/create_msi.cmake.in b/packaging/WiX/create_msi.cmake.in index b306c0c70d3..ae6a5773dce 100644 --- a/packaging/WiX/create_msi.cmake.in +++ b/packaging/WiX/create_msi.cmake.in @@ -218,37 +218,6 @@ MACRO(GENERATE_GUID VarName) OUTPUT_STRIP_TRAILING_WHITESPACE) ENDMACRO() -# Make sure that WIX identifier created from a path matches all the rules: -# - it is shorter than 72 characters -# - doesn't contain reserver characters ('+', '-' and '/') -# ID_SET contains a global list of all identifiers which are too long. -# Every time we use an identifier which is too long we use its index in -# ID_SET to shorten the name. -SET_PROPERTY(GLOBAL PROPERTY ID_SET) -MACRO(MAKE_WIX_IDENTIFIER str varname) - STRING(REPLACE "/" "." ${varname} "${str}") - STRING(REPLACE "+" "p" ${varname} "${str}") - STRING(REPLACE "-" "m" ${varname} "${str}") - STRING(REGEX REPLACE "[^a-zA-Z_0-9.]" "_" ${varname} "${${varname}}") - STRING(LENGTH "${${varname}}" len) - # FIXME: the prefix length has to be controlled better - # Identifier should be smaller than 72 character - # We have to cut down the length to 40 chars, since we add prefixes - # pretty often - IF(len GREATER 40) - STRING(SUBSTRING "${${varname}}" 0 37 shortstr) - GET_PROPERTY(LOCAL_LIST GLOBAL PROPERTY ID_SET) - LIST(FIND LOCAL_LIST "${${varname}}" STRING_ID) - IF(${STRING_ID} EQUAL -1) - LIST(APPEND LOCAL_LIST "${${varname}}") - SET_PROPERTY(GLOBAL PROPERTY ID_SET "${LOCAL_LIST}") - LIST(LENGTH LOCAL_LIST STRING_ID) - MATH(EXPR STRING_ID "${STRING_ID}-1" ) - ENDIF() - SET(${varname} "${shortstr}${STRING_ID}") - ENDIF() -ENDMACRO() - FUNCTION(TRAVERSE_FILES dir topdir file file_comp dir_root) FILE(RELATIVE_PATH dir_rel ${topdir} ${dir}) IF(dir_rel) From 34cd74e52185de2ea3156e8295de3c638cde8c88 Mon Sep 17 00:00:00 2001 From: Piotr Obrzut Date: Mon, 5 Jun 2017 08:09:07 +0200 Subject: [PATCH 50/97] Bug#26171638 MYSQL 5.5.57 - MSI COMMUNITY PACKAGES NOT GETTING INSTALLED Corrected the revert. (cherry picked from commit f637e524bf9b692c3ed46d856e2beac193b42a3e) --- packaging/WiX/create_msi.cmake.in | 31 +++++++++++++++++++++++++++++++ packaging/WiX/mysql_server.wxs.in | 26 -------------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/packaging/WiX/create_msi.cmake.in b/packaging/WiX/create_msi.cmake.in index ae6a5773dce..b306c0c70d3 100644 --- a/packaging/WiX/create_msi.cmake.in +++ b/packaging/WiX/create_msi.cmake.in @@ -218,6 +218,37 @@ MACRO(GENERATE_GUID VarName) OUTPUT_STRIP_TRAILING_WHITESPACE) ENDMACRO() +# Make sure that WIX identifier created from a path matches all the rules: +# - it is shorter than 72 characters +# - doesn't contain reserver characters ('+', '-' and '/') +# ID_SET contains a global list of all identifiers which are too long. +# Every time we use an identifier which is too long we use its index in +# ID_SET to shorten the name. +SET_PROPERTY(GLOBAL PROPERTY ID_SET) +MACRO(MAKE_WIX_IDENTIFIER str varname) + STRING(REPLACE "/" "." ${varname} "${str}") + STRING(REPLACE "+" "p" ${varname} "${str}") + STRING(REPLACE "-" "m" ${varname} "${str}") + STRING(REGEX REPLACE "[^a-zA-Z_0-9.]" "_" ${varname} "${${varname}}") + STRING(LENGTH "${${varname}}" len) + # FIXME: the prefix length has to be controlled better + # Identifier should be smaller than 72 character + # We have to cut down the length to 40 chars, since we add prefixes + # pretty often + IF(len GREATER 40) + STRING(SUBSTRING "${${varname}}" 0 37 shortstr) + GET_PROPERTY(LOCAL_LIST GLOBAL PROPERTY ID_SET) + LIST(FIND LOCAL_LIST "${${varname}}" STRING_ID) + IF(${STRING_ID} EQUAL -1) + LIST(APPEND LOCAL_LIST "${${varname}}") + SET_PROPERTY(GLOBAL PROPERTY ID_SET "${LOCAL_LIST}") + LIST(LENGTH LOCAL_LIST STRING_ID) + MATH(EXPR STRING_ID "${STRING_ID}-1" ) + ENDIF() + SET(${varname} "${shortstr}${STRING_ID}") + ENDIF() +ENDMACRO() + FUNCTION(TRAVERSE_FILES dir topdir file file_comp dir_root) FILE(RELATIVE_PATH dir_rel ${topdir} ${dir}) IF(dir_rel) diff --git a/packaging/WiX/mysql_server.wxs.in b/packaging/WiX/mysql_server.wxs.in index 2092d0ebe3d..3eb81ec532c 100644 --- a/packaging/WiX/mysql_server.wxs.in +++ b/packaging/WiX/mysql_server.wxs.in @@ -61,32 +61,6 @@ - - - - - - - - Installed OR VS08REDISTX64 - - - - - - - Installed OR VS08REDISTX86 - - - From c258ca2463947fcc3d69bb50a8b5cf6906778508 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 7 Jun 2017 12:45:09 -0700 Subject: [PATCH 51/97] Fixed the bug mdev-12838. If the optimizer chose an execution plan where a semi-join nest were materialized and the result of materialization was scanned to access other tables by ref access it could build a key over columns of the tables from the nest that were actually inaccessible. The patch performs a proper check whether a key that uses columns of the tables from a materialized semi-join nest can be employed to access outer tables. --- mysql-test/r/subselect_mat.result | 88 ++++++++++++ mysql-test/r/subselect_sj_mat.result | 88 ++++++++++++ mysql-test/t/subselect_sj_mat.test | 207 +++++++++++++++++++++++++++ sql/opt_subselect.cc | 4 + sql/sql_select.cc | 71 ++++++++- sql/sql_select.h | 8 ++ 6 files changed, 461 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/subselect_mat.result b/mysql-test/r/subselect_mat.result index ffa37b025eb..d4dc519227b 100644 --- a/mysql-test/r/subselect_mat.result +++ b/mysql-test/r/subselect_mat.result @@ -2272,6 +2272,94 @@ pk f1 sq 5 3 5 set optimizer_switch= @save_optimizer_switch; DROP TABLE t1,t2; +# +# mdev-12838: scan of materialized of semi-join subquery in join +# +set @save_optimizer_switch=@@optimizer_switch; +CREATE TABLE t1 ( +dispatch_group varchar(32), +assignment_group varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx1 (dispatch_group), +KEY idx2 (assignment_group) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +ugroup varchar(32), +user varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx3 (ugroup), +KEY idx4 (user) +) ENGINE=MyISAM; +CREATE TABLE t3 ( +type mediumtext, +sys_id char(32), +PRIMARY KEY (sys_id) +) ENGINE=MyISAM; +set optimizer_switch='materialization=off'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary +1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where +1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +set optimizer_switch='materialization=on'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL distinct_key NULL NULL NULL 2 +1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index +2 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where +2 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +DROP TABLE t1,t2,t3; +set optimizer_switch=@save_optimizer_switch; # End of 5.5 tests set @subselect_mat_test_optimizer_switch_value=null; set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result index 47f578fb589..cb5012a91c9 100644 --- a/mysql-test/r/subselect_sj_mat.result +++ b/mysql-test/r/subselect_sj_mat.result @@ -2312,4 +2312,92 @@ pk f1 sq 5 3 5 set optimizer_switch= @save_optimizer_switch; DROP TABLE t1,t2; +# +# mdev-12838: scan of materialized of semi-join subquery in join +# +set @save_optimizer_switch=@@optimizer_switch; +CREATE TABLE t1 ( +dispatch_group varchar(32), +assignment_group varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx1 (dispatch_group), +KEY idx2 (assignment_group) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +ugroup varchar(32), +user varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx3 (ugroup), +KEY idx4 (user) +) ENGINE=MyISAM; +CREATE TABLE t3 ( +type mediumtext, +sys_id char(32), +PRIMARY KEY (sys_id) +) ENGINE=MyISAM; +set optimizer_switch='materialization=off'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary +1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where +1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +set optimizer_switch='materialization=on'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL distinct_key NULL NULL NULL 2 +1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index +2 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where +2 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +DROP TABLE t1,t2,t3; +set optimizer_switch=@save_optimizer_switch; # End of 5.5 tests diff --git a/mysql-test/t/subselect_sj_mat.test b/mysql-test/t/subselect_sj_mat.test index cd71ae5c901..90f63bea561 100644 --- a/mysql-test/t/subselect_sj_mat.test +++ b/mysql-test/t/subselect_sj_mat.test @@ -1944,4 +1944,211 @@ set optimizer_switch= @save_optimizer_switch; DROP TABLE t1,t2; +--echo # +--echo # mdev-12838: scan of materialized of semi-join subquery in join +--echo # + +set @save_optimizer_switch=@@optimizer_switch; + +CREATE TABLE t1 ( + dispatch_group varchar(32), + assignment_group varchar(32), + sys_id char(32), + PRIMARY KEY (sys_id), + KEY idx1 (dispatch_group), + KEY idx2 (assignment_group) +) ENGINE=MyISAM; + +CREATE TABLE t2 ( + ugroup varchar(32), + user varchar(32), + sys_id char(32), + PRIMARY KEY (sys_id), + KEY idx3 (ugroup), + KEY idx4 (user) +) ENGINE=MyISAM; + +CREATE TABLE t3 ( + type mediumtext, + sys_id char(32), + PRIMARY KEY (sys_id) +) ENGINE=MyISAM; + +--disable_query_log + +INSERT INTO t1 VALUES +('e5d9f63237232000158bbfc8bcbe5dbf','f304ae0037332000158bbfc8bcbe5d4f', +'5398c0e037003000158bbfc8bcbe5dbb'), +('69d9f63237232000158bbfc8bcbe5dcb','7172ea0037332000158bbfc8bcbe5db6', +'5c188ca037003000158bbfc8bcbe5dbc'), +('577ed708d773020058c92cf65e61037a','699708d4d773020058c92cf65e61037c', +'623a8cd4d773020058c92cf65e6103ea'), +('96fb652637232000158bbfc8bcbe5db4','df50316637232000158bbfc8bcbe5d23', +'6835bd6637232000158bbfc8bcbe5d21'), +('e1d9f63237232000158bbfc8bcbe5db8','96346e0037332000158bbfc8bcbe5daa', +'697880e037003000158bbfc8bcbe5dcd'), +('25d9f63237232000158bbfc8bcbe5dbe','f304ae0037332000158bbfc8bcbe5d4f', +'6a9804e037003000158bbfc8bcbe5d09'), +('96fb652637232000158bbfc8bcbe5db4','e08fad2637232000158bbfc8bcbe5d39', +'6d25f96637232000158bbfc8bcbe5d79'), +('e9d9f63237232000158bbfc8bcbe5dc6','7172ea0037332000158bbfc8bcbe5db6', +'702880e037003000158bbfc8bcbe5d94'), +('a5d9f63237232000158bbfc8bcbe5dca','f304ae0037332000158bbfc8bcbe5d4f', +'7188c0e037003000158bbfc8bcbe5d75'), +('65d9f63237232000158bbfc8bcbe5dc4','f304ae0037332000158bbfc8bcbe5d4f', +'778880e037003000158bbfc8bcbe5d9e'), +('a1d9f63237232000158bbfc8bcbe5dc3','7172ea0037332000158bbfc8bcbe5db6', +'7d0840e037003000158bbfc8bcbe5dde'), +('21d9f63237232000158bbfc8bcbe5db7','96346e0037332000158bbfc8bcbe5daa', +'7f6880e037003000158bbfc8bcbe5da7'), +('96fb652637232000158bbfc8bcbe5db4','ec70316637232000158bbfc8bcbe5d60', +'8025f96637232000158bbfc8bcbe5dd0'), +('3dd9f63237232000158bbfc8bcbe5dcc','7172ea0037332000158bbfc8bcbe5db6', +'823880e037003000158bbfc8bcbe5ded'), +('96fb652637232000158bbfc8bcbe5db4','7b10fd2637232000158bbfc8bcbe5d30', +'9a353d6637232000158bbfc8bcbe5dee'), +('75d9f63237232000158bbfc8bcbe5dd0','ebb4620037332000158bbfc8bcbe5d89', +'a558c0e037003000158bbfc8bcbe5d36'), +('6dd9f63237232000158bbfc8bcbe5db5','96346e0037332000158bbfc8bcbe5daa', +'bc78cca037003000158bbfc8bcbe5d74'), +('add9f63237232000158bbfc8bcbe5dc7','7172ea0037332000158bbfc8bcbe5db6', +'c53804a037003000158bbfc8bcbe5db8'), +('fdd9f63237232000158bbfc8bcbe5dcd','7864ae0037332000158bbfc8bcbe5db8', +'cfe740e037003000158bbfc8bcbe5de8'), +('96fb652637232000158bbfc8bcbe5db4','3120fd2637232000158bbfc8bcbe5d42', +'e2257d6637232000158bbfc8bcbe5ded'), +('3c3725e237232000158bbfc8bcbe5da1','96346e0037332000158bbfc8bcbe5daa', +'ee78c0e037003000158bbfc8bcbe5db5'), +('a9d9f63237232000158bbfc8bcbe5dc0','7172ea0037332000158bbfc8bcbe5db6', +'f00888a037003000158bbfc8bcbe5dd3'), +('29d9f63237232000158bbfc8bcbe5db9','7172ea0037332000158bbfc8bcbe5db6', +'fa0880e037003000158bbfc8bcbe5d70'), +('b1d9f63237232000158bbfc8bcbe5dcf','ebb4620037332000158bbfc8bcbe5d89', +'fa48c0e037003000158bbfc8bcbe5d28'); + +INSERT INTO t2 VALUES +('17801ac21b13200050fdfbcd2c0713e8','8e826bf03710200044e0bfc8bcbe5d86', +'14c19a061b13200050fdfbcd2c07134b'), +('577ed708d773020058c92cf65e61037a','931644d4d773020058c92cf65e61034c', +'339888d4d773020058c92cf65e6103aa'), +('df50316637232000158bbfc8bcbe5d23','92826bf03710200044e0bfc8bcbe5da9', +'3682f56637232000158bbfc8bcbe5d44'), +('b4f342b237232000158bbfc8bcbe5def','86826bf03710200044e0bfc8bcbe5d70', +'38e4c2b237232000158bbfc8bcbe5dea'), +('7b10fd2637232000158bbfc8bcbe5d30','8a826bf03710200044e0bfc8bcbe5d72', +'4442b56637232000158bbfc8bcbe5d43'), +('3120fd2637232000158bbfc8bcbe5d42','82826bf03710200044e0bfc8bcbe5d89', +'49d2396637232000158bbfc8bcbe5d12'), +('96fb652637232000158bbfc8bcbe5db4','86826bf03710200044e0bfc8bcbe5d79', +'4e3ca52637232000158bbfc8bcbe5d3e'), +('17801ac21b13200050fdfbcd2c0713e8','824fd523bf4320007a6d257b3f073963', +'58c19a061b13200050fdfbcd2c07134e'), +('699708d4d773020058c92cf65e61037c','901784d4d773020058c92cf65e6103da', +'5bc708d4d773020058c92cf65e6103d5'), +('75d9f63237232000158bbfc8bcbe5dd0','86826bf03710200044e0bfc8bcbe5d79', +'6b52cb7237232000158bbfc8bcbe5ded'), +('f253da061b13200050fdfbcd2c0713ab','8e826bf03710200044e0bfc8bcbe5d86', +'81045e061b13200050fdfbcd2c071373'), +('7b10fd2637232000158bbfc8bcbe5d30','8e826bf03710200044e0bfc8bcbe5d74', +'8c42b56637232000158bbfc8bcbe5d3f'), +('e5d9f63237232000158bbfc8bcbe5dbf','7a826bf03710200044e0bfc8bcbe5df5', +'a7acfe3237232000158bbfc8bcbe5d78'), +('8a5055c9c61122780043563ef53438e3','9ee1b13dc6112271007f9d0efdb69cd0', +'a9aff553c6112276015a8006174bee21'), +('8a4dde73c6112278017a6a4baf547aa7','9ee1b13dc6112271007f9d0efdb69cd0', +'a9b2f526c61122760003ae07349d294f'), +('aaccc971c0a8001500fe1ff4302de101','9ee1b13dc6112271007f9d0efdb69cd0', +'aacceed3c0a80015009069bba51c4e21'), +('65d9f63237232000158bbfc8bcbe5dc4','8d56406a0a0a0a6b004070b354aada28', +'ac1bfa3237232000158bbfc8bcbe5dc3'), +('b85d44954a3623120004689b2d5dd60a','97000fcc0a0a0a6e0104ca999f619e5b', +'b77bc032cbb00200d71cb9c0c24c9c45'), +('220f8e71c61122840197e57c33464f70','8d56406a0a0a0a6b004070b354aada28', +'b9b74f080a0a0b343ba75b95bdb27056'), +('e08fad2637232000158bbfc8bcbe5d39','82826bf03710200044e0bfc8bcbe5d80', +'be02756637232000158bbfc8bcbe5d8b'), +('ebb4620037332000158bbfc8bcbe5d89','7682abf03710200044e0bfc8bcbe5d25', +'c0122f4437732000158bbfc8bcbe5d7d'), +('96fb652637232000158bbfc8bcbe5db4','7a82abf03710200044e0bfc8bcbe5d27', +'c23ca52637232000158bbfc8bcbe5d3b'), +('22122b37c611228400f9ff91c857581d','9ee1b13dc6112271007f9d0efdb69cd0', +'d23bbf5dac14641866947512bde59dc5'), +('db53a9290a0a0a650091abebccf833c6','9ee1b13dc6112271007f9d0efdb69cd0', +'db54a0f60a0a0a65002c54dcb72b4f41'), +('e08fad2637232000158bbfc8bcbe5d39','8e826bf03710200044e0bfc8bcbe5d86', +'f602756637232000158bbfc8bcbe5d88'), +('699708d4d773020058c92cf65e61037c','8d59d601d7b3020058c92cf65e6103c2', +'f718a241d7b3020058c92cf65e610332'), +('df50316637232000158bbfc8bcbe5d23','9e826bf03710200044e0bfc8bcbe5da6', +'fe82f56637232000158bbfc8bcbe5d4e'), +('f972d6061b13200050fdfbcd2c0713e5','780395f0df031100a9e78b6c3df2631f', +'ff4395f0df031100a9e78b6c3df2637e'); + +INSERT INTO t3 VALUES +('87245e061b13200050fdfbcd2c0713cc','7172ea0037332000158bbfc8bcbe5db6'), +('74af88c6c611227d0066386e74dc853d','74ad1ff3c611227d01d25feac2af603f'), +('59e22fb137032000158bbfc8bcbe5d52','75d9f63237232000158bbfc8bcbe5dd0'), +('98906fb137032000158bbfc8bcbe5d65','781da52637232000158bbfc8bcbe5db8'), +('87245e061b13200050fdfbcd2c0713cc','7864ae0037332000158bbfc8bcbe5db8'), +('87245e061b13200050fdfbcd2c0713cc','7b10fd2637232000158bbfc8bcbe5d30'), +('59e22fb137032000158bbfc8bcbe5d52','81a880e037003000158bbfc8bcbe5df8'), +('74af88c6c611227d0066386e74dc853d','8a4cb6d4c61122780043b1642efcd52b'), +('1cb8ab9bff500200158bffffffffff62','8a4dde73c6112278017a6a4baf547aa7'), +('1cb8ab9bff500200158bffffffffff62','8a5055c9c61122780043563ef53438e3'), +('87245e061b13200050fdfbcd2c0713cc','96346e0037332000158bbfc8bcbe5daa'), +('59e22fb137032000158bbfc8bcbe5d52','96fb652637232000158bbfc8bcbe5db4'), +('59e22fb137032000158bbfc8bcbe5d52','a1d9f63237232000158bbfc8bcbe5dc3'), +('59e22fb137032000158bbfc8bcbe5d52','a5d9f63237232000158bbfc8bcbe5dca'), +('1cb8ab9bff500200158bffffffffff62','a715cd759f2002002920bde8132e7018'), +('59e22fb137032000158bbfc8bcbe5d52','a9d9f63237232000158bbfc8bcbe5dc0'), +('74af88c6c611227d0066386e74dc853d','aacb62e2c0a80015007f67f752c2b12c'), +('74af88c6c611227d0066386e74dc853d','aaccc971c0a8001500fe1ff4302de101'), +('59e22fb137032000158bbfc8bcbe5d52','add9f63237232000158bbfc8bcbe5dbb'), +('59e22fb137032000158bbfc8bcbe5d52','add9f63237232000158bbfc8bcbe5dc7'), +('59e22fb137032000158bbfc8bcbe5d52','b1d9f63237232000158bbfc8bcbe5dcf'), +('1cb8ab9bff500200158bffffffffff62','b85d44954a3623120004689b2d5dd60a'), +('1cb8ab9bff500200158bffffffffff62','b97e89b94a36231201676b73322a0311'), +('1cb8ab9bff500200158bffffffffff62','cfcbad03d711110050f5edcb9e61038f'), +('1cb8ab9bff500200158bffffffffff62','d625dccec0a8016700a222a0f7900d06'), +('1cb8ab9bff500200158bffffffffff62','db53580b0a0a0a6501aa37c294a2ba6b'), +('1cb8ab9bff500200158bffffffffff62','db53a9290a0a0a650091abebccf833c6'), +('1cb8ab9bff500200158bffffffffff62','dc0db135c332010016194ffe5bba8f23'), +('87245e061b13200050fdfbcd2c0713cc','df50316637232000158bbfc8bcbe5d23'), +('87245e061b13200050fdfbcd2c0713cc','e08fad2637232000158bbfc8bcbe5d39'), +('59e22fb137032000158bbfc8bcbe5d52','e1d9f63237232000158bbfc8bcbe5db8'), +('59e22fb137032000158bbfc8bcbe5d52','e5d9f63237232000158bbfc8bcbe5db4'), +('59e22fb137032000158bbfc8bcbe5d52','e5d9f63237232000158bbfc8bcbe5dbf'), +('59e22fb137032000158bbfc8bcbe5d52','e9d9f63237232000158bbfc8bcbe5dba'), +('59e22fb137032000158bbfc8bcbe5d52','e9d9f63237232000158bbfc8bcbe5dc6'), +('87245e061b13200050fdfbcd2c0713cc','ebb4620037332000158bbfc8bcbe5d89'), +('87245e061b13200050fdfbcd2c0713cc','ec70316637232000158bbfc8bcbe5d60'), +('87245e061b13200050fdfbcd2c0713cc','f253da061b13200050fdfbcd2c0713ab'), +('87245e061b13200050fdfbcd2c0713cc','f304ae0037332000158bbfc8bcbe5d4f'), +('98906fb137032000158bbfc8bcbe5d65','f972d6061b13200050fdfbcd2c0713e5'), +('59e22fb137032000158bbfc8bcbe5d52','fdd9f63237232000158bbfc8bcbe5dcd'); + +--enable_query_log + +let $q= +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND + t1.dispatch_group IN + (SELECT t2.ugroup + FROM t2, t3 t3_i + WHERE t2.ugroup = t3_i.sys_id AND + t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND + t2.user = '86826bf03710200044e0bfc8bcbe5d79'); + +set optimizer_switch='materialization=off'; +eval explain $q; +eval $q; + +set optimizer_switch='materialization=on'; +eval explain $q; +eval $q; + +DROP TABLE t1,t2,t3; +set optimizer_switch=@save_optimizer_switch; + --echo # End of 5.5 tests diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index d8b4de29f47..af1abb2001e 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -3429,6 +3429,7 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) table_map remaining_tables= 0; table_map handled_tabs= 0; join->sjm_lookup_tables= 0; + join->sjm_scan_tables= 0; for (tablenr= table_count - 1 ; tablenr != join->const_tables - 1; tablenr--) { POSITION *pos= join->best_positions + tablenr; @@ -3487,6 +3488,9 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join) for (i= tablenr; i != (first + sjm->tables - 1); i--) rem_tables |= join->best_positions[i].table->table->map; + for (i= first; i < first+ sjm->tables; i++) + join->sjm_scan_tables |= join->best_positions[i].table->table->map; + POSITION dummy; join->cur_sj_inner_tables= 0; for (i= first + sjm->tables; i <= tablenr; i++) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bad57aeac87..86ba0346366 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7361,6 +7361,63 @@ bool JOIN_TAB::hash_join_is_possible() } +/** + @brief + Check whether a KEYUSE can be really used for access this join table + + @param join Join structure with the best join order + for which the check is performed + @param keyuse Evaluated KEYUSE structure + + @details + This function is supposed to be used after the best execution plan have been + already chosen and the JOIN_TAB array for the best join order been already set. + For a given KEYUSE to access this JOIN_TAB in the best execution plan the + function checks whether it really can be used. The function first performs + the check with access_from_tables_is_allowed(). If it succeeds it checks + whether the keyuse->val does not use some fields of a materialized semijoin + nest that cannot be used to build keys to access outer tables. + Such KEYUSEs exists for the query like this: + select * from ot + where ot.c in (select it1.c from it1, it2 where it1.c=f(it2.c)) + Here we have two KEYUSEs to access table ot: with val=it1.c and val=f(it2.c). + However if the subquery was materialized the second KEYUSE cannot be employed + to access ot. + + @retval true the given keyuse can be used for ref access of this JOIN_TAB + @retval false otherwise +*/ + +bool JOIN_TAB::keyuse_is_valid_for_access_in_chosen_plan(JOIN *join, + KEYUSE *keyuse) +{ + if (!access_from_tables_is_allowed(keyuse->used_tables, + join->sjm_lookup_tables)) + return false; + if (join->sjm_scan_tables & table->map) + return true; + table_map keyuse_sjm_scan_tables= keyuse->used_tables & + join->sjm_scan_tables; + if (!keyuse_sjm_scan_tables) + return true; + uint sjm_tab_nr= 0; + while (!(keyuse_sjm_scan_tables & table_map(1) << sjm_tab_nr)) + sjm_tab_nr++; + JOIN_TAB *sjm_tab= join->map2table[sjm_tab_nr]; + TABLE_LIST *emb_sj_nest= sjm_tab->emb_sj_nest; + if (!(emb_sj_nest->sj_mat_info && emb_sj_nest->sj_mat_info->is_used && + emb_sj_nest->sj_mat_info->is_sj_scan)) + return true; + st_select_lex *sjm_sel= emb_sj_nest->sj_subq_pred->unit->first_select(); + for (uint i= 0; i < sjm_sel->item_list.elements; i++) + { + if (sjm_sel->ref_pointer_array[i] == keyuse->val) + return true; + } + return false; +} + + static uint cache_record_length(JOIN *join,uint idx) { @@ -7904,6 +7961,7 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab, do { if (!(~used_tables & keyuse->used_tables) && + join_tab->keyuse_is_valid_for_access_in_chosen_plan(join, keyuse) && are_tables_local(join_tab, keyuse->used_tables)) { if (first_keyuse) @@ -7918,6 +7976,8 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab, { if (curr->keypart == keyuse->keypart && !(~used_tables & curr->used_tables) && + join_tab->keyuse_is_valid_for_access_in_chosen_plan(join, + keyuse) && are_tables_local(join_tab, curr->used_tables)) break; } @@ -7951,6 +8011,7 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab, do { if (!(~used_tables & keyuse->used_tables) && + join_tab->keyuse_is_valid_for_access_in_chosen_plan(join, keyuse) && are_tables_local(join_tab, keyuse->used_tables)) { bool add_key_part= TRUE; @@ -7960,7 +8021,9 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab, { if (curr->keypart == keyuse->keypart && !(~used_tables & curr->used_tables) && - are_tables_local(join_tab, curr->used_tables)) + join_tab->keyuse_is_valid_for_access_in_chosen_plan(join, + curr) && + are_tables_local(join_tab, curr->used_tables)) { keyuse->keypart= NO_KEYPART; add_key_part= FALSE; @@ -8062,8 +8125,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, do { if (!(~used_tables & keyuse->used_tables) && - j->access_from_tables_is_allowed(keyuse->used_tables, - join->sjm_lookup_tables)) + j->keyuse_is_valid_for_access_in_chosen_plan(join, keyuse)) { if (are_tables_local(j, keyuse->val->used_tables())) { @@ -8132,8 +8194,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, for (i=0 ; i < keyparts ; keyuse++,i++) { while (((~used_tables) & keyuse->used_tables) || - !j->access_from_tables_is_allowed(keyuse->used_tables, - join->sjm_lookup_tables) || + !j->keyuse_is_valid_for_access_in_chosen_plan(join, keyuse) || keyuse->keypart == NO_KEYPART || (keyuse->keypart != (is_hash_join_key_no(key) ? diff --git a/sql/sql_select.h b/sql/sql_select.h index 0623672840e..1bc1e4c2b7a 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -540,6 +540,8 @@ typedef struct st_join_table { !(used_sjm_lookup_tables & ~emb_sj_nest->sj_inner_tables)); } + bool keyuse_is_valid_for_access_in_chosen_plan(JOIN *join, KEYUSE *keyuse); + } JOIN_TAB; @@ -1003,6 +1005,11 @@ public: to materialize and access by lookups */ table_map sjm_lookup_tables; + /** + Bitmap of semijoin tables that the chosen plan decided + to materialize to scan the results of materialization + */ + table_map sjm_scan_tables; /* Constant tables for which we have found a row (as opposed to those for which we didn't). @@ -1331,6 +1338,7 @@ public: pre_sort_join_tab= NULL; emb_sjm_nest= NULL; sjm_lookup_tables= 0; + sjm_scan_tables= 0; /* The following is needed because JOIN::cleanup(true) may be called for joins for which JOIN::optimize was aborted with an error before a proper From 151f4e9b4adea020fbe19b640016845dfa65d820 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 7 Jun 2017 16:29:55 -0700 Subject: [PATCH 52/97] Fixed the bug mdev-12963. This patch corrects the fix for bug mdev-7599. When the min/max optimization of the function opt_sum_query() optimizes away all tables of a subquery it should not ever be rolled back. --- mysql-test/r/subselect_mat_cost_bugs.result | 17 +++++++++++++++++ mysql-test/t/subselect_mat_cost_bugs.test | 16 ++++++++++++++++ sql/sql_select.cc | 1 + 3 files changed, 34 insertions(+) diff --git a/mysql-test/r/subselect_mat_cost_bugs.result b/mysql-test/r/subselect_mat_cost_bugs.result index dba4d049da3..57b0526c6a3 100644 --- a/mysql-test/r/subselect_mat_cost_bugs.result +++ b/mysql-test/r/subselect_mat_cost_bugs.result @@ -485,3 +485,20 @@ FROM t2 AS t2a INNER JOIN t2 t2b INNER JOIN t3 ON (f3 = t2b.f2) ); f1 DROP TABLE t1,t2,t3; +# +# MDEV-12963: min/max optimization optimizing away all tables employed +# for uncorrelated IN subquery used in a disjunct of WHERE +# +create table t1 (a int, index idx(a)) engine=myisam; +insert into t1 values (4),(7),(1),(3),(9); +select * from t1 where a in (select max(a) from t1 where a < 4) or a > 5; +a +3 +7 +9 +explain +select * from t1 where a in (select max(a) from t1 where a < 4) or a > 5; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index idx idx 5 NULL 5 Using where; Using index +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +drop table t1; diff --git a/mysql-test/t/subselect_mat_cost_bugs.test b/mysql-test/t/subselect_mat_cost_bugs.test index 9e3ac603ec6..35f2b9588fe 100644 --- a/mysql-test/t/subselect_mat_cost_bugs.test +++ b/mysql-test/t/subselect_mat_cost_bugs.test @@ -507,3 +507,19 @@ SELECT * FROM t1 ON (f3 = t2b.f2) ); DROP TABLE t1,t2,t3; + +--echo # +--echo # MDEV-12963: min/max optimization optimizing away all tables employed +--echo # for uncorrelated IN subquery used in a disjunct of WHERE +--echo # + +create table t1 (a int, index idx(a)) engine=myisam; +insert into t1 values (4),(7),(1),(3),(9); + +select * from t1 where a in (select max(a) from t1 where a < 4) or a > 5; +explain +select * from t1 where a in (select max(a) from t1 where a < 4) or a > 5; + +drop table t1; + + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 86ba0346366..f2be17f71d6 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1195,6 +1195,7 @@ JOIN::optimize() DBUG_PRINT("info",("Select tables optimized away")); zero_result_cause= "Select tables optimized away"; tables_list= 0; // All tables resolved + select_lex->min_max_opt_list.empty(); const_tables= top_join_tab_count= table_count; /* Extract all table-independent conditions and replace the WHERE From b850fc66ca72ed9b63cb8b899b64f8c555a525c7 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 7 Jun 2017 22:54:57 -0700 Subject: [PATCH 53/97] Fixed the bug mdev-12855. This is actually a legacy bug: SQL_SELECT::test_quick_select() was called with SQL_SELECT::head not set. It looks like that this problem can be reproduced only on queries with ORDER BY that use IN predicates converted to semi-joins. --- mysql-test/r/subselect_sj2_mat.result | 22 ++++++++++++++++++++++ mysql-test/t/subselect_sj2_mat.test | 20 ++++++++++++++++++++ sql/sql_select.cc | 5 ++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/subselect_sj2_mat.result b/mysql-test/r/subselect_sj2_mat.result index 202e6cc4b9e..835742a3ff4 100644 --- a/mysql-test/r/subselect_sj2_mat.result +++ b/mysql-test/r/subselect_sj2_mat.result @@ -1579,3 +1579,25 @@ Warnings: Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` semi join (`test`.`t2`) where ((rand() < 0)) drop table t1,t2; set optimizer_switch=@save_optimizer_switch; +# +# mdev-12855: materialization of a semi-join subquery + ORDER BY +# +CREATE TABLE t1 (f1 varchar(8), KEY(f1)) ENGINE=InnoDB; +INSERT INTO t1 VALUES ('qux'),('foo'); +CREATE TABLE t2 (f2 varchar(8)) ENGINE=InnoDB; +INSERT INTO t2 VALUES ('bar'),('foo'),('qux'); +SELECT f1 FROM t1 +WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' ) +HAVING f1 != 'foo' +ORDER BY f1; +f1 +qux +explain SELECT f1 FROM t1 +WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' ) +HAVING f1 != 'foo' +ORDER BY f1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index f1 f1 11 NULL 2 Using index +1 PRIMARY eq_ref distinct_key distinct_key 11 func 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +DROP TABLE t1,t2; diff --git a/mysql-test/t/subselect_sj2_mat.test b/mysql-test/t/subselect_sj2_mat.test index 0f2892ae2dc..cfb6c8c2819 100644 --- a/mysql-test/t/subselect_sj2_mat.test +++ b/mysql-test/t/subselect_sj2_mat.test @@ -283,3 +283,23 @@ select * from t1 where (rand() < 0) and i in (select i from t2); drop table t1,t2; set optimizer_switch=@save_optimizer_switch; + +--echo # +--echo # mdev-12855: materialization of a semi-join subquery + ORDER BY +--echo # + +CREATE TABLE t1 (f1 varchar(8), KEY(f1)) ENGINE=InnoDB; +INSERT INTO t1 VALUES ('qux'),('foo'); +CREATE TABLE t2 (f2 varchar(8)) ENGINE=InnoDB; +INSERT INTO t2 VALUES ('bar'),('foo'),('qux'); + +let $q= +SELECT f1 FROM t1 +WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' ) +HAVING f1 != 'foo' +ORDER BY f1; + +eval $q; +eval explain $q; + +DROP TABLE t1,t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f2be17f71d6..720c0a22681 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2759,8 +2759,11 @@ JOIN::exec() if (sort_table_cond) { if (!curr_table->select) + { if (!(curr_table->select= new SQL_SELECT)) DBUG_VOID_RETURN; + curr_table->select->head= curr_table->table; + } if (!curr_table->select->cond) curr_table->select->cond= sort_table_cond; else @@ -2846,7 +2849,7 @@ JOIN::exec() curr_join->select_limit, (select_options & OPTION_FOUND_ROWS ? HA_POS_ERROR : unit->select_limit_cnt), - curr_join->group_list ? TRUE : FALSE)) + curr_join->group_list ? FALSE : TRUE)) DBUG_VOID_RETURN; sortorder= curr_join->sortorder; if (curr_join->const_tables != curr_join->table_count && From 70b94c35d79eb9cef6963d535a5e8eb74a76198f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 14 Jun 2017 11:27:36 +0200 Subject: [PATCH 54/97] cleanup: move common test into a function --- sql/sql_plugin.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 2ec67a89746..0ceb3088c6a 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -316,6 +316,12 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref plugin); static void intern_plugin_unlock(LEX *lex, plugin_ref plugin); static void reap_plugins(void); +bool plugin_is_forced(struct st_plugin_int *p) +{ + return p->load_option == PLUGIN_FORCE || + p->load_option == PLUGIN_FORCE_PLUS_PERMANENT; +} + static void report_error(int where_to, uint error, ...) { va_list args; @@ -1657,8 +1663,7 @@ int plugin_init(int *argc, char **argv, int flags) while ((plugin_ptr= *(--reap))) { mysql_mutex_unlock(&LOCK_plugin); - if (plugin_ptr->load_option == PLUGIN_FORCE || - plugin_ptr->load_option == PLUGIN_FORCE_PLUS_PERMANENT) + if (plugin_is_forced(plugin_ptr)) reaped_mandatory_plugin= TRUE; plugin_deinitialize(plugin_ptr, true); mysql_mutex_lock(&LOCK_plugin); @@ -3505,8 +3510,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, plugin_dash.length + 1); strxmov(plugin_name_with_prefix_ptr, plugin_dash.str, plugin_name_ptr, NullS); - if (tmp->load_option != PLUGIN_FORCE && - tmp->load_option != PLUGIN_FORCE_PLUS_PERMANENT) + if (!plugin_is_forced(tmp)) { /* support --skip-plugin-foo syntax */ options[0].name= plugin_name_ptr; @@ -3823,8 +3827,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, We adjust the default value to account for the hardcoded exceptions we have set for the federated and ndbcluster storage engines. */ - if (tmp->load_option != PLUGIN_FORCE && - tmp->load_option != PLUGIN_FORCE_PLUS_PERMANENT) + if (!plugin_is_forced(tmp)) opts[0].def_value= opts[1].def_value= plugin_load_option; error= handle_options(argc, &argv, opts, NULL); @@ -3840,8 +3843,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, Set plugin loading policy from option value. First element in the option list is always the option value. */ - if (tmp->load_option != PLUGIN_FORCE && - tmp->load_option != PLUGIN_FORCE_PLUS_PERMANENT) + if (!plugin_is_forced(tmp)) plugin_load_option= (enum_plugin_load_option) *(ulong*) opts[0].value; } From 918e47030b49867d449bd9aaa54257616d5ebe42 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 14 Jun 2017 11:30:32 +0200 Subject: [PATCH 55/97] MDEV-13063 Server crashes in intern_plugin_lock or assertion `plugin_ptr->ref_count == 1' fails in plugin_init if a forced plugin is disabled (for any reason, e.g. invalid command-line option) - it's an error --- mysql-test/t/bootstrap.test | 6 ++++++ sql/sql_plugin.cc | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mysql-test/t/bootstrap.test b/mysql-test/t/bootstrap.test index 405c24a6d74..2930d936830 100644 --- a/mysql-test/t/bootstrap.test +++ b/mysql-test/t/bootstrap.test @@ -60,4 +60,10 @@ SHOW VARIABLES LIKE 'have_innodb'; SELECT 'bug' as '' FROM INFORMATION_SCHEMA.ENGINES WHERE engine='innodb' and SUPPORT='YES'; +# +# MDEV-13063 Server crashes in intern_plugin_lock or assertion `plugin_ptr->ref_count == 1' fails in plugin_init +# +--error 1 +--exec $MYSQLD_BOOTSTRAP_CMD --myisam_recover_options=NONE + --echo End of 5.5 tests diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 0ceb3088c6a..75aca02990d 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1359,7 +1359,7 @@ static int plugin_initialize(MEM_ROOT *tmp_root, struct st_plugin_int *plugin, if (options_only || state == PLUGIN_IS_DISABLED) { - ret= 0; + ret= !options_only && plugin_is_forced(plugin); goto err; } From 5cbbfe9f54f15a5281439dc21f22b599a69b5f87 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 14 Jun 2017 00:33:11 +0200 Subject: [PATCH 56/97] cleanup: remove duplicate code --- sql/sql_partition.cc | 37 ++++++++++++++----------------------- sql/sql_priv.h | 2 +- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index b0fb38bf748..43f9797eb62 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1913,6 +1913,19 @@ static int add_subpartition_by(File fptr) return err + add_partition_by(fptr); } +static int add_name_string(File fptr, const char *name) +{ + int err; + String name_string("", 0, system_charset_info); + THD *thd= current_thd; + ulonglong save_options= thd->variables.option_bits; + thd->variables.option_bits&= ~OPTION_QUOTE_SHOW_CREATE; + append_identifier(thd, &name_string, name, strlen(name)); + thd->variables.option_bits= save_options; + err= add_string_object(fptr, &name_string); + return err; +} + static int add_part_field_list(File fptr, List field_list) { uint i, num_fields; @@ -1924,15 +1937,7 @@ static int add_part_field_list(File fptr, List field_list) err+= add_begin_parenthesis(fptr); while (i < num_fields) { - const char *field_str= part_it++; - String field_string("", 0, system_charset_info); - THD *thd= current_thd; - ulonglong save_options= thd->variables.option_bits; - thd->variables.option_bits&= ~OPTION_QUOTE_SHOW_CREATE; - append_identifier(thd, &field_string, field_str, - strlen(field_str)); - thd->variables.option_bits= save_options; - err+= add_string_object(fptr, &field_string); + err+= add_name_string(fptr, part_it++); if (i != (num_fields-1)) err+= add_comma(fptr); i++; @@ -1941,20 +1946,6 @@ static int add_part_field_list(File fptr, List field_list) return err; } -static int add_name_string(File fptr, const char *name) -{ - int err; - String name_string("", 0, system_charset_info); - THD *thd= current_thd; - ulonglong save_options= thd->variables.option_bits; - thd->variables.option_bits&= ~OPTION_QUOTE_SHOW_CREATE; - append_identifier(thd, &name_string, name, - strlen(name)); - thd->variables.option_bits= save_options; - err= add_string_object(fptr, &name_string); - return err; -} - static int add_int(File fptr, longlong number) { char buff[32]; diff --git a/sql/sql_priv.h b/sql/sql_priv.h index 749ee245aa7..b5589cb4b22 100644 --- a/sql/sql_priv.h +++ b/sql/sql_priv.h @@ -121,7 +121,7 @@ #define OPTION_AUTOCOMMIT (1ULL << 8) // THD, user #define OPTION_BIG_SELECTS (1ULL << 9) // THD, user #define OPTION_LOG_OFF (1ULL << 10) // THD, user -#define OPTION_QUOTE_SHOW_CREATE (1ULL << 11) // THD, user, unused +#define OPTION_QUOTE_SHOW_CREATE (1ULL << 11) // THD, user #define TMP_TABLE_ALL_COLUMNS (1ULL << 12) // SELECT, intern #define OPTION_WARNINGS (1ULL << 13) // THD, user #define OPTION_AUTO_IS_NULL (1ULL << 14) // THD, user, binlog From c661b4d0fb38c103fc0b659a95e8552ea72574cf Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 14 Jun 2017 00:48:34 +0200 Subject: [PATCH 57/97] MDEV-13017 LOCK TABLE fails with irrelevant error while working with tables affected by ANSI_QUOTES --- mysql-test/suite/parts/r/quoting.result | 6 ++++++ mysql-test/suite/parts/t/quoting.test | 10 ++++++++++ sql/sql_partition.cc | 3 +++ 3 files changed, 19 insertions(+) create mode 100644 mysql-test/suite/parts/r/quoting.result create mode 100644 mysql-test/suite/parts/t/quoting.test diff --git a/mysql-test/suite/parts/r/quoting.result b/mysql-test/suite/parts/r/quoting.result new file mode 100644 index 00000000000..ba6a155e6ac --- /dev/null +++ b/mysql-test/suite/parts/r/quoting.result @@ -0,0 +1,6 @@ +set sql_mode=ansi_quotes; +create table t1 (i int) partition by range (i) (partition flush values less than maxvalue); +set sql_mode=default; +lock tables t1 read local; +unlock tables; +drop table t1; diff --git a/mysql-test/suite/parts/t/quoting.test b/mysql-test/suite/parts/t/quoting.test new file mode 100644 index 00000000000..297896fd9cf --- /dev/null +++ b/mysql-test/suite/parts/t/quoting.test @@ -0,0 +1,10 @@ +# +# MDEV-13017 LOCK TABLE fails with irrelevant error while working with tables affected by ANSI_QUOTES +# +--source include/have_partition.inc +set sql_mode=ansi_quotes; +create table t1 (i int) partition by range (i) (partition flush values less than maxvalue); +set sql_mode=default; +lock tables t1 read local; +unlock tables; +drop table t1; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 43f9797eb62..e6513fc7476 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1918,9 +1918,12 @@ static int add_name_string(File fptr, const char *name) int err; String name_string("", 0, system_charset_info); THD *thd= current_thd; + ulonglong save_sql_mode= thd->variables.sql_mode; + thd->variables.sql_mode&= ~MODE_ANSI_QUOTES; ulonglong save_options= thd->variables.option_bits; thd->variables.option_bits&= ~OPTION_QUOTE_SHOW_CREATE; append_identifier(thd, &name_string, name, strlen(name)); + thd->variables.sql_mode= save_sql_mode; thd->variables.option_bits= save_options; err= add_string_object(fptr, &name_string); return err; From c7141fa75df91ae4c2a1214283111eeb1c2eda11 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 15 Jun 2017 14:41:59 +0200 Subject: [PATCH 58/97] MDEV-13002 mysqltest regex replace results in incorrect result regex didn't replace lines that were split by 16K chunk reads. --- client/mysqltest.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index b22959677d0..4de40953f7d 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -1698,12 +1698,22 @@ int cat_file(DYNAMIC_STRING* ds, const char* filename) { int fd; size_t len; - char buff[16384]; + char *buff; if ((fd= my_open(filename, O_RDONLY, MYF(0))) < 0) return 1; - while((len= my_read(fd, (uchar*)&buff, - sizeof(buff)-1, MYF(0))) > 0) + + len= (size_t) my_seek(fd, 0, SEEK_END, MYF(0)); + my_seek(fd, 0, SEEK_SET, MYF(0)); + if (len == (size_t)MY_FILEPOS_ERROR || + !(buff= (char*)my_malloc(len + 1, MYF(0)))) + { + my_close(fd, MYF(0)); + return 1; + } + len= my_read(fd, (uchar*)buff, len, MYF(0)); + my_close(fd, MYF(0)); + { char *p= buff, *start= buff,*end=buff+len; while (p < end) @@ -1726,7 +1736,7 @@ int cat_file(DYNAMIC_STRING* ds, const char* filename) *p= 0; replace_dynstr_append_mem(ds, start, p-start); } - my_close(fd, MYF(0)); + my_free(buff); return 0; } From e548e2184bed04478ba1fe5107da817bc768d023 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 26 Mar 2017 16:00:35 +1100 Subject: [PATCH 59/97] Use CPACK_RPM_FILE_NAME="RPM-DEFAULT" This has been implemented in for cmake-3.6 to match distro version of what the filename should look like. Thanks to Domen Vranka for the suggestion. --- cmake/cpack_rpm.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/cpack_rpm.cmake b/cmake/cpack_rpm.cmake index 5789eb7694a..c3ec731144b 100644 --- a/cmake/cpack_rpm.cmake +++ b/cmake/cpack_rpm.cmake @@ -28,7 +28,11 @@ SET(CPACK_COMPONENTS_ALL Server ManPagesServer IniFiles Server_Scripts Common Client SharedLibraries) SET(CPACK_RPM_PACKAGE_NAME "MariaDB") -SET(CPACK_PACKAGE_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${VERSION}-${RPM}-${CMAKE_SYSTEM_PROCESSOR}") +IF(CMAKE_VERSION VERSION_LESS "3.6.0") + SET(CPACK_PACKAGE_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${VERSION}-${RPM}-${CMAKE_SYSTEM_PROCESSOR}") +ELSE() + SET(CPACK_RPM_FILE_NAME "RPM-DEFAULT") +ENDIF() SET(CPACK_RPM_PACKAGE_RELEASE "1%{?dist}") SET(CPACK_RPM_PACKAGE_LICENSE "GPLv2") From 48429359d6bb6382245f1949c458f8219996aa4a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 16 Jun 2017 11:34:59 +0200 Subject: [PATCH 60/97] MDEV-4646 No mysqld-debug or debuginfo in MariaDB-Server RPM --- cmake/cpack_rpm.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/cpack_rpm.cmake b/cmake/cpack_rpm.cmake index c3ec731144b..4e9410306a8 100644 --- a/cmake/cpack_rpm.cmake +++ b/cmake/cpack_rpm.cmake @@ -32,6 +32,7 @@ IF(CMAKE_VERSION VERSION_LESS "3.6.0") SET(CPACK_PACKAGE_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${VERSION}-${RPM}-${CMAKE_SYSTEM_PROCESSOR}") ELSE() SET(CPACK_RPM_FILE_NAME "RPM-DEFAULT") + SET(CPACK_RPM_DEBUGINFO_PACKAGE ON) ENDIF() SET(CPACK_RPM_PACKAGE_RELEASE "1%{?dist}") From ded614d7dbc930e373d1a69a0d2a7e4bf0a2c6d3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 14 Jun 2017 13:44:31 +0200 Subject: [PATCH 61/97] MDEV-12778 mariadb-10.1 FTBFS on GNU/Hurd due to use of PATH_MAX --- mysys/my_symlink.c | 2 +- mysys/mysys_priv.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c index ed35fff41e9..12959f1f24a 100644 --- a/mysys/my_symlink.c +++ b/mysys/my_symlink.c @@ -197,7 +197,7 @@ int my_realpath(char *to, const char *filename, myf MyFlags) const char *my_open_parent_dir_nosymlinks(const char *pathname, int *pdfd) { - char buf[PATH_MAX+1]; + char buf[FN_REFLEN + 1]; char *s= buf, *e= buf+1, *end= strnmov(buf, pathname, sizeof(buf)); int fd, dfd= -1; diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h index 661c4c184f1..1004bf8889f 100644 --- a/mysys/mysys_priv.h +++ b/mysys/mysys_priv.h @@ -107,12 +107,21 @@ const char *my_open_parent_dir_nosymlinks(const char *pathname, int *pdfd); res= AT; \ if (dfd >= 0) close(dfd); \ return res; -#elif defined(HAVE_REALPATH) +#elif defined(HAVE_REALPATH) && defined(PATH_MAX) #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ char buf[PATH_MAX+1]; \ if (realpath(pathname, buf) == NULL) return -1; \ if (strcmp(pathname, buf)) { errno= ENOTDIR; return -1; } \ return NOAT; +#elif defined(HAVE_REALPATH) +#define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ + char *buf= realpath(pathname, NULL); \ + int res; \ + if (buf == NULL) return -1; \ + if (strcmp(pathname, buf)) { errno= ENOTDIR; res= -1; } \ + else res= NOAT; \ + free(buf); \ + return res; #else #define NOSYMLINK_FUNCTION_BODY(AT,NOAT) \ return NOAT; From 39385ff7b253302723a94c896d199a83adb8622f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 27 Jun 2017 13:25:50 +0200 Subject: [PATCH 62/97] MDEV-13187 incorrect backslash parsing in clients don't do backslash escapes inside backticks --- client/mysql.cc | 4 ++-- client/mysqltest.cc | 4 ++-- mysql-test/r/mysql.result | 28 ++++++++++++++++++++++++++++ mysql-test/t/mysql.test | 15 +++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index 57cb0a918a7..6a800e407a3 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2287,8 +2287,8 @@ static bool add_line(String &buffer, char *line, ulong line_length, continue; } #endif - if (!*ml_comment && inchar == '\\' && - !(*in_string && + if (!*ml_comment && inchar == '\\' && *in_string != '`' && + !(*in_string && (mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))) { // Found possbile one character command like \c diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 4de40953f7d..ee636c9401d 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6594,7 +6594,7 @@ int read_line(char *buf, int size) state= R_Q; } } - have_slash= (c == '\\'); + have_slash= (c == '\\' && last_quote != '`'); break; case R_COMMENT: @@ -6664,7 +6664,7 @@ int read_line(char *buf, int size) case R_Q: if (c == last_quote) state= R_NORMAL; - else if (c == '\\') + else if (c == '\\' && last_quote != '`') state= R_SLASH_IN_Q; break; diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index dd0129df0d9..dad8b3a701c 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -529,3 +529,31 @@ a +-------------------+ End of tests +create table `a1\``b1` (a int); +show tables; +Tables_in_test +a1\`b1 +insert `a1\``b1` values (1),(2); +show create table `a1\``b1`; +Table Create Table +a1\`b1 CREATE TABLE `a1\``b1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `a1\``b1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO `a1\``b1` VALUES (1),(2); +insert `a1\``b1` values (4),(5); +show create table `a1\``b1`; +Table Create Table +a1\`b1 CREATE TABLE `a1\``b1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from `a1\``b1`; +a +1 +2 +drop table `a1\``b1`; diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index d59083d66b0..20205924e15 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -618,3 +618,18 @@ EOF --echo --echo End of tests + +# +# MDEV-13187 incorrect backslash parsing in clients +# +create table `a1\``b1` (a int); +show tables; +insert `a1\``b1` values (1),(2); +show create table `a1\``b1`; +--exec $MYSQL_DUMP --compact test +--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug.sql +insert `a1\``b1` values (4),(5); +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql +show create table `a1\``b1`; +select * from `a1\``b1`; +drop table `a1\``b1`; From d5cd33450413816f8696125cd66c8393921e6267 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 27 Jun 2017 14:00:10 +0200 Subject: [PATCH 63/97] MDEV-13187 incorrect backslash parsing in clients cover ANSI_QUOTES and NO_BACKSLASH_ESCAPES in mysqltest --- client/mysql.cc | 2 ++ client/mysqltest.cc | 14 ++++++++++++-- include/mysql_com.h | 2 ++ mysql-test/r/mysql.result | 30 ++++++++++++++++++++++++++++++ mysql-test/r/mysqltest.result | 5 +++++ mysql-test/t/mysql.test | 15 +++++++++++++++ mysql-test/t/mysqltest.test | 8 +++++++- sql/sql_class.cc | 2 ++ sql/sys_vars.cc | 4 ++++ 9 files changed, 79 insertions(+), 3 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index 6a800e407a3..a965ced89c6 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2288,6 +2288,8 @@ static bool add_line(String &buffer, char *line, ulong line_length, } #endif if (!*ml_comment && inchar == '\\' && *in_string != '`' && + !(*in_string == '"' && + (mysql.server_status & SERVER_STATUS_ANSI_QUOTES)) && !(*in_string && (mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))) { diff --git a/client/mysqltest.cc b/client/mysqltest.cc index ee636c9401d..f5ee94f1839 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6486,6 +6486,16 @@ my_bool end_of_query(int c) } +static inline bool is_escape_char(char c, char in_string) +{ + if (c != '\\' || in_string == '`') return false; + if (!cur_con) return true; + uint server_status= cur_con->mysql->server_status; + if (server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) return false; + return !(server_status & SERVER_STATUS_ANSI_QUOTES && in_string == '"'); +} + + /* Read one "line" from the file @@ -6594,7 +6604,7 @@ int read_line(char *buf, int size) state= R_Q; } } - have_slash= (c == '\\' && last_quote != '`'); + have_slash= is_escape_char(c, last_quote); break; case R_COMMENT: @@ -6664,7 +6674,7 @@ int read_line(char *buf, int size) case R_Q: if (c == last_quote) state= R_NORMAL; - else if (c == '\\' && last_quote != '`') + else if (is_escape_char(c, last_quote)) state= R_SLASH_IN_Q; break; diff --git a/include/mysql_com.h b/include/mysql_com.h index 0d57b178937..df9681e02a4 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -296,6 +296,8 @@ enum enum_server_command */ #define SERVER_PS_OUT_PARAMS 4096 +#define SERVER_STATUS_ANSI_QUOTES 32768 + /** Server status flags that must be cleared when starting execution of a new SQL statement. diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index dad8b3a701c..8a24128daa2 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -557,3 +557,33 @@ a 1 2 drop table `a1\``b1`; +set sql_mode=ansi_quotes; +create table "a1\""b1" (a int); +show tables; +Tables_in_test +a1\"b1 +insert "a1\""b1" values (1),(2); +show create table "a1\""b1"; +Table Create Table +a1\"b1 CREATE TABLE "a1\""b1" ( + "a" int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE "a1\""b1" ( + "a" int(11) DEFAULT NULL +); +/*!40101 SET character_set_client = @saved_cs_client */; +INSERT INTO "a1\""b1" VALUES (1),(2); +insert "a1\""b1" values (4),(5); +show create table "a1\""b1"; +Table Create Table +a1\"b1 CREATE TABLE "a1\""b1" ( + "a" int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from "a1\""b1"; +a +1 +2 +drop table "a1\""b1"; +set sql_mode=default; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 0ebef585974..9800aed6368 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -957,4 +957,9 @@ con1 con2 con2 -closed_connection- +set sql_mode=no_backslash_escapes; +select "foo\""bar"; +foo\"bar +foo\"bar +set sql_mode=default; End of tests diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index 20205924e15..dd964c46420 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -633,3 +633,18 @@ insert `a1\``b1` values (4),(5); show create table `a1\``b1`; select * from `a1\``b1`; drop table `a1\``b1`; + +# same with ansi_quotes +set sql_mode=ansi_quotes; +create table "a1\""b1" (a int); +show tables; +insert "a1\""b1" values (1),(2); +show create table "a1\""b1"; +--exec $MYSQL_DUMP --compact --compatible=postgres test +--exec $MYSQL_DUMP --compatible=postgres test > $MYSQLTEST_VARDIR/tmp/bug.sql +insert "a1\""b1" values (4),(5); +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql +show create table "a1\""b1"; +select * from "a1\""b1"; +drop table "a1\""b1"; +set sql_mode=default; diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 6470ede4f14..afe37926591 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -2942,11 +2942,17 @@ disconnect $x; # Disconnect the selected connection disconnect $y; --echo $CURRENT_CONNECTION +connection default; +# +# MDEV-13187 incorrect backslash parsing in clients +# +set sql_mode=no_backslash_escapes; +select "foo\""bar"; +set sql_mode=default; --echo End of tests -connection default; # Wait till we reached the initial number of concurrent sessions --source include/wait_until_count_sessions.inc diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 46eabb41a74..3c07c1606a2 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1250,6 +1250,8 @@ void THD::init(void) server_status= SERVER_STATUS_AUTOCOMMIT; if (variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES; + if (variables.sql_mode & MODE_ANSI_QUOTES) + server_status|= SERVER_STATUS_ANSI_QUOTES; transaction.all.modified_non_trans_table= transaction.stmt.modified_non_trans_table= FALSE; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 35997525456..ffe861ddfbc 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -2173,6 +2173,10 @@ static bool fix_sql_mode(sys_var *self, THD *thd, enum_var_type type) thd->server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES; else thd->server_status&= ~SERVER_STATUS_NO_BACKSLASH_ESCAPES; + if (thd->variables.sql_mode & MODE_ANSI_QUOTES) + thd->server_status|= SERVER_STATUS_ANSI_QUOTES; + else + thd->server_status&= ~SERVER_STATUS_ANSI_QUOTES; } return false; } From 4db6e1e4a502df5a4b30aed60552314533b35d79 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 29 Jun 2017 20:47:08 +0200 Subject: [PATCH 64/97] uninitialized variable --- client/mysqltest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index f5ee94f1839..98e35136b2a 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -6522,7 +6522,7 @@ static inline bool is_escape_char(char c, char in_string) int read_line(char *buf, int size) { - char c, UNINIT_VAR(last_quote), last_char= 0; + char c, last_quote=0, last_char= 0; char *p= buf, *buf_end= buf + size - 1; int skip_char= 0; my_bool have_slash= FALSE; From 9fc71eebb6b96d76a2688a08bb810f2856b7a113 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 16:48:11 +1000 Subject: [PATCH 65/97] item_timefunc: identical operands CID 971836 (#1 of 1): Same on both sides (CONSTANT_EXPRESSION_RESULT) pointless_expression: The expression val != end && val != end does not accomplish anything because it evaluates to either of its identical operands, val != end. --- sql/item_timefunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 420fb29f518..0ed1506bbee 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -3041,7 +3041,7 @@ get_date_time_result_type(const char *format, uint length) const char *val= format; const char *end= format + length; - for (; val != end && val != end; val++) + for (; val != end; val++) { if (*val == '%' && val+1 != end) { From cb870674d437d1f544ad0ccb2c759207b1735e8e Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 15:40:37 +1000 Subject: [PATCH 66/97] ha_archive::info remove hidden assignment max_data_file_size is overwritten in next statement so this assignment didn't ever get used. Found by Coverity (ID 1409644) --- storage/archive/ha_archive.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 872373bbeb6..d39d1187ce6 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -1640,7 +1640,6 @@ int ha_archive::info(uint flag) stats.update_time= (ulong) file_stat.st_mtime; if (flag & HA_STATUS_CONST) { - stats.max_data_file_length= share->rows_recorded * stats.mean_rec_length; stats.max_data_file_length= MAX_FILE_SIZE; stats.create_time= (ulong) file_stat.st_ctime; } From 623c3f673195e143338cb657df554e397097fb42 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 11:26:02 +1000 Subject: [PATCH 67/97] thread_group_close: release mutex in all branches Found by Coverity scan - id 92087 --- sql/threadpool_unix.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc index 6075c758e40..0ffe08a8051 100644 --- a/sql/threadpool_unix.cc +++ b/sql/threadpool_unix.cc @@ -979,24 +979,26 @@ static void thread_group_close(thread_group_t *thread_group) if (pipe(thread_group->shutdown_pipe)) { - DBUG_VOID_RETURN; + goto end; } /* Wake listener */ if (io_poll_associate_fd(thread_group->pollfd, thread_group->shutdown_pipe[0], NULL)) { - DBUG_VOID_RETURN; + goto end; + } + { + char c= 0; + if (write(thread_group->shutdown_pipe[1], &c, 1) < 0) + goto end; } - char c= 0; - if (write(thread_group->shutdown_pipe[1], &c, 1) < 0) - DBUG_VOID_RETURN; - /* Wake all workers. */ while(wake_thread(thread_group) == 0) { } +end: mysql_mutex_unlock(&thread_group->mutex); DBUG_VOID_RETURN; From 051f90a534758c4da038023a8ebdb57bd414cfe3 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 13:37:14 +1000 Subject: [PATCH 68/97] ma_loghandler: release file_header_lock on error translog_stop_writing doesn't release a lock (though does to a DBUG_ASSERT). Better to just release the lock. Found by Coverity id 972092 --- storage/maria/ma_loghandler.c | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/maria/ma_loghandler.c b/storage/maria/ma_loghandler.c index 16cd0a09af5..fd256a48358 100644 --- a/storage/maria/ma_loghandler.c +++ b/storage/maria/ma_loghandler.c @@ -1269,6 +1269,7 @@ static my_bool translog_set_lsn_for_files(uint32 from_file, uint32 to_file, mysql_file_close(fd, MYF(MY_WME)))) { translog_stop_writing(); + mysql_mutex_unlock(&log_descriptor.file_header_lock); DBUG_RETURN(1); } } From 2328860379eb6e1df240f5428213ed005b35a975 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 13:42:46 +1000 Subject: [PATCH 69/97] ma_loghandler: translog_set_only_in_buffers failed to release lock Release the lock for the error path. Found by Coverity (id 972093). --- storage/maria/ma_loghandler.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/maria/ma_loghandler.c b/storage/maria/ma_loghandler.c index fd256a48358..e2e52546fc9 100644 --- a/storage/maria/ma_loghandler.c +++ b/storage/maria/ma_loghandler.c @@ -2292,10 +2292,11 @@ static void translog_set_only_in_buffers(TRANSLOG_ADDRESS in_buffers) if (cmp_translog_addr(in_buffers, log_descriptor.in_buffers_only) > 0) { if (translog_status != TRANSLOG_OK) - DBUG_VOID_RETURN; + goto end; log_descriptor.in_buffers_only= in_buffers; DBUG_PRINT("info", ("set new in_buffers_only")); } +end: mysql_mutex_unlock(&log_descriptor.sent_to_disk_lock); DBUG_VOID_RETURN; } From 89b81a9a24c08221dc551d8572ef68e426afce3a Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 13:52:34 +1000 Subject: [PATCH 70/97] ma_pagecache: release lock in pagecache_read make_lock_and_pin didn't release the lock so we should. Found by Coverity (id 972095). --- storage/maria/ma_pagecache.c | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/maria/ma_pagecache.c b/storage/maria/ma_pagecache.c index 1a791d43034..bb9f5a03ad7 100644 --- a/storage/maria/ma_pagecache.c +++ b/storage/maria/ma_pagecache.c @@ -3474,6 +3474,7 @@ restart: lock_to_read[lock].unlock_lock, unlock_pin, FALSE)) { + pagecache_pthread_mutex_unlock(&pagecache->cache_lock); DBUG_ASSERT(0); return (uchar*) 0; } From 23ac2dd2a4c5f281479980d0156a2ccebab510b2 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 4 Jul 2017 13:28:47 +1000 Subject: [PATCH 71/97] sql_class: incorrect assignment in Security_context::destroy Found by Coverity (id 971843). Signed-off-by: Daniel Black --- sql/sql_class.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 3c07c1606a2..00d860e7887 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3670,7 +3670,7 @@ void Security_context::destroy() if (external_user) { my_free(external_user); - user= NULL; + external_user= NULL; } my_free(ip); From a7ed4644a6f3e38dbad3658fc35890ce31cc0749 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 3 Jul 2017 13:35:32 +0200 Subject: [PATCH 72/97] MDEV-10146: Wrong result (or questionable result and behavior) with aggregate function in uncorrelated SELECT subquery When outer reference resolved in a VIEW it still should mark aggregate function resolving border. --- mysql-test/r/subselect.result | 22 ++++++++++++++++++++ mysql-test/r/subselect_no_mat.result | 22 ++++++++++++++++++++ mysql-test/r/subselect_no_opts.result | 22 ++++++++++++++++++++ mysql-test/r/subselect_no_scache.result | 22 ++++++++++++++++++++ mysql-test/r/subselect_no_semijoin.result | 22 ++++++++++++++++++++ mysql-test/t/subselect.test | 25 +++++++++++++++++++++++ sql/item.cc | 7 +++++++ 7 files changed, 142 insertions(+) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 789cfe2fdca..000d8927542 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -7116,3 +7116,25 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 ); f1 f2 foo bar DROP TABLE t1; +# +# MDEV-10146: Wrong result (or questionable result and behavior) +# with aggregate function in uncorrelated SELECT subquery +# +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 int); +INSERT INTO t2 VALUES (3); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +( SELECT MAX(f1) FROM t2 ) +2 +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +( SELECT MAX(f1) FROM t2 ) +2 +INSERT INTO t2 VALUES (4); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +ERROR 21000: Subquery returns more than 1 row +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +ERROR 21000: Subquery returns more than 1 row +drop view v1; +drop table t1,t2; diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index c729c17f94f..914f20d502a 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -7113,6 +7113,28 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 ); f1 f2 foo bar DROP TABLE t1; +# +# MDEV-10146: Wrong result (or questionable result and behavior) +# with aggregate function in uncorrelated SELECT subquery +# +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 int); +INSERT INTO t2 VALUES (3); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +( SELECT MAX(f1) FROM t2 ) +2 +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +( SELECT MAX(f1) FROM t2 ) +2 +INSERT INTO t2 VALUES (4); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +ERROR 21000: Subquery returns more than 1 row +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +ERROR 21000: Subquery returns more than 1 row +drop view v1; +drop table t1,t2; set optimizer_switch=default; select @@optimizer_switch like '%materialization=on%'; @@optimizer_switch like '%materialization=on%' diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index dc308ea77e5..1b25e16ba7c 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -7111,4 +7111,26 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 ); f1 f2 foo bar DROP TABLE t1; +# +# MDEV-10146: Wrong result (or questionable result and behavior) +# with aggregate function in uncorrelated SELECT subquery +# +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 int); +INSERT INTO t2 VALUES (3); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +( SELECT MAX(f1) FROM t2 ) +2 +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +( SELECT MAX(f1) FROM t2 ) +2 +INSERT INTO t2 VALUES (4); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +ERROR 21000: Subquery returns more than 1 row +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +ERROR 21000: Subquery returns more than 1 row +drop view v1; +drop table t1,t2; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index e7c85c10f2d..90a11fbce7d 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -7122,6 +7122,28 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 ); f1 f2 foo bar DROP TABLE t1; +# +# MDEV-10146: Wrong result (or questionable result and behavior) +# with aggregate function in uncorrelated SELECT subquery +# +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 int); +INSERT INTO t2 VALUES (3); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +( SELECT MAX(f1) FROM t2 ) +2 +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +( SELECT MAX(f1) FROM t2 ) +2 +INSERT INTO t2 VALUES (4); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +ERROR 21000: Subquery returns more than 1 row +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +ERROR 21000: Subquery returns more than 1 row +drop view v1; +drop table t1,t2; set optimizer_switch=default; select @@optimizer_switch like '%subquery_cache=on%'; @@optimizer_switch like '%subquery_cache=on%' diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index b6261f05098..936aae07227 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -7111,5 +7111,27 @@ SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 ); f1 f2 foo bar DROP TABLE t1; +# +# MDEV-10146: Wrong result (or questionable result and behavior) +# with aggregate function in uncorrelated SELECT subquery +# +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 int); +INSERT INTO t2 VALUES (3); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +( SELECT MAX(f1) FROM t2 ) +2 +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +( SELECT MAX(f1) FROM t2 ) +2 +INSERT INTO t2 VALUES (4); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +ERROR 21000: Subquery returns more than 1 row +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; +ERROR 21000: Subquery returns more than 1 row +drop view v1; +drop table t1,t2; set @optimizer_switch_for_subselect_test=null; set @join_cache_level_for_subselect_test=NULL; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index a8ad3ba52a5..c5f5b229656 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -5998,3 +5998,28 @@ INSERT INTO t1 VALUES ('foo','bar'); SELECT * FROM t1 WHERE f2 >= SOME ( SELECT f1 FROM t1 ); SELECT * FROM t1 WHERE f2 <= SOME ( SELECT f1 FROM t1 ); DROP TABLE t1; + +--echo # +--echo # MDEV-10146: Wrong result (or questionable result and behavior) +--echo # with aggregate function in uncorrelated SELECT subquery +--echo # +CREATE TABLE t1 (f1 INT); +CREATE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES (1),(2); + +CREATE TABLE t2 (f2 int); + +INSERT INTO t2 VALUES (3); +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; + +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; + +INSERT INTO t2 VALUES (4); + +--error ER_SUBQUERY_NO_1_ROW +SELECT ( SELECT MAX(f1) FROM t2 ) FROM v1; +--error ER_SUBQUERY_NO_1_ROW +SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; + +drop view v1; +drop table t1,t2; diff --git a/sql/item.cc b/sql/item.cc index 1df91dc2534..68411860274 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5045,6 +5045,13 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) ((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ? (Item_ident*) (*reference) : 0)); + if (thd->lex->in_sum_func && + thd->lex->in_sum_func->nest_level >= select->nest_level) + { + Item::Type ref_type= (*reference)->type(); + set_if_bigger(thd->lex->in_sum_func->max_arg_level, + select->nest_level); + } /* A reference to a view field had been found and we substituted it instead of this Item (find_field_in_tables From f305a7ce4bccbd56520d874e1d81a4f29bc17a96 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 6 Jul 2017 14:06:37 +0200 Subject: [PATCH 73/97] bugfix: long partition names --- mysql-test/suite/parts/r/longname.result | 33 ++++ mysql-test/suite/parts/t/longname.test | 29 ++++ sql/ha_partition.cc | 195 +++++++++++++---------- sql/sql_partition.cc | 118 ++++++++------ sql/sql_partition.h | 12 +- 5 files changed, 253 insertions(+), 134 deletions(-) create mode 100644 mysql-test/suite/parts/r/longname.result create mode 100644 mysql-test/suite/parts/t/longname.test diff --git a/mysql-test/suite/parts/r/longname.result b/mysql-test/suite/parts/r/longname.result new file mode 100644 index 00000000000..40097d60d15 --- /dev/null +++ b/mysql-test/suite/parts/r/longname.result @@ -0,0 +1,33 @@ +set names utf8; +create database mysqltest1; +CREATE TABLE mysqltest1.test_jfg_table_name_with_64_chars_123456789012345678901234567890 ( +id int(10) unsigned NOT NULL, +id2 int(10) unsigned NOT NULL, +PRIMARY KEY ( id, id2 ) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC +PARTITION BY RANGE ( id ) +SUBPARTITION BY HASH ( id2 ) +SUBPARTITIONS 2 ( +PARTITION test_jfg_partition_name_with_60_chars_1234567890123456789012 VALUES LESS THAN (1000) ENGINE = InnoDB, +PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB); +Warnings: +Warning 1478 InnoDB: ROW_FORMAT=DYNAMIC requires innodb_file_per_table. +Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT. +Warning 1478 InnoDB: ROW_FORMAT=DYNAMIC requires innodb_file_per_table. +Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT. +Warning 1478 InnoDB: ROW_FORMAT=DYNAMIC requires innodb_file_per_table. +Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT. +Warning 1478 InnoDB: ROW_FORMAT=DYNAMIC requires innodb_file_per_table. +Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT. +CREATE TABLE mysqltest1.éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé ( +id int(10) unsigned NOT NULL, +id2 int(10) unsigned NOT NULL, +PRIMARY KEY ( id, id2 ) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC +PARTITION BY RANGE ( id ) +SUBPARTITION BY HASH ( id2 ) +SUBPARTITIONS 2 ( +PARTITION çççççççççççççççççççççççççççççççççççççççççççççççççççççççççççç VALUES LESS THAN (1000) ENGINE = InnoDB, +PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB); +ERROR HY000: The path specified for @0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@0n@ is too long. +drop database mysqltest1; diff --git a/mysql-test/suite/parts/t/longname.test b/mysql-test/suite/parts/t/longname.test new file mode 100644 index 00000000000..feea5a790f2 --- /dev/null +++ b/mysql-test/suite/parts/t/longname.test @@ -0,0 +1,29 @@ +source include/have_innodb.inc; +source include/have_partition.inc; +set names utf8; + +create database mysqltest1; +CREATE TABLE mysqltest1.test_jfg_table_name_with_64_chars_123456789012345678901234567890 ( + id int(10) unsigned NOT NULL, + id2 int(10) unsigned NOT NULL, + PRIMARY KEY ( id, id2 ) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC +PARTITION BY RANGE ( id ) + SUBPARTITION BY HASH ( id2 ) + SUBPARTITIONS 2 ( + PARTITION test_jfg_partition_name_with_60_chars_1234567890123456789012 VALUES LESS THAN (1000) ENGINE = InnoDB, + PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB); + +--error ER_PATH_LENGTH +CREATE TABLE mysqltest1.éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé ( + id int(10) unsigned NOT NULL, + id2 int(10) unsigned NOT NULL, + PRIMARY KEY ( id, id2 ) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC +PARTITION BY RANGE ( id ) + SUBPARTITION BY HASH ( id2 ) + SUBPARTITIONS 2 ( + PARTITION çççççççççççççççççççççççççççççççççççççççççççççççççççççççççççç VALUES LESS THAN (1000) ENGINE = InnoDB, + PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = InnoDB); + +drop database mysqltest1; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 43743544c25..e048dbad5e6 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -634,7 +634,7 @@ int ha_partition::create(const char *name, TABLE *table_arg, int ha_partition::drop_partitions(const char *path) { List_iterator part_it(m_part_info->partitions); - char part_name_buff[FN_REFLEN]; + char part_name_buff[FN_REFLEN + 1]; uint num_parts= m_part_info->partitions.elements; uint num_subparts= m_part_info->num_subparts; uint i= 0; @@ -667,9 +667,11 @@ int ha_partition::drop_partitions(const char *path) { partition_element *sub_elem= sub_it++; part= i * num_subparts + j; - create_subpartition_name(part_name_buff, path, - part_elem->partition_name, - sub_elem->partition_name, name_variant); + if ((ret_error= create_subpartition_name(part_name_buff, + sizeof(part_name_buff), path, + part_elem->partition_name, + sub_elem->partition_name, name_variant))) + error= ret_error; file= m_file[part]; DBUG_PRINT("info", ("Drop subpartition %s", part_name_buff)); if ((ret_error= file->ha_delete_table(part_name_buff))) @@ -680,15 +682,19 @@ int ha_partition::drop_partitions(const char *path) } else { - create_partition_name(part_name_buff, path, - part_elem->partition_name, name_variant, - TRUE); - file= m_file[i]; - DBUG_PRINT("info", ("Drop partition %s", part_name_buff)); - if ((ret_error= file->ha_delete_table(part_name_buff))) + if ((ret_error= create_partition_name(part_name_buff, + sizeof(part_name_buff), path, + part_elem->partition_name, name_variant, TRUE))) error= ret_error; - if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) - error= 1; + else + { + file= m_file[i]; + DBUG_PRINT("info", ("Drop partition %s", part_name_buff)); + if ((ret_error= file->ha_delete_table(part_name_buff))) + error= ret_error; + if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) + error= 1; + } } if (part_elem->part_state == PART_IS_CHANGED) part_elem->part_state= PART_NORMAL; @@ -724,8 +730,8 @@ int ha_partition::rename_partitions(const char *path) { List_iterator part_it(m_part_info->partitions); List_iterator temp_it(m_part_info->temp_partitions); - char part_name_buff[FN_REFLEN]; - char norm_name_buff[FN_REFLEN]; + char part_name_buff[FN_REFLEN + 1]; + char norm_name_buff[FN_REFLEN + 1]; uint num_parts= m_part_info->partitions.elements; uint part_count= 0; uint num_subparts= m_part_info->num_subparts; @@ -767,10 +773,11 @@ int ha_partition::rename_partitions(const char *path) { sub_elem= sub_it++; file= m_reorged_file[part_count++]; - create_subpartition_name(norm_name_buff, path, - part_elem->partition_name, - sub_elem->partition_name, - NORMAL_PART_NAME); + if ((ret_error= create_subpartition_name(norm_name_buff, + sizeof(norm_name_buff), path, + part_elem->partition_name, + sub_elem->partition_name, NORMAL_PART_NAME))) + error= ret_error; DBUG_PRINT("info", ("Delete subpartition %s", norm_name_buff)); if ((ret_error= file->ha_delete_table(norm_name_buff))) error= ret_error; @@ -783,16 +790,20 @@ int ha_partition::rename_partitions(const char *path) else { file= m_reorged_file[part_count++]; - create_partition_name(norm_name_buff, path, - part_elem->partition_name, NORMAL_PART_NAME, - TRUE); - DBUG_PRINT("info", ("Delete partition %s", norm_name_buff)); - if ((ret_error= file->ha_delete_table(norm_name_buff))) + if ((ret_error= create_partition_name(norm_name_buff, + sizeof(norm_name_buff), path, + part_elem->partition_name, NORMAL_PART_NAME, TRUE))) error= ret_error; - else if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) - error= 1; else - part_elem->log_entry= NULL; /* Indicate success */ + { + DBUG_PRINT("info", ("Delete partition %s", norm_name_buff)); + if ((ret_error= file->ha_delete_table(norm_name_buff))) + error= ret_error; + else if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) + error= 1; + else + part_elem->log_entry= NULL; /* Indicate success */ + } } } while (++i < temp_partitions); (void) sync_ddl_log(); @@ -835,10 +846,11 @@ int ha_partition::rename_partitions(const char *path) { sub_elem= sub_it++; part= i * num_subparts + j; - create_subpartition_name(norm_name_buff, path, - part_elem->partition_name, - sub_elem->partition_name, - NORMAL_PART_NAME); + if ((ret_error= create_subpartition_name(norm_name_buff, + sizeof(norm_name_buff), path, + part_elem->partition_name, + sub_elem->partition_name, NORMAL_PART_NAME))) + error= ret_error; if (part_elem->part_state == PART_IS_CHANGED) { file= m_reorged_file[part_count++]; @@ -850,10 +862,11 @@ int ha_partition::rename_partitions(const char *path) (void) sync_ddl_log(); } file= m_new_file[part]; - create_subpartition_name(part_name_buff, path, - part_elem->partition_name, - sub_elem->partition_name, - TEMP_PART_NAME); + if ((ret_error= create_subpartition_name(part_name_buff, + sizeof(part_name_buff), path, + part_elem->partition_name, + sub_elem->partition_name, TEMP_PART_NAME))) + error= ret_error; DBUG_PRINT("info", ("Rename subpartition from %s to %s", part_name_buff, norm_name_buff)); if ((ret_error= file->ha_rename_table(part_name_buff, @@ -867,32 +880,36 @@ int ha_partition::rename_partitions(const char *path) } else { - create_partition_name(norm_name_buff, path, - part_elem->partition_name, NORMAL_PART_NAME, - TRUE); - if (part_elem->part_state == PART_IS_CHANGED) + if ((ret_error= create_partition_name(norm_name_buff, + sizeof(norm_name_buff), path, + part_elem->partition_name, NORMAL_PART_NAME, TRUE)) || + (ret_error= create_partition_name(part_name_buff, + sizeof(part_name_buff), path, + part_elem->partition_name, TEMP_PART_NAME, TRUE))) + error= ret_error; + else { - file= m_reorged_file[part_count++]; - DBUG_PRINT("info", ("Delete partition %s", norm_name_buff)); - if ((ret_error= file->ha_delete_table(norm_name_buff))) + if (part_elem->part_state == PART_IS_CHANGED) + { + file= m_reorged_file[part_count++]; + DBUG_PRINT("info", ("Delete partition %s", norm_name_buff)); + if ((ret_error= file->ha_delete_table(norm_name_buff))) + error= ret_error; + else if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) + error= 1; + (void) sync_ddl_log(); + } + file= m_new_file[i]; + DBUG_PRINT("info", ("Rename partition from %s to %s", + part_name_buff, norm_name_buff)); + if ((ret_error= file->ha_rename_table(part_name_buff, + norm_name_buff))) error= ret_error; else if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) error= 1; - (void) sync_ddl_log(); + else + part_elem->log_entry= NULL; } - file= m_new_file[i]; - create_partition_name(part_name_buff, path, - part_elem->partition_name, TEMP_PART_NAME, - TRUE); - DBUG_PRINT("info", ("Rename partition from %s to %s", - part_name_buff, norm_name_buff)); - if ((ret_error= file->ha_rename_table(part_name_buff, - norm_name_buff))) - error= ret_error; - else if (deactivate_ddl_log_entry(part_elem->log_entry->entry_pos)) - error= 1; - else - part_elem->log_entry= NULL; } } } while (++i < num_parts); @@ -1488,7 +1505,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info, { List_iterator part_it(m_part_info->partitions); List_iterator t_it(m_part_info->temp_partitions); - char part_name_buff[FN_REFLEN]; + char part_name_buff[FN_REFLEN + 1]; uint num_parts= m_part_info->partitions.elements; uint num_subparts= m_part_info->num_subparts; uint i= 0; @@ -1698,10 +1715,14 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info, do { partition_element *sub_elem= sub_it++; - create_subpartition_name(part_name_buff, path, - part_elem->partition_name, - sub_elem->partition_name, - name_variant); + if ((error= create_subpartition_name(part_name_buff, + sizeof(part_name_buff), path, + part_elem->partition_name, sub_elem->partition_name, + name_variant))) + { + cleanup_new_partition(part_count); + DBUG_RETURN(error); + } part= i * num_subparts + j; DBUG_PRINT("info", ("Add subpartition %s", part_name_buff)); if ((error= prepare_new_partition(table, create_info, @@ -1719,9 +1740,14 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info, } else { - create_partition_name(part_name_buff, path, - part_elem->partition_name, name_variant, - TRUE); + if ((error= create_partition_name(part_name_buff, + sizeof(part_name_buff), path, part_elem->partition_name, + name_variant, TRUE))) + { + cleanup_new_partition(part_count); + DBUG_RETURN(error); + } + DBUG_PRINT("info", ("Add partition %s", part_name_buff)); if ((error= prepare_new_partition(table, create_info, new_file_array[i], @@ -1980,8 +2006,8 @@ int ha_partition::del_ren_cre_table(const char *from, { int save_error= 0; int error= HA_ERR_INTERNAL_ERROR; - char from_buff[FN_REFLEN], to_buff[FN_REFLEN], from_lc_buff[FN_REFLEN], - to_lc_buff[FN_REFLEN], buff[FN_REFLEN]; + char from_buff[FN_REFLEN + 1], to_buff[FN_REFLEN + 1], + from_lc_buff[FN_REFLEN], to_lc_buff[FN_REFLEN], buff[FN_REFLEN]; char *name_buffer_ptr; const char *from_path; const char *to_path= NULL; @@ -2028,13 +2054,15 @@ int ha_partition::del_ren_cre_table(const char *from, i= 0; do { - create_partition_name(from_buff, from_path, name_buffer_ptr, - NORMAL_PART_NAME, FALSE); + if ((error= create_partition_name(from_buff, sizeof(from_buff), from_path, + name_buffer_ptr, NORMAL_PART_NAME, FALSE))) + goto rename_error; if (to != NULL) { // Rename branch - create_partition_name(to_buff, to_path, name_buffer_ptr, - NORMAL_PART_NAME, FALSE); + if ((error= create_partition_name(to_buff, sizeof(to_buff), to_path, + name_buffer_ptr, NORMAL_PART_NAME, FALSE))) + goto rename_error; error= (*file)->ha_rename_table(from_buff, to_buff); if (error) goto rename_error; @@ -2081,9 +2109,9 @@ create_error: name_buffer_ptr= m_name_buffer_ptr; for (abort_file= file, file= m_file; file < abort_file; file++) { - create_partition_name(from_buff, from_path, name_buffer_ptr, NORMAL_PART_NAME, - FALSE); - (void) (*file)->ha_delete_table((const char*) from_buff); + if (!create_partition_name(from_buff, sizeof(from_buff), from_path, + name_buffer_ptr, NORMAL_PART_NAME, FALSE)) + (void) (*file)->ha_delete_table(from_buff); name_buffer_ptr= strend(name_buffer_ptr) + 1; } DBUG_RETURN(error); @@ -2092,12 +2120,11 @@ rename_error: for (abort_file= file, file= m_file; file < abort_file; file++) { /* Revert the rename, back from 'to' to the original 'from' */ - create_partition_name(from_buff, from_path, name_buffer_ptr, - NORMAL_PART_NAME, FALSE); - create_partition_name(to_buff, to_path, name_buffer_ptr, - NORMAL_PART_NAME, FALSE); - /* Ignore error here */ - (void) (*file)->ha_rename_table(to_buff, from_buff); + if (!create_partition_name(from_buff, sizeof(from_buff), from_path, + name_buffer_ptr, NORMAL_PART_NAME, FALSE) && + !create_partition_name(to_buff, sizeof(to_buff), to_path, name_buffer_ptr, + NORMAL_PART_NAME, FALSE)) + (void) (*file)->ha_rename_table(to_buff, from_buff); name_buffer_ptr= strend(name_buffer_ptr) + 1; } DBUG_RETURN(error); @@ -2895,7 +2922,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) char *name_buffer_ptr; int error= HA_ERR_INITIALIZATION; handler **file; - char name_buff[FN_REFLEN]; + char name_buff[FN_REFLEN + 1]; bool is_not_tmp_table= (table_share->tmp_table == NO_TMP_TABLE); ulonglong check_table_flags; DBUG_ENTER("ha_partition::open"); @@ -2965,8 +2992,9 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) file= m_is_clone_of->m_file; for (i= 0; i < m_tot_parts; i++) { - create_partition_name(name_buff, name, name_buffer_ptr, NORMAL_PART_NAME, - FALSE); + if ((error= create_partition_name(name_buff, sizeof(name_buff), name, + name_buffer_ptr, NORMAL_PART_NAME, FALSE))) + goto err_handler; if (!(m_file[i]= file[i]->clone(name_buff, m_clone_mem_root))) { error= HA_ERR_INITIALIZATION; @@ -2981,8 +3009,9 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) file= m_file; do { - create_partition_name(name_buff, name, name_buffer_ptr, NORMAL_PART_NAME, - FALSE); + if ((error= create_partition_name(name_buff, sizeof(name_buff), name, + name_buffer_ptr, NORMAL_PART_NAME, FALSE))) + goto err_handler; table->s->connect_string = m_connect_string[(uint)(file-m_file)]; if ((error= (*file)->ha_open(table, name_buff, mode, test_if_locked))) goto err_handler; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index e6513fc7476..0d9f6e6a1f5 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -5882,8 +5882,8 @@ static bool write_log_changed_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, DDL_LOG_ENTRY ddl_log_entry; partition_info *part_info= lpt->part_info; DDL_LOG_MEMORY_ENTRY *log_entry; - char tmp_path[FN_REFLEN]; - char normal_path[FN_REFLEN]; + char tmp_path[FN_REFLEN + 1]; + char normal_path[FN_REFLEN + 1]; List_iterator part_it(part_info->partitions); uint temp_partitions= part_info->temp_partitions.elements; uint num_elements= part_info->partitions.elements; @@ -5907,14 +5907,15 @@ static bool write_log_changed_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, ddl_log_entry.next_entry= *next_entry; ddl_log_entry.handler_name= ha_resolve_storage_engine_name(sub_elem->engine_type); - create_subpartition_name(tmp_path, path, - part_elem->partition_name, - sub_elem->partition_name, - TEMP_PART_NAME); - create_subpartition_name(normal_path, path, - part_elem->partition_name, - sub_elem->partition_name, - NORMAL_PART_NAME); + if (create_subpartition_name(tmp_path, sizeof(tmp_path), path, + part_elem->partition_name, + sub_elem->partition_name, + TEMP_PART_NAME) || + create_subpartition_name(normal_path, sizeof(normal_path), path, + part_elem->partition_name, + sub_elem->partition_name, + NORMAL_PART_NAME)) + DBUG_RETURN(TRUE); ddl_log_entry.name= normal_path; ddl_log_entry.from_name= tmp_path; if (part_elem->part_state == PART_IS_CHANGED) @@ -5935,12 +5936,13 @@ static bool write_log_changed_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, ddl_log_entry.next_entry= *next_entry; ddl_log_entry.handler_name= ha_resolve_storage_engine_name(part_elem->engine_type); - create_partition_name(tmp_path, path, - part_elem->partition_name, - TEMP_PART_NAME, TRUE); - create_partition_name(normal_path, path, - part_elem->partition_name, - NORMAL_PART_NAME, TRUE); + if (create_partition_name(tmp_path, sizeof(tmp_path), path, + part_elem->partition_name, TEMP_PART_NAME, + TRUE) || + create_partition_name(normal_path, sizeof(normal_path), path, + part_elem->partition_name, NORMAL_PART_NAME, + TRUE)) + DBUG_RETURN(TRUE); ddl_log_entry.name= normal_path; ddl_log_entry.from_name= tmp_path; if (part_elem->part_state == PART_IS_CHANGED) @@ -5979,7 +5981,7 @@ static bool write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, DDL_LOG_ENTRY ddl_log_entry; partition_info *part_info= lpt->part_info; DDL_LOG_MEMORY_ENTRY *log_entry; - char tmp_path[FN_LEN]; + char tmp_path[FN_REFLEN + 1]; List_iterator part_it(part_info->partitions); List_iterator temp_it(part_info->temp_partitions); uint num_temp_partitions= part_info->temp_partitions.elements; @@ -6018,10 +6020,10 @@ static bool write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, ddl_log_entry.next_entry= *next_entry; ddl_log_entry.handler_name= ha_resolve_storage_engine_name(sub_elem->engine_type); - create_subpartition_name(tmp_path, path, - part_elem->partition_name, - sub_elem->partition_name, - name_variant); + if (create_subpartition_name(tmp_path, sizeof(tmp_path), path, + part_elem->partition_name, + sub_elem->partition_name, name_variant)) + DBUG_RETURN(TRUE); ddl_log_entry.name= tmp_path; if (write_ddl_log_entry(&ddl_log_entry, &log_entry)) { @@ -6037,9 +6039,10 @@ static bool write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, ddl_log_entry.next_entry= *next_entry; ddl_log_entry.handler_name= ha_resolve_storage_engine_name(part_elem->engine_type); - create_partition_name(tmp_path, path, - part_elem->partition_name, - name_variant, TRUE); + if (create_partition_name(tmp_path, sizeof(tmp_path), path, + part_elem->partition_name, name_variant, + TRUE)) + DBUG_RETURN(TRUE); ddl_log_entry.name= tmp_path; if (write_ddl_log_entry(&ddl_log_entry, &log_entry)) { @@ -8117,31 +8120,41 @@ static uint32 get_next_subpartition_via_walking(PARTITION_ITERATOR *part_iter) } +/* used in error messages below */ +static const char *longest_str(const char *s1, const char *s2, + const char *s3=0) +{ + if (strlen(s2) > strlen(s1)) s1= s2; + if (s3 && strlen(s3) > strlen(s1)) s1= s3; + return s1; +} + /* Create partition names SYNOPSIS create_partition_name() - out:out Created partition name string + out:out The buffer for the created partition name string + must be *at least* of FN_REFLEN+1 bytes in1 First part in2 Second part name_variant Normal, temporary or renamed partition name RETURN VALUE - NONE + 0 if ok, error if name too long DESCRIPTION This method is used to calculate the partition name, service routine to the del_ren_cre_table method. */ -void create_partition_name(char *out, const char *in1, - const char *in2, uint name_variant, - bool translate) +int create_partition_name(char *out, size_t outlen, const char *in1, + const char *in2, uint name_variant, bool translate) { char transl_part_name[FN_REFLEN]; - const char *transl_part; + const char *transl_part, *end; + DBUG_ASSERT(outlen >= FN_REFLEN + 1); // consistency! same limit everywhere if (translate) { @@ -8151,11 +8164,17 @@ void create_partition_name(char *out, const char *in1, else transl_part= in2; if (name_variant == NORMAL_PART_NAME) - strxmov(out, in1, "#P#", transl_part, NullS); + end= strxnmov(out, outlen-1, in1, "#P#", transl_part, NullS); else if (name_variant == TEMP_PART_NAME) - strxmov(out, in1, "#P#", transl_part, "#TMP#", NullS); + end= strxnmov(out, outlen-1, in1, "#P#", transl_part, "#TMP#", NullS); else if (name_variant == RENAMED_PART_NAME) - strxmov(out, in1, "#P#", transl_part, "#REN#", NullS); + end= strxnmov(out, outlen-1, in1, "#P#", transl_part, "#REN#", NullS); + if (end - out == static_cast(outlen-1)) + { + my_error(ER_PATH_LENGTH, MYF(0), longest_str(in1, transl_part)); + return HA_WRONG_CREATE_OPTION; + } + return 0; } @@ -8164,37 +8183,46 @@ void create_partition_name(char *out, const char *in1, SYNOPSIS create_subpartition_name() - out:out Created partition name string + out:out The buffer for the created partition name string + must be *at least* of FN_REFLEN+1 bytes in1 First part in2 Second part in3 Third part name_variant Normal, temporary or renamed partition name RETURN VALUE - NONE + 0 if ok, error if name too long DESCRIPTION This method is used to calculate the subpartition name, service routine to the del_ren_cre_table method. */ -void create_subpartition_name(char *out, const char *in1, - const char *in2, const char *in3, - uint name_variant) +int create_subpartition_name(char *out, size_t outlen, + const char *in1, const char *in2, + const char *in3, uint name_variant) { - char transl_part_name[FN_REFLEN], transl_subpart_name[FN_REFLEN]; + char transl_part_name[FN_REFLEN], transl_subpart_name[FN_REFLEN], *end; + DBUG_ASSERT(outlen >= FN_REFLEN + 1); // consistency! same limit everywhere tablename_to_filename(in2, transl_part_name, FN_REFLEN); tablename_to_filename(in3, transl_subpart_name, FN_REFLEN); if (name_variant == NORMAL_PART_NAME) - strxmov(out, in1, "#P#", transl_part_name, - "#SP#", transl_subpart_name, NullS); + end= strxnmov(out, outlen-1, in1, "#P#", transl_part_name, + "#SP#", transl_subpart_name, NullS); else if (name_variant == TEMP_PART_NAME) - strxmov(out, in1, "#P#", transl_part_name, - "#SP#", transl_subpart_name, "#TMP#", NullS); + end= strxnmov(out, outlen-1, in1, "#P#", transl_part_name, + "#SP#", transl_subpart_name, "#TMP#", NullS); else if (name_variant == RENAMED_PART_NAME) - strxmov(out, in1, "#P#", transl_part_name, - "#SP#", transl_subpart_name, "#REN#", NullS); + end= strxnmov(out, outlen-1, in1, "#P#", transl_part_name, + "#SP#", transl_subpart_name, "#REN#", NullS); + if (end - out == static_cast(outlen-1)) + { + my_error(ER_PATH_LENGTH, MYF(0), + longest_str(in1, transl_part_name, transl_subpart_name)); + return HA_WRONG_CREATE_OPTION; + } + return 0; } uint get_partition_field_store_length(Field *field) diff --git a/sql/sql_partition.h b/sql/sql_partition.h index 951d58a655b..838006203c0 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -274,12 +274,12 @@ bool partition_key_modified(TABLE *table, const MY_BITMAP *fields); #define partition_key_modified(X,Y) 0 #endif -void create_partition_name(char *out, const char *in1, - const char *in2, uint name_variant, - bool translate); -void create_subpartition_name(char *out, const char *in1, - const char *in2, const char *in3, - uint name_variant); +int __attribute__((warn_unused_result)) + create_partition_name(char *out, size_t outlen, const char *in1, const char + *in2, uint name_variant, bool translate); +int __attribute__((warn_unused_result)) + create_subpartition_name(char *out, size_t outlen, const char *in1, const + char *in2, const char *in3, uint name_variant); void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf); void set_key_field_ptr(KEY *key_info, const uchar *new_buf, From c5975eaea174460e774e77717e972a8d32e6c8de Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 12 Jul 2017 08:05:42 +0200 Subject: [PATCH 74/97] MDEV-7339 Server crashes in Item_func_trig_cond::val_int Item_in_subselect::pushed_cond_guards[] array is allocated only when left_expr->maybe_null. And it is used (for row expressions) when left_expr->element_index(i)->maybe_null. For left_expr being a multi-column subquery, its maybe_null is always false when the subquery doesn't use tables (see Item_singlerow_subselect::fix_length_and_dec() and subselect_single_select_engine::fix_length_and_dec()), otherwise it's always true. But row elements can be NULL regardless, so let's always allocate pushed_cond_guards for multi-column subqueries, no matter whether its maybe_null was forced to true or false. --- mysql-test/r/subselect_nulls.result | 6 ++++++ mysql-test/t/subselect_nulls.test | 6 ++++++ sql/item_subselect.cc | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/subselect_nulls.result b/mysql-test/r/subselect_nulls.result index 584c184870d..08982371269 100644 --- a/mysql-test/r/subselect_nulls.result +++ b/mysql-test/r/subselect_nulls.result @@ -115,3 +115,9 @@ k d1 d2 set optimizer_switch= @tmp_subselect_nulls; drop table x1; drop table x2; +select (select 1, 2) in (select 3, 4); +(select 1, 2) in (select 3, 4) +0 +select (select NULL, NULL) in (select 3, 4); +(select NULL, NULL) in (select 3, 4) +NULL diff --git a/mysql-test/t/subselect_nulls.test b/mysql-test/t/subselect_nulls.test index 4b08e773b17..3e7b2189ed5 100644 --- a/mysql-test/t/subselect_nulls.test +++ b/mysql-test/t/subselect_nulls.test @@ -97,3 +97,9 @@ set optimizer_switch= @tmp_subselect_nulls; drop table x1; drop table x2; + +# +# MDEV-7339 Server crashes in Item_func_trig_cond::val_int +# +select (select 1, 2) in (select 3, 4); +select (select NULL, NULL) in (select 3, 4); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index e0da946d190..068f32c99b9 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -2871,7 +2871,8 @@ bool Item_in_subselect::init_cond_guards() { DBUG_ASSERT(thd); uint cols_num= left_expr->cols(); - if (!abort_on_null && left_expr->maybe_null && !pushed_cond_guards) + if (!abort_on_null && !pushed_cond_guards && + (left_expr->maybe_null || cols_num > 1)) { if (!(pushed_cond_guards= (bool*)thd->alloc(sizeof(bool) * cols_num))) return TRUE; From be55bbc2b206f2fe295ad4179b23791c3119fe02 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 12 Jul 2017 12:49:29 +0200 Subject: [PATCH 75/97] MDEV-7826 Server crashes in Item_subselect::enumerate_field_refs_processor upper->item can be NULL if we're referring to an aggregate function --- mysql-test/r/group_by.result | 14 ++++++++++++++ mysql-test/t/group_by.test | 19 +++++++++++++++++++ sql/item_subselect.cc | 3 ++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 262bb2ebd84..2bd3c5c5c3d 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -2531,3 +2531,17 @@ select a from t1 group by a having a > 1; a drop table t1; set sql_mode= @save_sql_mode; +create table t1 (f1 int); +insert into t1 values (5),(9); +create table t2 (f2 int); +insert into t2 values (0),(6); +create table t3 (f3 int); +insert into t3 values (6),(3); +create table t4 (f4 int); +insert into t4 values (1),(0); +select +(select min(f1) from t1 where f1 in (select min(f4) from t2)) as field7, +(select count(*) from t3 where f3 in (select max(f4) from t2 group by field7)) +from t4; +ERROR 42S22: Reference 'field7' not supported (reference to group function) +drop table t1, t2, t3, t4; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 4162e9c67a1..9117262d9b0 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -1703,6 +1703,25 @@ select a as x from t1 group by x having x > 1; select a from t1 group by a having a > 1; drop table t1; set sql_mode= @save_sql_mode; + +# +# MDEV-7826 Server crashes in Item_subselect::enumerate_field_refs_processor +# +create table t1 (f1 int); +insert into t1 values (5),(9); +create table t2 (f2 int); +insert into t2 values (0),(6); +create table t3 (f3 int); +insert into t3 values (6),(3); +create table t4 (f4 int); +insert into t4 values (1),(0); +--error ER_ILLEGAL_REFERENCE +select +(select min(f1) from t1 where f1 in (select min(f4) from t2)) as field7, +(select count(*) from t3 where f3 in (select max(f4) from t2 group by field7)) +from t4; +drop table t1, t2, t3, t4; + # # End of MariaDB 5.5 tests # diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 068f32c99b9..ef90dd59be3 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -316,7 +316,8 @@ bool Item_subselect::enumerate_field_refs_processor(uchar *arg) while ((upper= it++)) { - if (upper->item->walk(&Item::enumerate_field_refs_processor, FALSE, arg)) + if (upper->item && + upper->item->walk(&Item::enumerate_field_refs_processor, FALSE, arg)) return TRUE; } return FALSE; From d2e66a6f199bd3c9e3fe82aabe617b8bf337aa01 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 12 Jul 2017 13:46:15 +0200 Subject: [PATCH 76/97] MDEV-7828 Assertion `key_read == 0' failed in TABLE::enable_keyread with SELECT SQ and WHERE SQ already fixed by a7ed4644a6f. just add a test case, --- mysql-test/r/subselect.result | 8 ++++++++ mysql-test/r/subselect_no_mat.result | 8 ++++++++ mysql-test/r/subselect_no_opts.result | 8 ++++++++ mysql-test/r/subselect_no_scache.result | 8 ++++++++ mysql-test/r/subselect_no_semijoin.result | 8 ++++++++ mysql-test/t/subselect.test | 10 ++++++++++ 6 files changed, 50 insertions(+) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 000d8927542..8fc9cd38728 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -7138,3 +7138,11 @@ SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; ERROR 21000: Subquery returns more than 1 row drop view v1; drop table t1,t2; +CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM; +INSERT t1 VALUES (4),(8); +CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM; +INSERT t2 VALUES (6),(9); +SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2; +(SELECT MAX(sq.f2) FROM t1) +NULL +drop table t1, t2; diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index 914f20d502a..a71df97e6bc 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -7135,6 +7135,14 @@ SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; ERROR 21000: Subquery returns more than 1 row drop view v1; drop table t1,t2; +CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM; +INSERT t1 VALUES (4),(8); +CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM; +INSERT t2 VALUES (6),(9); +SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2; +(SELECT MAX(sq.f2) FROM t1) +NULL +drop table t1, t2; set optimizer_switch=default; select @@optimizer_switch like '%materialization=on%'; @@optimizer_switch like '%materialization=on%' diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 1b25e16ba7c..2f8c67fa167 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -7133,4 +7133,12 @@ SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; ERROR 21000: Subquery returns more than 1 row drop view v1; drop table t1,t2; +CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM; +INSERT t1 VALUES (4),(8); +CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM; +INSERT t2 VALUES (6),(9); +SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2; +(SELECT MAX(sq.f2) FROM t1) +NULL +drop table t1, t2; set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index 90a11fbce7d..8dda0a4fd36 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -7144,6 +7144,14 @@ SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; ERROR 21000: Subquery returns more than 1 row drop view v1; drop table t1,t2; +CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM; +INSERT t1 VALUES (4),(8); +CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM; +INSERT t2 VALUES (6),(9); +SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2; +(SELECT MAX(sq.f2) FROM t1) +NULL +drop table t1, t2; set optimizer_switch=default; select @@optimizer_switch like '%subquery_cache=on%'; @@optimizer_switch like '%subquery_cache=on%' diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index 936aae07227..339e2b89786 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -7133,5 +7133,13 @@ SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; ERROR 21000: Subquery returns more than 1 row drop view v1; drop table t1,t2; +CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM; +INSERT t1 VALUES (4),(8); +CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM; +INSERT t2 VALUES (6),(9); +SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2; +(SELECT MAX(sq.f2) FROM t1) +NULL +drop table t1, t2; set @optimizer_switch_for_subselect_test=null; set @join_cache_level_for_subselect_test=NULL; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index c5f5b229656..50d9517043a 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -6023,3 +6023,13 @@ SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1; drop view v1; drop table t1,t2; + +# +# MDEV-7828 Assertion `key_read == 0' failed in TABLE::enable_keyread with SELECT SQ and WHERE SQ +# +CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM; +INSERT t1 VALUES (4),(8); +CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM; +INSERT t2 VALUES (6),(9); +SELECT (SELECT MAX(sq.f2) FROM t1) FROM (SELECT * FROM t2) AS sq WHERE f2 = 2; +drop table t1, t2; From c83d6ff881dcfd1cc68124a9663c2a31ca7e2dce Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 12 Jul 2017 13:55:04 +0200 Subject: [PATCH 77/97] compiler warning remove unused variable --- sql/item.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/item.cc b/sql/item.cc index 68411860274..61ad4bdb853 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5048,7 +5048,6 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) if (thd->lex->in_sum_func && thd->lex->in_sum_func->nest_level >= select->nest_level) { - Item::Type ref_type= (*reference)->type(); set_if_bigger(thd->lex->in_sum_func->max_arg_level, select->nest_level); } From 05b678bc8c166c9015ca3dc3ccd9e9c89094f3ca Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 12 Jul 2017 14:21:41 +0200 Subject: [PATCH 78/97] MDEV-12489 The select stmt may fail due to "having clause is ambiguous" unexpected only compare field references with an alias (from the SELECT clause) when this reference doesn't specify an explicit table name part. --- mysql-test/r/group_by.result | 5 +++++ mysql-test/t/group_by.test | 8 ++++++++ sql/item.cc | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 2bd3c5c5c3d..7744d98bc11 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -2545,3 +2545,8 @@ select from t4; ERROR 42S22: Reference 'field7' not supported (reference to group function) drop table t1, t2, t3, t4; +create table t1 (c1 int, c2 int); +create table t2 (c1 int, c2 int); +select t1.c1 as c1, t2.c2 as c1 from t1, t2 where t1.c1 < 20 and t2.c2 > 5 group by t1.c1, t2.c2 having t1.c1 < 3; +c1 c1 +drop table t1, t2; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 9117262d9b0..c137edeeba5 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -1722,6 +1722,14 @@ select from t4; drop table t1, t2, t3, t4; +# +# MDEV-12489 The select stmt may fail due to "having clause is ambiguous" unexpected +# +create table t1 (c1 int, c2 int); +create table t2 (c1 int, c2 int); +select t1.c1 as c1, t2.c2 as c1 from t1, t2 where t1.c1 < 20 and t2.c2 > 5 group by t1.c1, t2.c2 having t1.c1 < 3; +drop table t1, t2; + # # End of MariaDB 5.5 tests # diff --git a/sql/item.cc b/sql/item.cc index 61ad4bdb853..b7dac96d418 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4622,7 +4622,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) int cur_match_degree= 0; /* SELECT list element with explicit alias */ - if ((*(cur_group->item))->name && + if ((*(cur_group->item))->name && !table_name && !(*(cur_group->item))->is_autogenerated_name && !my_strcasecmp(system_charset_info, (*(cur_group->item))->name, field_name)) From 181d9d2892739629382727cf956364106c947ea2 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 12 Jul 2017 15:54:04 +0200 Subject: [PATCH 79/97] MDEV-13180 Unused left join causes server crash already fixed by be55bbc2b20 just add a test case --- mysql-test/r/group_by.result | 8 ++++++++ mysql-test/t/group_by.test | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 7744d98bc11..b948c9a6f88 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -2545,6 +2545,14 @@ select from t4; ERROR 42S22: Reference 'field7' not supported (reference to group function) drop table t1, t2, t3, t4; +create table t1 (i1 int); +insert into t1 values (1); +create table t2 (i int); +insert into t2 values (2); +select 1 from t1 left join t2 b on b.i = (select max(b.i) from t2); +1 +1 +drop table t1, t2; create table t1 (c1 int, c2 int); create table t2 (c1 int, c2 int); select t1.c1 as c1, t2.c2 as c1 from t1, t2 where t1.c1 < 20 and t2.c2 > 5 group by t1.c1, t2.c2 having t1.c1 < 3; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index c137edeeba5..80ecfea539b 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -1722,6 +1722,17 @@ select from t4; drop table t1, t2, t3, t4; +# +# MDEV-13180 Unused left join causes server crash +# +create table t1 (i1 int); +insert into t1 values (1); +create table t2 (i int); +insert into t2 values (2); +select 1 from t1 left join t2 b on b.i = (select max(b.i) from t2); +drop table t1, t2; + + # # MDEV-12489 The select stmt may fail due to "having clause is ambiguous" unexpected # From e7f51e5d269ba8adb917226724564274a57d07b3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 12 Jul 2017 19:20:52 +0200 Subject: [PATCH 80/97] MDEV-12136 SELECT COUNT(DISTINCT) returns the wrong value when tmp_table_size is limited use the correct value for the merge_buffer size, max_in_memory_size is too small and merge_walk() fails. also: remove a cast. --- mysql-test/r/count_distinct.result | 8 ++++++++ mysql-test/t/count_distinct.test | 14 ++++++++++++++ sql/uniques.cc | 6 +++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/count_distinct.result b/mysql-test/r/count_distinct.result index 3b65dd0e608..3decd5f60bc 100644 --- a/mysql-test/r/count_distinct.result +++ b/mysql-test/r/count_distinct.result @@ -94,3 +94,11 @@ count(distinct i) 2 drop table t1; drop view v1; +create table t1 (user_id char(64) character set utf8); +insert t1 values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17); +set @@tmp_table_size = 1024; +select count(distinct user_id) from t1; +count(distinct user_id) +17 +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 10b4ac6f0e7..ac97cdba357 100644 --- a/mysql-test/t/count_distinct.test +++ b/mysql-test/t/count_distinct.test @@ -107,3 +107,17 @@ create view v1 as select * from t1; select count(distinct i) from v1; drop table t1; drop view v1; + +# +# MDEV-12136 SELECT COUNT(DISTINCT) returns the wrong value when tmp_table_size is limited +# +create table t1 (user_id char(64) character set utf8); +insert t1 values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17); +set @@tmp_table_size = 1024; +select count(distinct user_id) from t1; +drop table t1; +set @@tmp_table_size = default; + +# +# End of 5.5 tests +# diff --git a/sql/uniques.cc b/sql/uniques.cc index fe3e329cda6..f80117065dd 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -461,7 +461,7 @@ C_MODE_END <> 0 error */ -static bool merge_walk(uchar *merge_buffer, ulong merge_buffer_size, +static bool merge_walk(uchar *merge_buffer, size_t merge_buffer_size, uint key_length, BUFFPEK *begin, BUFFPEK *end, tree_walk_action walk_action, void *walk_action_arg, qsort_cmp2 compare, void *compare_arg, @@ -470,7 +470,7 @@ static bool merge_walk(uchar *merge_buffer, ulong merge_buffer_size, BUFFPEK_COMPARE_CONTEXT compare_context = { compare, compare_arg }; QUEUE queue; if (end <= begin || - merge_buffer_size < (ulong) (key_length * (end - begin + 1)) || + merge_buffer_size < (size_t) (key_length * (end - begin + 1)) || init_queue(&queue, (uint) (end - begin), offsetof(BUFFPEK, key), 0, buffpek_compare, &compare_context, 0, 0)) return 1; @@ -615,7 +615,7 @@ bool Unique::walk(TABLE *table, tree_walk_action action, void *walk_action_arg) if (!res) { - res= merge_walk(merge_buffer, (ulong) max_in_memory_size, full_size, + res= merge_walk(merge_buffer, buff_sz, full_size, (BUFFPEK *) file_ptrs.buffer, (BUFFPEK *) file_ptrs.buffer + file_ptrs.elements, action, walk_action_arg, From 27bc13b7a2f99a6011a5081670b320c685dde443 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 12 Jul 2017 19:31:01 +0200 Subject: [PATCH 81/97] MDEV-12136 SELECT COUNT(DISTINCT) returns the wrong value when tmp_table_size is limited Same MDEV, second bug. Merge buffer must fit at least MERGEBUFF2 (that is, 15) key values. Because merge_index() can merge that many buffers, and merge_many_buff() leaves that many buffers unmerged. --- mysql-test/r/count_distinct.result | 4 ++++ mysql-test/t/count_distinct.test | 2 ++ sql/uniques.cc | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/count_distinct.result b/mysql-test/r/count_distinct.result index 3decd5f60bc..d55a232c715 100644 --- a/mysql-test/r/count_distinct.result +++ b/mysql-test/r/count_distinct.result @@ -100,5 +100,9 @@ set @@tmp_table_size = 1024; select count(distinct user_id) from t1; count(distinct user_id) 17 +alter table t1 modify user_id char(128) character set utf8; +select count(distinct user_id) from t1; +count(distinct user_id) +17 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 ac97cdba357..a00574b6cba 100644 --- a/mysql-test/t/count_distinct.test +++ b/mysql-test/t/count_distinct.test @@ -115,6 +115,8 @@ create table t1 (user_id char(64) character set utf8); insert t1 values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17); set @@tmp_table_size = 1024; select count(distinct user_id) from t1; +alter table t1 modify user_id char(128) character set utf8; +select count(distinct user_id) from t1; drop table t1; set @@tmp_table_size = default; diff --git a/sql/uniques.cc b/sql/uniques.cc index f80117065dd..8b7da7e6e52 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -607,11 +607,15 @@ bool Unique::walk(TABLE *table, tree_walk_action action, void *walk_action_arg) return 1; if (flush_io_cache(&file) || reinit_io_cache(&file, READ_CACHE, 0L, 0, 0)) return 1; - size_t buff_sz= (max_in_memory_size / full_size + 1) * full_size; + /* + merge_buffer must fit at least MERGEBUFF2 keys, because + merge_index() can merge that many BUFFPEKs at once. + */ + size_t buff_sz= max(MERGEBUFF2, 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))) - res= merge(table, merge_buffer, buff_sz >= full_size * MERGEBUFF2) ; + res= merge(table, merge_buffer, true) ; if (!res) { From 7338d3f221e33042dfcf5c1a245317aa7cb015a7 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 14 Jul 2017 13:37:37 +1000 Subject: [PATCH 82/97] client: mysql - fix type field_names[x][y] is a pointer client/mysql.cc: In function 'void build_completion_hash(bool, bool)': client/mysql.cc:2855:37: error: invalid conversion from 'char' to 'char*' [-fpermissive] field_names[i][num_fields*2]= '\0'; Signed-off-by: Daniel Black --- client/mysql.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysql.cc b/client/mysql.cc index a965ced89c6..ca586a5590f 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2852,7 +2852,7 @@ You can turn off this feature to get a quicker startup with -A\n\n"); mysql_free_result(fields); break; } - field_names[i][num_fields*2]= '\0'; + field_names[i][num_fields*2]= NULL; j=0; while ((sql_field=mysql_fetch_field(fields))) { From 0375f2e2730c6e30f3e6f171c9b73d8553a3ae9a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 14 Jul 2017 15:30:27 +0200 Subject: [PATCH 83/97] MDEV-12144 Signal 6 crash corrupts ibd files Avoid using STDERR_FILENO. The server uses freopen(stderr), so stderr can be on any file descriptor. --- include/my_global.h | 5 ++--- mysys/my_fopen.c | 2 +- mysys/stacktrace.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index 0c15478439f..42e3c1ad0c8 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -421,9 +421,8 @@ extern "C" int madvise(void *addr, size_t len, int behav); #define SIGNAL_HANDLER_RESET_ON_DELIVERY #endif -#ifndef STDERR_FILENO -#define STDERR_FILENO fileno(stderr) -#endif +/* don't assume that STDERR_FILENO is 2, mysqld can freopen */ +#undef STDERR_FILENO /* Deprecated workaround for false-positive uninitialized variables diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c index 99a9035c0c2..9131a2549e0 100644 --- a/mysys/my_fopen.c +++ b/mysys/my_fopen.c @@ -143,7 +143,7 @@ static int no_close(void *cookie __attribute__((unused))) /* A hack around a race condition in the implementation of freopen. - The race condition steams from the fact that the current fd of + The race condition stems from the fact that the current fd of the stream is closed before its number is used to duplicate the new file descriptor. This defeats the desired atomicity of the close and duplicate of dup2(). diff --git a/mysys/stacktrace.c b/mysys/stacktrace.c index 402520990b6..ae715c04621 100644 --- a/mysys/stacktrace.c +++ b/mysys/stacktrace.c @@ -744,7 +744,7 @@ void my_safe_print_str(const char *val, int len) size_t my_write_stderr(const void *buf, size_t count) { - return (size_t) write(STDERR_FILENO, buf, count); + return (size_t) write(fileno(stderr), buf, count); } From ec4e39558ee33da4e10fb1afc6702f325e6aec30 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 17:02:03 +1000 Subject: [PATCH 84/97] ma_recovery: unintentional order of operations Coverity report this as: CID 971840 (#1 of 1): Operands don't affect result (CONSTANT_EXPRESSION_RESULT) result_independent_of_operands: 4 | (flags & 1) is always true regardless of the values of its operands. This occurs as the logical first operand of "?:". The C order of precidence has | of higher precidence than ?:. The intenting implies an | of the 3 terms. Adjust to intented meaning. --- storage/maria/ma_recovery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/maria/ma_recovery.c b/storage/maria/ma_recovery.c index 5e42ebc8d5d..618e6381f27 100644 --- a/storage/maria/ma_recovery.c +++ b/storage/maria/ma_recovery.c @@ -888,7 +888,7 @@ prototype_redo_exec_hook(REDO_CREATE_TABLE) goto end; fn_format(filename, name, "", MARIA_NAME_IEXT, (MY_UNPACK_FILENAME | - (flags & HA_DONT_TOUCH_DATA) ? MY_RETURN_REAL_PATH : 0) | + ((flags & HA_DONT_TOUCH_DATA) ? MY_RETURN_REAL_PATH : 0)) | MY_APPEND_EXT); linkname_ptr= NULL; create_flag= MY_DELETE_OLD; From 6efee2254110206a037bb726de00a4e734ae8453 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 14 Jul 2017 19:08:59 +0200 Subject: [PATCH 85/97] change flags as it was done in MyISAM in ab785bfe5b50 --- storage/maria/ma_recovery.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/storage/maria/ma_recovery.c b/storage/maria/ma_recovery.c index 618e6381f27..b2e8705b15e 100644 --- a/storage/maria/ma_recovery.c +++ b/storage/maria/ma_recovery.c @@ -887,9 +887,7 @@ prototype_redo_exec_hook(REDO_CREATE_TABLE) if (create_database_if_not_exists(name)) goto end; fn_format(filename, name, "", MARIA_NAME_IEXT, - (MY_UNPACK_FILENAME | - ((flags & HA_DONT_TOUCH_DATA) ? MY_RETURN_REAL_PATH : 0)) | - MY_APPEND_EXT); + MY_UNPACK_FILENAME | MY_RETURN_REAL_PATH | MY_APPEND_EXT); linkname_ptr= NULL; create_flag= MY_DELETE_OLD; tprint(tracef, "Table '%s' creating as '%s'\n", name, filename); From d023156782ce37f508c121437b8b3544fb03ef14 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 30 Oct 2015 10:10:43 +0400 Subject: [PATCH 86/97] MDEV-8692 prefschema test failures on ARM (on Debian build system) A few tests assumes that the CYCLE timer is always available, which is not true on some platforms (e.g. ARM). Fixing the tests not to reply on the CYCLE availability. --- .../perfschema/include/have_timer_cycle.inc | 4 +++ .../suite/perfschema/r/privilege.result | 8 +++--- .../perfschema/t/dml_performance_timers.test | 1 + .../suite/perfschema/t/dml_setup_timers.test | 1 + mysql-test/suite/perfschema/t/privilege.test | 14 ++++++++--- mysys/my_rdtsc.c | 25 +++++++++++++++++++ 6 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 mysql-test/suite/perfschema/include/have_timer_cycle.inc diff --git a/mysql-test/suite/perfschema/include/have_timer_cycle.inc b/mysql-test/suite/perfschema/include/have_timer_cycle.inc new file mode 100644 index 00000000000..b801ea256d6 --- /dev/null +++ b/mysql-test/suite/perfschema/include/have_timer_cycle.inc @@ -0,0 +1,4 @@ +if (!`SELECT count(*) FROM performance_schema.performance_timers WHERE timer_name='CYCLE' AND timer_frequency IS NOT NULL`) +{ + Skip Need performance timer CYCLE; +} diff --git a/mysql-test/suite/perfschema/r/privilege.result b/mysql-test/suite/perfschema/r/privilege.result index d1831c9c4be..61eade13bbf 100644 --- a/mysql-test/suite/perfschema/r/privilege.result +++ b/mysql-test/suite/perfschema/r/privilege.result @@ -554,7 +554,7 @@ ERROR 42000: DROP command denied to user 'pfs_user_4'@'localhost' for table 'eve # # Grant access to change tables with the root account GRANT UPDATE ON performance_schema.setup_consumers TO pfs_user_4; -GRANT UPDATE ON performance_schema.setup_timers TO pfs_user_4; +GRANT UPDATE, SELECT ON performance_schema.setup_timers TO pfs_user_4; GRANT UPDATE, SELECT ON performance_schema.setup_instruments TO pfs_user_4; GRANT DROP ON performance_schema.events_waits_current TO pfs_user_4; GRANT DROP ON performance_schema.events_waits_history TO pfs_user_4; @@ -565,7 +565,7 @@ UPDATE performance_schema.setup_instruments SET enabled = 'YES' WHERE name LIKE 'wait/synch/mutex/%' OR name LIKE 'wait/synch/rwlock/%'; UPDATE performance_schema.setup_consumers SET enabled = 'YES'; -UPDATE performance_schema.setup_timers SET timer_name = 'TICK'; +UPDATE performance_schema.setup_timers SET timer_name = 'TICK' WHERE name <> "wait"; TRUNCATE TABLE performance_schema.events_waits_history_long; TRUNCATE TABLE performance_schema.events_waits_history; TRUNCATE TABLE performance_schema.events_waits_current; @@ -575,4 +575,6 @@ DROP USER pfs_user_4; flush privileges; UPDATE performance_schema.setup_instruments SET enabled = 'YES', timed = 'YES'; UPDATE performance_schema.setup_consumers SET enabled = 'YES'; -UPDATE performance_schema.setup_timers SET timer_name = 'CYCLE'; +UPDATE performance_schema.setup_timers SET timer_name = 'MICROSECOND' where name="idle"; +UPDATE performance_schema.setup_timers SET timer_name = 'NANOSECOND' where name="stage"; +UPDATE performance_schema.setup_timers SET timer_name = 'NANOSECOND' where name="statement"; diff --git a/mysql-test/suite/perfschema/t/dml_performance_timers.test b/mysql-test/suite/perfschema/t/dml_performance_timers.test index 2ec37fbe7e9..587c54144aa 100644 --- a/mysql-test/suite/perfschema/t/dml_performance_timers.test +++ b/mysql-test/suite/perfschema/t/dml_performance_timers.test @@ -2,6 +2,7 @@ --source include/not_embedded.inc --source include/have_perfschema.inc +--source include/have_timer_cycle.inc --replace_column 2 3 4 select * from performance_schema.performance_timers; diff --git a/mysql-test/suite/perfschema/t/dml_setup_timers.test b/mysql-test/suite/perfschema/t/dml_setup_timers.test index 0956ae2cc95..6a6b813ab07 100644 --- a/mysql-test/suite/perfschema/t/dml_setup_timers.test +++ b/mysql-test/suite/perfschema/t/dml_setup_timers.test @@ -2,6 +2,7 @@ --source include/not_embedded.inc --source include/have_perfschema.inc +--source include/have_timer_cycle.inc select * from performance_schema.setup_timers; diff --git a/mysql-test/suite/perfschema/t/privilege.test b/mysql-test/suite/perfschema/t/privilege.test index 3b4cd1a4d2b..47a68602fa4 100644 --- a/mysql-test/suite/perfschema/t/privilege.test +++ b/mysql-test/suite/perfschema/t/privilege.test @@ -291,7 +291,7 @@ TRUNCATE TABLE performance_schema.events_waits_current; --echo # Grant access to change tables with the root account GRANT UPDATE ON performance_schema.setup_consumers TO pfs_user_4; -GRANT UPDATE ON performance_schema.setup_timers TO pfs_user_4; +GRANT UPDATE, SELECT ON performance_schema.setup_timers TO pfs_user_4; GRANT UPDATE, SELECT ON performance_schema.setup_instruments TO pfs_user_4; GRANT DROP ON performance_schema.events_waits_current TO pfs_user_4; GRANT DROP ON performance_schema.events_waits_history TO pfs_user_4; @@ -308,7 +308,11 @@ WHERE name LIKE 'wait/synch/mutex/%' UPDATE performance_schema.setup_consumers SET enabled = 'YES'; -UPDATE performance_schema.setup_timers SET timer_name = 'TICK'; +# We do not touch "wait", to avoid restoring it at the end of the test, +# as its default value initialized at server startup is ambiguous: +# it can be CYCLE or NANOSECOND depending on platform + +UPDATE performance_schema.setup_timers SET timer_name = 'TICK' WHERE name <> "wait"; TRUNCATE TABLE performance_schema.events_waits_history_long; TRUNCATE TABLE performance_schema.events_waits_history; @@ -323,5 +327,9 @@ DROP USER pfs_user_4; flush privileges; UPDATE performance_schema.setup_instruments SET enabled = 'YES', timed = 'YES'; UPDATE performance_schema.setup_consumers SET enabled = 'YES'; -UPDATE performance_schema.setup_timers SET timer_name = 'CYCLE'; +# Restore the default values for the timers that we changed. +# Note, we did not touch "wait", see above. +UPDATE performance_schema.setup_timers SET timer_name = 'MICROSECOND' where name="idle"; +UPDATE performance_schema.setup_timers SET timer_name = 'NANOSECOND' where name="stage"; +UPDATE performance_schema.setup_timers SET timer_name = 'NANOSECOND' where name="statement"; diff --git a/mysys/my_rdtsc.c b/mysys/my_rdtsc.c index 028c7f810d4..ad11e8c6a6c 100644 --- a/mysys/my_rdtsc.c +++ b/mysys/my_rdtsc.c @@ -129,6 +129,31 @@ ulonglong my_timer_cycles_il_x86_64(); clock_gettime(CLOCK_SGI_CYCLE) for Irix platforms, or on read_real_time for aix platforms. There is nothing for Alpha platforms, they would be tricky. + + On the platforms that do not have a CYCLE timer, + "wait" events are initialized to use NANOSECOND instead of CYCLE + during performance_schema initialization (at the server startup). + + Linux performance monitor (see "man perf_event_open") can + provide cycle counter on the platforms that do not have + other kinds of cycle counters. But we don't use it so far. + + ARM notes + --------- + During tests on ARMv7 Debian, perf_even_open() based cycle counter provided + too low frequency with too high overhead: + MariaDB [performance_schema]> SELECT * FROM performance_timers; + +-------------+-----------------+------------------+----------------+ + | TIMER_NAME | TIMER_FREQUENCY | TIMER_RESOLUTION | TIMER_OVERHEAD | + +-------------+-----------------+------------------+----------------+ + | CYCLE | 689368159 | 1 | 970 | + | NANOSECOND | 1000000000 | 1 | 308 | + | MICROSECOND | 1000000 | 1 | 417 | + | MILLISECOND | 1000 | 1000 | 407 | + | TICK | 127 | 1 | 612 | + +-------------+-----------------+------------------+----------------+ + Therefore, it was decided not to use perf_even_open() on ARM + (i.e. go without CYCLE and have "wait" events use NANOSECOND by default). */ ulonglong my_timer_cycles(void) From 7d309b5f74982861efdfd069fd0e46c18d0cb7fe Mon Sep 17 00:00:00 2001 From: Elena Stepanova Date: Tue, 18 Jul 2017 01:38:13 +0300 Subject: [PATCH 87/97] Add storage_engine/parts overlay for MyISAM --- storage/myisam/mysql-test/storage_engine/parts/disabled.def | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 storage/myisam/mysql-test/storage_engine/parts/disabled.def diff --git a/storage/myisam/mysql-test/storage_engine/parts/disabled.def b/storage/myisam/mysql-test/storage_engine/parts/disabled.def new file mode 100644 index 00000000000..e69de29bb2d From c9883b75914d0ba4975aae0fbf8164f026e88559 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 14:53:23 +1000 Subject: [PATCH 88/97] ma_check/mi_check: maria_repair_parallel initialization for !quick end_io_call uses uninitialized values from the new_data_cache As such we the buffer 0 and check this before calling end_io_cache on it. Thanks Sergey Vojtovich for the review and for this solution. Found by Coverity (ref 972481). --- storage/maria/ma_check.c | 4 +++- storage/myisam/mi_check.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index fb35edc3be3..198df72a1d6 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -4250,6 +4250,8 @@ int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info, } */ DBUG_PRINT("info", ("is quick repair: %d", (int) rep_quick)); + if (!rep_quick) + my_b_clear(&new_data_cache); /* Initialize pthread structures before goto err. */ mysql_mutex_init(key_SORT_INFO_mutex, &sort_info.mutex, MY_MUTEX_INIT_FAST); @@ -4608,7 +4610,7 @@ err: already or they were not yet started (if the error happend before creating the threads). */ - if (!rep_quick) + if (!rep_quick && my_b_inited(&new_data_cache)) end_io_cache(&new_data_cache); if (!got_error) { diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index df97d6035d8..23e54966e2d 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -2676,6 +2676,8 @@ int mi_repair_parallel(HA_CHECK *param, register MI_INFO *info, */ DBUG_PRINT("info", ("is quick repair: %d", rep_quick)); bzero((char*)&sort_info,sizeof(sort_info)); + if (!rep_quick) + my_b_clear(&new_data_cache); /* Initialize pthread structures before goto err. */ mysql_mutex_init(mi_key_mutex_MI_SORT_INFO_mutex, &sort_info.mutex, MY_MUTEX_INIT_FAST); @@ -3050,7 +3052,7 @@ err: already or they were not yet started (if the error happend before creating the threads). */ - if (!rep_quick) + if (!rep_quick && my_b_inited(&new_data_cache)) (void) end_io_cache(&new_data_cache); if (!got_error) { From 7e44eabdad59993c504699e01d15ddb106f64e9b Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Tue, 18 Jul 2017 13:19:34 +0400 Subject: [PATCH 89/97] MDEV-11205 UDF_ARGS "attribute_lengths" incorrect value. Set name_length properly in Item_idnet constructors. --- sql/item.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/item.cc b/sql/item.cc index b7dac96d418..dff2f3d3ee6 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -817,6 +817,7 @@ Item_ident::Item_ident(Name_resolution_context *context_arg, cached_table(0), depended_from(0), can_be_depended(TRUE) { name = (char*) field_name_arg; + name_length= name ? strlen(name) : 0; } @@ -829,6 +830,7 @@ Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg) cached_table(NULL), depended_from(NULL), can_be_depended(TRUE) { name = (char*) field_name_arg; + name_length= name ? strlen(name) : 0; } From e7fd6ed3875bd91dbd30a62291ae471c35da8fdf Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 17 Jul 2017 22:34:07 +0200 Subject: [PATCH 90/97] MDEV-11240: Server crashes in check_view_single_update or Assertion `derived->table' failed in mysql_derived_merge_for_insert Move table pointer for single table view (even if it is view over other view) to make the access universal. --- mysql-test/r/view.result | 14 ++++++++++++++ mysql-test/t/view.test | 16 ++++++++++++++++ sql/sql_derived.cc | 4 +++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 414de5662f3..0f8e9999730 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -5618,6 +5618,20 @@ Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`c` = `test`.`t1`.`b`) and (`test`.`t3`.`f` = `test`.`t1`.`a`) and (`test`.`t2`.`d` = `test`.`t3`.`e`) and (`test`.`t1`.`a` is not null) and (`test`.`t1`.`a` is not null) and (`test`.`t1`.`b` is not null))) where (`test`.`t1`.`a` < 5) drop view v1; drop table t1,t2,t3; +# +# MDEV-11240: Server crashes in check_view_single_update or +# Assertion `derived->table' failed in mysql_derived_merge_for_insert +# +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; # ----------------------------------------------------------------- # -- End of 5.5 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index aece2000cd4..659327eebb1 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -5565,6 +5565,22 @@ select * drop view v1; drop table t1,t2,t3; +--echo # +--echo # MDEV-11240: Server crashes in check_view_single_update or +--echo # Assertion `derived->table' failed in mysql_derived_merge_for_insert +--echo # + +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'; +--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; + --echo # ----------------------------------------------------------------- --echo # -- End of 5.5 tests. --echo # ----------------------------------------------------------------- diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 20fca2de8cf..493f0eccc8c 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -525,7 +525,9 @@ bool mysql_derived_merge_for_insert(THD *thd, LEX *lex, TABLE_LIST *derived) derived->schema_table= derived->merge_underlying_list->schema_table; derived->merged_for_insert= TRUE; } - } + } + else + derived->table= derived->merge_underlying_list->table; DBUG_RETURN(FALSE); } From f6bcdb9e3c955f0a998a996edd93362deca31edf Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 18 Jul 2017 14:45:44 +0200 Subject: [PATCH 91/97] test case for loadxml and spaces --- mysql-test/r/loadxml.result | 16 ++++++++-------- mysql-test/std_data/loadxml.dat | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mysql-test/r/loadxml.result b/mysql-test/r/loadxml.result index 1128caf9122..250037f60b8 100644 --- a/mysql-test/r/loadxml.result +++ b/mysql-test/r/loadxml.result @@ -5,10 +5,10 @@ load xml infile '../../std_data/loadxml.dat' into table t1 rows identified by ''; select * from t1 order by a; a b -1 b1 -2 b2 -3 b3 -11 b11 +1 b1 +2 b2 +3 b3 +11 b11 111 b111 112 b112 & < > " ' &unknown; -- check entities 212 b212 @@ -81,17 +81,17 @@ LOAD XML INFILE '../../std_data/loadxml.dat' INTO TABLE t1 ROWS IDENTIFIED BY '' (a,@b) SET b=concat('!',@b); SELECT * FROM t1 ORDER BY a; a b -1 !b1 -11 !b11 +1 ! b1 +11 ! b11 111 !b111 112 !b112 & < > " ' &unknown; -- check entities -2 !b2 +2 ! b2 212 !b212 213 !b213 214 !b214 215 !b215 216 !&bb b; -3 !b3 +3 ! b3 DROP TABLE t1; # # Bug#16171518 LOAD XML DOES NOT HANDLE EMPTY ELEMENTS diff --git a/mysql-test/std_data/loadxml.dat b/mysql-test/std_data/loadxml.dat index b72fac9da74..d5ccd4a1b13 100644 --- a/mysql-test/std_data/loadxml.dat +++ b/mysql-test/std_data/loadxml.dat @@ -9,19 +9,19 @@ 1 - b1 + b1 2 - b2 + b2 3 - b3 + b3 11 - b11 + b11 From 9b3360ea4417ed653d5c7eed29f4ef7e80618e43 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 18 Jul 2017 14:47:40 +0200 Subject: [PATCH 92/97] BUG#25250768: WRITING ON A READ_ONLY=ON SERVER WITHOUT SUPER PRIVILEGE simplify. add a test case. --- mysql-test/r/read_only.result | 2 ++ mysql-test/t/read_only.test | 3 +++ sql/sql_parse.cc | 26 +++++++++----------------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/mysql-test/r/read_only.result b/mysql-test/r/read_only.result index 1ffe2b86f70..807dc426696 100644 --- a/mysql-test/r/read_only.result +++ b/mysql-test/r/read_only.result @@ -30,6 +30,8 @@ create temporary table t3 (a int); create temporary table t4 (a int) select * from t3; insert into t3 values(1); insert into t4 select * from t3; +create table t3 (a int); +ERROR HY000: The MariaDB server is running with the --read-only option so it cannot execute this statement update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a; ERROR HY000: The MariaDB server is running with the --read-only option so it cannot execute this statement update t1,t3 set t3.a=t1.a+1 where t1.a=t3.a; diff --git a/mysql-test/t/read_only.test b/mysql-test/t/read_only.test index 52349747883..a0bd7b49273 100644 --- a/mysql-test/t/read_only.test +++ b/mysql-test/t/read_only.test @@ -80,6 +80,9 @@ insert into t3 values(1); insert into t4 select * from t3; +--error ER_OPTION_PREVENTS_STATEMENT +create table t3 (a int); + # a non-temp table updated: --error ER_OPTION_PREVENTS_STATEMENT update t1,t3 set t1.a=t3.a+1 where t1.a=t3.a; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 83cd6cccba5..1d596ed9df7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -835,24 +835,16 @@ static my_bool deny_updates_if_read_only_option(THD *thd, if (lex->sql_command == SQLCOM_UPDATE_MULTI) DBUG_RETURN(FALSE); - const my_bool create_temp_tables= - (lex->sql_command == SQLCOM_CREATE_TABLE) && - (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE); + /* + a table-to-be-created is not in the temp table list yet, + so CREATE TABLE needs a special treatment + */ + const bool update_real_tables= + lex->sql_command == SQLCOM_CREATE_TABLE + ? !(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) + : some_non_temp_table_to_be_updated(thd, all_tables); - const my_bool create_real_tables= - (lex->sql_command == SQLCOM_CREATE_TABLE) && - !(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE); - - const my_bool drop_temp_tables= - (lex->sql_command == SQLCOM_DROP_TABLE) && - lex->drop_temporary; - - const my_bool update_real_tables= - ((create_real_tables || - some_non_temp_table_to_be_updated(thd, all_tables)) && - !(create_temp_tables || drop_temp_tables)); - - const my_bool create_or_drop_databases= + const bool create_or_drop_databases= (lex->sql_command == SQLCOM_CREATE_DB) || (lex->sql_command == SQLCOM_DROP_DB); From 7c9d00e0bb1977e474dff28c2ce93f27599bbc10 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 18 Jul 2017 14:48:25 +0200 Subject: [PATCH 93/97] Bug #24595639: INCORRECT BEHAVIOR IN QUERY WITH UNION AND GROUP BY test case --- mysql-test/r/union.result | 18 ++++++++++++++++++ mysql-test/t/union.test | 15 +++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 5a6cd8907e9..fe2339db471 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -1978,3 +1978,21 @@ d 2016-06-04 00:00:00 drop table t1; End of 5.0 tests +create table t1 (a int, b int); +insert into t1 values (1,1),(2,2),(3,3); +create table t2 (c varchar(30), d varchar(30)); +insert into t1 values ('1','1'),('2','2'),('4','4'); +create table t3 (e int, f int); +insert into t3 values (1,1),(2,2),(31,31),(32,32); +select e,f, (e , f) in (select e,b from t1 union select c,d from t2) as sub from t3; +e f sub +1 1 1 +2 2 1 +31 31 0 +32 32 0 +select avg(f), (e , f) in (select e,b from t1 union select c,d from t2) as sub from t3 group by sub; +avg(f) sub +31.5000 0 +1.5000 1 +drop table t1,t2,t3; +End of 5.5 tests diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index f4dc6a5d449..4a3c19b49ab 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -1370,3 +1370,18 @@ order by d; drop table t1; --echo End of 5.0 tests + +# +# Bug #24595639: INCORRECT BEHAVIOR IN QUERY WITH UNION AND GROUP BY +# +create table t1 (a int, b int); +insert into t1 values (1,1),(2,2),(3,3); +create table t2 (c varchar(30), d varchar(30)); +insert into t1 values ('1','1'),('2','2'),('4','4'); +create table t3 (e int, f int); +insert into t3 values (1,1),(2,2),(31,31),(32,32); +select e,f, (e , f) in (select e,b from t1 union select c,d from t2) as sub from t3; +select avg(f), (e , f) in (select e,b from t1 union select c,d from t2) as sub from t3 group by sub; +drop table t1,t2,t3; + +--echo End of 5.5 tests From f9dbfa58a564262a5c696b0635c8186ecd84eeea Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 15 Mar 2017 08:33:46 +1100 Subject: [PATCH 94/97] MDEV-658: debian debug symbols require compat 9 Signed-off-by: Daniel Black --- debian/compat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/compat b/debian/compat index 7ed6ff82de6..ec635144f60 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -5 +9 From 172e3a1bc6ab1e38dd8be074b2c10cc734456e35 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 1 May 2017 18:34:11 +1000 Subject: [PATCH 95/97] MDEV-12646: Apply fixes found by Coverity static analysis tool Inspired by: https://github.com/devexp-db/mariadb/blob/f27/mariadb-covscan-stroverflow.patch --- plugin/semisync/semisync_master.cc | 6 +++--- sql/rpl_handler.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/semisync/semisync_master.cc b/plugin/semisync/semisync_master.cc index 3c22bcb94f2..16e6b091ca8 100644 --- a/plugin/semisync/semisync_master.cc +++ b/plugin/semisync/semisync_master.cc @@ -552,7 +552,7 @@ int ReplSemiSyncMaster::reportReplyBinlog(uint32 server_id, if (need_copy_send_pos) { - strcpy(reply_file_name_, log_file_name); + strmake_buf(reply_file_name_, log_file_name); reply_file_pos_ = log_file_pos; reply_file_name_inited_ = true; @@ -659,7 +659,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, if (cmp <= 0) { /* This thd has a lower position, let's update the minimum info. */ - strcpy(wait_file_name_, trx_wait_binlog_name); + strmake_buf(wait_file_name_, trx_wait_binlog_name); wait_file_pos_ = trx_wait_binlog_pos; rpl_semi_sync_master_wait_pos_backtraverse++; @@ -670,7 +670,7 @@ int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name, } else { - strcpy(wait_file_name_, trx_wait_binlog_name); + strmake_buf(wait_file_name_, trx_wait_binlog_name); wait_file_pos_ = trx_wait_binlog_pos; wait_file_name_inited_ = true; diff --git a/sql/rpl_handler.cc b/sql/rpl_handler.cc index 5b75d6c30ea..ca3b57edce3 100644 --- a/sql/rpl_handler.cc +++ b/sql/rpl_handler.cc @@ -260,7 +260,7 @@ int Binlog_storage_delegate::after_flush(THD *thd, thd->semisync_info= log_info; } - strcpy(log_info->log_file, log_file+dirname_length(log_file)); + strmake_buf(log_info->log_file, log_file+dirname_length(log_file)); log_info->log_pos = log_pos; FOREACH_OBSERVER(ret, after_flush, false, From 58aaae6f2a23e68b23727016844d177f178ea8ff Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 18 Jul 2017 16:42:40 +0200 Subject: [PATCH 96/97] ensure that filename in COM_BINLOG_DUMP isn't too long --- sql/sql_parse.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 1d596ed9df7..ba0520de4bb 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1271,9 +1271,12 @@ bool dispatch_command(enum enum_server_command command, THD *thd, kill_zombie_dump_threads(slave_server_id); thd->server_id = slave_server_id; - general_log_print(thd, command, "Log: '%s' Pos: %ld", packet+10, - (long) pos); - mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags); + const char *name= packet + 10; + size_t nlen= strlen(name); + + general_log_print(thd, command, "Log: '%s' Pos: %lu", name, pos); + if (nlen < FN_REFLEN) + mysql_binlog_send(thd, thd->strmake(name, nlen), (my_off_t)pos, flags); unregister_slave(thd,1,1); /* fake COM_QUIT -- if we get here, the thread needs to terminate */ error = TRUE; From 46977e0a01ae2118df08c3cccaf2f0eaaabd2715 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 18 Jul 2017 19:47:01 +0200 Subject: [PATCH 97/97] 5.5.55-38.8 --- storage/xtradb/btr/btr0btr.c | 2 +- storage/xtradb/dict/dict0crea.c | 10 +- storage/xtradb/dict/dict0load.c | 10 +- storage/xtradb/dict/dict0mem.c | 2 +- storage/xtradb/fil/fil0fil.c | 2 +- storage/xtradb/fsp/fsp0fsp.c | 7 +- storage/xtradb/handler/i_s.cc | 24 +---- storage/xtradb/include/btr0cur.h | 13 +-- storage/xtradb/include/btr0sea.h | 7 +- storage/xtradb/include/buf0buddy.ic | 2 +- storage/xtradb/include/buf0buf.h | 3 +- storage/xtradb/include/dict0dict.h | 16 +-- storage/xtradb/include/dict0mem.h | 2 +- storage/xtradb/include/dyn0dyn.h | 18 ++-- storage/xtradb/include/dyn0dyn.ic | 2 +- storage/xtradb/include/fsp0fsp.h | 2 +- storage/xtradb/include/log0online.h | 20 ++-- storage/xtradb/include/mach0data.h | 16 +-- storage/xtradb/include/mtr0mtr.h | 5 +- storage/xtradb/include/os0file.h | 5 +- storage/xtradb/include/page0page.h | 18 ++-- storage/xtradb/include/page0zip.h | 5 +- storage/xtradb/include/rem0rec.h | 3 +- storage/xtradb/include/row0upd.h | 5 +- storage/xtradb/include/trx0trx.h | 4 +- storage/xtradb/include/univ.i | 2 +- storage/xtradb/log/log0online.c | 148 ++++++++++++++++++++-------- storage/xtradb/mach/mach0data.c | 48 ++++++--- storage/xtradb/os/os0file.c | 49 +++------ storage/xtradb/rem/rem0rec.c | 2 +- storage/xtradb/row/row0merge.c | 4 +- storage/xtradb/row/row0purge.c | 2 +- storage/xtradb/srv/srv0srv.c | 9 +- storage/xtradb/srv/srv0start.c | 2 + storage/xtradb/trx/trx0roll.c | 4 + 35 files changed, 257 insertions(+), 216 deletions(-) diff --git a/storage/xtradb/btr/btr0btr.c b/storage/xtradb/btr/btr0btr.c index 0c429363789..da848b1b4f8 100644 --- a/storage/xtradb/btr/btr0btr.c +++ b/storage/xtradb/btr/btr0btr.c @@ -2958,7 +2958,7 @@ Removes a page from the level list of pages. /*************************************************************//** Removes a page from the level list of pages. */ -static __attribute__((nonnull)) +static void btr_level_list_remove_func( /*=======================*/ diff --git a/storage/xtradb/dict/dict0crea.c b/storage/xtradb/dict/dict0crea.c index b950c2d9b3f..673bafacf31 100644 --- a/storage/xtradb/dict/dict0crea.c +++ b/storage/xtradb/dict/dict0crea.c @@ -112,13 +112,13 @@ dict_create_sys_tables_tuple( dfield = dtuple_get_nth_field(entry, 3/*TYPE*/); ptr = mem_heap_alloc(heap, 4); - if (table->flags & (~DICT_TF_COMPACT & ~(~0 << DICT_TF_BITS))) { + if (table->flags & (~DICT_TF_COMPACT & ~(~0U << DICT_TF_BITS))) { ut_a(table->flags & DICT_TF_COMPACT); ut_a(dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP); ut_a((table->flags & DICT_TF_ZSSIZE_MASK) <= (DICT_TF_ZSSIZE_MAX << DICT_TF_ZSSIZE_SHIFT)); - ut_a(!(table->flags & (~0 << DICT_TF2_BITS))); - mach_write_to_4(ptr, table->flags & ~(~0 << DICT_TF_BITS)); + ut_a(!(table->flags & (~0U << DICT_TF2_BITS))); + mach_write_to_4(ptr, table->flags & ~(~0U << DICT_TF_BITS)); } else { mach_write_to_4(ptr, DICT_TABLE_ORDINARY); } @@ -306,7 +306,7 @@ dict_build_table_def_step( ut_ad(!dict_table_zip_size(table) || dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP); - flags = table->flags & ~(~0 << DICT_TF_BITS); + flags = table->flags & ~(~0U << DICT_TF_BITS); error = fil_create_new_single_table_tablespace( space, path_or_name, is_path, flags == DICT_TF_COMPACT ? 0 : flags, @@ -325,7 +325,7 @@ dict_build_table_def_step( mtr_commit(&mtr); } else { /* Create in the system tablespace: disallow new features */ - table->flags &= (~0 << DICT_TF_BITS) | DICT_TF_COMPACT; + table->flags &= (~0U << DICT_TF_BITS) | DICT_TF_COMPACT; } row = dict_create_sys_tables_tuple(table, node->heap); diff --git a/storage/xtradb/dict/dict0load.c b/storage/xtradb/dict/dict0load.c index 067c9d2b8f9..1d11868ef73 100644 --- a/storage/xtradb/dict/dict0load.c +++ b/storage/xtradb/dict/dict0load.c @@ -717,7 +717,7 @@ dict_sys_tables_get_flags( return(ULINT_UNDEFINED); } - if (UNIV_UNLIKELY(flags & (~0 << DICT_TF_BITS))) { + if (UNIV_UNLIKELY(flags & (~0U << DICT_TF_BITS))) { /* Some unused bits are set. */ return(ULINT_UNDEFINED); } @@ -1406,7 +1406,7 @@ err_len: goto err_len; } type = mach_read_from_4(field); - if (UNIV_UNLIKELY(type & (~0 << DICT_IT_BITS))) { + if (UNIV_UNLIKELY(type & (~0U << DICT_IT_BITS))) { return("unknown SYS_INDEXES.TYPE bits"); } @@ -1771,7 +1771,7 @@ err_len: flags2 = mach_read_from_4(field); - if (flags2 & (~0 << (DICT_TF2_BITS - DICT_TF2_SHIFT))) { + if (flags2 & (~0U << (DICT_TF2_BITS - DICT_TF2_SHIFT))) { ut_print_timestamp(stderr); fputs(" InnoDB: Warning: table ", stderr); ut_print_filename(stderr, name); @@ -1780,7 +1780,7 @@ err_len: " has unknown flags %lx.\n", (ulong) flags2); - flags2 &= ~(~0 << (DICT_TF2_BITS - DICT_TF2_SHIFT)); + flags2 &= ~(~0U << (DICT_TF2_BITS - DICT_TF2_SHIFT)); } flags |= flags2 << DICT_TF2_SHIFT; @@ -1913,7 +1913,7 @@ err_exit: if (!fil_open_single_table_tablespace( TRUE, table->space, table->flags == DICT_TF_COMPACT ? 0 : - table->flags & ~(~0 << DICT_TF_BITS), name, NULL)) { + table->flags & ~(~0U << DICT_TF_BITS), name, NULL)) { /* We failed to find a sensible tablespace file */ diff --git a/storage/xtradb/dict/dict0mem.c b/storage/xtradb/dict/dict0mem.c index 40099c06823..18917a30ff6 100644 --- a/storage/xtradb/dict/dict0mem.c +++ b/storage/xtradb/dict/dict0mem.c @@ -69,7 +69,7 @@ dict_mem_table_create( DBUG_ENTER("dict_mem_table_create"); ut_ad(name); - ut_a(!(flags & (~0 << DICT_TF2_BITS))); + ut_a(!(flags & (~0U << DICT_TF2_BITS))); heap = mem_heap_create(DICT_HEAP_SIZE); diff --git a/storage/xtradb/fil/fil0fil.c b/storage/xtradb/fil/fil0fil.c index 67ad5ef7855..e824526e097 100644 --- a/storage/xtradb/fil/fil0fil.c +++ b/storage/xtradb/fil/fil0fil.c @@ -3868,7 +3868,7 @@ skip_write: } if (space_id != id - || space_flags != (flags & ~(~0 << DICT_TF_BITS))) { + || space_flags != (flags & ~(~0U << DICT_TF_BITS))) { ut_print_timestamp(stderr); fputs(" InnoDB: Error: tablespace id and flags in file ", diff --git a/storage/xtradb/fsp/fsp0fsp.c b/storage/xtradb/fsp/fsp0fsp.c index 2d145f44bab..8927e7c5841 100644 --- a/storage/xtradb/fsp/fsp0fsp.c +++ b/storage/xtradb/fsp/fsp0fsp.c @@ -249,8 +249,7 @@ fsp_fill_free_list( then we do not allocate more extents */ ulint space, /*!< in: space */ fsp_header_t* header, /*!< in/out: space header */ - mtr_t* mtr) /*!< in/out: mini-transaction */ - __attribute__((nonnull)); + mtr_t* mtr); /*!< in/out: mini-transaction */ /**********************************************************************//** Allocates a single free page from a segment. This function implements the intelligent allocation strategy which tries to minimize file space @@ -279,7 +278,7 @@ fseg_alloc_free_page_low( in which the page should be initialized. If init_mtr!=mtr, but the page is already latched in mtr, do not initialize the page. */ - __attribute__((warn_unused_result, nonnull)); + __attribute__((warn_unused_result)); #endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** @@ -1572,7 +1571,7 @@ Allocates a single free page from a space. The page is marked as used. @retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded (init_mtr == mtr, or the page was not previously freed in mtr) @retval block (not allocated or initialized) otherwise */ -static __attribute__((nonnull, warn_unused_result)) +static __attribute__((warn_unused_result)) buf_block_t* fsp_alloc_free_page( /*================*/ diff --git a/storage/xtradb/handler/i_s.cc b/storage/xtradb/handler/i_s.cc index cb4a8f2357a..0c6449ef183 100644 --- a/storage/xtradb/handler/i_s.cc +++ b/storage/xtradb/handler/i_s.cc @@ -7544,29 +7544,7 @@ i_s_innodb_changed_pages_fill( while(log_online_bitmap_iterator_next(&i) && (!srv_max_changed_pages || - output_rows_num < srv_max_changed_pages) && - /* - There is no need to compare both start LSN and end LSN fields - with maximum value. It's enough to compare only start LSN. - Example: - - max_lsn = 100 - \\\\\\\\\\\\\\\\\\\\\\\\\|\\\\\\\\ - Query 1 - I------I I-------I I-------------I I----I - ////////////////// | - Query 2 - 1 2 3 4 - - Query 1: - SELECT * FROM INNODB_CHANGED_PAGES WHERE start_lsn < 100 - will select 1,2,3 bitmaps - Query 2: - SELECT * FROM INNODB_CHANGED_PAGES WHERE end_lsn < 100 - will select 1,2 bitmaps - - The condition start_lsn <= 100 will be false after reading - 1,2,3 bitmaps which suits for both cases. - */ - LOG_BITMAP_ITERATOR_START_LSN(i) <= max_lsn) + output_rows_num < srv_max_changed_pages)) { if (!LOG_BITMAP_ITERATOR_PAGE_CHANGED(i)) continue; diff --git a/storage/xtradb/include/btr0cur.h b/storage/xtradb/include/btr0cur.h index 7b56c1bbb6e..7f6fd34635f 100644 --- a/storage/xtradb/include/btr0cur.h +++ b/storage/xtradb/include/btr0cur.h @@ -261,7 +261,7 @@ btr_cur_update_alloc_zip( FALSE=update-in-place */ mtr_t* mtr, /*!< in: mini-transaction */ trx_t* trx) /*!< in: NULL or transaction */ - __attribute__((nonnull (1, 2, 3, 6), warn_unused_result)); + __attribute__((warn_unused_result)); /*************************************************************//** Updates a record when the update causes no size changes in its fields. @return DB_SUCCESS or error number */ @@ -345,8 +345,7 @@ btr_cur_del_mark_set_clust_rec( const ulint* offsets,/*!< in: rec_get_offsets(rec) */ ibool val, /*!< in: value to set */ que_thr_t* thr, /*!< in: query thread */ - mtr_t* mtr) /*!< in: mtr */ - __attribute__((nonnull)); + mtr_t* mtr); /*!< in: mtr */ /***********************************************************//** Sets a secondary index record delete mark to TRUE or FALSE. @return DB_SUCCESS, DB_LOCK_WAIT, or error number */ @@ -499,8 +498,7 @@ btr_cur_disown_inherited_fields( dict_index_t* index, /*!< in: index of the page */ const ulint* offsets,/*!< in: array returned by rec_get_offsets() */ const upd_t* update, /*!< in: update vector */ - mtr_t* mtr) /*!< in/out: mini-transaction */ - __attribute__((nonnull(2,3,4,5,6))); + mtr_t* mtr); /*!< in/out: mini-transaction */ /** Operation code for btr_store_big_rec_extern_fields(). */ enum blob_op { @@ -545,7 +543,7 @@ btr_store_big_rec_extern_fields( mtr_t* btr_mtr, /*!< in: mtr containing the latches to the clustered index */ enum blob_op op) /*! in: operation code */ - __attribute__((nonnull, warn_unused_result)); + __attribute__((warn_unused_result)); /*******************************************************************//** Frees the space in an externally stored field to the file space @@ -621,8 +619,7 @@ btr_push_update_extern_fields( /*==========================*/ dtuple_t* tuple, /*!< in/out: data tuple */ const upd_t* update, /*!< in: update vector */ - mem_heap_t* heap) /*!< in: memory heap */ - __attribute__((nonnull)); + mem_heap_t* heap); /*!< in: memory heap */ /***********************************************************//** Sets a secondary index record's delete mark to the given value. This function is only used by the insert buffer merge mechanism. */ diff --git a/storage/xtradb/include/btr0sea.h b/storage/xtradb/include/btr0sea.h index 39c0a66fb9a..bdffe402277 100644 --- a/storage/xtradb/include/btr0sea.h +++ b/storage/xtradb/include/btr0sea.h @@ -205,14 +205,14 @@ hash_table_t* btr_search_get_hash_table( /*======================*/ const dict_index_t* index) /*!< in: index */ - __attribute__((nonnull,pure,warn_unused_result)); + __attribute__((warn_unused_result)); UNIV_INLINE rw_lock_t* btr_search_get_latch( /*=================*/ const dict_index_t* index) /*!< in: index */ - __attribute__((nonnull,pure,warn_unused_result)); + __attribute__((warn_unused_result)); /*********************************************************************//** Returns the AHI partition number corresponding to a given index ID. */ @@ -229,8 +229,7 @@ UNIV_INLINE void btr_search_index_init( /*===============*/ - dict_index_t* index) /*!< in: index */ - __attribute__((nonnull)); + dict_index_t* index); /*!< in: index */ UNIV_INLINE void diff --git a/storage/xtradb/include/buf0buddy.ic b/storage/xtradb/include/buf0buddy.ic index d7053881caa..2b5e62e97b2 100644 --- a/storage/xtradb/include/buf0buddy.ic +++ b/storage/xtradb/include/buf0buddy.ic @@ -51,7 +51,7 @@ buf_buddy_alloc_low( buf_pool->mutex was temporarily released */ ibool have_page_hash_mutex) - __attribute__((malloc, nonnull)); + __attribute__((malloc)); /**********************************************************************//** Deallocate a block. */ diff --git a/storage/xtradb/include/buf0buf.h b/storage/xtradb/include/buf0buf.h index 23692c92c09..d584062a81f 100644 --- a/storage/xtradb/include/buf0buf.h +++ b/storage/xtradb/include/buf0buf.h @@ -274,8 +274,7 @@ buf_relocate( buf_page_t* bpage, /*!< in/out: control block being relocated; buf_page_get_state(bpage) must be BUF_BLOCK_ZIP_DIRTY or BUF_BLOCK_ZIP_PAGE */ - buf_page_t* dpage) /*!< in/out: destination control block */ - __attribute__((nonnull)); + buf_page_t* dpage); /*!< in/out: destination control block */ /*********************************************************************//** Gets the current size of buffer buf_pool in bytes. @return size in bytes */ diff --git a/storage/xtradb/include/dict0dict.h b/storage/xtradb/include/dict0dict.h index 121f9241cbc..5a3465fd9c5 100644 --- a/storage/xtradb/include/dict0dict.h +++ b/storage/xtradb/include/dict0dict.h @@ -605,7 +605,7 @@ ulint dict_index_is_clust( /*================*/ const dict_index_t* index) /*!< in: index */ - __attribute__((nonnull, pure, warn_unused_result)); + __attribute__((warn_unused_result)); /********************************************************************//** Check whether the index is unique. @return nonzero for unique index, zero for other indexes */ @@ -614,7 +614,7 @@ ulint dict_index_is_unique( /*=================*/ const dict_index_t* index) /*!< in: index */ - __attribute__((nonnull, pure, warn_unused_result)); + __attribute__((warn_unused_result)); /********************************************************************//** Check whether the index is the insert buffer tree. @return nonzero for insert buffer, zero for other indexes */ @@ -623,7 +623,7 @@ ulint dict_index_is_ibuf( /*===============*/ const dict_index_t* index) /*!< in: index */ - __attribute__((nonnull, pure, warn_unused_result)); + __attribute__((warn_unused_result)); /********************************************************************//** Check whether the index is a secondary index or the insert buffer tree. @return nonzero for insert buffer, zero for other indexes */ @@ -632,7 +632,7 @@ ulint dict_index_is_sec_or_ibuf( /*======================*/ const dict_index_t* index) /*!< in: index */ - __attribute__((nonnull, pure, warn_unused_result)); + __attribute__((warn_unused_result)); /********************************************************************//** Gets the number of user-defined columns in a table in the dictionary @@ -643,7 +643,7 @@ ulint dict_table_get_n_user_cols( /*=======================*/ const dict_table_t* table) /*!< in: table */ - __attribute__((nonnull, pure, warn_unused_result)); + __attribute__((warn_unused_result)); /********************************************************************//** Gets the number of system columns in a table in the dictionary cache. @return number of system (e.g., ROW_ID) columns of a table */ @@ -662,7 +662,7 @@ ulint dict_table_get_n_cols( /*==================*/ const dict_table_t* table) /*!< in: table */ - __attribute__((nonnull, pure, warn_unused_result)); + __attribute__((warn_unused_result)); #ifdef UNIV_DEBUG /********************************************************************//** Gets the nth column of a table. @@ -1313,7 +1313,7 @@ ulint dict_index_is_corrupted( /*====================*/ const dict_index_t* index) /*!< in: index */ - __attribute__((nonnull, pure, warn_unused_result)); + __attribute__((warn_unused_result)); #endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** @@ -1324,7 +1324,7 @@ void dict_set_corrupted( /*===============*/ dict_index_t* index) /*!< in/out: index */ - UNIV_COLD __attribute__((nonnull)); + UNIV_COLD; /**********************************************************************//** Flags an index corrupted in the data dictionary cache only. This diff --git a/storage/xtradb/include/dict0mem.h b/storage/xtradb/include/dict0mem.h index ba98eed7701..2bdad46ae08 100644 --- a/storage/xtradb/include/dict0mem.h +++ b/storage/xtradb/include/dict0mem.h @@ -87,7 +87,7 @@ combination of types */ /* @{ */ #define DICT_TF_FORMAT_SHIFT 5 /* file format */ #define DICT_TF_FORMAT_MASK \ -((~(~0 << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT) +((~(~0U << (DICT_TF_BITS - DICT_TF_FORMAT_SHIFT))) << DICT_TF_FORMAT_SHIFT) #define DICT_TF_FORMAT_51 0 /*!< InnoDB/MySQL up to 5.1 */ #define DICT_TF_FORMAT_ZIP 1 /*!< InnoDB plugin for 5.1: compressed tables, diff --git a/storage/xtradb/include/dyn0dyn.h b/storage/xtradb/include/dyn0dyn.h index 62ed862e82c..e3517108a29 100644 --- a/storage/xtradb/include/dyn0dyn.h +++ b/storage/xtradb/include/dyn0dyn.h @@ -47,9 +47,8 @@ UNIV_INLINE dyn_array_t* dyn_array_create( /*=============*/ - dyn_array_t* arr) /*!< in/out memory buffer of + dyn_array_t* arr); /*!< in/out memory buffer of size sizeof(dyn_array_t) */ - __attribute__((nonnull)); /************************************************************//** Frees a dynamic array. */ UNIV_INLINE @@ -70,7 +69,7 @@ dyn_array_open( dyn_array_t* arr, /*!< in: dynamic array */ ulint size) /*!< in: size in bytes of the buffer; MUST be smaller than DYN_ARRAY_DATA_SIZE! */ - __attribute__((nonnull, warn_unused_result)); + __attribute__((warn_unused_result)); /*********************************************************************//** Closes the buffer returned by dyn_array_open. */ UNIV_INLINE @@ -78,8 +77,7 @@ void dyn_array_close( /*============*/ dyn_array_t* arr, /*!< in: dynamic array */ - const byte* ptr) /*!< in: end of used space */ - __attribute__((nonnull)); + const byte* ptr); /*!< in: end of used space */ /*********************************************************************//** Makes room on top of a dyn array and returns a pointer to the added element. The caller must copy the element to @@ -91,7 +89,7 @@ dyn_array_push( /*===========*/ dyn_array_t* arr, /*!< in/out: dynamic array */ ulint size) /*!< in: size in bytes of the element */ - __attribute__((nonnull, warn_unused_result)); + __attribute__((warn_unused_result)); /************************************************************//** Returns pointer to an element in dyn array. @return pointer to element */ @@ -102,7 +100,7 @@ dyn_array_get_element( const dyn_array_t* arr, /*!< in: dyn array */ ulint pos) /*!< in: position of element in bytes from array start */ - __attribute__((nonnull, warn_unused_result)); + __attribute__((warn_unused_result)); /************************************************************//** Returns the size of stored data in a dyn array. @return data size in bytes */ @@ -111,7 +109,7 @@ ulint dyn_array_get_data_size( /*====================*/ const dyn_array_t* arr) /*!< in: dyn array */ - __attribute__((nonnull, warn_unused_result, pure)); + __attribute__((warn_unused_result)); /************************************************************//** Gets the first block in a dyn array. @param arr dyn array @@ -145,7 +143,7 @@ ulint dyn_block_get_used( /*===============*/ const dyn_block_t* block) /*!< in: dyn array block */ - __attribute__((nonnull, warn_unused_result, pure)); + __attribute__((warn_unused_result)); /********************************************************************//** Gets pointer to the start of data in a dyn array block. @return pointer to data */ @@ -154,7 +152,7 @@ byte* dyn_block_get_data( /*===============*/ const dyn_block_t* block) /*!< in: dyn array block */ - __attribute__((nonnull, warn_unused_result, pure)); + __attribute__((warn_unused_result)); /********************************************************//** Pushes n bytes to a dyn array. */ UNIV_INLINE diff --git a/storage/xtradb/include/dyn0dyn.ic b/storage/xtradb/include/dyn0dyn.ic index 177877ed1fd..239d0547c6c 100644 --- a/storage/xtradb/include/dyn0dyn.ic +++ b/storage/xtradb/include/dyn0dyn.ic @@ -36,7 +36,7 @@ dyn_block_t* dyn_array_add_block( /*================*/ dyn_array_t* arr) /*!< in/out: dyn array */ - __attribute__((nonnull, warn_unused_result)); + __attribute__((warn_unused_result)); /********************************************************************//** Gets the number of used bytes in a dyn array block. diff --git a/storage/xtradb/include/fsp0fsp.h b/storage/xtradb/include/fsp0fsp.h index f07e3decc66..0b813182947 100644 --- a/storage/xtradb/include/fsp0fsp.h +++ b/storage/xtradb/include/fsp0fsp.h @@ -42,7 +42,7 @@ Created 12/18/1995 Heikki Tuuri #define FSP_FLAGS_POS_PAGE_SSIZE 6 /** Bit mask of the PAGE_SSIZE field */ #define FSP_FLAGS_MASK_PAGE_SSIZE \ - ((~(~0 << FSP_FLAGS_WIDTH_PAGE_SSIZE)) \ + ((~(~0U << FSP_FLAGS_WIDTH_PAGE_SSIZE)) \ << FSP_FLAGS_POS_PAGE_SSIZE) /** Return the value of the PAGE_SSIZE field */ #define FSP_FLAGS_GET_PAGE_SSIZE(flags) \ diff --git a/storage/xtradb/include/log0online.h b/storage/xtradb/include/log0online.h index 02d75001505..2462263dec2 100644 --- a/storage/xtradb/include/log0online.h +++ b/storage/xtradb/include/log0online.h @@ -37,19 +37,25 @@ log_online_bitmap_file_range_t; /** An iterator over changed page info */ typedef struct log_bitmap_iterator_struct log_bitmap_iterator_t; -/*********************************************************************//** -Initializes the online log following subsytem. */ +/** Initialize the constant part of the log tracking subsystem */ +UNIV_INTERN +void +log_online_init(void); + +/** Initialize the dynamic part of the log tracking subsystem */ UNIV_INTERN void log_online_read_init(void); -/*=======================*/ -/*********************************************************************//** -Shuts down the online log following subsystem. */ +/** Shut down the dynamic part of the log tracking subsystem */ UNIV_INTERN void log_online_read_shutdown(void); -/*===========================*/ + +/** Shut down the constant part of the log tracking subsystem */ +UNIV_INTERN +void +log_online_shutdown(void); /*********************************************************************//** Reads and parses the redo log up to last checkpoint LSN to build the changed @@ -159,6 +165,8 @@ struct log_online_bitmap_file_range_struct { /** Struct for an iterator through all bits of changed pages bitmap blocks */ struct log_bitmap_iterator_struct { + ib_uint64_t max_lsn; /*!< End LSN of the + range */ ibool failed; /*!< Has the iteration stopped prematurely */ log_online_bitmap_file_range_t in_files; /*!< The bitmap files diff --git a/storage/xtradb/include/mach0data.h b/storage/xtradb/include/mach0data.h index 81c0866f367..d9a4a9170c7 100644 --- a/storage/xtradb/include/mach0data.h +++ b/storage/xtradb/include/mach0data.h @@ -51,7 +51,7 @@ ulint mach_read_from_1( /*=============*/ const byte* b) /*!< in: pointer to byte */ - __attribute__((nonnull, pure)); + __attribute__((warn_unused_result)); /*******************************************************//** The following function is used to store data in two consecutive bytes. We store the most significant byte to the lower address. */ @@ -112,7 +112,7 @@ ulint mach_read_from_3( /*=============*/ const byte* b) /*!< in: pointer to 3 bytes */ - __attribute__((nonnull, pure)); + __attribute__((warn_unused_result)); /*******************************************************//** The following function is used to store data in four consecutive bytes. We store the most significant byte to the lowest address. */ @@ -131,7 +131,7 @@ ulint mach_read_from_4( /*=============*/ const byte* b) /*!< in: pointer to four bytes */ - __attribute__((nonnull, pure)); + __attribute__((warn_unused_result)); /*********************************************************//** Writes a ulint in a compressed form (1..5 bytes). @return stored size in bytes */ @@ -158,7 +158,7 @@ ulint mach_read_compressed( /*=================*/ const byte* b) /*!< in: pointer to memory from where to read */ - __attribute__((nonnull, pure)); + __attribute__((warn_unused_result)); /*******************************************************//** The following function is used to store data in 6 consecutive bytes. We store the most significant byte to the lowest address. */ @@ -177,7 +177,7 @@ ib_uint64_t mach_read_from_6( /*=============*/ const byte* b) /*!< in: pointer to 6 bytes */ - __attribute__((nonnull, pure)); + __attribute__((warn_unused_result)); /*******************************************************//** The following function is used to store data in 7 consecutive bytes. We store the most significant byte to the lowest address. */ @@ -196,7 +196,7 @@ ib_uint64_t mach_read_from_7( /*=============*/ const byte* b) /*!< in: pointer to 7 bytes */ - __attribute__((nonnull, pure)); + __attribute__((warn_unused_result)); /*******************************************************//** The following function is used to store data in 8 consecutive bytes. We store the most significant byte to the lowest address. */ @@ -241,7 +241,7 @@ ib_uint64_t mach_ull_read_compressed( /*=====================*/ const byte* b) /*!< in: pointer to memory from where to read */ - __attribute__((nonnull, pure)); + __attribute__((warn_unused_result)); /*********************************************************//** Writes a 64-bit integer in a compressed form (1..11 bytes). @return size in bytes */ @@ -268,7 +268,7 @@ ib_uint64_t mach_ull_read_much_compressed( /*==========================*/ const byte* b) /*!< in: pointer to memory from where to read */ - __attribute__((nonnull, pure)); + __attribute__((warn_unused_result)); /*********************************************************//** Reads a ulint in a compressed form if the log record fully contains it. @return pointer to end of the stored field, NULL if not complete */ diff --git a/storage/xtradb/include/mtr0mtr.h b/storage/xtradb/include/mtr0mtr.h index 031fccd300c..bb60ffbd9bb 100644 --- a/storage/xtradb/include/mtr0mtr.h +++ b/storage/xtradb/include/mtr0mtr.h @@ -205,8 +205,7 @@ UNIV_INTERN void mtr_commit( /*=======*/ - mtr_t* mtr) /*!< in/out: mini-transaction */ - __attribute__((nonnull)); + mtr_t* mtr); /*!< in/out: mini-transaction */ /**********************************************************//** Sets and returns a savepoint in mtr. @return savepoint */ @@ -311,7 +310,7 @@ mtr_memo_contains( mtr_t* mtr, /*!< in: mtr */ const void* object, /*!< in: object to search */ ulint type) /*!< in: type of object */ - __attribute__((warn_unused_result, nonnull)); + __attribute__((warn_unused_result)); /**********************************************************//** Checks if memo contains the given page. diff --git a/storage/xtradb/include/os0file.h b/storage/xtradb/include/os0file.h index 71da5ea6125..618d6f540ae 100644 --- a/storage/xtradb/include/os0file.h +++ b/storage/xtradb/include/os0file.h @@ -515,9 +515,10 @@ os_file_create_simple_no_error_handling_func( it would be enabled otherwise). */ ibool* success);/*!< out: TRUE if succeed, FALSE if error */ /****************************************************************//** -Tries to disable OS caching on an opened file descriptor. */ +Tries to disable OS caching on an opened file descriptor. +@return TRUE if operation is success and FALSE otherwise */ UNIV_INTERN -void +ibool os_file_set_nocache( /*================*/ int fd, /*!< in: file descriptor to alter */ diff --git a/storage/xtradb/include/page0page.h b/storage/xtradb/include/page0page.h index b4755dce61d..6c8281b40cb 100644 --- a/storage/xtradb/include/page0page.h +++ b/storage/xtradb/include/page0page.h @@ -231,8 +231,7 @@ ulint page_header_get_offs( /*=================*/ const page_t* page, /*!< in: page */ - ulint field) /*!< in: PAGE_FREE, ... */ - __attribute__((nonnull, pure)); + ulint field); /*!< in: PAGE_FREE, ... */ /*************************************************************//** Returns the pointer stored in the given header field, or NULL. */ @@ -792,8 +791,7 @@ page_copy_rec_list_end( buf_block_t* block, /*!< in: index page containing rec */ rec_t* rec, /*!< in: record on page */ dict_index_t* index, /*!< in: record descriptor */ - mtr_t* mtr) /*!< in: mtr */ - __attribute__((nonnull)); + mtr_t* mtr); /*!< in: mtr */ /*************************************************************//** Copies records from page to new_page, up to the given record, NOT including that record. Infimum and supremum records are not copied. @@ -808,8 +806,7 @@ page_copy_rec_list_start( buf_block_t* block, /*!< in: index page containing rec */ rec_t* rec, /*!< in: record on page */ dict_index_t* index, /*!< in: record descriptor */ - mtr_t* mtr) /*!< in: mtr */ - __attribute__((nonnull)); + mtr_t* mtr); /*!< in: mtr */ /*************************************************************//** Deletes records from a page from a given record onward, including that record. The infimum and supremum records are not deleted. */ @@ -852,8 +849,7 @@ page_move_rec_list_end( buf_block_t* block, /*!< in: index page from where to move */ rec_t* split_rec, /*!< in: first record to move */ dict_index_t* index, /*!< in: record descriptor */ - mtr_t* mtr) /*!< in: mtr */ - __attribute__((nonnull(1, 2, 4, 5))); + mtr_t* mtr); /*!< in: mtr */ /*************************************************************//** Moves record list start to another page. Moved records do not include split_rec. @@ -877,8 +873,7 @@ page_dir_split_slot( page_t* page, /*!< in: index page */ page_zip_des_t* page_zip,/*!< in/out: compressed page whose uncompressed part will be written, or NULL */ - ulint slot_no)/*!< in: the directory slot */ - __attribute__((nonnull(1))); + ulint slot_no);/*!< in: the directory slot */ /*************************************************************//** Tries to balance the given directory slot with too few records with the upper neighbor, so that there are at least the minimum number @@ -890,8 +885,7 @@ page_dir_balance_slot( /*==================*/ page_t* page, /*!< in/out: index page */ page_zip_des_t* page_zip,/*!< in/out: compressed page, or NULL */ - ulint slot_no)/*!< in: the directory slot */ - __attribute__((nonnull(1))); + ulint slot_no);/*!< in: the directory slot */ /**********************************************************//** Parses a log record of a record list end or start deletion. @return end of log record or NULL */ diff --git a/storage/xtradb/include/page0zip.h b/storage/xtradb/include/page0zip.h index a33407e78bc..abd62ab99a5 100644 --- a/storage/xtradb/include/page0zip.h +++ b/storage/xtradb/include/page0zip.h @@ -402,8 +402,7 @@ page_zip_reorganize( out: data, n_blobs, m_start, m_end, m_nonempty */ dict_index_t* index, /*!< in: index of the B-tree node */ - mtr_t* mtr) /*!< in: mini-transaction */ - __attribute__((nonnull)); + mtr_t* mtr); /*!< in: mini-transaction */ #ifndef UNIV_HOTBACKUP /**********************************************************************//** Copy the records of a page byte for byte. Do not copy the page header @@ -436,7 +435,7 @@ page_zip_parse_compress( byte* end_ptr,/*!< in: buffer end */ page_t* page, /*!< out: uncompressed page */ page_zip_des_t* page_zip)/*!< out: compressed page */ - __attribute__((nonnull(1,2))); + __attribute__((warn_unused_result)); /**********************************************************************//** Calculate the compressed page checksum. diff --git a/storage/xtradb/include/rem0rec.h b/storage/xtradb/include/rem0rec.h index 9dd96f609ea..18e89eacccd 100644 --- a/storage/xtradb/include/rem0rec.h +++ b/storage/xtradb/include/rem0rec.h @@ -626,8 +626,7 @@ rec_copy( /*=====*/ void* buf, /*!< in: buffer */ const rec_t* rec, /*!< in: physical record */ - const ulint* offsets)/*!< in: array returned by rec_get_offsets() */ - __attribute__((nonnull)); + const ulint* offsets);/*!< in: array returned by rec_get_offsets() */ #ifndef UNIV_HOTBACKUP /**********************************************************//** Determines the size of a data tuple prefix in a temporary file. diff --git a/storage/xtradb/include/row0upd.h b/storage/xtradb/include/row0upd.h index 16c069d5ae8..e23a71374c2 100644 --- a/storage/xtradb/include/row0upd.h +++ b/storage/xtradb/include/row0upd.h @@ -232,9 +232,8 @@ row_upd_index_replace_new_col_vals_index_pos( /*!< in: if TRUE, limit the replacement to ordering fields of index; note that this does not work for non-clustered indexes. */ - mem_heap_t* heap) /*!< in: memory heap for allocating and + mem_heap_t* heap); /*!< in: memory heap for allocating and copying the new values */ - __attribute__((nonnull)); /***********************************************************//** Replaces the new column values stored in the update vector to the index entry given. */ @@ -295,7 +294,7 @@ row_upd_changes_ord_field_binary_func( compile time */ const row_ext_t*ext) /*!< NULL, or prefixes of the externally stored columns in the old row */ - __attribute__((nonnull(1,2), warn_unused_result)); + __attribute__((warn_unused_result)); #ifdef UNIV_DEBUG # define row_upd_changes_ord_field_binary(index,update,thr,row,ext) \ row_upd_changes_ord_field_binary_func(index,update,thr,row,ext) diff --git a/storage/xtradb/include/trx0trx.h b/storage/xtradb/include/trx0trx.h index b223f7cb39c..17f26956e78 100644 --- a/storage/xtradb/include/trx0trx.h +++ b/storage/xtradb/include/trx0trx.h @@ -90,7 +90,7 @@ trx_t* trx_create( /*=======*/ sess_t* sess) /*!< in: session */ - __attribute__((nonnull)); + __attribute__((warn_unused_result)); /********************************************************************//** Creates a transaction object for MySQL. @return own: transaction object */ @@ -119,7 +119,7 @@ void trx_free_prepared( /*==============*/ trx_t* trx) /*!< in, own: trx object */ - UNIV_COLD __attribute__((nonnull)); + UNIV_COLD; /********************************************************************//** Frees a transaction object for MySQL. */ UNIV_INTERN diff --git a/storage/xtradb/include/univ.i b/storage/xtradb/include/univ.i index d198fbf021b..a7475bbf396 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.5 +#define PERCONA_INNODB_VERSION 38.8 #endif #define INNODB_VERSION_STR MYSQL_SERVER_VERSION diff --git a/storage/xtradb/log/log0online.c b/storage/xtradb/log/log0online.c index fa2c8b882bf..45739dffa5d 100644 --- a/storage/xtradb/log/log0online.c +++ b/storage/xtradb/log/log0online.c @@ -84,12 +84,14 @@ struct log_bitmap_struct { both the correct type and the tree does not mind its overwrite during rbt_next() tree traversal. */ - mutex_t mutex; /*!< mutex protecting all the fields.*/ }; /* The log parsing and bitmap output struct instance */ static struct log_bitmap_struct* log_bmp_sys; +/* Mutex protecting log_bmp_sys */ +static mutex_t log_bmp_sys_mutex; + /** File name stem for bitmap files. */ static const char* bmp_file_name_stem = "ib_modified_log_"; @@ -188,7 +190,7 @@ log_online_set_page_bit( byte search_page[MODIFIED_PAGE_BLOCK_SIZE]; byte *page_ptr; - ut_ad(mutex_own(&log_bmp_sys->mutex)); + ut_ad(mutex_own(&log_bmp_sys_mutex)); ut_a(space != ULINT_UNDEFINED); ut_a(page_no != ULINT_UNDEFINED); @@ -339,7 +341,7 @@ log_online_read_last_tracked_lsn(void) ib_uint64_t result; ib_uint64_t read_offset = log_bmp_sys->out.offset; - while (!checksum_ok && read_offset > 0 && !is_last_page) + while ((!checksum_ok || !is_last_page) && read_offset > 0) { read_offset -= MODIFIED_PAGE_BLOCK_SIZE; log_bmp_sys->out.offset = read_offset; @@ -609,12 +611,19 @@ log_online_is_bitmap_file( && (!strcmp(stem, bmp_file_name_stem))); } -/*********************************************************************//** -Initialize the online log following subsytem. */ +/** Initialize the constant part of the log tracking subsystem */ +UNIV_INTERN +void +log_online_init(void) +{ + mutex_create(log_bmp_sys_mutex_key, &log_bmp_sys_mutex, + SYNC_LOG_ONLINE); +} + +/** Initialize the dynamic part of the log tracking subsystem */ UNIV_INTERN void log_online_read_init(void) -/*======================*/ { ibool success; ib_uint64_t tracking_start_lsn @@ -635,9 +644,6 @@ log_online_read_init(void) log_bmp_sys->read_buf = ut_align(log_bmp_sys->read_buf_ptr, OS_FILE_LOG_BLOCK_SIZE); - mutex_create(log_bmp_sys_mutex_key, &log_bmp_sys->mutex, - SYNC_LOG_ONLINE); - /* Initialize bitmap file directory from srv_data_home and add a path separator if needed. */ srv_data_home_len = strlen(srv_data_home); @@ -720,6 +726,7 @@ log_online_read_init(void) ulint size_high; ib_uint64_t last_tracked_lsn; ib_uint64_t file_start_lsn; + ibool need_rotate; success = os_file_get_size(log_bmp_sys->out.file, &size_low, &size_high); @@ -742,7 +749,11 @@ log_online_read_init(void) } last_tracked_lsn = log_online_read_last_tracked_lsn(); + /* Do not rotate if we truncated the file to zero length - we + can just start writing there */ + need_rotate = (last_tracked_lsn != 0); if (!last_tracked_lsn) { + last_tracked_lsn = last_file_start_lsn; } @@ -754,7 +765,10 @@ log_online_read_init(void) } else { file_start_lsn = tracking_start_lsn; } - if (!log_online_rotate_bitmap_file(file_start_lsn)) { + + if (need_rotate + && !log_online_rotate_bitmap_file(file_start_lsn)) { + exit(1); } @@ -782,14 +796,18 @@ log_online_read_init(void) log_set_tracked_lsn(tracking_start_lsn); } -/*********************************************************************//** -Shut down the online log following subsystem. */ +/** Shut down the dynamic part of the log tracking subsystem */ UNIV_INTERN void log_online_read_shutdown(void) -/*==========================*/ { - ib_rbt_node_t *free_list_node = log_bmp_sys->page_free_list; + ib_rbt_node_t *free_list_node; + + mutex_enter(&log_bmp_sys_mutex); + + srv_track_changed_pages = FALSE; + + free_list_node = log_bmp_sys->page_free_list; if (log_bmp_sys->out.file != os_file_invalid) { os_file_close(log_bmp_sys->out.file); @@ -804,10 +822,21 @@ log_online_read_shutdown(void) free_list_node = next; } - mutex_free(&log_bmp_sys->mutex); - ut_free(log_bmp_sys->read_buf_ptr); ut_free(log_bmp_sys); + log_bmp_sys = NULL; + + srv_redo_log_thread_started = FALSE; + + mutex_exit(&log_bmp_sys_mutex); +} + +/** Shut down the constant part of the log tracking subsystem */ +UNIV_INTERN +void +log_online_shutdown(void) +{ + mutex_free(&log_bmp_sys_mutex); } /*********************************************************************//** @@ -858,7 +887,7 @@ log_online_parse_redo_log(void) ulint len = 0; - ut_ad(mutex_own(&log_bmp_sys->mutex)); + ut_ad(mutex_own(&log_bmp_sys_mutex)); while (ptr != end && log_bmp_sys->next_parse_lsn < log_bmp_sys->end_lsn) { @@ -950,7 +979,7 @@ log_online_add_to_parse_buf( ulint actual_data_len = (end_offset >= start_offset) ? end_offset - start_offset : 0; - ut_ad(mutex_own(&log_bmp_sys->mutex)); + ut_ad(mutex_own(&log_bmp_sys_mutex)); ut_memcpy(log_bmp_sys->parse_buf_end, log_block + start_offset, actual_data_len); @@ -976,7 +1005,7 @@ log_online_parse_redo_log_block( { ulint block_data_len; - ut_ad(mutex_own(&log_bmp_sys->mutex)); + ut_ad(mutex_own(&log_bmp_sys_mutex)); block_data_len = log_block_get_data_len(log_block); @@ -1004,7 +1033,7 @@ log_online_follow_log_seg( byte* log_block_end = log_bmp_sys->read_buf + (block_end_lsn - block_start_lsn); - ut_ad(mutex_own(&log_bmp_sys->mutex)); + ut_ad(mutex_own(&log_bmp_sys_mutex)); mutex_enter(&log_sys->mutex); log_group_read_log_seg(LOG_RECOVER, log_bmp_sys->read_buf, @@ -1068,7 +1097,7 @@ log_online_follow_log_group( ib_uint64_t block_start_lsn = contiguous_lsn; ib_uint64_t block_end_lsn; - ut_ad(mutex_own(&log_bmp_sys->mutex)); + ut_ad(mutex_own(&log_bmp_sys_mutex)); log_bmp_sys->next_parse_lsn = log_bmp_sys->start_lsn; log_bmp_sys->parse_buf_end = log_bmp_sys->parse_buf; @@ -1108,10 +1137,35 @@ log_online_write_bitmap_page( { ibool success; - ut_ad(mutex_own(&log_bmp_sys->mutex)); + ut_ad(mutex_own(&log_bmp_sys_mutex)); /* Simulate a write error */ - DBUG_EXECUTE_IF("bitmap_page_write_error", return FALSE;); + DBUG_EXECUTE_IF("bitmap_page_write_error", + { + ulint space_id + = mach_read_from_4(block + + MODIFIED_PAGE_SPACE_ID); + if (space_id > 0) { + fprintf(stderr, "InnoDB: Error: " + "simulating bitmap write " + "error in " + "log_online_write_bitmap_page " + "for space ID %lu\n", + space_id); + return FALSE; + } + }); + + /* A crash injection site that ensures last checkpoint LSN > last + tracked LSN, so that LSN tracking for this interval is tested. */ + DBUG_EXECUTE_IF("crash_before_bitmap_write", + { + ulint space_id + = mach_read_from_4(block + + MODIFIED_PAGE_SPACE_ID); + if (space_id > 0) + DBUG_SUICIDE(); + }); success = os_file_write(log_bmp_sys->out.name, log_bmp_sys->out.file, block, @@ -1161,7 +1215,7 @@ log_online_write_bitmap(void) const ib_rbt_node_t *last_bmp_tree_node; ibool success = TRUE; - ut_ad(mutex_own(&log_bmp_sys->mutex)); + ut_ad(mutex_own(&log_bmp_sys_mutex)); if (log_bmp_sys->out.offset >= srv_max_bitmap_file_size) { if (!log_online_rotate_bitmap_file(log_bmp_sys->start_lsn)) { @@ -1204,7 +1258,11 @@ log_online_write_bitmap(void) rbt_next(log_bmp_sys->modified_pages, bmp_tree_node); DBUG_EXECUTE_IF("bitmap_page_2_write_error", - DBUG_SET("+d,bitmap_page_write_error");); + if (bmp_tree_node) + { + DBUG_SET("+d,bitmap_page_write_error"); + DBUG_SET("-d,bitmap_page_2_write_error"); + }); } rbt_reset(log_bmp_sys->modified_pages); @@ -1225,11 +1283,16 @@ log_online_follow_redo_log(void) log_group_t* group; ibool result; - mutex_enter(&log_bmp_sys->mutex); + if (!srv_track_changed_pages) + return TRUE; + + DEBUG_SYNC_C("log_online_follow_redo_log"); + + mutex_enter(&log_bmp_sys_mutex); if (!srv_track_changed_pages) { - mutex_exit(&log_bmp_sys->mutex); - return FALSE; + mutex_exit(&log_bmp_sys_mutex); + return TRUE; } /* Grab the LSN of the last checkpoint, we will parse up to it */ @@ -1238,7 +1301,7 @@ log_online_follow_redo_log(void) mutex_exit(&(log_sys->mutex)); if (log_bmp_sys->end_lsn == log_bmp_sys->start_lsn) { - mutex_exit(&log_bmp_sys->mutex); + mutex_exit(&log_bmp_sys_mutex); return TRUE; } @@ -1253,15 +1316,11 @@ log_online_follow_redo_log(void) group = UT_LIST_GET_NEXT(log_groups, group); } - /* A crash injection site that ensures last checkpoint LSN > last - tracked LSN, so that LSN tracking for this interval is tested. */ - DBUG_EXECUTE_IF("crash_before_bitmap_write", DBUG_SUICIDE();); - result = log_online_write_bitmap(); log_bmp_sys->start_lsn = log_bmp_sys->end_lsn; log_set_tracked_lsn(log_bmp_sys->start_lsn); - mutex_exit(&log_bmp_sys->mutex); + mutex_exit(&log_bmp_sys_mutex); return result; } @@ -1608,6 +1667,8 @@ log_online_bitmap_iterator_init( { ut_a(i); + i->max_lsn = max_lsn; + if (UNIV_UNLIKELY(min_lsn > max_lsn)) { /* Empty range */ @@ -1716,6 +1777,9 @@ log_online_bitmap_iterator_next( return TRUE; } + if (i->end_lsn >= i->max_lsn && i->last_page_in_run) + return FALSE; + while (!checksum_ok) { while (i->in.size < MODIFIED_PAGE_BLOCK_SIZE @@ -1808,6 +1872,7 @@ log_online_purge_changed_page_bitmaps( log_online_bitmap_file_range_t bitmap_files; size_t i; ibool result = FALSE; + ibool log_bmp_sys_inited = FALSE; if (lsn == 0) { lsn = IB_ULONGLONG_MAX; @@ -1816,13 +1881,18 @@ log_online_purge_changed_page_bitmaps( if (srv_redo_log_thread_started) { /* User requests might happen with both enabled and disabled tracking */ - mutex_enter(&log_bmp_sys->mutex); + log_bmp_sys_inited = TRUE; + mutex_enter(&log_bmp_sys_mutex); + if (!srv_redo_log_thread_started) { + log_bmp_sys_inited = FALSE; + mutex_exit(&log_bmp_sys_mutex); + } } if (!log_online_setup_bitmap_file_range(&bitmap_files, 0, IB_ULONGLONG_MAX)) { - if (srv_redo_log_thread_started) { - mutex_exit(&log_bmp_sys->mutex); + if (log_bmp_sys_inited) { + mutex_exit(&log_bmp_sys_mutex); } return TRUE; } @@ -1858,7 +1928,7 @@ log_online_purge_changed_page_bitmaps( } } - if (srv_redo_log_thread_started) { + if (log_bmp_sys_inited) { if (lsn > log_bmp_sys->end_lsn) { ib_uint64_t new_file_lsn; if (lsn == IB_ULONGLONG_MAX) { @@ -1874,7 +1944,7 @@ log_online_purge_changed_page_bitmaps( } } - mutex_exit(&log_bmp_sys->mutex); + mutex_exit(&log_bmp_sys_mutex); } free(bitmap_files.files); diff --git a/storage/xtradb/mach/mach0data.c b/storage/xtradb/mach/mach0data.c index 00378f036c9..9669516244d 100644 --- a/storage/xtradb/mach/mach0data.c +++ b/storage/xtradb/mach/mach0data.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -55,7 +55,6 @@ mach_parse_compressed( if (flag < 0x80UL) { *val = flag; return(ptr + 1); - } /* Workaround GCC bug @@ -64,7 +63,11 @@ mach_parse_compressed( function, causing and out-of-bounds read if we are reading a short integer close to the end of buffer. */ #if defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__clang__) - asm volatile("": : :"memory"); +#define DEPLOY_FENCE +#endif + +#ifdef DEPLOY_FENCE + __atomic_thread_fence(__ATOMIC_ACQUIRE); #endif if (flag < 0xC0UL) { @@ -75,8 +78,13 @@ mach_parse_compressed( *val = mach_read_from_2(ptr) & 0x7FFFUL; return(ptr + 2); + } - } else if (flag < 0xE0UL) { +#ifdef DEPLOY_FENCE + __atomic_thread_fence(__ATOMIC_ACQUIRE); +#endif + + if (flag < 0xE0UL) { if (end_ptr < ptr + 3) { return(NULL); } @@ -84,7 +92,13 @@ mach_parse_compressed( *val = mach_read_from_3(ptr) & 0x3FFFFFUL; return(ptr + 3); - } else if (flag < 0xF0UL) { + } + +#ifdef DEPLOY_FENCE + __atomic_thread_fence(__ATOMIC_ACQUIRE); +#endif + + if (flag < 0xF0UL) { if (end_ptr < ptr + 4) { return(NULL); } @@ -92,14 +106,20 @@ mach_parse_compressed( *val = mach_read_from_4(ptr) & 0x1FFFFFFFUL; return(ptr + 4); - } else { - ut_ad(flag == 0xF0UL); - - if (end_ptr < ptr + 5) { - return(NULL); - } - - *val = mach_read_from_4(ptr + 1); - return(ptr + 5); } + +#ifdef DEPLOY_FENCE + __atomic_thread_fence(__ATOMIC_ACQUIRE); +#endif + +#undef DEPLOY_FENCE + + ut_ad(flag == 0xF0UL); + + if (end_ptr < ptr + 5) { + return(NULL); + } + + *val = mach_read_from_4(ptr + 1); + return(ptr + 5); } diff --git a/storage/xtradb/os/os0file.c b/storage/xtradb/os/os0file.c index 21f8c3eed11..25692e73db1 100644 --- a/storage/xtradb/os/os0file.c +++ b/storage/xtradb/os/os0file.c @@ -961,50 +961,15 @@ next_file: char* full_path; int ret; struct stat statinfo; -#ifdef HAVE_READDIR_R - char dirent_buf[sizeof(struct dirent) - + _POSIX_PATH_MAX + 100]; - /* In /mysys/my_lib.c, _POSIX_PATH_MAX + 1 is used as - the max file name len; but in most standards, the - length is NAME_MAX; we add 100 to be even safer */ -#endif next_file: -#ifdef HAVE_READDIR_R - ret = readdir_r(dir, (struct dirent*)dirent_buf, &ent); - - if (ret != 0 -#ifdef UNIV_AIX - /* On AIX, only if we got non-NULL 'ent' (result) value and - a non-zero 'ret' (return) value, it indicates a failed - readdir_r() call. An NULL 'ent' with an non-zero 'ret' - would indicate the "end of the directory" is reached. */ - && ent != NULL -#endif - ) { - fprintf(stderr, - "InnoDB: cannot read directory %s, error %lu\n", - dirname, (ulong)ret); - - return(-1); - } - - if (ent == NULL) { - /* End of directory */ - - return(1); - } - - ut_a(strlen(ent->d_name) < _POSIX_PATH_MAX + 100 - 1); -#else ent = readdir(dir); if (ent == NULL) { return(1); } -#endif ut_a(strlen(ent->d_name) < OS_FILE_MAX_PATH); if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { @@ -1382,9 +1347,10 @@ os_file_create_simple_no_error_handling_func( } /****************************************************************//** -Tries to disable OS caching on an opened file descriptor. */ +Tries to disable OS caching on an opened file descriptor. +@return TRUE if operation is success and FALSE otherwise */ UNIV_INTERN -void +ibool os_file_set_nocache( /*================*/ int fd /*!< in: file descriptor to alter */ @@ -1405,6 +1371,7 @@ os_file_set_nocache( " InnoDB: Failed to set DIRECTIO_ON " "on file %s: %s: %s, continuing anyway\n", file_name, operation_name, strerror(errno_save)); + return FALSE; } #elif defined(O_DIRECT) if (fcntl(fd, F_SETFL, O_DIRECT) == -1) { @@ -1422,8 +1389,10 @@ os_file_set_nocache( "'Invalid argument' on Linux on tmpfs, " "see MySQL Bug#26662\n"); } + return FALSE; } #endif + return TRUE; } /****************************************************************//** @@ -1699,7 +1668,11 @@ try_again: /* ALL_O_DIRECT: O_DIRECT also for transaction log file */ if (srv_unix_file_flush_method == SRV_UNIX_ALL_O_DIRECT) { - os_file_set_nocache(file, name, mode_str); + /* Do fsync() on log files when setting O_DIRECT fails. + See log_io_complete() */ + if (!os_file_set_nocache(file, name, mode_str)) { + srv_unix_file_flush_method = SRV_UNIX_O_DIRECT; + } } #ifdef USE_FILE_LOCK diff --git a/storage/xtradb/rem/rem0rec.c b/storage/xtradb/rem/rem0rec.c index d938aa696dd..5d55fa1add0 100644 --- a/storage/xtradb/rem/rem0rec.c +++ b/storage/xtradb/rem/rem0rec.c @@ -774,7 +774,7 @@ rec_get_nth_field_offs_old( /**********************************************************//** Determines the size of a data tuple prefix in ROW_FORMAT=COMPACT. @return total size */ -UNIV_INLINE __attribute__((warn_unused_result, nonnull(1,2))) +UNIV_INLINE __attribute__((warn_unused_result)) ulint rec_get_converted_size_comp_prefix_low( /*===================================*/ diff --git a/storage/xtradb/row/row0merge.c b/storage/xtradb/row/row0merge.c index 746eb8be261..580eca1efee 100644 --- a/storage/xtradb/row/row0merge.c +++ b/storage/xtradb/row/row0merge.c @@ -802,7 +802,7 @@ row_merge_write( /********************************************************************//** Read a merge record. @return pointer to next record, or NULL on I/O error or end of list */ -static __attribute__((nonnull)) +static __attribute__((warn_unused_result)) const byte* row_merge_read_rec( /*===============*/ @@ -1168,7 +1168,7 @@ row_merge_cmp( Reads clustered index of the table and create temporary files containing the index entries for the indexes to be built. @return DB_SUCCESS or error */ -static __attribute__((nonnull)) +static __attribute__((warn_unused_result)) ulint row_merge_read_clustered_index( /*===========================*/ diff --git a/storage/xtradb/row/row0purge.c b/storage/xtradb/row/row0purge.c index 9018582f5d6..0187199f4f5 100644 --- a/storage/xtradb/row/row0purge.c +++ b/storage/xtradb/row/row0purge.c @@ -742,7 +742,7 @@ err_exit: Fetches an undo log record and does the purge for the recorded operation. If none left, or the current purge completed, returns the control to the parent node, which is always a query thread node. */ -static __attribute__((nonnull)) +static void row_purge( /*======*/ diff --git a/storage/xtradb/srv/srv0srv.c b/storage/xtradb/srv/srv0srv.c index 0acce91f2c4..3770a8804dd 100644 --- a/storage/xtradb/srv/srv0srv.c +++ b/storage/xtradb/srv/srv0srv.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. @@ -3208,10 +3208,8 @@ srv_redo_log_follow_thread( } while (srv_shutdown_state < SRV_SHUTDOWN_LAST_PHASE); - srv_track_changed_pages = FALSE; log_online_read_shutdown(); os_event_set(srv_redo_log_thread_finished_event); - srv_redo_log_thread_started = FALSE; /* Defensive, not required */ my_thread_end(); os_thread_exit(NULL); @@ -3390,6 +3388,7 @@ srv_master_thread( ib_uint64_t oldest_lsn; ib_time_t last_print_time; + my_thread_init(); #ifdef UNIV_DEBUG_THREAD_CREATION fprintf(stderr, "Master thread starts, id %lu\n", os_thread_pf(os_thread_get_curr_id())); @@ -4093,6 +4092,7 @@ suspend_thread: os_event_wait(slot->event); if (srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS) { + my_thread_end(); os_thread_exit(NULL); } @@ -4117,6 +4117,7 @@ srv_purge_thread( ulint n_total_purged = ULINT_UNDEFINED; ulint next_itr_time; + my_thread_init(); ut_a(srv_n_purge_threads == 1); #ifdef UNIV_PFS_THREAD @@ -4222,6 +4223,8 @@ srv_purge_thread( os_thread_pf(os_thread_get_curr_id())); #endif /* UNIV_DEBUG_THREAD_CREATION */ + my_thread_end(); + /* We count the number of threads in os_thread_exit(). A created thread should always use that to exit and not use return() to exit. */ os_thread_exit(NULL); diff --git a/storage/xtradb/srv/srv0start.c b/storage/xtradb/srv/srv0start.c index 2d39cddbcce..ade62aa2797 100644 --- a/storage/xtradb/srv/srv0start.c +++ b/storage/xtradb/srv/srv0start.c @@ -1619,6 +1619,7 @@ innobase_start_or_create_for_mysql(void) fsp_init(); log_init(); + log_online_init(); lock_sys_create(srv_lock_table_size); @@ -2465,6 +2466,7 @@ innobase_shutdown_for_mysql(void) btr_search_disable(); ibuf_close(); + log_online_shutdown(); log_shutdown(); trx_sys_file_format_close(); trx_sys_close(); diff --git a/storage/xtradb/trx/trx0roll.c b/storage/xtradb/trx/trx0roll.c index 25c1d5d4692..96a679a243d 100644 --- a/storage/xtradb/trx/trx0roll.c +++ b/storage/xtradb/trx/trx0roll.c @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 2017, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -610,12 +611,15 @@ trx_rollback_or_clean_all_recovered( /*!< in: a dummy parameter required by os_thread_create */ { + my_thread_init(); + #ifdef UNIV_PFS_THREAD pfs_register_thread(trx_rollback_clean_thread_key); #endif /* UNIV_PFS_THREAD */ trx_rollback_or_clean_recovered(TRUE); + my_thread_end(); /* We count the number of threads in os_thread_exit(). A created thread should always use that to exit and not use return() to exit. */