From 21689d125282f85123b6807b814683c74e9ea23c Mon Sep 17 00:00:00 2001 From: Jacob Mathew Date: Fri, 30 Jun 2017 15:58:27 -0700 Subject: [PATCH 01/14] Run spider mtr suites in 10.0 only on demand. --- storage/spider/mysql-test/spider/bg/suite.pm | 1 + storage/spider/mysql-test/spider/suite.pm | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/spider/mysql-test/spider/bg/suite.pm b/storage/spider/mysql-test/spider/bg/suite.pm index 5569c57bec9..1bb6d7592c8 100644 --- a/storage/spider/mysql-test/spider/bg/suite.pm +++ b/storage/spider/mysql-test/spider/bg/suite.pm @@ -4,6 +4,7 @@ package My::Suite::Spider; return "No Spider engine" unless $ENV{HA_SPIDER_SO}; return "Not run for embedded server" if $::opt_embedded_server; +return "Test needs --big-test" unless $::opt_big_test; bless { }; diff --git a/storage/spider/mysql-test/spider/suite.pm b/storage/spider/mysql-test/spider/suite.pm index 171fa6c4f01..1bb6d7592c8 100644 --- a/storage/spider/mysql-test/spider/suite.pm +++ b/storage/spider/mysql-test/spider/suite.pm @@ -4,8 +4,7 @@ package My::Suite::Spider; return "No Spider engine" unless $ENV{HA_SPIDER_SO}; return "Not run for embedded server" if $::opt_embedded_server; - -sub is_default { 1 } +return "Test needs --big-test" unless $::opt_big_test; bless { }; From 46d6f74c4892e0e2952d129888c34b61b66ba350 Mon Sep 17 00:00:00 2001 From: Monty Date: Sun, 2 Jul 2017 14:59:06 +0300 Subject: [PATCH 02/14] Fix for MDEV-13191. Assert for !is_set() when doing LOAD DATA This could happen when the client connection dies while sending a progress report packet. Fixed by not raising any errors when sending progress packets. --- sql/sql_class.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index e397dd88a88..0b016f7d816 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -4084,6 +4084,10 @@ extern "C" enum thd_kill_levels thd_kill_level(const MYSQL_THD thd) however not more often than global.progress_report_time. If global.progress_report_time is 0, then don't send progress reports, but check every second if the value has changed + + We clear any errors that we get from sending the progress packet to + the client as we don't want to set an error without the caller knowing + about it. */ static void thd_send_progress(THD *thd) @@ -4100,8 +4104,12 @@ static void thd_send_progress(THD *thd) thd->progress.next_report_time= (report_time + seconds_to_next * 1000000000ULL); if (global_system_variables.progress_report_time && - thd->variables.progress_report_time) + thd->variables.progress_report_time && !thd->is_error()) + { net_send_progress_packet(thd); + if (thd->is_error()) + thd->clear_error(); + } } } From 946a07e8a85c5553b3906b46052b8044cb70a480 Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Sun, 2 Jul 2017 19:45:04 +0300 Subject: [PATCH 03/14] Fix for MDEV-9670 server_id mysteriously set to 0 Problem was that in a circular replication setup the master remembers position to events it has generated itself when reading from a slave. If there are no new events in the queue from the slave, a Gtid_list_log_event is generated to remember the last skipped event. The problem happens if there is a network delay and we generate a Gtid_list_log_event in the middle of the transaction, in which case there will be an implicit comment and a new transaction with serverid=0 will be logged. The fix was to not generate any Gtid_list_log_events in the middle of a transaction. --- .../suite/rpl/r/circular_serverid0.result | 30 +++++ mysql-test/suite/rpl/t/circular_serverid0.cnf | 30 +++++ .../suite/rpl/t/circular_serverid0.test | 104 ++++++++++++++++++ sql/slave.cc | 32 +++++- 4 files changed, 193 insertions(+), 3 deletions(-) create mode 100644 mysql-test/suite/rpl/r/circular_serverid0.result create mode 100644 mysql-test/suite/rpl/t/circular_serverid0.cnf create mode 100644 mysql-test/suite/rpl/t/circular_serverid0.test diff --git a/mysql-test/suite/rpl/r/circular_serverid0.result b/mysql-test/suite/rpl/r/circular_serverid0.result new file mode 100644 index 00000000000..899b4bd343b --- /dev/null +++ b/mysql-test/suite/rpl/r/circular_serverid0.result @@ -0,0 +1,30 @@ +include/rpl_init.inc [topology=1->2->1] +include/rpl_connect.inc [creating M4] +include/rpl_connect.inc [creating M2] +SET @old_debug= @@global.debug; +STOP SLAVE; +SET GLOBAL debug_dbug= "+d,dbug.rows_events_to_delay_relay_logging"; +START SLAVE IO_THREAD; +include/wait_for_slave_io_to_start.inc +CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b VARCHAR(30000)) ENGINE=innodb; +INSERT INTO `t1` VALUES (null, repeat('a', 1024)), (null, repeat('b', 1024)); +SET debug_sync='now WAIT_FOR start_sql_thread'; +START SLAVE SQL_THREAD; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +slave-bin.000001 # Gtid # # GTID #-#-# +slave-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b VARCHAR(30000)) ENGINE=innodb +SET debug_sync='now SIGNAL go_on_relay_logging'; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +slave-bin.000001 # Gtid # # GTID #-#-# +slave-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b VARCHAR(30000)) ENGINE=innodb +slave-bin.000001 # Gtid # # BEGIN GTID #-#-# +slave-bin.000001 # Table_map # # table_id: # (test.t1) +slave-bin.000001 # Write_rows_v1 # # table_id: # +slave-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F +slave-bin.000001 # Xid # # COMMIT /* XID */ +drop table t1; +SET GLOBAL debug_dbug= @old_debug; +SET debug_sync='RESET'; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/circular_serverid0.cnf b/mysql-test/suite/rpl/t/circular_serverid0.cnf new file mode 100644 index 00000000000..277aac2869b --- /dev/null +++ b/mysql-test/suite/rpl/t/circular_serverid0.cnf @@ -0,0 +1,30 @@ +!include ../my.cnf + +[mysqld.1] +gtid-domain-id=4 +server-id=4 +# +log-slave-updates +slave-parallel-threads=0 +gtid-strict-mode=1 +gtid-ignore-duplicates=1 + +# +# Max-size row events to minimum with the idea to create +# a number of Rows_log_event per Query. +# +binlog-row-event-max-size=1024 + +[mysqld.2] +gtid-domain-id=2 +server-id=2 +# +log-slave-updates +slave-parallel-threads=0 +gtid-strict-mode=1 +gtid-ignore-duplicates=1 +binlog-row-event-max-size=1024 +# The slave will be initialized with a @@global.dbug-var value +skip-slave-start=1 + + diff --git a/mysql-test/suite/rpl/t/circular_serverid0.test b/mysql-test/suite/rpl/t/circular_serverid0.test new file mode 100644 index 00000000000..20ad58e2c52 --- /dev/null +++ b/mysql-test/suite/rpl/t/circular_serverid0.test @@ -0,0 +1,104 @@ +# +# Testing chain/circular replication scenario of MDEV-9670 +# The effect of the bug was that we got a commit with a GTID with server_id +# + +--source include/have_binlog_format_row.inc +--source include/have_innodb.inc +--source include/have_debug.inc +--source include/have_debug_sync.inc + +--let $rpl_topology= 1->2->1 +--source include/rpl_init.inc + +--let $rpl_connection_name= M4 +--let $rpl_server_number= 1 +--source include/rpl_connect.inc + +--let $rpl_connection_name= M2 +--let $rpl_server_number= 2 +--source include/rpl_connect.inc + +# The parameter reflects binlog-row-event-max-size @cnf. +--let $row_size=1024 + +SET @old_debug= @@global.debug; + +--connection M2 +STOP SLAVE; +SET GLOBAL debug_dbug= "+d,dbug.rows_events_to_delay_relay_logging"; +START SLAVE IO_THREAD; +--source include/wait_for_slave_io_to_start.inc + +--connection M2 +# This query also creates a Gtid event group whose Gtid will remain in +# ignored status for too long causing a following group split. + +CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, b VARCHAR(30000)) ENGINE=innodb; +--sync_slave_with_master M4 + +# This INSERT will be logged as two Write_log events which the buggy +# slave applier would split. + +--connection M4 +eval INSERT INTO `t1` VALUES (null, repeat('a', $row_size)), (null, repeat('b', $row_size)); + +# START M2 IO thread and wait for its signal to follow with the SQL +# thread start. At this moment the SQL thread shall be having 2 and +# "half" groups to execute. The "hafl" one would be committed by the +# buggy applier after which the IO is released to queue the rest of +# the 3rd group which the SQL thread commits separately to complete +# the split. + +--connection M2 + +# wait for IO signal to start the SQL thread. IO will be hanging upon that. +SET debug_sync='now WAIT_FOR start_sql_thread'; + +# Now the slave server has relay log whose last group is incomplete. +# An unfixed slave server would go to "insert" a "fake" +# Gtid_list_log_event event which actually would commit the incomplete +# group. However before to actual commit do_apply_event() hits some assert. +# In the fixed server the fake Gtid_list_log_event is *not* inserted +# in the middle of a group. +START SLAVE SQL_THREAD; + +# Sleep for a little time to give SQL thread a chance to commit while +# the IO thread is hanging (see +# DBUG_EXECUTE_IF("dbug.rows_events_to_delay_relay_logging"...) in +# queue_event). Alternatively to reproduce the case when buggy slave +# wait for the 1st group commit + +#--let $count= 1 +#--let $table= t1 +#--source include/wait_until_rows_count.inc + +--sleep 2 + +# Demonstrate either no split group in the correct slave or the 1nd +# group in the buggy one +--source include/show_binlog_events.inc + +# Release the IO thread +SET debug_sync='now SIGNAL go_on_relay_logging'; + +# Sync servers +--sync_slave_with_master M4 +--connection M4 +--sync_slave_with_master M2 +--connection M2 + +# Demonstrate replication goes correctly not to create any split, or +# the 2nd group in the buggy slave +--source include/show_binlog_events.inc + +# +# Cleanup +# +--connection M4 +drop table t1; + +--connection M2 +SET GLOBAL debug_dbug= @old_debug; +SET debug_sync='RESET'; +--source include/rpl_end.inc diff --git a/sql/slave.cc b/sql/slave.cc index 8c3627514ac..4e61c161a93 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -2363,6 +2363,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) } if (rli->ign_gtids.count()) { + DBUG_ASSERT(!rli->is_in_group()); // Ensure no active transaction glev= new Gtid_list_log_event(&rli->ign_gtids, Gtid_list_log_event::FLAG_IGN_GTIDS); rli->ign_gtids.reset(); @@ -5317,7 +5318,9 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) bool gtid_skip_enqueue= false; bool got_gtid_event= false; rpl_gtid event_gtid; - +#ifndef DBUG_OFF + static uint dbug_rows_event_count= 0; +#endif /* FD_q must have been prepared for the first R_a event inside get_master_version_and_clock() @@ -5384,6 +5387,26 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) (uchar)buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT /* a way to escape */) DBUG_RETURN(queue_old_event(mi,buf,event_len)); +#ifdef ENABLED_DEBUG_SYNC + /* + A (+d,dbug.rows_events_to_delay_relay_logging)-test is supposed to + create a few Write_log_events and after receiving the 1st of them + the IO thread signals to launch the SQL thread, and sets itself to + wait for a release signal. + */ + DBUG_EXECUTE_IF("dbug.rows_events_to_delay_relay_logging", + if ((buf[EVENT_TYPE_OFFSET] == WRITE_ROWS_EVENT_V1 || + buf[EVENT_TYPE_OFFSET] == WRITE_ROWS_EVENT) && + ++dbug_rows_event_count == 2) + { + const char act[]= + "now SIGNAL start_sql_thread " + "WAIT_FOR go_on_relay_logging"; + DBUG_ASSERT(debug_sync_service); + DBUG_ASSERT(!debug_sync_set_action(current_thd, + STRING_WITH_LEN(act))); + };); +#endif mysql_mutex_lock(&mi->data_lock); switch ((uchar)buf[EVENT_TYPE_OFFSET]) { @@ -6588,9 +6611,12 @@ static Log_event* next_event(rpl_group_info *rgi, ulonglong *event_size) DBUG_RETURN(ev); } - if (rli->ign_gtids.count()) + if (rli->ign_gtids.count() && !rli->is_in_group()) { - /* We generate and return a Gtid_list, to update gtid_slave_pos. */ + /* + We generate and return a Gtid_list, to update gtid_slave_pos, + unless being in the middle of a group. + */ DBUG_PRINT("info",("seeing ignored end gtids")); ev= new Gtid_list_log_event(&rli->ign_gtids, Gtid_list_log_event::FLAG_IGN_GTIDS); From 9fc71eebb6b96d76a2688a08bb810f2856b7a113 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 2 Jul 2017 16:48:11 +1000 Subject: [PATCH 04/14] 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 05/14] 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 06/14] 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 07/14] 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 08/14] 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 09/14] 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 10/14] 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 11/14] 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 12/14] 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 4d2131354914f54f85abf0bb8cb4bdd42d817f73 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 24 May 2017 13:11:33 +0200 Subject: [PATCH 13/14] coverity medium warnings --- client/mysql.cc | 5 +++-- client/mysql_upgrade.c | 2 ++ client/mysqldump.c | 5 ++--- client/mysqlimport.c | 2 +- client/mysqltest.cc | 10 +++++----- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index faef4670b31..9b5a9fb8aaa 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -4803,10 +4803,11 @@ com_status(String *buffer __attribute__((unused)), tee_fprintf(stdout, "Protocol:\t\tCompressed\n"); #endif - if ((status_str= mysql_stat(&mysql)) && !mysql_error(&mysql)[0]) + const char *pos; + if ((status_str= mysql_stat(&mysql)) && !mysql_error(&mysql)[0] && + (pos= strchr(status_str,' '))) { ulong sec; - const char *pos= strchr(status_str,' '); /* print label */ tee_fprintf(stdout, "%.*s\t\t\t", (int) (pos-status_str), status_str); if ((status_str= str2int(pos,10,0,LONG_MAX,(long*) &sec))) diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 397a252cdc0..e131aabd8b6 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -1083,6 +1083,8 @@ int main(int argc, char **argv) { int fd= create_temp_file(cnf_file_path, opt_tmpdir[0] ? opt_tmpdir : NULL, "mysql_upgrade-", O_CREAT | O_WRONLY, MYF(MY_FAE)); + if (fd < 0) + die(NULL); my_write(fd, USTRING_WITH_LEN( "[client]\n"), MYF(MY_FAE)); my_write(fd, (uchar*)ds_args.str, ds_args.length, MYF(MY_FAE)); my_close(fd, MYF(0)); diff --git a/client/mysqldump.c b/client/mysqldump.c index 6877a5cee3b..66a2b5f795c 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -92,8 +92,7 @@ static void add_load_option(DYNAMIC_STRING *str, const char *option, const char *option_value); -static ulong find_set(TYPELIB *lib, const char *x, size_t length, - char **err_pos, uint *err_len); +static ulong find_set(TYPELIB *, const char *, size_t, char **, uint *); static char *alloc_query_str(ulong size); static void field_escape(DYNAMIC_STRING* in, const char *from); @@ -5373,7 +5372,7 @@ static ulong find_set(TYPELIB *lib, const char *x, size_t length, var_len= (uint) (pos - start); strmake(buff, start, MY_MIN(sizeof(buff) - 1, var_len)); find= find_type(buff, lib, FIND_TYPE_BASIC); - if (!find) + if (find <= 0) { *err_pos= (char*) start; *err_len= var_len; diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 216359c82ec..7f03cb355f8 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -675,7 +675,7 @@ int main(int argc, char **argv) MYF(0)))) return -2; - for (counter= 0; *argv != NULL; argv++) /* Loop through tables */ + for (; *argv != NULL; argv++) /* Loop through tables */ { pthread_mutex_lock(&counter_mutex); while (counter == opt_use_threads) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index bfbbdb0bdfb..f1c50432e4d 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -600,7 +600,7 @@ void do_eval(DYNAMIC_STRING *query_eval, const char *query, void str_to_file(const char *fname, char *str, int size); void str_to_file2(const char *fname, char *str, int size, my_bool append); -void fix_win_paths(const char *val, int len); +void fix_win_paths(const char *val, size_t len); const char *get_errname_from_code (uint error_code); int multi_reg_replace(struct st_replace_regex* r,char* val); @@ -814,8 +814,7 @@ public: LogFile log_file; LogFile progress_file; -void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, - int len); +void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, size_t len); void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val); void replace_dynstr_append_uint(DYNAMIC_STRING *ds, uint val); void dynstr_append_sorted(DYNAMIC_STRING* ds, DYNAMIC_STRING* ds_input, @@ -2654,6 +2653,7 @@ void var_query_set(VAR *var, const char *query, const char** query_end) if (!mysql) { struct st_command command; + DBUG_ASSERT(query_end); memset(&command, 0, sizeof(command)); command.query= (char*)query; command.first_word_len= (*query_end - query); @@ -7530,7 +7530,7 @@ void free_win_path_patterns() => all \ from c:\mysql\m... until next space is converted into / */ -void fix_win_paths(const char *val, int len) +void fix_win_paths(const char *val, size_t len) { uint i; char *p; @@ -11031,7 +11031,7 @@ void free_pointer_array(POINTER_ARRAY *pa) /* Append the string to ds, with optional replace */ void replace_dynstr_append_mem(DYNAMIC_STRING *ds, - const char *val, int len) + const char *val, size_t len) { char lower[512]; #ifdef __WIN__ From 6b99859fff6b8c0a52ea45965834c9c3fdfc4cb3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 6 Jul 2017 23:26:18 +0200 Subject: [PATCH 14/14] after-merge fix for a7ed4644a6f (10.0+ changes, as specified in the MDEV) and remove unused variable (compiler warning) --- mysql-test/r/subselect.result | 10 +++--- mysql-test/r/subselect_no_exists_to_in.result | 32 ++++++++++++++++--- mysql-test/r/subselect_no_mat.result | 10 +++--- mysql-test/r/subselect_no_opts.result | 10 +++--- mysql-test/r/subselect_no_scache.result | 10 +++--- mysql-test/r/subselect_no_semijoin.result | 10 +++--- mysql-test/t/subselect.test | 6 ++++ sql/item.cc | 1 - 8 files changed, 64 insertions(+), 25 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index f12c437d64a..7dae5e56ac0 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -7121,9 +7121,10 @@ INSERT INTO t1 VALUES (1),(2); CREATE TABLE t2 (f2 INT, KEY(f2)); INSERT INTO t2 VALUES (3); CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -3 +ERROR 42000: Can't group on 'sq' SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0; f2 3 @@ -7131,9 +7132,10 @@ SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 ); count(*) 1 delete from t1; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -NULL +ERROR 42000: Can't group on 'sq' drop view v2; drop table t1,t2; # diff --git a/mysql-test/r/subselect_no_exists_to_in.result b/mysql-test/r/subselect_no_exists_to_in.result index 8c0e6041a90..8bc3b8c6efb 100644 --- a/mysql-test/r/subselect_no_exists_to_in.result +++ b/mysql-test/r/subselect_no_exists_to_in.result @@ -7121,9 +7121,10 @@ INSERT INTO t1 VALUES (1),(2); CREATE TABLE t2 (f2 INT, KEY(f2)); INSERT INTO t2 VALUES (3); CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -3 +ERROR 42000: Can't group on 'sq' SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0; f2 3 @@ -7131,9 +7132,10 @@ SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 ); count(*) 1 delete from t1; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -NULL +ERROR 42000: Can't group on 'sq' drop view v2; drop table t1,t2; # @@ -7147,6 +7149,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 '%exists_to_in=off%'; @@optimizer_switch like '%exists_to_in=off%' diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index 5ab60e9bf0f..0e116a7d71f 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -7114,9 +7114,10 @@ INSERT INTO t1 VALUES (1),(2); CREATE TABLE t2 (f2 INT, KEY(f2)); INSERT INTO t2 VALUES (3); CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -3 +ERROR 42000: Can't group on 'sq' SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0; f2 3 @@ -7124,9 +7125,10 @@ SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 ); count(*) 1 delete from t1; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -NULL +ERROR 42000: Can't group on 'sq' drop view v2; drop table t1,t2; # diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 91aacbc5cdb..5794779bc31 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -7112,9 +7112,10 @@ INSERT INTO t1 VALUES (1),(2); CREATE TABLE t2 (f2 INT, KEY(f2)); INSERT INTO t2 VALUES (3); CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -3 +ERROR 42000: Can't group on 'sq' SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0; f2 3 @@ -7122,9 +7123,10 @@ SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 ); count(*) 1 delete from t1; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -NULL +ERROR 42000: Can't group on 'sq' drop view v2; drop table t1,t2; # diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index 13819ec6ad5..efca324efe7 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -7127,9 +7127,10 @@ INSERT INTO t1 VALUES (1),(2); CREATE TABLE t2 (f2 INT, KEY(f2)); INSERT INTO t2 VALUES (3); CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -3 +ERROR 42000: Can't group on 'sq' SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0; f2 3 @@ -7137,9 +7138,10 @@ SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 ); count(*) 1 delete from t1; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -NULL +ERROR 42000: Can't group on 'sq' drop view v2; drop table t1,t2; # diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index 774c18020d8..3896adbfdd2 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -7112,9 +7112,10 @@ INSERT INTO t1 VALUES (1),(2); CREATE TABLE t2 (f2 INT, KEY(f2)); INSERT INTO t2 VALUES (3); CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -3 +ERROR 42000: Can't group on 'sq' SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0; f2 3 @@ -7122,9 +7123,10 @@ SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 ); count(*) 1 delete from t1; +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +ERROR 42000: Can't group on 'sq' SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; -sq -NULL +ERROR 42000: Can't group on 'sq' drop view v2; drop table t1,t2; # diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index c9b2d88e9c4..7b18e6b4cf5 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -6002,11 +6002,17 @@ INSERT INTO t2 VALUES (3); CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +--error ER_WRONG_GROUP_FIELD +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +--error ER_WRONG_GROUP_FIELD SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; SELECT * FROM v2 where ( SELECT MIN(v2.f2) FROM t1 ) > 0; SELECT count(*) FROM v2 group by ( SELECT MIN(v2.f2) FROM t1 ); delete from t1; +--error ER_WRONG_GROUP_FIELD +SELECT ( SELECT MIN(t2.f2) FROM t1 ) AS sq FROM t2 GROUP BY sq; +--error ER_WRONG_GROUP_FIELD SELECT ( SELECT MIN(v2.f2) FROM t1 ) AS sq FROM v2 GROUP BY sq; drop view v2; diff --git a/sql/item.cc b/sql/item.cc index 7c0979e1b8d..5a6440213ed 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4991,7 +4991,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); }