summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <rburnett@bk-internal.mysql.com>2006-08-03 16:54:06 +0200
committerunknown <rburnett@bk-internal.mysql.com>2006-08-03 16:54:06 +0200
commit6017f911e33c3a44e6b7b090215446300c38b7be (patch)
tree2e0b33c7cd3f1083dce485137fd952b52a37dfbd
parent6e5d9284ed35fbf8dbe1af01e45923c3109aa7ad (diff)
parent3c8150b79bf5302879897e0d1ebd594798bb419e (diff)
downloadmariadb-git-6017f911e33c3a44e6b7b090215446300c38b7be.tar.gz
Merge bk-internal.mysql.com:/data0/bk/mysql-5.0
into bk-internal.mysql.com:/data0/bk/mysql-5.0-kt client/mysql.cc: Auto merged mysql-test/r/im_life_cycle.result: Auto merged mysql-test/t/im_life_cycle.imtest: Auto merged sql/sql_lex.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_view.cc: Auto merged sql/table.h: Auto merged
-rw-r--r--BitKeeper/etc/collapsed1
-rw-r--r--client/mysql.cc3
-rw-r--r--client/mysqlbinlog.cc3
-rw-r--r--client/mysqltest.c2
-rw-r--r--include/mysql.h1
-rw-r--r--include/mysql_com.h1
-rw-r--r--include/sql_common.h2
-rw-r--r--innobase/btr/btr0cur.c3
-rw-r--r--innobase/fil/fil0fil.c15
-rw-r--r--innobase/ibuf/ibuf0ibuf.c31
-rw-r--r--innobase/include/sync0rw.ic2
-rw-r--r--libmysql/libmysql.c16
-rw-r--r--mysql-test/Makefile.am1
-rw-r--r--mysql-test/include/im_check_env.inc27
-rwxr-xr-xmysql-test/mysql-test-run.pl47
-rw-r--r--mysql-test/r/create.result2
-rw-r--r--mysql-test/r/func_gconcat.result13
-rw-r--r--mysql-test/r/func_group.result11
-rw-r--r--mysql-test/r/func_str.result28
-rw-r--r--mysql-test/r/group_by.result25
-rw-r--r--mysql-test/r/group_min_max.result43
-rw-r--r--mysql-test/r/im_daemon_life_cycle.result3
-rw-r--r--mysql-test/r/im_life_cycle.result11
-rw-r--r--mysql-test/r/im_options_set.result7
-rw-r--r--mysql-test/r/im_options_unset.result7
-rw-r--r--mysql-test/r/im_utils.result3
-rw-r--r--mysql-test/r/information_schema.result70
-rw-r--r--mysql-test/r/innodb.result4
-rw-r--r--mysql-test/r/mysql_client.result4
-rw-r--r--mysql-test/r/mysqldump.result2
-rw-r--r--mysql-test/r/ps.result262
-rw-r--r--mysql-test/r/ps_1general.result2
-rw-r--r--mysql-test/r/rpl_sp.result44
-rw-r--r--mysql-test/r/rpl_trigger.result47
-rw-r--r--mysql-test/r/rpl_view.result37
-rw-r--r--mysql-test/r/select.result75
-rw-r--r--mysql-test/r/show_check.result4
-rw-r--r--mysql-test/r/sp-code.result11
-rw-r--r--mysql-test/r/sp-error.result13
-rw-r--r--mysql-test/r/sp-security.result52
-rw-r--r--mysql-test/r/sp.result184
-rw-r--r--mysql-test/r/subselect.result27
-rw-r--r--mysql-test/r/subselect2.result12
-rw-r--r--mysql-test/r/udf.result12
-rw-r--r--mysql-test/r/union.result31
-rw-r--r--mysql-test/r/view.result78
-rw-r--r--mysql-test/t/disabled.def1
-rw-r--r--mysql-test/t/func_gconcat.test14
-rw-r--r--mysql-test/t/func_group.test15
-rw-r--r--mysql-test/t/func_str.test15
-rw-r--r--mysql-test/t/group_by.test23
-rw-r--r--mysql-test/t/group_min_max.test48
-rw-r--r--mysql-test/t/im_daemon_life_cycle.imtest16
-rw-r--r--mysql-test/t/im_life_cycle.imtest66
-rw-r--r--mysql-test/t/im_options_set.imtest27
-rw-r--r--mysql-test/t/im_options_unset.imtest27
-rw-r--r--mysql-test/t/im_utils.imtest31
-rw-r--r--mysql-test/t/information_schema.test43
-rw-r--r--mysql-test/t/innodb.test2
-rw-r--r--mysql-test/t/mysql_client.test11
-rw-r--r--mysql-test/t/ps.test293
-rw-r--r--mysql-test/t/ps_1general.test1
-rw-r--r--mysql-test/t/rpl_sp.test80
-rw-r--r--mysql-test/t/rpl_trigger.test92
-rw-r--r--mysql-test/t/rpl_view.test84
-rw-r--r--mysql-test/t/select.test45
-rw-r--r--mysql-test/t/show_check.test11
-rw-r--r--mysql-test/t/sp-code.test22
-rw-r--r--mysql-test/t/sp-error.test22
-rw-r--r--mysql-test/t/sp-security.test78
-rw-r--r--mysql-test/t/sp.test201
-rw-r--r--mysql-test/t/sp.test.orig5716
-rw-r--r--mysql-test/t/subselect.test18
-rw-r--r--mysql-test/t/subselect2.test18
-rw-r--r--mysql-test/t/udf.test18
-rw-r--r--mysql-test/t/union.test12
-rw-r--r--mysql-test/t/view.test75
-rw-r--r--mysys/my_open.c4
-rw-r--r--scripts/make_win_src_distribution.sh2
-rw-r--r--sql-common/client.c69
-rw-r--r--sql/field.cc18
-rw-r--r--sql/field.h17
-rw-r--r--sql/ha_innodb.cc26
-rw-r--r--sql/item.cc18
-rw-r--r--sql/item.h1
-rw-r--r--sql/item_cmpfunc.cc22
-rw-r--r--sql/item_cmpfunc.h2
-rw-r--r--sql/item_func.cc91
-rw-r--r--sql/item_func.h10
-rw-r--r--sql/item_strfunc.cc17
-rw-r--r--sql/item_strfunc.h6
-rw-r--r--sql/item_subselect.cc6
-rw-r--r--sql/item_subselect.h9
-rw-r--r--sql/item_sum.cc8
-rw-r--r--sql/mysql_priv.h9
-rw-r--r--sql/protocol.cc2
-rw-r--r--sql/slave.cc2
-rw-r--r--sql/sp.cc17
-rw-r--r--sql/sp_head.cc248
-rw-r--r--sql/sp_head.h14
-rw-r--r--sql/sql_base.cc47
-rw-r--r--sql/sql_db.cc94
-rw-r--r--sql/sql_lex.cc25
-rw-r--r--sql/sql_lex.h4
-rw-r--r--sql/sql_parse.cc20
-rw-r--r--sql/sql_prepare.cc36
-rw-r--r--sql/sql_select.cc85
-rw-r--r--sql/sql_show.cc138
-rw-r--r--sql/sql_table.cc7
-rw-r--r--sql/sql_trigger.cc40
-rw-r--r--sql/sql_view.cc113
-rw-r--r--sql/sql_yacc.yy46
-rw-r--r--sql/table.cc16
-rw-r--r--sql/table.h8
-rw-r--r--sql/udf_example.c2
-rw-r--r--tests/mysql_client_test.c98
116 files changed, 3260 insertions, 6541 deletions
diff --git a/BitKeeper/etc/collapsed b/BitKeeper/etc/collapsed
new file mode 100644
index 00000000000..8b90deae622
--- /dev/null
+++ b/BitKeeper/etc/collapsed
@@ -0,0 +1 @@
+44d03f27qNdqJmARzBoP3Is_cN5e0w
diff --git a/client/mysql.cc b/client/mysql.cc
index 92ad7864f84..921804a1298 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -1221,7 +1221,8 @@ static bool add_line(String &buffer,char *line,char *in_string,
continue;
}
#endif
- if (!*ml_comment && inchar == '\\')
+ if (!*ml_comment && inchar == '\\' &&
+ !(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))
{
// Found possbile one character command like \c
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 518ab7cf832..9cecdb4eafc 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -36,6 +36,7 @@
/* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */
#include "mysql_priv.h"
#include "log_event.h"
+#include "sql_common.h"
#define BIN_LOG_HEADER_SIZE 4
#define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4)
@@ -1077,7 +1078,7 @@ could be out of memory");
const char *error_msg;
Log_event *ev;
- len = net_safe_read(mysql);
+ len= cli_safe_read(mysql);
if (len == packet_error)
{
fprintf(stderr, "Got error reading packet from server: %s\n",
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 2fc09fbc3d2..352971c4c38 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -620,7 +620,7 @@ static void die(const char *fmt, ...)
if (cur_file && cur_file != file_stack)
fprintf(stderr, "In included file \"%s\": ",
cur_file->file_name);
- if (start_lineno != 0)
+ if (start_lineno > 0)
fprintf(stderr, "At line %u: ", start_lineno);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
diff --git a/include/mysql.h b/include/mysql.h
index 7ed205024e2..72e5c457d5a 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -848,7 +848,6 @@ int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
#define stmt_command(mysql, command, arg, length, stmt) \
(*(mysql)->methods->advanced_command)(mysql, command, NullS, \
0, arg, length, 1, stmt)
-unsigned long net_safe_read(MYSQL* mysql);
#ifdef __NETWARE__
#pragma pack(pop) /* restore alignment */
diff --git a/include/mysql_com.h b/include/mysql_com.h
index ec1c133799f..60e726396cb 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -140,7 +140,6 @@ enum enum_server_command
#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
-#define SERVER_STATUS_MORE_RESULTS 4 /* More results on server */
#define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */
#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
#define SERVER_QUERY_NO_INDEX_USED 32
diff --git a/include/sql_common.h b/include/sql_common.h
index 7ea8b6c87e0..29a9cbd4b08 100644
--- a/include/sql_common.h
+++ b/include/sql_common.h
@@ -36,7 +36,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
const char *header, ulong header_length,
const char *arg, ulong arg_length, my_bool skip_check,
MYSQL_STMT *stmt);
-
+unsigned long cli_safe_read(MYSQL *mysql);
void set_stmt_errmsg(MYSQL_STMT * stmt, const char *err, int errcode,
const char *sqlstate);
void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
diff --git a/innobase/btr/btr0cur.c b/innobase/btr/btr0cur.c
index 3d7b6fffb52..d51a090be75 100644
--- a/innobase/btr/btr0cur.c
+++ b/innobase/btr/btr0cur.c
@@ -439,7 +439,7 @@ retry_page_get:
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
}
- return;
+ goto func_exit;
}
/* Insert to the insert buffer did not succeed:
@@ -555,6 +555,7 @@ retry_page_get:
|| mode != PAGE_CUR_LE);
}
+func_exit:
if (has_search_latch) {
rw_lock_s_lock(&btr_search_latch);
diff --git a/innobase/fil/fil0fil.c b/innobase/fil/fil0fil.c
index cfd9813101d..2272f7cd8b3 100644
--- a/innobase/fil/fil0fil.c
+++ b/innobase/fil/fil0fil.c
@@ -251,9 +251,6 @@ struct fil_system_struct {
initialized. */
fil_system_t* fil_system = NULL;
-/* The tablespace memory cache hash table size */
-#define FIL_SYSTEM_HASH_SIZE 50 /* TODO: make bigger! */
-
/************************************************************************
NOTE: you must call fil_mutex_enter_and_prepare_for_io() first!
@@ -1324,11 +1321,17 @@ fil_init(
/*=====*/
ulint max_n_open) /* in: max number of open files */
{
+ ulint hash_size;
+
ut_a(fil_system == NULL);
- /*printf("Initializing the tablespace cache with max %lu open files\n",
- max_n_open); */
- fil_system = fil_system_create(FIL_SYSTEM_HASH_SIZE, max_n_open);
+ if (srv_file_per_table) {
+ hash_size = 50000;
+ } else {
+ hash_size = 5000;
+ }
+
+ fil_system = fil_system_create(hash_size, max_n_open);
}
/***********************************************************************
diff --git a/innobase/ibuf/ibuf0ibuf.c b/innobase/ibuf/ibuf0ibuf.c
index e4694ed52ae..9c7d9c5c3da 100644
--- a/innobase/ibuf/ibuf0ibuf.c
+++ b/innobase/ibuf/ibuf0ibuf.c
@@ -950,14 +950,11 @@ ibool
ibuf_fixed_addr_page(
/*=================*/
/* out: TRUE if a fixed address ibuf i/o page */
+ ulint space, /* in: space id */
ulint page_no)/* in: page number */
{
- if ((ibuf_bitmap_page(page_no))
- || (page_no == IBUF_TREE_ROOT_PAGE_NO)) {
- return(TRUE);
- }
-
- return(FALSE);
+ return((space == 0 && page_no == IBUF_TREE_ROOT_PAGE_NO)
+ || ibuf_bitmap_page(page_no));
}
/***************************************************************************
@@ -981,7 +978,7 @@ ibuf_page(
return(FALSE);
}
- if (ibuf_fixed_addr_page(page_no)) {
+ if (ibuf_fixed_addr_page(space, page_no)) {
return(TRUE);
}
@@ -1029,7 +1026,7 @@ ibuf_page_low(
return(FALSE);
}
#endif
- if (ibuf_fixed_addr_page(page_no)) {
+ if (ibuf_fixed_addr_page(space, page_no)) {
return(TRUE);
}
@@ -3052,7 +3049,7 @@ ibuf_merge_or_delete_for_page(
return;
}
#endif
- if (ibuf_fixed_addr_page(page_no) || fsp_descr_page(page_no)
+ if (ibuf_fixed_addr_page(space, page_no) || fsp_descr_page(page_no)
|| trx_sys_hdr_page(space, page_no)) {
return;
}
@@ -3502,21 +3499,9 @@ ibuf_print(
data = UT_LIST_GET_FIRST(ibuf->data_list);
while (data) {
- fprintf(file,
- "Ibuf for space %lu: size %lu, free list len %lu, seg size %lu,",
- (ulong) data->space, (ulong) data->size,
- (ulong) data->free_list_len,
- (ulong) data->seg_size);
-
- if (data->empty) {
- fputs(" is empty\n", file);
- } else {
- fputs(" is not empty\n", file);
- }
fprintf(file,
- "Ibuf for space %lu: size %lu, free list len %lu, seg size %lu,\n"
- "%lu inserts, %lu merged recs, %lu merges\n",
- (ulong) data->space,
+ "Ibuf: size %lu, free list len %lu, seg size %lu,\n"
+ "%lu inserts, %lu merged recs, %lu merges\n",
(ulong) data->size,
(ulong) data->free_list_len,
(ulong) data->seg_size,
diff --git a/innobase/include/sync0rw.ic b/innobase/include/sync0rw.ic
index b1ae636010a..9e15475ae53 100644
--- a/innobase/include/sync0rw.ic
+++ b/innobase/include/sync0rw.ic
@@ -362,7 +362,7 @@ rw_lock_s_unlock_func(
/* Reset the shared lock by decrementing the reader count */
- ut_ad(lock->reader_count > 0);
+ ut_a(lock->reader_count > 0);
lock->reader_count--;
#ifdef UNIV_SYNC_DEBUG
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index 4efc3c2fd1c..21fb84fb19a 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -645,7 +645,7 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd)
NET *net= &mysql->net;
ulong pkt_length;
- pkt_length= net_safe_read(mysql);
+ pkt_length= cli_safe_read(mysql);
if (pkt_length == packet_error)
return 1;
@@ -666,7 +666,7 @@ int cli_read_change_user_result(MYSQL *mysql, char *buff, const char *passwd)
return 1;
}
/* Read what server thinks about out new auth message report */
- if (net_safe_read(mysql) == packet_error)
+ if (cli_safe_read(mysql) == packet_error)
return 1;
}
return 0;
@@ -1887,7 +1887,7 @@ my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt)
DBUG_ENTER("cli_read_prepare_result");
mysql= mysql->last_used_con;
- if ((packet_length= net_safe_read(mysql)) == packet_error)
+ if ((packet_length= cli_safe_read(mysql)) == packet_error)
DBUG_RETURN(1);
mysql->warning_count= 0;
@@ -2505,7 +2505,8 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
if (stmt->param_count)
{
- NET *net= &stmt->mysql->net;
+ MYSQL *mysql= stmt->mysql;
+ NET *net= &mysql->net;
MYSQL_BIND *param, *param_end;
char *param_data;
ulong length;
@@ -2517,7 +2518,8 @@ int cli_stmt_execute(MYSQL_STMT *stmt)
set_stmt_error(stmt, CR_PARAMS_NOT_BOUND, unknown_sqlstate);
DBUG_RETURN(1);
}
- if (stmt->mysql->status != MYSQL_STATUS_READY)
+ if (mysql->status != MYSQL_STATUS_READY ||
+ mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
{
set_stmt_error(stmt, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
DBUG_RETURN(1);
@@ -4532,7 +4534,7 @@ static int stmt_fetch_row(MYSQL_STMT *stmt, uchar *row)
int cli_unbuffered_fetch(MYSQL *mysql, char **row)
{
- if (packet_error == net_safe_read(mysql))
+ if (packet_error == cli_safe_read(mysql))
return 1;
*row= ((mysql->net.read_pos[0] == 254) ? NULL :
@@ -4641,7 +4643,7 @@ int cli_read_binary_rows(MYSQL_STMT *stmt)
mysql= mysql->last_used_con;
- while ((pkt_len= net_safe_read(mysql)) != packet_error)
+ while ((pkt_len= cli_safe_read(mysql)) != packet_error)
{
cp= net->read_pos;
if (cp[0] != 254 || pkt_len >= 8)
diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am
index 39fc425bf06..11bcef10fff 100644
--- a/mysql-test/Makefile.am
+++ b/mysql-test/Makefile.am
@@ -89,6 +89,7 @@ install-data-local:
$(INSTALL_DATA) $(srcdir)/include/*.inc $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/std_data/*.dat $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.*001 $(DESTDIR)$(testdir)/std_data
+ $(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.pem $(DESTDIR)$(testdir)/std_data
diff --git a/mysql-test/include/im_check_env.inc b/mysql-test/include/im_check_env.inc
new file mode 100644
index 00000000000..169edbac6b3
--- /dev/null
+++ b/mysql-test/include/im_check_env.inc
@@ -0,0 +1,27 @@
+# This file is intended to be used in each IM-test. It contains stamements,
+# that ensure that starting conditions (environment) for the IM-test are as
+# expected.
+
+# Wait for mysqld1 (guarded instance) to start.
+
+--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
+
+# Check the running instances.
+
+--connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK)
+
+--connection mysql1_con
+
+SHOW VARIABLES LIKE 'server_id';
+
+--connection default
+
+# Let IM detect that mysqld1 is online. This delay should be longer than
+# monitoring interval.
+
+--sleep 2
+
+# Check that IM understands that mysqld1 is online, while mysqld2 is
+# offline.
+
+SHOW INSTANCES;
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 91a9a758d1d..a5d857845ba 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -2898,12 +2898,16 @@ sub im_stop($) {
while (1)
{
+ # Check that IM-main died.
+
if (kill (0, $instance_manager->{'pid'}))
{
mtr_debug("IM-main is still alive.");
last;
}
+ # Check that IM-angel died.
+
if (defined $instance_manager->{'angel_pid'} &&
kill (0, $instance_manager->{'angel_pid'}))
{
@@ -2911,21 +2915,39 @@ sub im_stop($) {
last;
}
+ # Check that all guarded mysqld-instances died.
+
+ my $guarded_mysqlds_dead= 1;
+
foreach my $pid (@mysqld_pids)
{
if (kill (0, $pid))
{
mtr_debug("Guarded mysqld ($pid) is still alive.");
+ $guarded_mysqlds_dead= 0;
last;
}
}
+ last unless $guarded_mysqlds_dead;
+
+ # Ok, all necessary processes are dead.
+
$clean_shutdown= 1;
last;
}
# Kill leftovers (the order is important).
+ if ($clean_shutdown)
+ {
+ mtr_debug("IM-shutdown was clean -- all processed died.");
+ }
+ else
+ {
+ mtr_debug("IM failed to shutdown gracefully. We have to clean the mess...");
+ }
+
unless ($clean_shutdown)
{
@@ -2946,17 +2968,24 @@ sub im_stop($) {
mtr_kill_processes(\@mysqld_pids);
# Complain in error log so that a warning will be shown.
-
- my $errlog= "$opt_vardir/log/mysql-test-run.pl.err";
-
- open (ERRLOG, ">>$errlog") ||
- mtr_error("Can not open error log ($errlog)");
+ #
+ # TODO: unless BUG#20761 is fixed, we will print the warning
+ # to stdout, so that it can be seen on console and does not
+ # produce pushbuild error.
+
+ # my $errlog= "$opt_vardir/log/mysql-test-run.pl.err";
+ #
+ # open (ERRLOG, ">>$errlog") ||
+ # mtr_error("Can not open error log ($errlog)");
+ #
+ # my $ts= localtime();
+ # print ERRLOG
+ # "Warning: [$ts] Instance Manager did not shutdown gracefully.\n";
+ #
+ # close ERRLOG;
my $ts= localtime();
- print ERRLOG
- "Warning: [$ts] Instance Manager did not shutdown gracefully.\n";
-
- close ERRLOG;
+ print "Warning: [$ts] Instance Manager did not shutdown gracefully.\n";
}
# That's all.
diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result
index aa8c6d3d277..ed83dfb4b49 100644
--- a/mysql-test/r/create.result
+++ b/mysql-test/r/create.result
@@ -452,7 +452,7 @@ t2 CREATE TABLE `t2` (
`ifnull(h,h)` decimal(5,4) default NULL,
`ifnull(i,i)` year(4) default NULL,
`ifnull(j,j)` date default NULL,
- `ifnull(k,k)` datetime NOT NULL default '0000-00-00 00:00:00',
+ `ifnull(k,k)` timestamp NOT NULL default '0000-00-00 00:00:00',
`ifnull(l,l)` datetime default NULL,
`ifnull(m,m)` varchar(1) default NULL,
`ifnull(n,n)` varchar(3) default NULL,
diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result
index d8a539da3fe..dc09a68682c 100644
--- a/mysql-test/r/func_gconcat.result
+++ b/mysql-test/r/func_gconcat.result
@@ -641,3 +641,16 @@ select charset(group_concat(c1 order by c2)) from t1;
charset(group_concat(c1 order by c2))
latin1
drop table t1;
+CREATE TABLE t1 (a INT(10), b LONGTEXT, PRIMARY KEY (a));
+SET GROUP_CONCAT_MAX_LEN = 20000000;
+INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000));
+INSERT INTO t1 SELECT a + 1, b FROM t1;
+SELECT a, CHAR_LENGTH(b) FROM t1;
+a CHAR_LENGTH(b)
+1 120000
+2 120000
+SELECT CHAR_LENGTH( GROUP_CONCAT(b) ) FROM t1;
+CHAR_LENGTH( GROUP_CONCAT(b) )
+240001
+SET GROUP_CONCAT_MAX_LEN = 1024;
+DROP TABLE t1;
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index f693c6190d5..896b79297f8 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -988,3 +988,14 @@ SUM(a)
6
DROP TABLE t1;
set div_precision_increment= @sav_dpi;
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
+INSERT INTO t1 VALUES (1,1), (2,2);
+CREATE TABLE t2 (a INT PRIMARY KEY, b INT);
+INSERT INTO t2 VALUES (1,1), (3,3);
+SELECT SQL_NO_CACHE
+(SELECT SUM(c.a) FROM t1 ttt, t2 ccc
+WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid
+FROM t1 t, t2 c WHERE t.a = c.b;
+minid
+NULL
+DROP TABLE t1,t2;
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index aebf3596751..14da630f61e 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -1056,6 +1056,34 @@ a c
abc abc abc
xyz xyz xyz
DROP TABLE t1;
+CREATE TABLE t1 (s varchar(10));
+INSERT INTO t1 VALUES ('yadda'), ('yaddy');
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(s) > 'ab';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(`test`.`t1`.`s`) > _latin1'ab')
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM('y' FROM s) > 'ab';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(both _latin1'y' from `test`.`t1`.`s`) > _latin1'ab')
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(LEADING 'y' FROM s) > 'ab';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(leading _latin1'y' from `test`.`t1`.`s`) > _latin1'ab')
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(TRAILING 'y' FROM s) > 'ab';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(trailing _latin1'y' from `test`.`t1`.`s`) > _latin1'ab')
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(BOTH 'y' FROM s) > 'ab';
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`s` AS `s` from `test`.`t1` where (trim(both _latin1'y' from `test`.`t1`.`s`) > _latin1'ab')
+DROP TABLE t1;
End of 4.1 tests
create table t1 (d decimal default null);
insert into t1 values (null);
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result
index 7bc886022cc..e5c177503fa 100644
--- a/mysql-test/r/group_by.result
+++ b/mysql-test/r/group_by.result
@@ -796,3 +796,28 @@ aaa
show warnings;
Level Code Message
drop table t1, t2;
+CREATE TABLE t1 (a tinyint(3), b varchar(255), PRIMARY KEY (a));
+INSERT INTO t1 VALUES (1,'-----'), (6,'Allemagne'), (17,'Autriche'),
+(25,'Belgique'), (54,'Danemark'), (62,'Espagne'), (68,'France');
+CREATE TABLE t2 (a tinyint(3), b tinyint(3), PRIMARY KEY (a), KEY b (b));
+INSERT INTO t2 VALUES (1,1), (2,1), (6,6), (18,17), (15,25), (16,25),
+(17,25), (10,54), (5,62),(3,68);
+CREATE VIEW v1 AS select t1.a, concat(t1.b,'') AS b, t1.b as real_b from t1;
+explain
+SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1
+where t2.b=v1.a GROUP BY t2.b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 index b b 2 NULL 10 Using index
+1 PRIMARY t1 eq_ref PRIMARY PRIMARY 1 test.t2.b 1
+SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1
+where t2.b=v1.a GROUP BY t2.b;
+a b real_b
+1 ----- -----
+6 Allemagne Allemagne
+17 Autriche Autriche
+25 Belgique Belgique
+54 Danemark Danemark
+62 Espagne Espagne
+68 France France
+DROP VIEW v1;
+DROP TABLE t1,t2;
diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result
index d62586dba85..fe6f7c4ca55 100644
--- a/mysql-test/r/group_min_max.result
+++ b/mysql-test/r/group_min_max.result
@@ -2099,3 +2099,46 @@ SOUTH EAST SOUTH EAST
SOUTH WEST SOUTH WEST
WESTERN WESTERN
DROP TABLE t1;
+CREATE TABLE t1 (id1 INT, id2 INT);
+CREATE TABLE t2 (id2 INT, id3 INT, id5 INT);
+CREATE TABLE t3 (id3 INT, id4 INT);
+CREATE TABLE t4 (id4 INT);
+CREATE TABLE t5 (id5 INT, id6 INT);
+CREATE TABLE t6 (id6 INT);
+INSERT INTO t1 VALUES(1,1);
+INSERT INTO t2 VALUES(1,1,1);
+INSERT INTO t3 VALUES(1,1);
+INSERT INTO t4 VALUES(1);
+INSERT INTO t5 VALUES(1,1);
+INSERT INTO t6 VALUES(1);
+SELECT * FROM
+t1
+NATURAL JOIN
+(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6)
+ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5));
+id2 id1 id3 id5 id4 id3 id6 id5
+1 1 1 1 1 1 1 1
+SELECT * FROM
+t1
+NATURAL JOIN
+(((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6) on t3.id4 = t5.id5) JOIN t2
+ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5));
+id2 id1 id4 id3 id6 id5 id3 id5
+1 1 1 1 1 1 1 1
+SELECT * FROM t1 NATURAL JOIN ((t3 join (t5 NATURAL JOIN t6)) JOIN t2);
+id2 id1 id3 id4 id6 id5 id3 id5
+1 1 1 1 1 1 1 1
+SELECT * FROM
+(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6)
+ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5))
+NATURAL JOIN
+t1;
+id2 id3 id5 id4 id3 id6 id5 id1
+1 1 1 1 1 1 1 1
+SELECT * FROM
+(t2 JOIN ((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6)))
+NATURAL JOIN
+t1;
+id2 id3 id5 id4 id3 id6 id5 id1
+1 1 1 1 1 1 1 1
+DROP TABLE t1,t2,t3,t4,t5,t6;
diff --git a/mysql-test/r/im_daemon_life_cycle.result b/mysql-test/r/im_daemon_life_cycle.result
index ea27fcb6db1..4f7dd77a88f 100644
--- a/mysql-test/r/im_daemon_life_cycle.result
+++ b/mysql-test/r/im_daemon_life_cycle.result
@@ -1,4 +1,7 @@
Success: the process has been started.
+SHOW VARIABLES LIKE 'server_id';
+Variable_name Value
+server_id 1
SHOW INSTANCES;
instance_name status
mysqld1 online
diff --git a/mysql-test/r/im_life_cycle.result b/mysql-test/r/im_life_cycle.result
index 211a82eb9cf..53737b64f28 100644
--- a/mysql-test/r/im_life_cycle.result
+++ b/mysql-test/r/im_life_cycle.result
@@ -1,8 +1,7 @@
-
---------------------------------------------------------------------
--- 1.1.1.
---------------------------------------------------------------------
Success: the process has been started.
+SHOW VARIABLES LIKE 'server_id';
+Variable_name Value
+server_id 1
SHOW INSTANCES;
instance_name status
mysqld1 online
@@ -40,10 +39,6 @@ ERROR HY000: Bad instance name. Check that the instance with such a name exists
--------------------------------------------------------------------
-- 1.1.6.
--------------------------------------------------------------------
-SHOW INSTANCES;
-instance_name status
-mysqld1 online
-mysqld2 offline
Killing the process...
Sleeping...
Success: the process was restarted.
diff --git a/mysql-test/r/im_options_set.result b/mysql-test/r/im_options_set.result
index 5e6c740624e..c3035079b39 100644
--- a/mysql-test/r/im_options_set.result
+++ b/mysql-test/r/im_options_set.result
@@ -1,8 +1,11 @@
-server_id = 1
-server_id = 2
+Success: the process has been started.
SHOW VARIABLES LIKE 'server_id';
Variable_name Value
server_id 1
+SHOW INSTANCES;
+instance_name status
+mysqld1 online
+mysqld2 offline
SET mysqld1.server_id = 11;
server_id =11
server_id = 2
diff --git a/mysql-test/r/im_options_unset.result b/mysql-test/r/im_options_unset.result
index bf54025edb7..ba468c78a5b 100644
--- a/mysql-test/r/im_options_unset.result
+++ b/mysql-test/r/im_options_unset.result
@@ -1,8 +1,11 @@
-server_id = 1
-server_id = 2
+Success: the process has been started.
SHOW VARIABLES LIKE 'server_id';
Variable_name Value
server_id 1
+SHOW INSTANCES;
+instance_name status
+mysqld1 online
+mysqld2 offline
UNSET mysqld1.server_id;
server_id = 2
SHOW VARIABLES LIKE 'server_id';
diff --git a/mysql-test/r/im_utils.result b/mysql-test/r/im_utils.result
index e6a5e007ed4..be696921812 100644
--- a/mysql-test/r/im_utils.result
+++ b/mysql-test/r/im_utils.result
@@ -1,4 +1,7 @@
Success: the process has been started.
+SHOW VARIABLES LIKE 'server_id';
+Variable_name Value
+server_id 1
SHOW INSTANCES;
instance_name status
mysqld1 online
diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result
index a2feba7ad5d..652af1c8387 100644
--- a/mysql-test/r/information_schema.result
+++ b/mysql-test/r/information_schema.result
@@ -1170,3 +1170,73 @@ f1()
DROP FUNCTION f1;
DROP PROCEDURE p1;
DROP USER mysql_bug20230@localhost;
+SELECT t.table_name, c1.column_name
+FROM information_schema.tables t
+INNER JOIN
+information_schema.columns c1
+ON t.table_schema = c1.table_schema AND
+t.table_name = c1.table_name
+WHERE t.table_schema = 'information_schema' AND
+c1.ordinal_position =
+( SELECT COALESCE(MIN(c2.ordinal_position),1)
+FROM information_schema.columns c2
+WHERE c2.table_schema = t.table_schema AND
+c2.table_name = t.table_name AND
+c2.column_name LIKE '%SCHEMA%'
+ );
+table_name column_name
+CHARACTER_SETS CHARACTER_SET_NAME
+COLLATIONS COLLATION_NAME
+COLLATION_CHARACTER_SET_APPLICABILITY COLLATION_NAME
+COLUMNS TABLE_SCHEMA
+COLUMN_PRIVILEGES TABLE_SCHEMA
+KEY_COLUMN_USAGE CONSTRAINT_SCHEMA
+ROUTINES ROUTINE_SCHEMA
+SCHEMATA SCHEMA_NAME
+SCHEMA_PRIVILEGES TABLE_SCHEMA
+STATISTICS TABLE_SCHEMA
+TABLES TABLE_SCHEMA
+TABLE_CONSTRAINTS CONSTRAINT_SCHEMA
+TABLE_PRIVILEGES TABLE_SCHEMA
+TRIGGERS TRIGGER_SCHEMA
+USER_PRIVILEGES GRANTEE
+VIEWS TABLE_SCHEMA
+SELECT t.table_name, c1.column_name
+FROM information_schema.tables t
+INNER JOIN
+information_schema.columns c1
+ON t.table_schema = c1.table_schema AND
+t.table_name = c1.table_name
+WHERE t.table_schema = 'information_schema' AND
+c1.ordinal_position =
+( SELECT COALESCE(MIN(c2.ordinal_position),1)
+FROM information_schema.columns c2
+WHERE c2.table_schema = 'information_schema' AND
+c2.table_name = t.table_name AND
+c2.column_name LIKE '%SCHEMA%'
+ );
+table_name column_name
+CHARACTER_SETS CHARACTER_SET_NAME
+COLLATIONS COLLATION_NAME
+COLLATION_CHARACTER_SET_APPLICABILITY COLLATION_NAME
+COLUMNS TABLE_SCHEMA
+COLUMN_PRIVILEGES TABLE_SCHEMA
+KEY_COLUMN_USAGE CONSTRAINT_SCHEMA
+ROUTINES ROUTINE_SCHEMA
+SCHEMATA SCHEMA_NAME
+SCHEMA_PRIVILEGES TABLE_SCHEMA
+STATISTICS TABLE_SCHEMA
+TABLES TABLE_SCHEMA
+TABLE_CONSTRAINTS CONSTRAINT_SCHEMA
+TABLE_PRIVILEGES TABLE_SCHEMA
+TRIGGERS TRIGGER_SCHEMA
+USER_PRIVILEGES GRANTEE
+VIEWS TABLE_SCHEMA
+SELECT MAX(table_name) FROM information_schema.tables;
+MAX(table_name)
+VIEWS
+SELECT table_name from information_schema.tables
+WHERE table_name=(SELECT MAX(table_name)
+FROM information_schema.tables);
+table_name
+VIEWS
diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result
index 77046cc1fd1..1d1f26e4b01 100644
--- a/mysql-test/r/innodb.result
+++ b/mysql-test/r/innodb.result
@@ -1473,8 +1473,8 @@ Error 1146 Table 'test.t4' doesn't exist
drop table t1,t2,t3;
create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
-select name2 from t1 union all select name from t1 union all select id from t1;
-name2
+select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
+trim(name2)
fff
sss
ttt
diff --git a/mysql-test/r/mysql_client.result b/mysql-test/r/mysql_client.result
index 87d09428ff6..a20bd60aaf3 100644
--- a/mysql-test/r/mysql_client.result
+++ b/mysql-test/r/mysql_client.result
@@ -2,3 +2,7 @@
1
ERROR 1064 (42000) at line 3: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
ERROR at line 1: USE must be followed by a database name
+\
+\\
+';
+';
diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result
index ff745021efb..0160d26527d 100644
--- a/mysql-test/r/mysqldump.result
+++ b/mysql-test/r/mysqldump.result
@@ -2220,7 +2220,7 @@ RETURN a+b */;;
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE*/;;
/*!50003 DROP FUNCTION IF EXISTS `bug9056_func2` */;;
/*!50003 SET SESSION SQL_MODE=""*/;;
-/*!50003 CREATE*/ /*!50020 DEFINER=`root`@`localhost`*/ /*!50003 FUNCTION `bug9056_func2`(f1 char binary) RETURNS char(1)
+/*!50003 CREATE*/ /*!50020 DEFINER=`root`@`localhost`*/ /*!50003 FUNCTION `bug9056_func2`(f1 char binary) RETURNS char(1) CHARSET latin1
begin
set f1= concat( 'hello', f1 );
return f1;
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 3d352a02ad2..d73dd03fc57 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -516,77 +516,6 @@ SELECT FOUND_ROWS();
FOUND_ROWS()
2
deallocate prepare stmt;
-create table t1 (a char(3) not null, b char(3) not null,
-c char(3) not null, primary key (a, b, c));
-create table t2 like t1;
-prepare stmt from
-"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b)
- where t1.a=1";
-execute stmt;
-a
-execute stmt;
-a
-execute stmt;
-a
-prepare stmt from
-"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from
-(t1 left outer join t2 on t2.a=? and t1.b=t2.b)
-left outer join t2 t3 on t3.a=? where t1.a=?";
-set @a:=1, @b:=1, @c:=1;
-execute stmt using @a, @b, @c;
-a b c a b c
-execute stmt using @a, @b, @c;
-a b c a b c
-execute stmt using @a, @b, @c;
-a b c a b c
-deallocate prepare stmt;
-drop table t1,t2;
-SET @aux= "SELECT COUNT(*)
- FROM INFORMATION_SCHEMA.COLUMNS A,
- INFORMATION_SCHEMA.COLUMNS B
- WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
- AND A.TABLE_NAME = B.TABLE_NAME
- AND A.COLUMN_NAME = B.COLUMN_NAME AND
- A.TABLE_NAME = 'user'";
-prepare my_stmt from @aux;
-execute my_stmt;
-COUNT(*)
-37
-execute my_stmt;
-COUNT(*)
-37
-execute my_stmt;
-COUNT(*)
-37
-deallocate prepare my_stmt;
-drop procedure if exists p1|
-drop table if exists t1|
-create table t1 (id int)|
-insert into t1 values(1)|
-create procedure p1(a int, b int)
-begin
-declare c int;
-select max(id)+1 into c from t1;
-insert into t1 select a+b;
-insert into t1 select a-b;
-insert into t1 select a-c;
-end|
-set @a= 3, @b= 4|
-prepare stmt from "call p1(?, ?)"|
-execute stmt using @a, @b|
-execute stmt using @a, @b|
-select * from t1|
-id
-1
-7
--1
-1
-7
--1
--5
-deallocate prepare stmt|
-drop procedure p1|
-drop table t1|
drop table if exists t1;
Warnings:
Note 1051 Unknown table 't1'
@@ -650,47 +579,6 @@ id
3
deallocate prepare stmt;
drop table t1, t2;
-create table t1 (a int);
-insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
-prepare stmt from "select * from t1 limit ?, ?";
-set @offset=0, @limit=1;
-execute stmt using @offset, @limit;
-a
-1
-select * from t1 limit 0, 1;
-a
-1
-set @offset=3, @limit=2;
-execute stmt using @offset, @limit;
-a
-4
-5
-select * from t1 limit 3, 2;
-a
-4
-5
-prepare stmt from "select * from t1 limit ?";
-execute stmt using @limit;
-a
-1
-2
-prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";
-ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
-prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";
-set @offset=9;
-set @limit=2;
-execute stmt using @offset, @limit;
-a
-10
-1
-prepare stmt from "(select * from t1 limit ?, ?) union all
- (select * from t1 limit ?, ?) order by a limit ?";
-execute stmt using @offset, @limit, @offset, @limit, @limit;
-a
-10
-10
-drop table t1;
-deallocate prepare stmt;
create table t1 (id int);
prepare stmt from "insert into t1 (id) select id from t1 union select id from t1";
execute stmt;
@@ -791,15 +679,6 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
select ? from t1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? from t1' at line 1
drop table t1;
-CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;
-CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;
-CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;
-PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';
-EXECUTE b12651;
-1
-DROP VIEW b12651_V1;
-DROP TABLE b12651_T1, b12651_T2;
-DEALLOCATE PREPARE b12651;
prepare stmt from "select @@time_zone";
execute stmt;
@@time_zone
@@ -1016,6 +895,147 @@ select @@max_prepared_stmt_count, @@prepared_stmt_count;
@@max_prepared_stmt_count @@prepared_stmt_count
3 0
set global max_prepared_stmt_count= @old_max_prepared_stmt_count;
+drop table if exists t1;
+create temporary table if not exists t1 (a1 int);
+prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1";
+drop temporary table t1;
+create temporary table if not exists t1 (a1 int);
+execute stmt;
+drop temporary table t1;
+create temporary table if not exists t1 (a1 int);
+execute stmt;
+drop temporary table t1;
+create temporary table if not exists t1 (a1 int);
+execute stmt;
+drop temporary table t1;
+deallocate prepare stmt;
+End of 4.1 tests
+create table t1 (a varchar(20));
+insert into t1 values ('foo');
+prepare stmt FROM 'SELECT char_length (a) FROM t1';
+ERROR 42000: FUNCTION test.char_length does not exist
+drop table t1;
+create table t1 (a char(3) not null, b char(3) not null,
+c char(3) not null, primary key (a, b, c));
+create table t2 like t1;
+prepare stmt from
+"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b)
+ where t1.a=1";
+execute stmt;
+a
+execute stmt;
+a
+execute stmt;
+a
+prepare stmt from
+"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from
+(t1 left outer join t2 on t2.a=? and t1.b=t2.b)
+left outer join t2 t3 on t3.a=? where t1.a=?";
+set @a:=1, @b:=1, @c:=1;
+execute stmt using @a, @b, @c;
+a b c a b c
+execute stmt using @a, @b, @c;
+a b c a b c
+execute stmt using @a, @b, @c;
+a b c a b c
+deallocate prepare stmt;
+drop table t1,t2;
+SET @aux= "SELECT COUNT(*)
+ FROM INFORMATION_SCHEMA.COLUMNS A,
+ INFORMATION_SCHEMA.COLUMNS B
+ WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
+ AND A.TABLE_NAME = B.TABLE_NAME
+ AND A.COLUMN_NAME = B.COLUMN_NAME AND
+ A.TABLE_NAME = 'user'";
+prepare my_stmt from @aux;
+execute my_stmt;
+COUNT(*)
+37
+execute my_stmt;
+COUNT(*)
+37
+execute my_stmt;
+COUNT(*)
+37
+deallocate prepare my_stmt;
+drop procedure if exists p1|
+drop table if exists t1|
+create table t1 (id int)|
+insert into t1 values(1)|
+create procedure p1(a int, b int)
+begin
+declare c int;
+select max(id)+1 into c from t1;
+insert into t1 select a+b;
+insert into t1 select a-b;
+insert into t1 select a-c;
+end|
+set @a= 3, @b= 4|
+prepare stmt from "call p1(?, ?)"|
+execute stmt using @a, @b|
+execute stmt using @a, @b|
+select * from t1|
+id
+1
+7
+-1
+1
+7
+-1
+-5
+deallocate prepare stmt|
+drop procedure p1|
+drop table t1|
+create table t1 (a int);
+insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
+prepare stmt from "select * from t1 limit ?, ?";
+set @offset=0, @limit=1;
+execute stmt using @offset, @limit;
+a
+1
+select * from t1 limit 0, 1;
+a
+1
+set @offset=3, @limit=2;
+execute stmt using @offset, @limit;
+a
+4
+5
+select * from t1 limit 3, 2;
+a
+4
+5
+prepare stmt from "select * from t1 limit ?";
+execute stmt using @limit;
+a
+1
+2
+prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";
+ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
+prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";
+set @offset=9;
+set @limit=2;
+execute stmt using @offset, @limit;
+a
+10
+1
+prepare stmt from "(select * from t1 limit ?, ?) union all
+ (select * from t1 limit ?, ?) order by a limit ?";
+execute stmt using @offset, @limit, @offset, @limit, @limit;
+a
+10
+10
+drop table t1;
+deallocate prepare stmt;
+CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;
+CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;
+CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;
+PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';
+EXECUTE b12651;
+1
+DROP VIEW b12651_V1;
+DROP TABLE b12651_T1, b12651_T2;
+DEALLOCATE PREPARE b12651;
create table t1 (id int);
prepare ins_call from "insert into t1 (id) values (1)";
execute ins_call;
diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result
index 3c736a508d3..ac8ae6def9f 100644
--- a/mysql-test/r/ps_1general.result
+++ b/mysql-test/r/ps_1general.result
@@ -298,7 +298,7 @@ t9 MyISAM 10 Dynamic 2 216 432 # 2048 0 NULL # # # latin1_swedish_ci NULL
prepare stmt4 from ' show status like ''Threads_running'' ';
execute stmt4;
Variable_name Value
-Threads_running 1
+Threads_running #
prepare stmt4 from ' show variables like ''sql_mode'' ';
execute stmt4;
Variable_name Value
diff --git a/mysql-test/r/rpl_sp.result b/mysql-test/r/rpl_sp.result
index 5dfda16c763..7b096b27733 100644
--- a/mysql-test/r/rpl_sp.result
+++ b/mysql-test/r/rpl_sp.result
@@ -420,4 +420,48 @@ SELECT * FROM t1;
col
test
DROP PROCEDURE p1;
+
+---> Test for BUG#20438
+
+---> Preparing environment...
+---> connection: master
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+
+---> Synchronizing slave with master...
+
+---> connection: master
+
+---> Creating procedure...
+/*!50003 CREATE PROCEDURE p1() SET @a = 1 */;
+/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */;
+
+---> Checking on master...
+SHOW CREATE PROCEDURE p1;
+Procedure sql_mode Create Procedure
+p1 CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @a = 1
+SHOW CREATE FUNCTION f1;
+Function sql_mode Create Function
+f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 0
+
+---> Synchronizing slave with master...
+---> connection: master
+
+---> Checking on slave...
+SHOW CREATE PROCEDURE p1;
+Procedure sql_mode Create Procedure
+p1 CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @a = 1
+SHOW CREATE FUNCTION f1;
+Function sql_mode Create Function
+f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 0
+
+---> connection: master
+
+---> Cleaning up...
+DROP PROCEDURE p1;
+DROP FUNCTION f1;
drop table t1;
diff --git a/mysql-test/r/rpl_trigger.result b/mysql-test/r/rpl_trigger.result
index 3e4a3349e13..49f0f5c4c44 100644
--- a/mysql-test/r/rpl_trigger.result
+++ b/mysql-test/r/rpl_trigger.result
@@ -896,3 +896,50 @@ Tables_in_test (t_)
SHOW TRIGGERS;
Trigger Event Table Statement Timing Created sql_mode Definer
RESET MASTER;
+START SLAVE;
+
+---> Test for BUG#20438
+
+---> Preparing environment...
+---> connection: master
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+
+---> Synchronizing slave with master...
+
+---> connection: master
+
+---> Creating objects...
+CREATE TABLE t1(c INT);
+CREATE TABLE t2(c INT);
+/*!50003 CREATE TRIGGER t1_bi BEFORE INSERT ON t1
+FOR EACH ROW
+INSERT INTO t2 VALUES(NEW.c * 10) */;
+
+---> Inserting value...
+INSERT INTO t1 VALUES(1);
+
+---> Checking on master...
+SELECT * FROM t1;
+c
+1
+SELECT * FROM t2;
+c
+10
+
+---> Synchronizing slave with master...
+---> connection: master
+
+---> Checking on slave...
+SELECT * FROM t1;
+c
+1
+SELECT * FROM t2;
+c
+10
+
+---> connection: master
+
+---> Cleaning up...
+DROP TABLE t1;
+DROP TABLE t2;
diff --git a/mysql-test/r/rpl_view.result b/mysql-test/r/rpl_view.result
index cf4c161b296..5a101defe38 100644
--- a/mysql-test/r/rpl_view.result
+++ b/mysql-test/r/rpl_view.result
@@ -54,3 +54,40 @@ slave-bin.000001 # Query 1 # use `test`; delete from v1 where a=2
slave-bin.000001 # Query 1 # use `test`; ALTER ALGORITHM=UNDEFINED DEFINER=root@localhost SQL SECURITY DEFINER VIEW v1 AS select a as b from t1
slave-bin.000001 # Query 1 # use `test`; drop view v1
slave-bin.000001 # Query 1 # use `test`; drop table t1
+
+---> Test for BUG#20438
+
+---> Preparing environment...
+---> connection: master
+DROP TABLE IF EXISTS t1;
+DROP VIEW IF EXISTS v1;
+
+---> Synchronizing slave with master...
+
+---> connection: master
+
+---> Creating objects...
+CREATE TABLE t1(c INT);
+/*!50003 CREATE VIEW v1 AS SELECT * FROM t1 */;
+
+---> Inserting value...
+INSERT INTO t1 VALUES(1);
+
+---> Checking on master...
+SELECT * FROM t1;
+c
+1
+
+---> Synchronizing slave with master...
+---> connection: master
+
+---> Checking on slave...
+SELECT * FROM t1;
+c
+1
+
+---> connection: master
+
+---> Cleaning up...
+DROP VIEW v1;
+DROP TABLE t1;
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index c2218585f7c..b5d059be4c5 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -2736,6 +2736,81 @@ SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1;
i='1e+01' i=1e+01 i in (1e+01,1e+01) i in ('1e+01','1e+01')
0 1 1 1
DROP TABLE t1;
+CREATE TABLE t1 (a int, b int);
+INSERT INTO t1 VALUES (1,1), (2,1), (4,10);
+CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b));
+INSERT INTO t2 VALUES (1,NULL), (2,10);
+ALTER TABLE t1 ENABLE KEYS;
+EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index b b 5 NULL 2 Using index
+1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
+SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+a b a b
+1 NULL 1 1
+1 NULL 2 1
+1 NULL 4 10
+2 10 4 10
+EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index b b 5 NULL 2 Using index
+1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
+SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+a b a b
+1 NULL 1 1
+1 NULL 2 1
+1 NULL 4 10
+2 10 4 10
+DROP TABLE IF EXISTS t1,t2;
+CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1));
+CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2));
+INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941);
+INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941);
+explain select max(key1) from t1 where key1 <= 0.6158;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+explain select max(key2) from t2 where key2 <= 1.6158;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+explain select min(key1) from t1 where key1 >= 0.3762;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+explain select min(key2) from t2 where key2 >= 1.3762;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+explain select max(key1), min(key2) from t1, t2
+where key1 <= 0.6158 and key2 >= 1.3762;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+select max(key1) from t1 where key1 <= 0.6158;
+max(key1)
+0.61580002307892
+select max(key2) from t2 where key2 <= 1.6158;
+max(key2)
+1.6158000230789
+select min(key1) from t1 where key1 >= 0.3762;
+min(key1)
+0.37619999051094
+select min(key2) from t2 where key2 >= 1.3762;
+min(key2)
+1.3761999607086
+select max(key1), min(key2) from t1, t2
+where key1 <= 0.6158 and key2 >= 1.3762;
+max(key1) min(key2)
+0.61580002307892 1.3761999607086
+select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
+max(key1)
+0.61580002307892
+select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
+min(key1)
+0.37619999051094
+DROP TABLE t1,t2;
CREATE TABLE t1 (
K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '',
K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000',
diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result
index 994501767ba..7bdfa78066c 100644
--- a/mysql-test/r/show_check.result
+++ b/mysql-test/r/show_check.result
@@ -625,3 +625,7 @@ View Create View
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select sql_cache 1 AS `1`
DROP PROCEDURE p1;
DROP VIEW v1;
+SHOW TABLES FROM no_such_database;
+ERROR 42000: Unknown database 'no_such_database'
+SHOW COLUMNS FROM no_such_table;
+ERROR 42S02: Table 'test.no_such_table' doesn't exist
diff --git a/mysql-test/r/sp-code.result b/mysql-test/r/sp-code.result
index 8bdb9a724d7..4ae38861d29 100644
--- a/mysql-test/r/sp-code.result
+++ b/mysql-test/r/sp-code.result
@@ -155,11 +155,11 @@ Pos Instruction
0 stmt 9 "drop temporary table if exists sudoku..."
1 stmt 1 "create temporary table sudoku_work ( ..."
2 stmt 1 "create temporary table sudoku_schedul..."
-3 stmt 95 "call sudoku_init("
+3 stmt 95 "call sudoku_init()"
4 jump_if_not 7(8) p_naive@0
5 stmt 4 "update sudoku_work set cnt = 0 where ..."
6 jump 8
-7 stmt 95 "call sudoku_count("
+7 stmt 95 "call sudoku_count()"
8 stmt 6 "insert into sudoku_schedule (row,col)..."
9 set v_scounter@2 0
10 set v_i@3 1
@@ -199,3 +199,10 @@ Pos Instruction
44 jump 14
45 stmt 9 "drop temporary table sudoku_work, sud..."
drop procedure sudoku_solve;
+DROP PROCEDURE IF EXISTS p1;
+CREATE PROCEDURE p1() CREATE INDEX idx ON t1 (c1);
+SHOW PROCEDURE CODE p1;
+Pos Instruction
+0 stmt 2 "CREATE INDEX idx ON t1 (c1)"
+DROP PROCEDURE p1;
+End of 5.0 tests.
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
index 924963017eb..da1fc58db57 100644
--- a/mysql-test/r/sp-error.result
+++ b/mysql-test/r/sp-error.result
@@ -1174,3 +1174,16 @@ drop procedure bug15091;
drop function if exists bug16896;
create aggregate function bug16896() returns int return 1;
ERROR 42000: AGGREGATE is not supported for stored functions
+DROP PROCEDURE IF EXISTS bug14702;
+CREATE IF NOT EXISTS PROCEDURE bug14702()
+BEGIN
+END;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS PROCEDURE bug14702()
+BEGIN
+END' at line 1
+CREATE PROCEDURE IF NOT EXISTS bug14702()
+BEGIN
+END;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS bug14702()
+BEGIN
+END' at line 1
diff --git a/mysql-test/r/sp-security.result b/mysql-test/r/sp-security.result
index a53b4c4d246..1198efc4f3b 100644
--- a/mysql-test/r/sp-security.result
+++ b/mysql-test/r/sp-security.result
@@ -451,3 +451,55 @@ SELECT Host,User,Password FROM mysql.user WHERE User='user19857';
Host User Password
localhost user19857 *82DC221D557298F6CE9961037DB1C90604792F5C
DROP USER user19857@localhost;
+DROP TABLE IF EXISTS t1;
+DROP VIEW IF EXISTS v1;
+DROP FUNCTION IF EXISTS f_suid;
+DROP PROCEDURE IF EXISTS p_suid;
+DROP FUNCTION IF EXISTS f_evil;
+DELETE FROM mysql.user WHERE user LIKE 'mysqltest\_%';
+DELETE FROM mysql.db WHERE user LIKE 'mysqltest\_%';
+DELETE FROM mysql.tables_priv WHERE user LIKE 'mysqltest\_%';
+DELETE FROM mysql.columns_priv WHERE user LIKE 'mysqltest\_%';
+FLUSH PRIVILEGES;
+CREATE TABLE t1 (i INT);
+CREATE FUNCTION f_suid(i INT) RETURNS INT SQL SECURITY DEFINER RETURN 0;
+CREATE PROCEDURE p_suid(IN i INT) SQL SECURITY DEFINER SET @c:= 0;
+CREATE USER mysqltest_u1@localhost;
+GRANT EXECUTE ON test.* TO mysqltest_u1@localhost;
+CREATE DEFINER=mysqltest_u1@localhost FUNCTION f_evil () RETURNS INT
+SQL SECURITY INVOKER
+BEGIN
+SET @a:= CURRENT_USER();
+SET @b:= (SELECT COUNT(*) FROM t1);
+RETURN @b;
+END|
+CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT f_evil();
+SELECT COUNT(*) FROM t1;
+ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't1'
+SELECT f_evil();
+ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't1'
+SELECT @a, @b;
+@a @b
+mysqltest_u1@localhost NULL
+SELECT f_suid(f_evil());
+ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't1'
+SELECT @a, @b;
+@a @b
+mysqltest_u1@localhost NULL
+CALL p_suid(f_evil());
+ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't1'
+SELECT @a, @b;
+@a @b
+mysqltest_u1@localhost NULL
+SELECT * FROM v1;
+ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 'v1'
+SELECT @a, @b;
+@a @b
+mysqltest_u1@localhost NULL
+DROP VIEW v1;
+DROP FUNCTION f_evil;
+DROP USER mysqltest_u1@localhost;
+DROP PROCEDURE p_suid;
+DROP FUNCTION f_suid;
+DROP TABLE t1;
+End of 5.0 tests.
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 7807b7b52ce..88a860d6c8a 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -5057,6 +5057,190 @@ concat('data was: /', var1, '/')
data was: /1/
drop table t3|
drop procedure bug15217|
+DROP PROCEDURE IF EXISTS bug21013 |
+CREATE PROCEDURE bug21013(IN lim INT)
+BEGIN
+DECLARE i INT DEFAULT 0;
+WHILE (i < lim) DO
+SET @b = LOCATE(_latin1'b', @a, 1);
+SET i = i + 1;
+END WHILE;
+END |
+SET @a = _latin2"aaaaaaaaaa" |
+CALL bug21013(10) |
+DROP PROCEDURE bug21013 |
+DROP DATABASE IF EXISTS mysqltest1|
+DROP DATABASE IF EXISTS mysqltest2|
+CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8|
+CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET utf8|
+use mysqltest1|
+CREATE FUNCTION bug16211_f1() RETURNS CHAR(10)
+RETURN ""|
+CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET koi8r
+RETURN ""|
+CREATE FUNCTION mysqltest2.bug16211_f3() RETURNS CHAR(10)
+RETURN ""|
+CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET koi8r
+RETURN ""|
+SHOW CREATE FUNCTION bug16211_f1|
+Function sql_mode Create Function
+bug16211_f1 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f1`() RETURNS char(10) CHARSET utf8
+RETURN ""
+SHOW CREATE FUNCTION bug16211_f2|
+Function sql_mode Create Function
+bug16211_f2 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f2`() RETURNS char(10) CHARSET koi8r
+RETURN ""
+SHOW CREATE FUNCTION mysqltest2.bug16211_f3|
+Function sql_mode Create Function
+bug16211_f3 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f3`() RETURNS char(10) CHARSET utf8
+RETURN ""
+SHOW CREATE FUNCTION mysqltest2.bug16211_f4|
+Function sql_mode Create Function
+bug16211_f4 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f4`() RETURNS char(10) CHARSET koi8r
+RETURN ""
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"|
+dtd_identifier
+char(10) CHARSET utf8
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"|
+dtd_identifier
+char(10) CHARSET koi8r
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"|
+dtd_identifier
+char(10) CHARSET utf8
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"|
+dtd_identifier
+char(10) CHARSET koi8r
+SELECT CHARSET(bug16211_f1())|
+CHARSET(bug16211_f1())
+utf8
+SELECT CHARSET(bug16211_f2())|
+CHARSET(bug16211_f2())
+koi8r
+SELECT CHARSET(mysqltest2.bug16211_f3())|
+CHARSET(mysqltest2.bug16211_f3())
+utf8
+SELECT CHARSET(mysqltest2.bug16211_f4())|
+CHARSET(mysqltest2.bug16211_f4())
+koi8r
+ALTER DATABASE mysqltest1 CHARACTER SET cp1251|
+ALTER DATABASE mysqltest2 CHARACTER SET cp1251|
+SHOW CREATE FUNCTION bug16211_f1|
+Function sql_mode Create Function
+bug16211_f1 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f1`() RETURNS char(10) CHARSET utf8
+RETURN ""
+SHOW CREATE FUNCTION bug16211_f2|
+Function sql_mode Create Function
+bug16211_f2 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f2`() RETURNS char(10) CHARSET koi8r
+RETURN ""
+SHOW CREATE FUNCTION mysqltest2.bug16211_f3|
+Function sql_mode Create Function
+bug16211_f3 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f3`() RETURNS char(10) CHARSET utf8
+RETURN ""
+SHOW CREATE FUNCTION mysqltest2.bug16211_f4|
+Function sql_mode Create Function
+bug16211_f4 CREATE DEFINER=`root`@`localhost` FUNCTION `bug16211_f4`() RETURNS char(10) CHARSET koi8r
+RETURN ""
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"|
+dtd_identifier
+char(10) CHARSET utf8
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"|
+dtd_identifier
+char(10) CHARSET koi8r
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"|
+dtd_identifier
+char(10) CHARSET utf8
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"|
+dtd_identifier
+char(10) CHARSET koi8r
+SELECT CHARSET(bug16211_f1())|
+CHARSET(bug16211_f1())
+utf8
+SELECT CHARSET(bug16211_f2())|
+CHARSET(bug16211_f2())
+koi8r
+SELECT CHARSET(mysqltest2.bug16211_f3())|
+CHARSET(mysqltest2.bug16211_f3())
+utf8
+SELECT CHARSET(mysqltest2.bug16211_f4())|
+CHARSET(mysqltest2.bug16211_f4())
+koi8r
+use test|
+DROP DATABASE mysqltest1|
+DROP DATABASE mysqltest2|
+DROP DATABASE IF EXISTS mysqltest1|
+CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8|
+use mysqltest1|
+CREATE PROCEDURE bug16676_p1(
+IN p1 CHAR(10),
+INOUT p2 CHAR(10),
+OUT p3 CHAR(10))
+BEGIN
+SELECT CHARSET(p1), COLLATION(p1);
+SELECT CHARSET(p2), COLLATION(p2);
+SELECT CHARSET(p3), COLLATION(p3);
+END|
+CREATE PROCEDURE bug16676_p2(
+IN p1 CHAR(10) CHARSET koi8r,
+INOUT p2 CHAR(10) CHARSET cp1251,
+OUT p3 CHAR(10) CHARSET greek)
+BEGIN
+SELECT CHARSET(p1), COLLATION(p1);
+SELECT CHARSET(p2), COLLATION(p2);
+SELECT CHARSET(p3), COLLATION(p3);
+END|
+SET @v2 = 'b'|
+SET @v3 = 'c'|
+CALL bug16676_p1('a', @v2, @v3)|
+CHARSET(p1) COLLATION(p1)
+utf8 utf8_general_ci
+CHARSET(p2) COLLATION(p2)
+utf8 utf8_general_ci
+CHARSET(p3) COLLATION(p3)
+utf8 utf8_general_ci
+CALL bug16676_p2('a', @v2, @v3)|
+CHARSET(p1) COLLATION(p1)
+koi8r koi8r_general_ci
+CHARSET(p2) COLLATION(p2)
+cp1251 cp1251_general_ci
+CHARSET(p3) COLLATION(p3)
+greek greek_general_ci
+use test|
+DROP DATABASE mysqltest1|
+drop procedure if exists bug19862|
+CREATE TABLE t11 (a INT)|
+CREATE TABLE t12 (a INT)|
+CREATE FUNCTION bug19862(x INT) RETURNS INT
+BEGIN
+INSERT INTO t11 VALUES (x);
+RETURN x+1;
+END|
+INSERT INTO t12 VALUES (1), (2)|
+SELECT bug19862(a) FROM t12 ORDER BY 1|
+bug19862(a)
+2
+3
+SELECT * FROM t11|
+a
+1
+2
+DROP TABLE t11, t12|
+DROP FUNCTION bug19862|
drop table if exists t3|
drop database if exists mysqltest1|
create table t3 (a int)|
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index ae929cf9c2e..b7f0866019c 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -2888,6 +2888,33 @@ select 1 from dual where 1 < any (select 2 from dual);
select 1 from dual where 1 < all (select 2 from dual where 1!=1);
1
1
+create table t1 (s1 char);
+insert into t1 values (1),(2);
+select * from t1 where (s1 < any (select s1 from t1));
+s1
+1
+select * from t1 where not (s1 < any (select s1 from t1));
+s1
+2
+select * from t1 where (s1 < ALL (select s1+1 from t1));
+s1
+1
+select * from t1 where not(s1 < ALL (select s1+1 from t1));
+s1
+2
+select * from t1 where (s1+1 = ANY (select s1 from t1));
+s1
+1
+select * from t1 where NOT(s1+1 = ANY (select s1 from t1));
+s1
+2
+select * from t1 where (s1 = ALL (select s1/s1 from t1));
+s1
+1
+select * from t1 where NOT(s1 = ALL (select s1/s1 from t1));
+s1
+2
+drop table t1;
create table t1 (df decimal(5,1));
insert into t1 values(1.1);
insert into t1 values(2.2);
diff --git a/mysql-test/r/subselect2.result b/mysql-test/r/subselect2.result
index 026bcb4b370..75aa339fb29 100644
--- a/mysql-test/r/subselect2.result
+++ b/mysql-test/r/subselect2.result
@@ -132,3 +132,15 @@ id select_type table type possible_keys key key_len ref rows Extra
5 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX PRIMARY 34 func 1 Using index; Using where
6 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 func 1 Using index; Using where
drop table t1, t2, t3, t4;
+CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t2 VALUES (1);
+CREATE TABLE t3 (a int(10), b int(10), c int(10),
+PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t3 VALUES (1,2,1);
+SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a
+and t2.a='1' AND t1.a=t3.b) > 0;
+a
+2
+DROP TABLE t1,t2,t3;
diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result
index 484c42c41bf..8e37cca6aa9 100644
--- a/mysql-test/r/udf.result
+++ b/mysql-test/r/udf.result
@@ -93,6 +93,18 @@ NULL
0R
FR
DROP TABLE bug19904;
+CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse
+RETURNS STRING SONAME "should_not_parse.so";
+ERROR HY000: Incorrect usage of SONAME and DEFINER
+CREATE DEFINER=someone@somewhere FUNCTION should_not_parse
+RETURNS STRING SONAME "should_not_parse.so";
+ERROR HY000: Incorrect usage of SONAME and DEFINER
+create table t1(f1 int);
+insert into t1 values(1),(2);
+explain select myfunc_int(f1) from t1 order by 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
+drop table t1;
End of 5.0 tests.
DROP FUNCTION metaphon;
DROP FUNCTION myfunc_double;
diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result
index 426387e04f5..5cce540f058 100644
--- a/mysql-test/r/union.result
+++ b/mysql-test/r/union.result
@@ -691,9 +691,9 @@ t1 CREATE TABLE `t1` (
`da` datetime default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
-create table t1 SELECT dt from t2 UNION select sc from t2;
-select * from t1;
-dt
+create table t1 SELECT dt from t2 UNION select trim(sc) from t2;
+select trim(dt) from t1;
+trim(dt)
1972-10-22 11:50:00
testc
show create table t1;
@@ -732,7 +732,7 @@ tetetetetest
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
- `dt` longblob
+ `dt` blob
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT sv from t2 UNION select b from t2;
@@ -743,7 +743,7 @@ tetetetetest
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
- `sv` longblob
+ `sv` blob
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT i from t2 UNION select d from t2 UNION select b from t2;
@@ -755,7 +755,7 @@ tetetetetest
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
- `i` longblob
+ `i` blob
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT sv from t2 UNION select tx from t2;
@@ -766,7 +766,7 @@ teeeeeeeeeeeest
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
- `sv` longtext
+ `sv` text
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 SELECT b from t2 UNION select tx from t2;
@@ -777,7 +777,7 @@ teeeeeeeeeeeest
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
- `b` longblob
+ `b` blob
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1,t2;
create table t1 select 1 union select -1;
@@ -1306,6 +1306,21 @@ id
5
99
drop table t1;
+create table t1(f1 char(1), f2 char(5), f3 binary(1), f4 binary(5), f5 timestamp, f6 varchar(1) character set utf8 collate utf8_general_ci, f7 text);
+create table t2 as select *, f6 as f8 from t1 union select *, f7 from t1;
+show create table t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `f1` char(1) default NULL,
+ `f2` char(5) default NULL,
+ `f3` binary(1) default NULL,
+ `f4` binary(5) default NULL,
+ `f5` timestamp NOT NULL default '0000-00-00 00:00:00',
+ `f6` varchar(1) character set utf8 default NULL,
+ `f7` text,
+ `f8` text character set utf8
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop table t1, t2;
(select avg(1)) union (select avg(1)) union (select avg(1)) union
(select avg(1)) union (select avg(1)) union (select avg(1)) union
(select avg(1)) union (select avg(1)) union (select avg(1)) union
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 7d2ab63ca77..534065a33b6 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -193,7 +193,7 @@ c d
2 5
3 10
drop view v100;
-ERROR 42S02: Unknown table 'test.v100'
+ERROR 42S02: Unknown table 'v100'
drop view t1;
ERROR HY000: 'test.t1' is not VIEW
drop table v1;
@@ -2774,3 +2774,79 @@ Field Type Null Key Default Extra
COALESCE(i,j) int(11) YES NULL
DROP VIEW v1;
DROP TABLE t1,t2;
+CREATE TABLE t1 (s varchar(10));
+INSERT INTO t1 VALUES ('yadda'), ('yady');
+SELECT TRIM(BOTH 'y' FROM s) FROM t1;
+TRIM(BOTH 'y' FROM s)
+adda
+ad
+CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1;
+SELECT * FROM v1;
+TRIM(BOTH 'y' FROM s)
+adda
+ad
+DROP VIEW v1;
+SELECT TRIM(LEADING 'y' FROM s) FROM t1;
+TRIM(LEADING 'y' FROM s)
+adda
+ady
+CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1;
+SELECT * FROM v1;
+TRIM(LEADING 'y' FROM s)
+adda
+ady
+DROP VIEW v1;
+SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
+TRIM(TRAILING 'y' FROM s)
+yadda
+yad
+CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
+SELECT * FROM v1;
+TRIM(TRAILING 'y' FROM s)
+yadda
+yad
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (x INT, y INT);
+CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1;
+SHOW CREATE VIEW v1;
+View Create View
+v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select `t1`.`x` AS `x` from `t1`
+ALTER VIEW v1 AS SELECT x, y FROM t1;
+SHOW CREATE VIEW v1;
+View Create View
+v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select `t1`.`x` AS `x`,`t1`.`y` AS `y` from `t1`
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (s1 char);
+INSERT INTO t1 VALUES ('Z');
+CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1;
+CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1;
+INSERT INTO v1 (col) VALUES ('b');
+INSERT INTO v2 (col) VALUES ('c');
+SELECT s1 FROM t1;
+s1
+Z
+b
+c
+DROP VIEW v1, v2;
+DROP TABLE t1;
+CREATE TABLE t1 (id INT);
+CREATE VIEW v1 AS SELECT id FROM t1;
+SHOW TABLES;
+Tables_in_test
+t1
+v1
+DROP VIEW v2,v1;
+ERROR 42S02: Unknown table 'v2'
+SHOW TABLES;
+Tables_in_test
+t1
+CREATE VIEW v1 AS SELECT id FROM t1;
+DROP VIEW t1,v1;
+ERROR HY000: 'test.t1' is not VIEW
+SHOW TABLES;
+Tables_in_test
+t1
+DROP TABLE t1;
+DROP VIEW IF EXISTS v1;
diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index 007847fab37..7f9170847db 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -11,3 +11,4 @@
##############################################################################
ndb_load : Bug#17233
+lowercase_fs_off : Bug#21419
diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test
index fbfdfa3b5d0..98c21986aa9 100644
--- a/mysql-test/t/func_gconcat.test
+++ b/mysql-test/t/func_gconcat.test
@@ -433,3 +433,17 @@ create table t1 (c1 varchar(10), c2 int);
select charset(group_concat(c1 order by c2)) from t1;
drop table t1;
+#
+# Bug #16712: group_concat returns odd string instead of intended result
+#
+CREATE TABLE t1 (a INT(10), b LONGTEXT, PRIMARY KEY (a));
+
+SET GROUP_CONCAT_MAX_LEN = 20000000;
+
+INSERT INTO t1 VALUES (1,REPEAT(CONCAT('A',CAST(CHAR(0) AS BINARY),'B'), 40000));
+INSERT INTO t1 SELECT a + 1, b FROM t1;
+
+SELECT a, CHAR_LENGTH(b) FROM t1;
+SELECT CHAR_LENGTH( GROUP_CONCAT(b) ) FROM t1;
+SET GROUP_CONCAT_MAX_LEN = 1024;
+DROP TABLE t1;
diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test
index e8c5fa18a25..f28ce234b73 100644
--- a/mysql-test/t/func_group.test
+++ b/mysql-test/t/func_group.test
@@ -660,3 +660,18 @@ SELECT SUM(a) FROM t1 GROUP BY b/c;
DROP TABLE t1;
set div_precision_increment= @sav_dpi;
+#
+# Bug #20868: Client connection is broken on SQL query error
+#
+CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
+INSERT INTO t1 VALUES (1,1), (2,2);
+
+CREATE TABLE t2 (a INT PRIMARY KEY, b INT);
+INSERT INTO t2 VALUES (1,1), (3,3);
+
+SELECT SQL_NO_CACHE
+ (SELECT SUM(c.a) FROM t1 ttt, t2 ccc
+ WHERE ttt.a = ccc.b AND ttt.a = t.a GROUP BY ttt.a) AS minid
+FROM t1 t, t2 c WHERE t.a = c.b;
+
+DROP TABLE t1,t2;
diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test
index 0fb866cf370..8753db0ebe1 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -706,6 +706,21 @@ SELECT a, CONCAT(a,' ',a) AS c FROM t1
INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
DROP TABLE t1;
+
+#
+# Bug#17526: WRONG PRINT for TRIM FUNCTION with two arguments
+#
+
+CREATE TABLE t1 (s varchar(10));
+INSERT INTO t1 VALUES ('yadda'), ('yaddy');
+
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(s) > 'ab';
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM('y' FROM s) > 'ab';
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(LEADING 'y' FROM s) > 'ab';
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(TRAILING 'y' FROM s) > 'ab';
+EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(BOTH 'y' FROM s) > 'ab';
+
+DROP TABLE t1;
--echo End of 4.1 tests
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index fb9835c5d7f..ce1e4e59600 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -632,3 +632,26 @@ group by t1.c1;
show warnings;
drop table t1, t2;
+#
+# Bug #20466: a view is mixing data when there's a trigger on the table
+#
+CREATE TABLE t1 (a tinyint(3), b varchar(255), PRIMARY KEY (a));
+
+INSERT INTO t1 VALUES (1,'-----'), (6,'Allemagne'), (17,'Autriche'),
+ (25,'Belgique'), (54,'Danemark'), (62,'Espagne'), (68,'France');
+
+CREATE TABLE t2 (a tinyint(3), b tinyint(3), PRIMARY KEY (a), KEY b (b));
+
+INSERT INTO t2 VALUES (1,1), (2,1), (6,6), (18,17), (15,25), (16,25),
+ (17,25), (10,54), (5,62),(3,68);
+
+CREATE VIEW v1 AS select t1.a, concat(t1.b,'') AS b, t1.b as real_b from t1;
+
+explain
+SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1
+where t2.b=v1.a GROUP BY t2.b;
+SELECT straight_join sql_no_cache v1.a, v1.b, v1.real_b from t2, v1
+where t2.b=v1.a GROUP BY t2.b;
+
+DROP VIEW v1;
+DROP TABLE t1,t2;
diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test
index 874f3cd1a80..5427727a8f4 100644
--- a/mysql-test/t/group_min_max.test
+++ b/mysql-test/t/group_min_max.test
@@ -746,3 +746,51 @@ EXPLAIN SELECT DISTINCT a,a FROM t1 ORDER BY a;
SELECT DISTINCT a,a FROM t1 ORDER BY a;
DROP TABLE t1;
+
+#
+# Bug #21007: NATURAL JOIN (any JOIN (2 x NATURAL JOIN)) crashes the server
+#
+
+CREATE TABLE t1 (id1 INT, id2 INT);
+CREATE TABLE t2 (id2 INT, id3 INT, id5 INT);
+CREATE TABLE t3 (id3 INT, id4 INT);
+CREATE TABLE t4 (id4 INT);
+CREATE TABLE t5 (id5 INT, id6 INT);
+CREATE TABLE t6 (id6 INT);
+
+INSERT INTO t1 VALUES(1,1);
+INSERT INTO t2 VALUES(1,1,1);
+INSERT INTO t3 VALUES(1,1);
+INSERT INTO t4 VALUES(1);
+INSERT INTO t5 VALUES(1,1);
+INSERT INTO t6 VALUES(1);
+
+-- original bug query
+SELECT * FROM
+t1
+ NATURAL JOIN
+(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6)
+ ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5));
+
+-- inner join swapped
+SELECT * FROM
+t1
+ NATURAL JOIN
+(((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6) on t3.id4 = t5.id5) JOIN t2
+ ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5));
+
+-- one join less, no ON cond
+SELECT * FROM t1 NATURAL JOIN ((t3 join (t5 NATURAL JOIN t6)) JOIN t2);
+
+-- wrong error message: 'id2' - ambiguous column
+SELECT * FROM
+(t2 JOIN (t3 NATURAL JOIN t4, t5 NATURAL JOIN t6)
+ ON (t3.id3 = t2.id3 AND t5.id5 = t2.id5))
+ NATURAL JOIN
+t1;
+SELECT * FROM
+(t2 JOIN ((t3 NATURAL JOIN t4) join (t5 NATURAL JOIN t6)))
+ NATURAL JOIN
+t1;
+
+DROP TABLE t1,t2,t3,t4,t5,t6;
diff --git a/mysql-test/t/im_daemon_life_cycle.imtest b/mysql-test/t/im_daemon_life_cycle.imtest
index 3afc36935f8..fe2345a9987 100644
--- a/mysql-test/t/im_daemon_life_cycle.imtest
+++ b/mysql-test/t/im_daemon_life_cycle.imtest
@@ -7,21 +7,7 @@
###########################################################################
--source include/im_check_os.inc
-
-###########################################################################
-
-# Wait for mysqld1 (guarded instance) to start.
-
---exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
-
-# Let IM detect that mysqld1 is online. This delay should be longer than
-# monitoring interval.
-
---sleep 3
-
-# Check that start conditions are as expected.
-
-SHOW INSTANCES;
+--source include/im_check_env.inc
###########################################################################
diff --git a/mysql-test/t/im_life_cycle.imtest b/mysql-test/t/im_life_cycle.imtest
index c3a5fb0a648..16cf25a8f35 100644
--- a/mysql-test/t/im_life_cycle.imtest
+++ b/mysql-test/t/im_life_cycle.imtest
@@ -7,33 +7,7 @@
###########################################################################
--source include/im_check_os.inc
-
-###########################################################################
-#
-# 1.1.1. Check that Instance Manager is able:
-# - to read definitions of two mysqld-instances;
-# - to start the first instance;
-# - to understand 'nonguarded' option and keep the second instance down;
-#
-###########################################################################
-
---echo
---echo --------------------------------------------------------------------
---echo -- 1.1.1.
---echo --------------------------------------------------------------------
-
-# Wait for mysqld1 (guarded instance) to start.
-
---exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
-
-# Let IM detect that mysqld1 is online. This delay should be longer than
-# monitoring interval.
-
---sleep 3
-
-# Check that start conditions are as expected.
-
-SHOW INSTANCES;
+--source include/im_check_env.inc
###########################################################################
#
@@ -54,9 +28,10 @@ START INSTANCE mysqld2;
# FIXME: START INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
-# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is
-# synchronous. Even waiting for mysqld to start by looking at its pid file is
-# not enough, because IM may not detect that mysqld has started.
+# FIXME: Result of SHOW INSTANCES here is not deterministic unless START
+# INSTANCE is synchronous. Even waiting for mysqld to start by looking at
+# its pid file is not enough, because it is unknown when IM detects that
+# mysqld has started.
# SHOW INSTANCES;
--connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD2_PORT,$IM_MYSQLD2_SOCK)
@@ -86,9 +61,10 @@ STOP INSTANCE mysqld2;
# FIXME: STOP INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped
-# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is
-# synchronous. Even waiting for mysqld to start by looking at its pid file is
-# not enough, because IM may not detect that mysqld has started.
+# FIXME: Result of SHOW INSTANCES here is not deterministic unless START
+# INSTANCE is synchronous. Even waiting for mysqld to start by looking at
+# its pid file is not enough, because it is unknown when IM detects that
+# mysqld has started.
# SHOW INSTANCES;
###########################################################################
@@ -114,8 +90,8 @@ START INSTANCE mysqld1;
###########################################################################
#
-# 1.1.5. Check that Instance Manager reports correct errors for 'STOP INSTANCE'
-# command:
+# 1.1.5. Check that Instance Manager reports correct errors for
+# 'STOP INSTANCE' command:
# - if the client tries to start unregistered instance;
# - if the client tries to start already stopped instance;
# - if the client submits invalid arguments;
@@ -146,12 +122,10 @@ STOP INSTANCE mysqld3;
--echo -- 1.1.6.
--echo --------------------------------------------------------------------
-SHOW INSTANCES;
-
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30
-# Give some time to IM to detect that mysqld was restarted. It should be longer
-# than monitoring interval.
+# Give some time to IM to detect that mysqld was restarted. It should be
+# longer than monitoring interval.
--sleep 3
@@ -172,16 +146,18 @@ START INSTANCE mysqld2;
# FIXME: START INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
-# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is
-# synchronous. Even waiting for mysqld to start by looking at its pid file is
-# not enough, because IM may not detect that mysqld has started.
+# FIXME: Result of SHOW INSTANCES here is not deterministic unless START
+# INSTANCE is synchronous. Even waiting for mysqld to start by looking at
+# its pid file is not enough, because it is unknown when IM detects that
+# mysqld has started.
# SHOW INSTANCES;
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10
-# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is
-# synchronous. Even waiting for mysqld to start by looking at its pid file is
-# not enough, because IM may not detect that mysqld has started.
+# FIXME: Result of SHOW INSTANCES here is not deterministic unless START
+# INSTANCE is synchronous. Even waiting for mysqld to start by looking at
+# its pid file is not enough, because it is unknown when IM detects that
+# mysqld has started.
# SHOW INSTANCES;
###########################################################################
diff --git a/mysql-test/t/im_options_set.imtest b/mysql-test/t/im_options_set.imtest
index a9b64861f99..76e209b6a66 100644
--- a/mysql-test/t/im_options_set.imtest
+++ b/mysql-test/t/im_options_set.imtest
@@ -39,32 +39,7 @@
###########################################################################
--source include/im_check_os.inc
-
-###########################################################################
-#
-# 0. Check starting conditions.
-#
-###########################################################################
-
-# - check the configuration file;
-
---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ;
-
-# - check the running instances.
-
---connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK)
-
---connection mysql1_con
-
-SHOW VARIABLES LIKE 'server_id';
-
---connection default
-
-# - check the internal cache.
-# TODO: we should check only server_id option here.
-
-# SHOW INSTANCE OPTIONS mysqld1;
-# SHOW INSTANCE OPTIONS mysqld2;
+--source include/im_check_env.inc
###########################################################################
#
diff --git a/mysql-test/t/im_options_unset.imtest b/mysql-test/t/im_options_unset.imtest
index 40629805d45..06f59e79ffe 100644
--- a/mysql-test/t/im_options_unset.imtest
+++ b/mysql-test/t/im_options_unset.imtest
@@ -46,32 +46,7 @@
###########################################################################
--source include/im_check_os.inc
-
-###########################################################################
-#
-# 0. Check starting conditions.
-#
-###########################################################################
-
-# - check the configuration file;
-
---exec grep server_id $MYSQLTEST_VARDIR/im.cnf ;
-
-# - check the running instances.
-
---connect (mysql1_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK)
-
---connection mysql1_con
-
-SHOW VARIABLES LIKE 'server_id';
-
---connection default
-
-# - check the internal cache.
-# TODO: we should check only server_id option here.
-
-# SHOW INSTANCE OPTIONS mysqld1;
-# SHOW INSTANCE OPTIONS mysqld2;
+--source include/im_check_env.inc
###########################################################################
#
diff --git a/mysql-test/t/im_utils.imtest b/mysql-test/t/im_utils.imtest
index 47902eeba52..4c05b342af5 100644
--- a/mysql-test/t/im_utils.imtest
+++ b/mysql-test/t/im_utils.imtest
@@ -7,36 +7,17 @@
###########################################################################
--source include/im_check_os.inc
+--source include/im_check_env.inc
###########################################################################
#
-# Check starting conditions. This test case assumes that:
-# - two mysqld-instances are registered;
-# - the first instance is online;
-# - the second instance is offline;
+# Check 'SHOW INSTANCE OPTIONS' command.
#
-
-# Wait for mysqld1 (guarded instance) to start.
-
---exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started
-
-# Let IM detect that mysqld1 is online. This delay should be longer than
-# monitoring interval.
-
---sleep 3
-
-# Check that start conditions are as expected.
-
-SHOW INSTANCES;
-
-#
-# Check 'SHOW INSTANCE OPTIONS' command:
-# - check that options of both offline and online instances are accessible;
-# - since configuration of an mysqld-instance contains directories, we should
-# completely ignore the second column (values) in order to make the test
-# case produce the same results on different installations;
-# TODO: ignore values of only directory-specific options.
+# Since configuration of an mysqld-instance contains directories, we should
+# completely ignore the second column (values) in order to make the test
+# case produce the same results on different installations;
+# TODO: ignore values of only directory-specific options.
#
--replace_column 2 VALUE
diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test
index a2e19112cf9..9e5dac8b853 100644
--- a/mysql-test/t/information_schema.test
+++ b/mysql-test/t/information_schema.test
@@ -887,4 +887,47 @@ DROP FUNCTION f1;
DROP PROCEDURE p1;
DROP USER mysql_bug20230@localhost;
+#
+# Bug#18925: subqueries with MIN/MAX functions on INFORMARTION_SCHEMA
+#
+
+SELECT t.table_name, c1.column_name
+ FROM information_schema.tables t
+ INNER JOIN
+ information_schema.columns c1
+ ON t.table_schema = c1.table_schema AND
+ t.table_name = c1.table_name
+ WHERE t.table_schema = 'information_schema' AND
+ c1.ordinal_position =
+ ( SELECT COALESCE(MIN(c2.ordinal_position),1)
+ FROM information_schema.columns c2
+ WHERE c2.table_schema = t.table_schema AND
+ c2.table_name = t.table_name AND
+ c2.column_name LIKE '%SCHEMA%'
+ );
+SELECT t.table_name, c1.column_name
+ FROM information_schema.tables t
+ INNER JOIN
+ information_schema.columns c1
+ ON t.table_schema = c1.table_schema AND
+ t.table_name = c1.table_name
+ WHERE t.table_schema = 'information_schema' AND
+ c1.ordinal_position =
+ ( SELECT COALESCE(MIN(c2.ordinal_position),1)
+ FROM information_schema.columns c2
+ WHERE c2.table_schema = 'information_schema' AND
+ c2.table_name = t.table_name AND
+ c2.column_name LIKE '%SCHEMA%'
+ );
+
+#
+# Bug#21231: query with a simple non-correlated subquery over
+# INFORMARTION_SCHEMA.TABLES
+#
+
+SELECT MAX(table_name) FROM information_schema.tables;
+SELECT table_name from information_schema.tables
+ WHERE table_name=(SELECT MAX(table_name)
+ FROM information_schema.tables);
+
# End of 5.0 tests.
diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test
index 71b178d0e57..0c083ccdfd3 100644
--- a/mysql-test/t/innodb.test
+++ b/mysql-test/t/innodb.test
@@ -1079,7 +1079,7 @@ drop table t1,t2,t3;
#
create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
-select name2 from t1 union all select name from t1 union all select id from t1;
+select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
drop table t1;
#
diff --git a/mysql-test/t/mysql_client.test b/mysql-test/t/mysql_client.test
index e4b6658b631..003a086212e 100644
--- a/mysql-test/t/mysql_client.test
+++ b/mysql-test/t/mysql_client.test
@@ -27,3 +27,14 @@
# client comment recognized, but parameter missing => error
--exec echo "use" > $MYSQLTEST_VARDIR/tmp/bug20432.sql
--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20432.sql 2>&1
+
+#
+# Bug #20103: Escaping with backslash does not work
+#
+--exec echo "SET SQL_MODE = 'NO_BACKSLASH_ESCAPES';" > $MYSQLTEST_VARDIR/tmp/bug20103.sql
+--exec echo "SELECT '\';" >> $MYSQLTEST_VARDIR/tmp/bug20103.sql
+--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20103.sql 2>&1
+
+--exec echo "SET SQL_MODE = '';" > $MYSQLTEST_VARDIR/tmp/bug20103.sql
+--exec echo "SELECT '\';';" >> $MYSQLTEST_VARDIR/tmp/bug20103.sql
+--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20103.sql 2>&1
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index 8eb383de57a..d0f31087c8f 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -491,6 +491,7 @@ deallocate prepare stmt;
drop table t1, t2;
#
+#
# Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating
# tables"
# Check that multi-delete tables are also cleaned up before re-execution.
@@ -538,86 +539,6 @@ SELECT FOUND_ROWS();
deallocate prepare stmt;
#
-# Bug#8115: equality propagation and prepared statements
-#
-
-create table t1 (a char(3) not null, b char(3) not null,
- c char(3) not null, primary key (a, b, c));
-create table t2 like t1;
-
-# reduced query
-prepare stmt from
- "select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b)
- where t1.a=1";
-execute stmt;
-execute stmt;
-execute stmt;
-
-# original query
-prepare stmt from
-"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from
-(t1 left outer join t2 on t2.a=? and t1.b=t2.b)
-left outer join t2 t3 on t3.a=? where t1.a=?";
-
-set @a:=1, @b:=1, @c:=1;
-
-execute stmt using @a, @b, @c;
-execute stmt using @a, @b, @c;
-execute stmt using @a, @b, @c;
-
-deallocate prepare stmt;
-
-drop table t1,t2;
-
-
-#
-# Bug#9383: INFORMATION_SCHEMA.COLUMNS, JOIN, Crash, prepared statement
-#
-
-eval SET @aux= "SELECT COUNT(*)
- FROM INFORMATION_SCHEMA.COLUMNS A,
- INFORMATION_SCHEMA.COLUMNS B
- WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
- AND A.TABLE_NAME = B.TABLE_NAME
- AND A.COLUMN_NAME = B.COLUMN_NAME AND
- A.TABLE_NAME = 'user'";
-
-let $exec_loop_count= 3;
-eval prepare my_stmt from @aux;
-while ($exec_loop_count)
-{
- eval execute my_stmt;
- dec $exec_loop_count;
-}
-deallocate prepare my_stmt;
-
-# Test CALL in prepared mode
-delimiter |;
---disable_warnings
-drop procedure if exists p1|
-drop table if exists t1|
---enable_warnings
-create table t1 (id int)|
-insert into t1 values(1)|
-create procedure p1(a int, b int)
-begin
- declare c int;
- select max(id)+1 into c from t1;
- insert into t1 select a+b;
- insert into t1 select a-b;
- insert into t1 select a-c;
-end|
-set @a= 3, @b= 4|
-prepare stmt from "call p1(?, ?)"|
-execute stmt using @a, @b|
-execute stmt using @a, @b|
-select * from t1|
-deallocate prepare stmt|
-drop procedure p1|
-drop table t1|
-delimiter ;|
-
-#
# Bug#9096 "select doesn't return all matched records if prepared statements
# is used"
# The bug was is bad co-operation of the optimizer's algorithm which determines
@@ -692,35 +613,6 @@ deallocate prepare stmt;
drop table t1, t2;
#
-# Bug#7306 LIMIT ?, ? and also WL#1785 " Prepared statements: implement
-# support for placeholders in LIMIT clause."
-# Add basic test coverage for the feature.
-#
-create table t1 (a int);
-insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
-prepare stmt from "select * from t1 limit ?, ?";
-set @offset=0, @limit=1;
-execute stmt using @offset, @limit;
-select * from t1 limit 0, 1;
-set @offset=3, @limit=2;
-execute stmt using @offset, @limit;
-select * from t1 limit 3, 2;
-prepare stmt from "select * from t1 limit ?";
-execute stmt using @limit;
---error 1235
-prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";
-prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";
-set @offset=9;
-set @limit=2;
-execute stmt using @offset, @limit;
-prepare stmt from "(select * from t1 limit ?, ?) union all
- (select * from t1 limit ?, ?) order by a limit ?";
-execute stmt using @offset, @limit, @offset, @limit, @limit;
-
-drop table t1;
-deallocate prepare stmt;
-
-#
# Bug#11060 "Server crashes on calling stored procedure with INSERT SELECT
# UNION SELECT" aka "Server crashes on re-execution of prepared INSERT ...
# SELECT with UNION".
@@ -837,22 +729,6 @@ select ??;
select ? from t1;
--enable_ps_protocol
drop table t1;
-
-#
-# Bug#12651
-# (Crash on a PS including a subquery which is a select from a simple view)
-#
-CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;
-CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;
-CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;
-
-PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';
-EXECUTE b12651;
-
-DROP VIEW b12651_V1;
-DROP TABLE b12651_T1, b12651_T2;
-DEALLOCATE PREPARE b12651;
-
#
# Bug#9359 "Prepared statements take snapshot of system vars at PREPARE
# time"
@@ -1087,7 +963,172 @@ select @@max_prepared_stmt_count, @@prepared_stmt_count;
set global max_prepared_stmt_count= @old_max_prepared_stmt_count;
--enable_ps_protocol
-# End of 4.1 tests
+#
+# Bug#19399 "Stored Procedures 'Lost Connection' when dropping/creating
+# tables"
+# Check that multi-delete tables are also cleaned up before re-execution.
+#
+--disable_warnings
+drop table if exists t1;
+create temporary table if not exists t1 (a1 int);
+--enable_warnings
+# exact delete syntax is essential
+prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1";
+drop temporary table t1;
+create temporary table if not exists t1 (a1 int);
+# the server crashed on the next statement without the fix
+execute stmt;
+drop temporary table t1;
+create temporary table if not exists t1 (a1 int);
+# the problem was in memory corruption: repeat the test just in case
+execute stmt;
+drop temporary table t1;
+create temporary table if not exists t1 (a1 int);
+execute stmt;
+drop temporary table t1;
+deallocate prepare stmt;
+
+--echo End of 4.1 tests
+############################# 5.0 tests start ################################
+#
+#
+# Bug#6102 "Server crash with prepared statement and blank after
+# function name"
+# ensure that stored functions are cached when preparing a statement
+# before we open tables
+#
+create table t1 (a varchar(20));
+insert into t1 values ('foo');
+--error 1305
+prepare stmt FROM 'SELECT char_length (a) FROM t1';
+drop table t1;
+
+#
+# Bug#8115: equality propagation and prepared statements
+#
+
+create table t1 (a char(3) not null, b char(3) not null,
+ c char(3) not null, primary key (a, b, c));
+create table t2 like t1;
+
+# reduced query
+prepare stmt from
+ "select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b)
+ where t1.a=1";
+execute stmt;
+execute stmt;
+execute stmt;
+
+# original query
+prepare stmt from
+"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from
+(t1 left outer join t2 on t2.a=? and t1.b=t2.b)
+left outer join t2 t3 on t3.a=? where t1.a=?";
+
+set @a:=1, @b:=1, @c:=1;
+
+execute stmt using @a, @b, @c;
+execute stmt using @a, @b, @c;
+execute stmt using @a, @b, @c;
+
+deallocate prepare stmt;
+
+drop table t1,t2;
+
+
+#
+# Bug#9383: INFORMATION_SCHEMA.COLUMNS, JOIN, Crash, prepared statement
+#
+
+eval SET @aux= "SELECT COUNT(*)
+ FROM INFORMATION_SCHEMA.COLUMNS A,
+ INFORMATION_SCHEMA.COLUMNS B
+ WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
+ AND A.TABLE_NAME = B.TABLE_NAME
+ AND A.COLUMN_NAME = B.COLUMN_NAME AND
+ A.TABLE_NAME = 'user'";
+
+let $exec_loop_count= 3;
+eval prepare my_stmt from @aux;
+while ($exec_loop_count)
+{
+ eval execute my_stmt;
+ dec $exec_loop_count;
+}
+deallocate prepare my_stmt;
+
+# Test CALL in prepared mode
+delimiter |;
+--disable_warnings
+drop procedure if exists p1|
+drop table if exists t1|
+--enable_warnings
+create table t1 (id int)|
+insert into t1 values(1)|
+create procedure p1(a int, b int)
+begin
+ declare c int;
+ select max(id)+1 into c from t1;
+ insert into t1 select a+b;
+ insert into t1 select a-b;
+ insert into t1 select a-c;
+end|
+set @a= 3, @b= 4|
+prepare stmt from "call p1(?, ?)"|
+execute stmt using @a, @b|
+execute stmt using @a, @b|
+select * from t1|
+deallocate prepare stmt|
+drop procedure p1|
+drop table t1|
+delimiter ;|
+
+
+#
+# Bug#7306 LIMIT ?, ? and also WL#1785 " Prepared statements: implement
+# support for placeholders in LIMIT clause."
+# Add basic test coverage for the feature.
+#
+create table t1 (a int);
+insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
+prepare stmt from "select * from t1 limit ?, ?";
+set @offset=0, @limit=1;
+execute stmt using @offset, @limit;
+select * from t1 limit 0, 1;
+set @offset=3, @limit=2;
+execute stmt using @offset, @limit;
+select * from t1 limit 3, 2;
+prepare stmt from "select * from t1 limit ?";
+execute stmt using @limit;
+--error 1235
+prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";
+prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";
+set @offset=9;
+set @limit=2;
+execute stmt using @offset, @limit;
+prepare stmt from "(select * from t1 limit ?, ?) union all
+ (select * from t1 limit ?, ?) order by a limit ?";
+execute stmt using @offset, @limit, @offset, @limit, @limit;
+
+drop table t1;
+deallocate prepare stmt;
+
+#
+# Bug#12651
+# (Crash on a PS including a subquery which is a select from a simple view)
+#
+CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;
+CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;
+CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;
+
+PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';
+EXECUTE b12651;
+
+DROP VIEW b12651_V1;
+DROP TABLE b12651_T1, b12651_T2;
+DEALLOCATE PREPARE b12651;
+
+
#
# Bug #14956: ROW_COUNT() returns incorrect result after EXECUTE of prepared
diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test
index 72b69fc8d9f..8d0f9885e80 100644
--- a/mysql-test/t/ps_1general.test
+++ b/mysql-test/t/ps_1general.test
@@ -316,6 +316,7 @@ prepare stmt4 from ' show table status from test like ''t9%'' ';
--replace_column 8 # 12 # 13 # 14 #
# Bug#4288
execute stmt4;
+--replace_column 2 #
prepare stmt4 from ' show status like ''Threads_running'' ';
execute stmt4;
prepare stmt4 from ' show variables like ''sql_mode'' ';
diff --git a/mysql-test/t/rpl_sp.test b/mysql-test/t/rpl_sp.test
index 8be17be3822..7479794eded 100644
--- a/mysql-test/t/rpl_sp.test
+++ b/mysql-test/t/rpl_sp.test
@@ -435,6 +435,86 @@ connection master;
DROP PROCEDURE p1;
+
+#
+# BUG#20438: CREATE statements for views, stored routines and triggers can be
+# not replicable.
+#
+
+--echo
+--echo ---> Test for BUG#20438
+
+# Prepare environment.
+
+--echo
+--echo ---> Preparing environment...
+--echo ---> connection: master
+--connection master
+
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+--enable_warnings
+
+--echo
+--echo ---> Synchronizing slave with master...
+
+--save_master_pos
+--connection slave
+--sync_with_master
+
+--echo
+--echo ---> connection: master
+--connection master
+
+# Test.
+
+--echo
+--echo ---> Creating procedure...
+
+/*!50003 CREATE PROCEDURE p1() SET @a = 1 */;
+
+/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */;
+
+--echo
+--echo ---> Checking on master...
+
+SHOW CREATE PROCEDURE p1;
+SHOW CREATE FUNCTION f1;
+
+--echo
+--echo ---> Synchronizing slave with master...
+
+--save_master_pos
+--connection slave
+--sync_with_master
+
+--echo ---> connection: master
+
+--echo
+--echo ---> Checking on slave...
+
+SHOW CREATE PROCEDURE p1;
+SHOW CREATE FUNCTION f1;
+
+# Cleanup.
+
+--echo
+--echo ---> connection: master
+--connection master
+
+--echo
+--echo ---> Cleaning up...
+
+DROP PROCEDURE p1;
+DROP FUNCTION f1;
+
+--save_master_pos
+--connection slave
+--sync_with_master
+--connection master
+
+
# cleanup
connection master;
drop table t1;
diff --git a/mysql-test/t/rpl_trigger.test b/mysql-test/t/rpl_trigger.test
index 35f0a0b0a4b..3c8cbb97b31 100644
--- a/mysql-test/t/rpl_trigger.test
+++ b/mysql-test/t/rpl_trigger.test
@@ -331,6 +331,98 @@ SHOW TRIGGERS;
RESET MASTER;
+# Restart slave.
+
+connection slave;
+START SLAVE;
+
+
+#
+# BUG#20438: CREATE statements for views, stored routines and triggers can be
+# not replicable.
+#
+
+--echo
+--echo ---> Test for BUG#20438
+
+# Prepare environment.
+
+--echo
+--echo ---> Preparing environment...
+--echo ---> connection: master
+--connection master
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+--enable_warnings
+
+--echo
+--echo ---> Synchronizing slave with master...
+
+--save_master_pos
+--connection slave
+--sync_with_master
+
+--echo
+--echo ---> connection: master
+--connection master
+
+# Test.
+
+--echo
+--echo ---> Creating objects...
+
+CREATE TABLE t1(c INT);
+CREATE TABLE t2(c INT);
+
+/*!50003 CREATE TRIGGER t1_bi BEFORE INSERT ON t1
+ FOR EACH ROW
+ INSERT INTO t2 VALUES(NEW.c * 10) */;
+
+--echo
+--echo ---> Inserting value...
+
+INSERT INTO t1 VALUES(1);
+
+--echo
+--echo ---> Checking on master...
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+--echo
+--echo ---> Synchronizing slave with master...
+
+--save_master_pos
+--connection slave
+--sync_with_master
+
+--echo ---> connection: master
+
+--echo
+--echo ---> Checking on slave...
+
+SELECT * FROM t1;
+SELECT * FROM t2;
+
+# Cleanup.
+
+--echo
+--echo ---> connection: master
+--connection master
+
+--echo
+--echo ---> Cleaning up...
+
+DROP TABLE t1;
+DROP TABLE t2;
+
+--save_master_pos
+--connection slave
+--sync_with_master
+--connection master
+
#
# End of tests
diff --git a/mysql-test/t/rpl_view.test b/mysql-test/t/rpl_view.test
index 0a0c6a6dddb..d0990b4fbee 100644
--- a/mysql-test/t/rpl_view.test
+++ b/mysql-test/t/rpl_view.test
@@ -45,3 +45,87 @@ drop table t1;
sync_slave_with_master;
--replace_column 2 # 5 #
show binlog events limit 1,100;
+
+
+
+#
+# BUG#20438: CREATE statements for views, stored routines and triggers can be
+# not replicable.
+#
+
+--echo
+--echo ---> Test for BUG#20438
+
+# Prepare environment.
+
+--echo
+--echo ---> Preparing environment...
+--echo ---> connection: master
+--connection master
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP VIEW IF EXISTS v1;
+--enable_warnings
+
+--echo
+--echo ---> Synchronizing slave with master...
+
+--save_master_pos
+--connection slave
+--sync_with_master
+
+--echo
+--echo ---> connection: master
+--connection master
+
+# Test.
+
+--echo
+--echo ---> Creating objects...
+
+CREATE TABLE t1(c INT);
+
+/*!50003 CREATE VIEW v1 AS SELECT * FROM t1 */;
+
+--echo
+--echo ---> Inserting value...
+
+INSERT INTO t1 VALUES(1);
+
+--echo
+--echo ---> Checking on master...
+
+SELECT * FROM t1;
+
+--echo
+--echo ---> Synchronizing slave with master...
+
+--save_master_pos
+--connection slave
+--sync_with_master
+
+--echo ---> connection: master
+
+--echo
+--echo ---> Checking on slave...
+
+SELECT * FROM t1;
+
+# Cleanup.
+
+--echo
+--echo ---> connection: master
+--connection master
+
+--echo
+--echo ---> Cleaning up...
+
+DROP VIEW v1;
+DROP TABLE t1;
+
+--save_master_pos
+--connection slave
+--sync_with_master
+--connection master
+
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 592e366f835..197d89d02d5 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -2304,6 +2304,51 @@ INSERT INTO t1 VALUES (10);
SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1;
DROP TABLE t1;
+#
+# Bug #21019: First result of SELECT COUNT(*) different than consecutive runs
+#
+CREATE TABLE t1 (a int, b int);
+INSERT INTO t1 VALUES (1,1), (2,1), (4,10);
+
+CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b));
+INSERT INTO t2 VALUES (1,NULL), (2,10);
+ALTER TABLE t1 ENABLE KEYS;
+
+EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+EXPLAIN SELECT STRAIGHT_JOIN SQL_NO_CACHE COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+SELECT STRAIGHT_JOIN SQL_NO_CACHE * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
+DROP TABLE IF EXISTS t1,t2;
+#
+# Bug #20954 "avg(keyval) retuns 0.38 but max(keyval) returns an empty set"
+#
+--disable_ps_protocol
+CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1));
+CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2));
+INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941);
+INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941);
+
+explain select max(key1) from t1 where key1 <= 0.6158;
+explain select max(key2) from t2 where key2 <= 1.6158;
+explain select min(key1) from t1 where key1 >= 0.3762;
+explain select min(key2) from t2 where key2 >= 1.3762;
+explain select max(key1), min(key2) from t1, t2
+where key1 <= 0.6158 and key2 >= 1.3762;
+explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
+explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
+
+select max(key1) from t1 where key1 <= 0.6158;
+select max(key2) from t2 where key2 <= 1.6158;
+select min(key1) from t1 where key1 >= 0.3762;
+select min(key2) from t2 where key2 >= 1.3762;
+select max(key1), min(key2) from t1, t2
+where key1 <= 0.6158 and key2 >= 1.3762;
+select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
+select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
+
+DROP TABLE t1,t2;
+--enable_ps_protocol
+
# End of 4.1 tests
#
diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test
index 6937cbe949d..65a81545c87 100644
--- a/mysql-test/t/show_check.test
+++ b/mysql-test/t/show_check.test
@@ -495,4 +495,15 @@ SHOW CREATE VIEW v1;
DROP PROCEDURE p1;
DROP VIEW v1;
+
+#
+# Check that SHOW TABLES and SHOW COLUMNS give a error if there is no
+# referenced database and table respectively.
+#
+--error ER_BAD_DB_ERROR
+SHOW TABLES FROM no_such_database;
+--error ER_NO_SUCH_TABLE
+SHOW COLUMNS FROM no_such_table;
+
+
# End of 5.0 tests.
diff --git a/mysql-test/t/sp-code.test b/mysql-test/t/sp-code.test
index 0a26ea644f6..72efa831059 100644
--- a/mysql-test/t/sp-code.test
+++ b/mysql-test/t/sp-code.test
@@ -190,3 +190,25 @@ delimiter ;//
show procedure code sudoku_solve;
drop procedure sudoku_solve;
+
+
+#
+# Bug#19207: Final parenthesis omitted for CREATE INDEX in Stored
+# Procedure
+#
+# Wrong criteria was used to distinguish the case when there was no
+# lookahead performed in the parser. Bug affected only statements
+# ending in one-character token without any optional tail, like CREATE
+# INDEX and CALL.
+#
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+--enable_warnings
+
+CREATE PROCEDURE p1() CREATE INDEX idx ON t1 (c1);
+SHOW PROCEDURE CODE p1;
+
+DROP PROCEDURE p1;
+
+
+--echo End of 5.0 tests.
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index a4ab5d98922..2abb923efbb 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -1707,6 +1707,28 @@ create aggregate function bug16896() returns int return 1;
#
+# BUG#14702: misleading error message when syntax error in CREATE
+# PROCEDURE
+#
+# Misleading error message was given when IF NOT EXISTS was used in
+# CREATE PROCEDURE.
+#
+--disable_warnings
+DROP PROCEDURE IF EXISTS bug14702;
+--enable_warnings
+
+--error ER_PARSE_ERROR
+CREATE IF NOT EXISTS PROCEDURE bug14702()
+BEGIN
+END;
+
+--error ER_PARSE_ERROR
+CREATE PROCEDURE IF NOT EXISTS bug14702()
+BEGIN
+END;
+
+
+#
# BUG#NNNN: New bug synopsis
#
#--disable_warnings
diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test
index d323b180216..a5d509f29b7 100644
--- a/mysql-test/t/sp-security.test
+++ b/mysql-test/t/sp-security.test
@@ -790,4 +790,80 @@ SELECT Host,User,Password FROM mysql.user WHERE User='user19857';
DROP USER user19857@localhost;
-# End of 5.0 bugs.
+--disconnect con1root
+--connection default
+
+
+#
+# BUG#18630: Arguments of suid routine calculated in wrong security
+# context
+#
+# Arguments of suid routines were calculated in definer's security
+# context instead of caller's context thus creating security hole.
+#
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP VIEW IF EXISTS v1;
+DROP FUNCTION IF EXISTS f_suid;
+DROP PROCEDURE IF EXISTS p_suid;
+DROP FUNCTION IF EXISTS f_evil;
+--enable_warnings
+DELETE FROM mysql.user WHERE user LIKE 'mysqltest\_%';
+DELETE FROM mysql.db WHERE user LIKE 'mysqltest\_%';
+DELETE FROM mysql.tables_priv WHERE user LIKE 'mysqltest\_%';
+DELETE FROM mysql.columns_priv WHERE user LIKE 'mysqltest\_%';
+FLUSH PRIVILEGES;
+
+CREATE TABLE t1 (i INT);
+CREATE FUNCTION f_suid(i INT) RETURNS INT SQL SECURITY DEFINER RETURN 0;
+CREATE PROCEDURE p_suid(IN i INT) SQL SECURITY DEFINER SET @c:= 0;
+
+CREATE USER mysqltest_u1@localhost;
+# Thanks to this grant statement privileges of anonymous users on
+# 'test' database are not applicable for mysqltest_u1@localhost.
+GRANT EXECUTE ON test.* TO mysqltest_u1@localhost;
+
+delimiter |;
+CREATE DEFINER=mysqltest_u1@localhost FUNCTION f_evil () RETURNS INT
+ SQL SECURITY INVOKER
+BEGIN
+ SET @a:= CURRENT_USER();
+ SET @b:= (SELECT COUNT(*) FROM t1);
+ RETURN @b;
+END|
+delimiter ;|
+
+CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT f_evil();
+
+connect (conn1, localhost, mysqltest_u1,,);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+SELECT COUNT(*) FROM t1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+SELECT f_evil();
+SELECT @a, @b;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+SELECT f_suid(f_evil());
+SELECT @a, @b;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+CALL p_suid(f_evil());
+SELECT @a, @b;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+SELECT * FROM v1;
+SELECT @a, @b;
+
+disconnect conn1;
+connection default;
+
+DROP VIEW v1;
+DROP FUNCTION f_evil;
+DROP USER mysqltest_u1@localhost;
+DROP PROCEDURE p_suid;
+DROP FUNCTION f_suid;
+DROP TABLE t1;
+
+--echo End of 5.0 tests.
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 9a0003bab9c..ba30699b1d0 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -5962,7 +5962,208 @@ call bug15217()|
drop table t3|
drop procedure bug15217|
+
+#
+# BUG#21013: Performance Degrades when importing data that uses
+# Trigger and Stored Procedure
+#
+# This is a performance and memory leak test. Run with large number
+# passed to bug21013() procedure.
+#
+--disable_warnings
+DROP PROCEDURE IF EXISTS bug21013 |
+--enable_warnings
+
+CREATE PROCEDURE bug21013(IN lim INT)
+BEGIN
+ DECLARE i INT DEFAULT 0;
+ WHILE (i < lim) DO
+ SET @b = LOCATE(_latin1'b', @a, 1);
+ SET i = i + 1;
+ END WHILE;
+END |
+
+SET @a = _latin2"aaaaaaaaaa" |
+CALL bug21013(10) |
+
+DROP PROCEDURE bug21013 |
+
+
+#
+# BUG#16211: Stored function return type for strings is ignored
+#
+
+# Prepare: create database with fixed, pre-defined character set.
+
+--disable_warnings
+DROP DATABASE IF EXISTS mysqltest1|
+DROP DATABASE IF EXISTS mysqltest2|
+--enable_warnings
+
+CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8|
+CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET utf8|
+
+# Test case:
+
+use mysqltest1|
+
+# - Create two stored functions -- with and without explicit CHARSET-clause
+# for return value;
+
+CREATE FUNCTION bug16211_f1() RETURNS CHAR(10)
+ RETURN ""|
+
+CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET koi8r
+ RETURN ""|
+
+CREATE FUNCTION mysqltest2.bug16211_f3() RETURNS CHAR(10)
+ RETURN ""|
+
+CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET koi8r
+ RETURN ""|
+
+# - Check that CHARSET-clause is specified for the second function;
+
+SHOW CREATE FUNCTION bug16211_f1|
+SHOW CREATE FUNCTION bug16211_f2|
+
+SHOW CREATE FUNCTION mysqltest2.bug16211_f3|
+SHOW CREATE FUNCTION mysqltest2.bug16211_f4|
+
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"|
+
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"|
+
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"|
+
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"|
+
+SELECT CHARSET(bug16211_f1())|
+SELECT CHARSET(bug16211_f2())|
+
+SELECT CHARSET(mysqltest2.bug16211_f3())|
+SELECT CHARSET(mysqltest2.bug16211_f4())|
+
+# - Alter database character set.
+
+ALTER DATABASE mysqltest1 CHARACTER SET cp1251|
+ALTER DATABASE mysqltest2 CHARACTER SET cp1251|
+
+# - Check that CHARSET-clause has not changed.
+
+SHOW CREATE FUNCTION bug16211_f1|
+SHOW CREATE FUNCTION bug16211_f2|
+
+SHOW CREATE FUNCTION mysqltest2.bug16211_f3|
+SHOW CREATE FUNCTION mysqltest2.bug16211_f4|
+
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"|
+
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"|
+
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"|
+
+SELECT dtd_identifier
+FROM INFORMATION_SCHEMA.ROUTINES
+WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"|
+
+SELECT CHARSET(bug16211_f1())|
+SELECT CHARSET(bug16211_f2())|
+
+SELECT CHARSET(mysqltest2.bug16211_f3())|
+SELECT CHARSET(mysqltest2.bug16211_f4())|
+
+# Cleanup.
+
+use test|
+
+DROP DATABASE mysqltest1|
+DROP DATABASE mysqltest2|
+
+
+#
+# BUG#16676: Database CHARSET not used for stored procedures
#
+
+# Prepare: create database with fixed, pre-defined character set.
+
+--disable_warnings
+DROP DATABASE IF EXISTS mysqltest1|
+--enable_warnings
+
+CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8|
+
+# Test case:
+
+use mysqltest1|
+
+# - Create two stored procedures -- with and without explicit CHARSET-clause;
+
+CREATE PROCEDURE bug16676_p1(
+ IN p1 CHAR(10),
+ INOUT p2 CHAR(10),
+ OUT p3 CHAR(10))
+BEGIN
+ SELECT CHARSET(p1), COLLATION(p1);
+ SELECT CHARSET(p2), COLLATION(p2);
+ SELECT CHARSET(p3), COLLATION(p3);
+END|
+
+CREATE PROCEDURE bug16676_p2(
+ IN p1 CHAR(10) CHARSET koi8r,
+ INOUT p2 CHAR(10) CHARSET cp1251,
+ OUT p3 CHAR(10) CHARSET greek)
+BEGIN
+ SELECT CHARSET(p1), COLLATION(p1);
+ SELECT CHARSET(p2), COLLATION(p2);
+ SELECT CHARSET(p3), COLLATION(p3);
+END|
+
+# - Call procedures.
+
+SET @v2 = 'b'|
+SET @v3 = 'c'|
+
+CALL bug16676_p1('a', @v2, @v3)|
+CALL bug16676_p2('a', @v2, @v3)|
+
+# Cleanup.
+
+use test|
+
+DROP DATABASE mysqltest1|
+#
+# BUG#19862: Sort with filesort by function evaluates function twice
+#
+--disable_warnings
+drop procedure if exists bug19862|
+--enable_warnings
+CREATE TABLE t11 (a INT)|
+CREATE TABLE t12 (a INT)|
+CREATE FUNCTION bug19862(x INT) RETURNS INT
+ BEGIN
+ INSERT INTO t11 VALUES (x);
+ RETURN x+1;
+ END|
+INSERT INTO t12 VALUES (1), (2)|
+SELECT bug19862(a) FROM t12 ORDER BY 1|
+SELECT * FROM t11|
+DROP TABLE t11, t12|
+DROP FUNCTION bug19862|
# Bug#21002 "Derived table not selecting from a "real" table fails in JOINs"
#
# A regression caused by the fix for Bug#18444: for derived tables we should
diff --git a/mysql-test/t/sp.test.orig b/mysql-test/t/sp.test.orig
deleted file mode 100644
index a4b99620344..00000000000
--- a/mysql-test/t/sp.test.orig
+++ /dev/null
@@ -1,5716 +0,0 @@
-#
-# Basic stored PROCEDURE tests
-#
-# Please keep this file free of --error cases and other
-# things that will not run in a single debugged mysqld
-# process (e.g. master-slave things).
-#
-# Test cases for bugs are added at the end. See template there.
-#
-# Tests that require --error go into sp-error.test
-# Tests that require inndb go into sp_trans.test
-# Tests that check privilege and security issues go to sp-security.test.
-# Tests that require multiple connections, except security/privilege tests,
-# go to sp-thread.
-# Tests that uses 'goto' to into sp-goto.test (currently disabled)
-# Tests that destroys system tables (e.g. mysql.proc) for error testing
-# go to sp-destruct.
-
-use test;
-
-# Test tables
-#
-# t1 and t2 are reused throughout the file, and dropped at the end.
-# t3 and up are created and dropped when needed.
-#
---disable_warnings
-drop table if exists t1,t2,t3,t4;
---enable_warnings
-create table t1 (
- id char(16) not null default '',
- data int not null
-);
-create table t2 (
- s char(16),
- i int,
- d double
-);
-
-
-# Single statement, no params.
---disable_warnings
-drop procedure if exists foo42;
---enable_warnings
-create procedure foo42()
- insert into test.t1 values ("foo", 42);
-
-call foo42();
-select * from t1;
-delete from t1;
-drop procedure foo42;
-
-
-# Single statement, two IN params.
---disable_warnings
-drop procedure if exists bar;
---enable_warnings
-create procedure bar(x char(16), y int)
- insert into test.t1 values (x, y);
-
-call bar("bar", 666);
-select * from t1;
-delete from t1;
-# Don't drop procedure yet...
-
-
-# Now for multiple statements...
-delimiter |;
-
-# Empty statement
---disable_warnings
-drop procedure if exists empty|
---enable_warnings
-create procedure empty()
-begin
-end|
-
-call empty()|
-drop procedure empty|
-
-# Scope test. This is legal (warnings might be possible in the future,
-# but for the time being, we just accept it).
---disable_warnings
-drop procedure if exists scope|
---enable_warnings
-create procedure scope(a int, b float)
-begin
- declare b int;
- declare c float;
-
- begin
- declare c int;
- end;
-end|
-
-drop procedure scope|
-
-# Two statements.
---disable_warnings
-drop procedure if exists two|
---enable_warnings
-create procedure two(x1 char(16), x2 char(16), y int)
-begin
- insert into test.t1 values (x1, y);
- insert into test.t1 values (x2, y);
-end|
-
-call two("one", "two", 3)|
-select * from t1|
-delete from t1|
-drop procedure two|
-
-
-# Simple test of local variables and SET.
---disable_warnings
-drop procedure if exists locset|
---enable_warnings
-create procedure locset(x char(16), y int)
-begin
- declare z1, z2 int;
- set z1 = y;
- set z2 = z1+2;
- insert into test.t1 values (x, z2);
-end|
-
-call locset("locset", 19)|
-select * from t1|
-delete from t1|
-drop procedure locset|
-
-
-# In some contexts local variables are not recognized
-# (and in some, you have to qualify the identifier).
---disable_warnings
-drop procedure if exists setcontext|
---enable_warnings
-create procedure setcontext()
-begin
- declare data int default 2;
-
- insert into t1 (id, data) values ("foo", 1);
- replace t1 set data = data, id = "bar";
- update t1 set id = "kaka", data = 3 where t1.data = data;
-end|
-
-call setcontext()|
-select * from t1|
-delete from t1|
-drop procedure setcontext|
-
-
-# Set things to null
-create table t3 ( d date, i int, f double, s varchar(32) )|
-
---disable_warnings
-drop procedure if exists nullset|
---enable_warnings
-create procedure nullset()
-begin
- declare ld date;
- declare li int;
- declare lf double;
- declare ls varchar(32);
-
- set ld = null, li = null, lf = null, ls = null;
- insert into t3 values (ld, li, lf, ls);
-
- insert into t3 (i, f, s) values ((ld is null), 1, "ld is null"),
- ((li is null), 1, "li is null"),
- ((li = 0), null, "li = 0"),
- ((lf is null), 1, "lf is null"),
- ((lf = 0), null, "lf = 0"),
- ((ls is null), 1, "ls is null");
-end|
-
-call nullset()|
-select * from t3|
-drop table t3|
-drop procedure nullset|
-
-
-# The peculiar (non-standard) mixture of variables types in SET.
---disable_warnings
-drop procedure if exists mixset|
---enable_warnings
-create procedure mixset(x char(16), y int)
-begin
- declare z int;
-
- set @z = y, z = 666, max_join_size = 100;
- insert into test.t1 values (x, z);
-end|
-
-call mixset("mixset", 19)|
-show variables like 'max_join_size'|
-select id,data,@z from t1|
-delete from t1|
-drop procedure mixset|
-
-
-# Multiple CALL statements, one with OUT parameter.
---disable_warnings
-drop procedure if exists zip|
---enable_warnings
-create procedure zip(x char(16), y int)
-begin
- declare z int;
- call zap(y, z);
- call bar(x, z);
-end|
-
-# SET local variables and OUT parameter.
---disable_warnings
-drop procedure if exists zap|
---enable_warnings
-create procedure zap(x int, out y int)
-begin
- declare z int;
- set z = x+1, y = z;
-end|
-
-call zip("zip", 99)|
-select * from t1|
-delete from t1|
-drop procedure zip|
-drop procedure bar|
-
-# Top-level OUT parameter
-call zap(7, @zap)|
-select @zap|
-
-drop procedure zap|
-
-
-# "Deep" calls...
---disable_warnings
-drop procedure if exists c1|
---enable_warnings
-create procedure c1(x int)
- call c2("c", x)|
---disable_warnings
-drop procedure if exists c2|
---enable_warnings
-create procedure c2(s char(16), x int)
- call c3(x, s)|
---disable_warnings
-drop procedure if exists c3|
---enable_warnings
-create procedure c3(x int, s char(16))
- call c4("level", x, s)|
---disable_warnings
-drop procedure if exists c4|
---enable_warnings
-create procedure c4(l char(8), x int, s char(16))
- insert into t1 values (concat(l,s), x)|
-
-call c1(42)|
-select * from t1|
-delete from t1|
-drop procedure c1|
-drop procedure c2|
-drop procedure c3|
-drop procedure c4|
-
-# INOUT test
---disable_warnings
-drop procedure if exists iotest|
---enable_warnings
-create procedure iotest(x1 char(16), x2 char(16), y int)
-begin
- call inc2(x2, y);
- insert into test.t1 values (x1, y);
-end|
-
---disable_warnings
-drop procedure if exists inc2|
---enable_warnings
-create procedure inc2(x char(16), y int)
-begin
- call inc(y);
- insert into test.t1 values (x, y);
-end|
-
---disable_warnings
-drop procedure if exists inc|
---enable_warnings
-create procedure inc(inout io int)
- set io = io + 1|
-
-call iotest("io1", "io2", 1)|
-select * from t1|
-delete from t1|
-drop procedure iotest|
-drop procedure inc2|
-
-# Propagating top-level @-vars
---disable_warnings
-drop procedure if exists incr|
---enable_warnings
-create procedure incr(inout x int)
- call inc(x)|
-
-# Before
-select @zap|
-call incr(@zap)|
-# After
-select @zap|
-
-drop procedure inc|
-drop procedure incr|
-
-# Call-by-value test
-# The expected result is:
-# ("cbv2", 4)
-# ("cbv1", 4711)
---disable_warnings
-drop procedure if exists cbv1|
---enable_warnings
-create procedure cbv1()
-begin
- declare y int default 3;
-
- call cbv2(y+1, y);
- insert into test.t1 values ("cbv1", y);
-end|
-
---disable_warnings
-drop procedure if exists cbv2|
---enable_warnings
-create procedure cbv2(y1 int, inout y2 int)
-begin
- set y2 = 4711;
- insert into test.t1 values ("cbv2", y1);
-end|
-
-call cbv1()|
-select * from t1|
-delete from t1|
-drop procedure cbv1|
-drop procedure cbv2|
-
-
-# Subselect arguments
-
-insert into t2 values ("a", 1, 1.1), ("b", 2, 1.2), ("c", 3, 1.3)|
-
---disable_warnings
-drop procedure if exists sub1|
---enable_warnings
-create procedure sub1(id char(16), x int)
- insert into test.t1 values (id, x)|
-
---disable_warnings
-drop procedure if exists sub2|
---enable_warnings
-create procedure sub2(id char(16))
-begin
- declare x int;
- set x = (select sum(t.i) from test.t2 t);
- insert into test.t1 values (id, x);
-end|
-
---disable_warnings
-drop procedure if exists sub3|
---enable_warnings
-create function sub3(i int) returns int
- return i+1|
-
-call sub1("sub1a", (select 7))|
-call sub1("sub1b", (select max(i) from t2))|
---error ER_OPERAND_COLUMNS
-call sub1("sub1c", (select i,d from t2 limit 1))|
-call sub1("sub1d", (select 1 from (select 1) a))|
-call sub2("sub2")|
-select * from t1|
-select sub3((select max(i) from t2))|
-drop procedure sub1|
-drop procedure sub2|
-drop function sub3|
-delete from t1|
-delete from t2|
-
-# Basic tests of the flow control constructs
-
-# Just test on 'x'...
---disable_warnings
-drop procedure if exists a0|
---enable_warnings
-create procedure a0(x int)
-while x do
- set x = x-1;
- insert into test.t1 values ("a0", x);
-end while|
-
-call a0(3)|
-select * from t1|
-delete from t1|
-drop procedure a0|
-
-
-# The same, but with a more traditional test.
---disable_warnings
-drop procedure if exists a|
---enable_warnings
-create procedure a(x int)
-while x > 0 do
- set x = x-1;
- insert into test.t1 values ("a", x);
-end while|
-
-call a(3)|
-select * from t1|
-delete from t1|
-drop procedure a|
-
-
-# REPEAT
---disable_warnings
-drop procedure if exists b|
---enable_warnings
-create procedure b(x int)
-repeat
- insert into test.t1 values (repeat("b",3), x);
- set x = x-1;
-until x = 0 end repeat|
-
-call b(3)|
-select * from t1|
-delete from t1|
-drop procedure b|
-
-
-# Check that repeat isn't parsed the wrong way
---disable_warnings
-drop procedure if exists b2|
---enable_warnings
-create procedure b2(x int)
-repeat(select 1 into outfile 'b2');
- insert into test.t1 values (repeat("b2",3), x);
- set x = x-1;
-until x = 0 end repeat|
-
-# We don't actually want to call it.
-drop procedure b2|
-
-
-# Labelled WHILE with ITERATE (pointless really)
---disable_warnings
-drop procedure if exists c|
---enable_warnings
-create procedure c(x int)
-hmm: while x > 0 do
- insert into test.t1 values ("c", x);
- set x = x-1;
- iterate hmm;
- insert into test.t1 values ("x", x);
-end while hmm|
-
-call c(3)|
-select * from t1|
-delete from t1|
-drop procedure c|
-
-
-# Labelled WHILE with LEAVE
---disable_warnings
-drop procedure if exists d|
---enable_warnings
-create procedure d(x int)
-hmm: while x > 0 do
- insert into test.t1 values ("d", x);
- set x = x-1;
- leave hmm;
- insert into test.t1 values ("x", x);
-end while|
-
-call d(3)|
-select * from t1|
-delete from t1|
-drop procedure d|
-
-
-# LOOP, with simple IF statement
---disable_warnings
-drop procedure if exists e|
---enable_warnings
-create procedure e(x int)
-foo: loop
- if x = 0 then
- leave foo;
- end if;
- insert into test.t1 values ("e", x);
- set x = x-1;
-end loop foo|
-
-call e(3)|
-select * from t1|
-delete from t1|
-drop procedure e|
-
-
-# A full IF statement
---disable_warnings
-drop procedure if exists f|
---enable_warnings
-create procedure f(x int)
-if x < 0 then
- insert into test.t1 values ("f", 0);
-elseif x = 0 then
- insert into test.t1 values ("f", 1);
-else
- insert into test.t1 values ("f", 2);
-end if|
-
-call f(-2)|
-call f(0)|
-call f(4)|
-select * from t1|
-delete from t1|
-drop procedure f|
-
-
-# This form of CASE is really just syntactic sugar for IF-ELSEIF-...
---disable_warnings
-drop procedure if exists g|
---enable_warnings
-create procedure g(x int)
-case
-when x < 0 then
- insert into test.t1 values ("g", 0);
-when x = 0 then
- insert into test.t1 values ("g", 1);
-else
- insert into test.t1 values ("g", 2);
-end case|
-
-call g(-42)|
-call g(0)|
-call g(1)|
-select * from t1|
-delete from t1|
-drop procedure g|
-
-
-# The "simple CASE"
---disable_warnings
-drop procedure if exists h|
---enable_warnings
-create procedure h(x int)
-case x
-when 0 then
- insert into test.t1 values ("h0", x);
-when 1 then
- insert into test.t1 values ("h1", x);
-else
- insert into test.t1 values ("h?", x);
-end case|
-
-call h(0)|
-call h(1)|
-call h(17)|
-select * from t1|
-delete from t1|
-drop procedure h|
-
-
-# It's actually possible to LEAVE a BEGIN-END block
---disable_warnings
-drop procedure if exists i|
---enable_warnings
-create procedure i(x int)
-foo:
-begin
- if x = 0 then
- leave foo;
- end if;
- insert into test.t1 values ("i", x);
-end foo|
-
-call i(0)|
-call i(3)|
-select * from t1|
-delete from t1|
-drop procedure i|
-
-
-# SELECT with one of more result set sent back to the clinet
-insert into t1 values ("foo", 3), ("bar", 19)|
-insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)|
-
---disable_warnings
-drop procedure if exists sel1|
---enable_warnings
-create procedure sel1()
-begin
- select * from t1;
-end|
-
-call sel1()|
-drop procedure sel1|
-
---disable_warnings
-drop procedure if exists sel2|
---enable_warnings
-create procedure sel2()
-begin
- select * from t1;
- select * from t2;
-end|
-
-call sel2()|
-drop procedure sel2|
-delete from t1|
-delete from t2|
-
-# SELECT INTO local variables
---disable_warnings
-drop procedure if exists into_test|
---enable_warnings
-create procedure into_test(x char(16), y int)
-begin
- insert into test.t1 values (x, y);
- select id,data into x,y from test.t1 limit 1;
- insert into test.t1 values (concat(x, "2"), y+2);
-end|
-
-call into_test("into", 100)|
-select * from t1|
-delete from t1|
-drop procedure into_test|
-
-
-# SELECT INTO with a mix of local and global variables
---disable_warnings
-drop procedure if exists into_tes2|
---enable_warnings
-create procedure into_test2(x char(16), y int)
-begin
- insert into test.t1 values (x, y);
- select id,data into x,@z from test.t1 limit 1;
- insert into test.t1 values (concat(x, "2"), y+2);
-end|
-
-call into_test2("into", 100)|
-select id,data,@z from t1|
-delete from t1|
-drop procedure into_test2|
-
-
-# SELECT * INTO ... (bug test)
---disable_warnings
-drop procedure if exists into_test3|
---enable_warnings
-create procedure into_test3()
-begin
- declare x char(16);
- declare y int;
-
- select * into x,y from test.t1 limit 1;
- insert into test.t2 values (x, y, 0.0);
-end|
-
-insert into t1 values ("into3", 19)|
-# Two call needed for bug test
-call into_test3()|
-call into_test3()|
-select * from t2|
-delete from t1|
-delete from t2|
-drop procedure into_test3|
-
-
-# SELECT INTO with no data is a warning ("no data", which we will
-# not see normally). When not caught, execution proceeds.
---disable_warnings
-drop procedure if exists into_test4|
---enable_warnings
-create procedure into_test4()
-begin
- declare x int;
-
- select data into x from test.t1 limit 1;
- insert into test.t3 values ("into4", x);
-end|
-
-delete from t1|
-create table t3 ( s char(16), d int)|
-call into_test4()|
-select * from t3|
-insert into t1 values ("i4", 77)|
-call into_test4()|
-select * from t3|
-delete from t1|
-drop table t3|
-drop procedure into_test4|
-
-
-# These two (and the two procedures above) caused an assert() to fail in
-# sql_base.cc:lock_tables() at some point.
---disable_warnings
-drop procedure if exists into_outfile|
---enable_warnings
-create procedure into_outfile(x char(16), y int)
-begin
- insert into test.t1 values (x, y);
- select * into outfile "../tmp/spout" from test.t1;
- insert into test.t1 values (concat(x, "2"), y+2);
-end|
-
---system rm -f $MYSQLTEST_VARDIR/tmp/spout
-call into_outfile("ofile", 1)|
---system rm -f $MYSQLTEST_VARDIR/tmp/spout
-delete from t1|
-drop procedure into_outfile|
-
---disable_warnings
-drop procedure if exists into_dumpfile|
---enable_warnings
-create procedure into_dumpfile(x char(16), y int)
-begin
- insert into test.t1 values (x, y);
- select * into dumpfile "../tmp/spdump" from test.t1 limit 1;
- insert into test.t1 values (concat(x, "2"), y+2);
-end|
-
---system rm -f $MYSQLTEST_VARDIR/tmp/spdump
-call into_dumpfile("dfile", 1)|
---system rm -f $MYSQLTEST_VARDIR/tmp/spdump
-delete from t1|
-drop procedure into_dumpfile|
-
---disable_warnings
-drop procedure if exists create_select|
---enable_warnings
-create procedure create_select(x char(16), y int)
-begin
- insert into test.t1 values (x, y);
- create temporary table test.t3 select * from test.t1;
- insert into test.t3 values (concat(x, "2"), y+2);
-end|
-
-call create_select("cs", 90)|
-select * from t1, t3|
-drop table t3|
-delete from t1|
-drop procedure create_select|
-
-
-# A minimal, constant FUNCTION.
---disable_warnings
-drop function if exists e|
---enable_warnings
-create function e() returns double
- return 2.7182818284590452354|
-
-set @e = e()|
-select e(), @e|
-
-# A minimal function with one argument
---disable_warnings
-drop function if exists inc|
---enable_warnings
-create function inc(i int) returns int
- return i+1|
-
-select inc(1), inc(99), inc(-71)|
-
-# A minimal function with two arguments
---disable_warnings
-drop function if exists mul|
---enable_warnings
-create function mul(x int, y int) returns int
- return x*y|
-
-select mul(1,1), mul(3,5), mul(4711, 666)|
-
-# A minimal string function
---disable_warnings
-drop function if exists append|
---enable_warnings
-create function append(s1 char(8), s2 char(8)) returns char(16)
- return concat(s1, s2)|
-
-select append("foo", "bar")|
-
-# A function with flow control
---disable_warnings
-drop function if exists fac|
---enable_warnings
-create function fac(n int unsigned) returns bigint unsigned
-begin
- declare f bigint unsigned default 1;
-
- while n > 1 do
- set f = f * n;
- set n = n - 1;
- end while;
- return f;
-end|
-
-select fac(1), fac(2), fac(5), fac(10)|
-
-# Nested calls
---disable_warnings
-drop function if exists fun|
---enable_warnings
-create function fun(d double, i int, u int unsigned) returns double
- return mul(inc(i), fac(u)) / e()|
-
-select fun(2.3, 3, 5)|
-
-
-# Various function calls in differen statements
-
-insert into t2 values (append("xxx", "yyy"), mul(4,3), e())|
-insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))|
-
-# Disable PS because double's give a bit different values
---disable_ps_protocol
-select * from t2 where s = append("a", "b")|
-select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2)|
-select * from t2 where d = e()|
-select * from t2|
---enable_ps_protocol
-delete from t2|
-
-drop function e|
-drop function inc|
-drop function mul|
-drop function append|
-drop function fun|
-
-
-#
-# CONDITIONs and HANDLERs
-#
-
---disable_warnings
-drop procedure if exists hndlr1|
---enable_warnings
-create procedure hndlr1(val int)
-begin
- declare x int default 0;
- declare foo condition for 1136;
- declare bar condition for sqlstate '42S98'; # Just for testing syntax
- declare zip condition for sqlstate value '42S99'; # Just for testing syntax
- declare continue handler for foo set x = 1;
-
- insert into test.t1 values ("hndlr1", val, 2); # Too many values
- if (x) then
- insert into test.t1 values ("hndlr1", val); # This instead then
- end if;
-end|
-
-call hndlr1(42)|
-select * from t1|
-delete from t1|
-drop procedure hndlr1|
-
---disable_warnings
-drop procedure if exists hndlr2|
---enable_warnings
-create procedure hndlr2(val int)
-begin
- declare x int default 0;
-
- begin
- declare exit handler for sqlstate '21S01' set x = 1;
-
- insert into test.t1 values ("hndlr2", val, 2); # Too many values
- end;
-
- insert into test.t1 values ("hndlr2", x);
-end|
-
-call hndlr2(42)|
-select * from t1|
-delete from t1|
-drop procedure hndlr2|
-
-
---disable_warnings
-drop procedure if exists hndlr3|
---enable_warnings
-create procedure hndlr3(val int)
-begin
- declare x int default 0;
- declare continue handler for sqlexception # Any error
- begin
- declare z int;
-
- set z = 2 * val;
- set x = 1;
- end;
-
- if val < 10 then
- begin
- declare y int;
-
- set y = val + 10;
- insert into test.t1 values ("hndlr3", y, 2); # Too many values
- if x then
- insert into test.t1 values ("hndlr3", y);
- end if;
- end;
- end if;
-end|
-
-call hndlr3(3)|
-select * from t1|
-delete from t1|
-drop procedure hndlr3|
-
-
-# Variables might be uninitialized when using handlers
-# (Otherwise the compiler can detect if a variable is not set, but
-# not in this case.)
-create table t3 ( id char(16), data int )|
-
---disable_warnings
-drop procedure if exists hndlr4|
---enable_warnings
-create procedure hndlr4()
-begin
- declare x int default 0;
- declare val int; # No default
- declare continue handler for sqlstate '02000' set x=1;
-
- select data into val from test.t3 where id='z' limit 1; # No hits
-
- insert into test.t3 values ('z', val);
-end|
-
-call hndlr4()|
-select * from t3|
-drop table t3|
-drop procedure hndlr4|
-
-
-#
-# Cursors
-#
---disable_warnings
-drop procedure if exists cur1|
---enable_warnings
-create procedure cur1()
-begin
- declare a char(16);
- declare b int;
- declare c double;
- declare done int default 0;
- declare c cursor for select * from test.t2;
- declare continue handler for sqlstate '02000' set done = 1;
-
- open c;
- repeat
- fetch c into a, b, c;
- if not done then
- insert into test.t1 values (a, b+c);
- end if;
- until done end repeat;
- close c;
-end|
-
-insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)|
-call cur1()|
-select * from t1|
-drop procedure cur1|
-
-create table t3 ( s char(16), i int )|
-
---disable_warnings
-drop procedure if exists cur2|
---enable_warnings
-create procedure cur2()
-begin
- declare done int default 0;
- declare c1 cursor for select id,data from test.t1;
- declare c2 cursor for select i from test.t2;
- declare continue handler for sqlstate '02000' set done = 1;
-
- open c1;
- open c2;
- repeat
- begin
- declare a char(16);
- declare b,c int;
-
- fetch from c1 into a, b;
- fetch next from c2 into c;
- if not done then
- if b < c then
- insert into test.t3 values (a, b);
- else
- insert into test.t3 values (a, c);
- end if;
- end if;
- end;
- until done end repeat;
- close c1;
- close c2;
-end|
-
-call cur2()|
-select * from t3|
-delete from t1|
-delete from t2|
-drop table t3|
-drop procedure cur2|
-
-
-# The few characteristics we parse
---disable_warnings
-drop procedure if exists chistics|
---enable_warnings
-create procedure chistics()
- language sql
- modifies sql data
- not deterministic
- sql security definer
- comment 'Characteristics procedure test'
- insert into t1 values ("chistics", 1)|
-
-show create procedure chistics|
-# Call it, just to make sure.
-call chistics()|
-select * from t1|
-delete from t1|
-alter procedure chistics sql security invoker|
-show create procedure chistics|
-drop procedure chistics|
-
---disable_warnings
-drop function if exists chistics|
---enable_warnings
-create function chistics() returns int
- language sql
- deterministic
- sql security invoker
- comment 'Characteristics procedure test'
- return 42|
-
-show create function chistics|
-# Call it, just to make sure.
-select chistics()|
-alter function chistics
- no sql
- comment 'Characteristics function test'|
-show create function chistics|
-drop function chistics|
-
-
-# Check mode settings
-insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)|
-
-set @@sql_mode = 'ANSI'|
-delimiter $|
---disable_warnings
-drop procedure if exists modes$
---enable_warnings
-create procedure modes(out c1 int, out c2 int)
-begin
- declare done int default 0;
- declare x int;
- declare c cursor for select data from t1;
- declare continue handler for sqlstate '02000' set done = 1;
-
- select 1 || 2 into c1;
- set c2 = 0;
- open c;
- repeat
- fetch c into x;
- if not done then
- set c2 = c2 + 1;
- end if;
- until done end repeat;
- close c;
-end$
-delimiter |$
-set @@sql_mode = ''|
-
-set sql_select_limit = 1|
-call modes(@c1, @c2)|
-set sql_select_limit = default|
-
-select @c1, @c2|
-delete from t1|
-drop procedure modes|
-
-
-# Check that dropping a database without routines works.
-# (Dropping with routines is tested in sp-security.test)
-# First an empty db.
-create database sp_db1|
-drop database sp_db1|
-
-# Again, with a table.
-create database sp_db2|
-use sp_db2|
-# Just put something in here...
-create table t3 ( s char(4), t int )|
-insert into t3 values ("abcd", 42), ("dcba", 666)|
-use test|
-drop database sp_db2|
-
-# And yet again, with just a procedure.
-create database sp_db3|
-use sp_db3|
---disable_warnings
-drop procedure if exists dummy|
---enable_warnings
-create procedure dummy(out x int)
- set x = 42|
-use test|
-drop database sp_db3|
-# Check that it's gone
-select type,db,name from mysql.proc where db = 'sp_db3'|
-
-
-# ROW_COUNT() function after a CALL
-# We test the other cases here too, although it's not strictly SP specific
---disable_warnings
-drop procedure if exists rc|
---enable_warnings
-create procedure rc()
-begin
- delete from t1;
- insert into t1 values ("a", 1), ("b", 2), ("c", 3);
-end|
-
-call rc()|
-select row_count()|
---disable_ps_protocol
-update t1 set data=42 where id = "b";
-select row_count()|
---enable_ps_protocol
-delete from t1|
-select row_count()|
-delete from t1|
-select row_count()|
-select * from t1|
-select row_count()|
-drop procedure rc|
-
-
-#
-# Let us test how well new locking scheme works.
-#
-
-# Let us prepare playground
---disable_warnings
-drop function if exists f0|
-drop function if exists f1|
-drop function if exists f2|
-drop function if exists f3|
-drop function if exists f4|
-drop function if exists f5|
-drop function if exists f6|
-drop function if exists f7|
-drop function if exists f8|
-drop function if exists f9|
-drop function if exists f10|
-drop function if exists f11|
-drop function if exists f12_1|
-drop function if exists f12_2|
-drop view if exists v0|
-drop view if exists v1|
-drop view if exists v2|
---enable_warnings
-delete from t1|
-delete from t2|
-insert into t1 values ("a", 1), ("b", 2) |
-insert into t2 values ("a", 1, 1.0), ("b", 2, 2.0), ("c", 3, 3.0) |
-
-# Test the simplest function using tables
-create function f1() returns int
- return (select sum(data) from t1)|
-select f1()|
-# This should work too (and give 2 rows as result)
-select id, f1() from t1|
-
-# Function which uses two instances of table simultaneously
-create function f2() returns int
- return (select data from t1 where data <= (select sum(data) from t1) limit 1)|
-select f2()|
-select id, f2() from t1|
-
-# Function which uses the same table twice in different queries
-create function f3() returns int
-begin
- declare n int;
- declare m int;
- set n:= (select min(data) from t1);
- set m:= (select max(data) from t1);
- return n < m;
-end|
-select f3()|
-select id, f3() from t1|
-
-# Calling two functions using same table
-select f1(), f3()|
-select id, f1(), f3() from t1|
-
-# Function which uses two different tables
-create function f4() returns double
- return (select d from t1, t2 where t1.data = t2.i and t1.id= "b")|
-select f4()|
-select s, f4() from t2|
-
-# Recursive functions which due to this recursion require simultaneous
-# access to several instance of the same table won't work
-create function f5(i int) returns int
-begin
- if i <= 0 then
- return 0;
- elseif i = 1 then
- return (select count(*) from t1 where data = i);
- else
- return (select count(*) + f5( i - 1) from t1 where data = i);
- end if;
-end|
-select f5(1)|
-# Since currently recursive functions are disallowed ER_SP_NO_RECURSION
-# error will be returned, once we will allow them error about
-# insufficient number of locked tables will be returned instead.
---error ER_SP_NO_RECURSION
-select f5(2)|
---error ER_SP_NO_RECURSION
-select f5(3)|
-
-# OTOH this should work
-create function f6() returns int
-begin
- declare n int;
- set n:= f1();
- return (select count(*) from t1 where data <= f7() and data <= n);
-end|
-create function f7() returns int
- return (select sum(data) from t1 where data <= f1())|
-select f6()|
-select id, f6() from t1|
-
-#
-# Let us test how new locking work with views
-#
-# The most trivial view
-create view v1 (a) as select f1()|
-select * from v1|
-select id, a from t1, v1|
-select * from v1, v1 as v|
-# A bit more complex construction
-create view v2 (a) as select a*10 from v1|
-select * from v2|
-select id, a from t1, v2|
-select * from v1, v2|
-
-# Nice example where the same view is used on
-# on different expression levels
-create function f8 () returns int
- return (select count(*) from v2)|
-
-select *, f8() from v1|
-
-# Let us test what will happen if function is missing
-drop function f1|
---error 1356
-select * from v1|
-
-# And what will happen if we have recursion which involves
-# views and functions ?
-create function f1() returns int
- return (select sum(data) from t1) + (select sum(data) from v1)|
---error ER_SP_NO_RECURSION
-select f1()|
---error ER_SP_NO_RECURSION
-select * from v1|
---error ER_SP_NO_RECURSION
-select * from v2|
-# Back to the normal cases
-drop function f1|
-create function f1() returns int
- return (select sum(data) from t1)|
-
-# Let us also test some weird cases where no real tables is used
-create function f0() returns int
- return (select * from (select 100) as r)|
-select f0()|
-select *, f0() from (select 1) as t|
-create view v0 as select f0()|
-select * from v0|
-select *, f0() from v0|
-
-#
-# Let us test how well prelocking works with explicit LOCK TABLES.
-#
-lock tables t1 read, t1 as t11 read|
-# These should work well
-select f3()|
-select id, f3() from t1 as t11|
-# Degenerate cases work too :)
-select f0()|
-select * from v0|
-select *, f0() from v0, (select 123) as d1|
-# But these should not !
---error 1100
-select id, f3() from t1|
---error 1100
-select f4()|
-unlock tables|
-
-# Let us test how LOCK TABLES which implicitly depends on functions
-# works
-lock tables v2 read, mysql.proc read|
-select * from v2|
-select * from v1|
-# These should not work as we have too little instances of tables locked
---error 1100
-select * from v1, t1|
---error 1100
-select f4()|
-unlock tables|
-
-# Tests for handling of temporary tables in functions.
-#
-# Unlike for permanent tables we should be able to create, use
-# and drop such tables in functions.
-#
-# Simplest function using temporary table. It is also test case for bug
-# #12198 "Temporary table aliasing does not work inside stored functions"
-create function f9() returns int
-begin
- declare a, b int;
- drop temporary table if exists t3;
- create temporary table t3 (id int);
- insert into t3 values (1), (2), (3);
- set a:= (select count(*) from t3);
- set b:= (select count(*) from t3 t3_alias);
- return a + b;
-end|
-# This will emit warning as t3 was not existing before.
-select f9()|
-select f9() from t1 limit 1|
-
-# Function which uses both temporary and permanent tables.
-create function f10() returns int
-begin
- drop temporary table if exists t3;
- create temporary table t3 (id int);
- insert into t3 select id from t4;
- return (select count(*) from t3);
-end|
-# Check that we don't ignore completely tables used in function
---error ER_NO_SUCH_TABLE
-select f10()|
-create table t4 as select 1 as id|
-select f10()|
-
-# Practical cases which we don't handle well (yet)
-#
-# Function which does not work because of well-known and documented
-# limitation of MySQL. We can't use the several instances of the
-# same temporary table in statement.
-create function f11() returns int
-begin
- drop temporary table if exists t3;
- create temporary table t3 (id int);
- insert into t3 values (1), (2), (3);
- return (select count(*) from t3 as a, t3 as b);
-end|
---error ER_CANT_REOPEN_TABLE
-select f11()|
---error ER_CANT_REOPEN_TABLE
-select f11() from t1|
-# We don't handle temporary tables used by nested functions well
-create function f12_1() returns int
-begin
- drop temporary table if exists t3;
- create temporary table t3 (id int);
- insert into t3 values (1), (2), (3);
- return f12_2();
-end|
-create function f12_2() returns int
- return (select count(*) from t3)|
-# We need clean start to get error
-drop temporary table t3|
---error ER_NO_SUCH_TABLE
-select f12_1()|
---error ER_NO_SUCH_TABLE
-select f12_1() from t1 limit 1|
-
-# Cleanup
-drop function f0|
-drop function f1|
-drop function f2|
-drop function f3|
-drop function f4|
-drop function f5|
-drop function f6|
-drop function f7|
-drop function f8|
-drop function f9|
-drop function f10|
-drop function f11|
-drop function f12_1|
-drop function f12_2|
-drop view v0|
-drop view v1|
-drop view v2|
-delete from t1 |
-delete from t2 |
-drop table t4|
-
-# End of non-bug tests
-
-
-#
-# Some "real" examples
-#
-
-# fac
-
---disable_warnings
-drop table if exists t3|
---enable_warnings
-create table t3 (n int unsigned not null primary key, f bigint unsigned)|
-
---disable_warnings
-drop procedure if exists ifac|
---enable_warnings
-create procedure ifac(n int unsigned)
-begin
- declare i int unsigned default 1;
-
- if n > 20 then
- set n = 20; # bigint overflow otherwise
- end if;
- while i <= n do
- begin
- insert into test.t3 values (i, fac(i));
- set i = i + 1;
- end;
- end while;
-end|
-
-call ifac(20)|
-select * from t3|
-drop table t3|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
-show function status like '%f%'|
-drop procedure ifac|
-drop function fac|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
-show function status like '%f%'|
-
-
-# primes
-
---disable_warnings
-drop table if exists t3|
---enable_warnings
-
-create table t3 (
- i int unsigned not null primary key,
- p bigint unsigned not null
-)|
-
-insert into t3 values
- ( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13),
- ( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31),
- (10, 37), (11, 41), (12, 43), (13, 47), (14, 53),
- (15, 59), (16, 61), (17, 67), (18, 71), (19, 73),
- (20, 79), (21, 83), (22, 89), (23, 97), (24, 101),
- (25, 103), (26, 107), (27, 109), (28, 113), (29, 127),
- (30, 131), (31, 137), (32, 139), (33, 149), (34, 151),
- (35, 157), (36, 163), (37, 167), (38, 173), (39, 179),
- (40, 181), (41, 191), (42, 193), (43, 197), (44, 199)|
-
---disable_warnings
-drop procedure if exists opp|
---enable_warnings
-create procedure opp(n bigint unsigned, out pp bool)
-begin
- declare r double;
- declare b, s bigint unsigned default 0;
-
- set r = sqrt(n);
-
- again:
- loop
- if s = 45 then
- set b = b+200, s = 0;
- else
- begin
- declare p bigint unsigned;
-
- select t.p into p from test.t3 t where t.i = s;
- if b+p > r then
- set pp = 1;
- leave again;
- end if;
- if mod(n, b+p) = 0 then
- set pp = 0;
- leave again;
- end if;
- set s = s+1;
- end;
- end if;
- end loop;
-end|
-
---disable_warnings
-drop procedure if exists ip|
---enable_warnings
-create procedure ip(m int unsigned)
-begin
- declare p bigint unsigned;
- declare i int unsigned;
-
- set i=45, p=201;
-
- while i < m do
- begin
- declare pp bool default 0;
-
- call opp(p, pp);
- if pp then
- insert into test.t3 values (i, p);
- set i = i+1;
- end if;
- set p = p+2;
- end;
- end while;
-end|
-show create procedure opp|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
-show procedure status like '%p%'|
-
-# This isn't the fastest way in the world to compute prime numbers, so
-# don't be too ambitious. ;-)
-call ip(200)|
-# We don't want to select the entire table here, just pick a few
-# examples.
-# The expected result is:
-# i p
-# --- ----
-# 45 211
-# 100 557
-# 199 1229
-select * from t3 where i=45 or i=100 or i=199|
-drop table t3|
-drop procedure opp|
-drop procedure ip|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
-show procedure status like '%p%'|
-
-
-# Fibonacci, for recursion test. (Yet Another Numerical series :)
-#
---disable_warnings
-drop table if exists t3|
---enable_warnings
-create table t3 ( f bigint unsigned not null )|
-
-# We deliberately do it the awkward way, fetching the last two
-# values from the table, in order to exercise various statements
-# and table accesses at each turn.
---disable_warnings
-drop procedure if exists fib|
---enable_warnings
-create procedure fib(n int unsigned)
-begin
- if n > 1 then
- begin
- declare x, y bigint unsigned;
- declare c cursor for select f from t3 order by f desc limit 2;
-
- open c;
- fetch c into y;
- fetch c into x;
- close c;
- insert into t3 values (x+y);
- call fib(n-1);
- end;
- end if;
-end|
-
-# Enable recursion
-set @@max_sp_recursion_depth= 20|
-
-# Minimum test: recursion of 3 levels
-
-insert into t3 values (0), (1)|
-
-call fib(3)|
-
-select * from t3 order by f asc|
-
-delete from t3|
-
-# The original test, 20 levels, ran into memory limits on some machines
-# and builds. Try 10 instead...
-
-insert into t3 values (0), (1)|
-
-call fib(10)|
-
-select * from t3 order by f asc|
-drop table t3|
-drop procedure fib|
-set @@max_sp_recursion_depth= 0|
-
-#
-# Comment & suid
-#
-
---disable_warnings
-drop procedure if exists bar|
---enable_warnings
-create procedure bar(x char(16), y int)
- comment "111111111111" sql security invoker
- insert into test.t1 values (x, y)|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
-show procedure status like 'bar'|
-alter procedure bar comment "2222222222" sql security definer|
-alter procedure bar comment "3333333333"|
-alter procedure bar|
-show create procedure bar|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
-show procedure status like 'bar'|
-drop procedure bar|
-
-#
-# rexecution
-#
---disable_warnings
-drop procedure if exists p1|
---enable_warnings
-create procedure p1 ()
- select (select s1 from t3) from t3|
-
-create table t3 (s1 int)|
-
-call p1()|
-insert into t3 values (1)|
-call p1()|
-drop procedure p1|
-drop table t3|
-
-#
-# backticks
-#
---disable_warnings
-drop function if exists foo|
---enable_warnings
-create function `foo` () returns int
- return 5|
-select `foo` ()|
-drop function `foo`|
-
-#
-# Implicit LOCK/UNLOCK TABLES for table access in functions
-#
-
---disable_warnings
-drop function if exists t1max|
---enable_warnings
-create function t1max() returns int
-begin
- declare x int;
- select max(data) into x from t1;
- return x;
-end|
-
-insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)|
-select t1max()|
-drop function t1max|
-
-create table t3 (
- v char(16) not null primary key,
- c int unsigned not null
-)|
-
-create function getcount(s char(16)) returns int
-begin
- declare x int;
-
- select count(*) into x from t3 where v = s;
- if x = 0 then
- insert into t3 values (s, 1);
- else
- update t3 set c = c+1 where v = s;
- end if;
- return x;
-end|
-
-select * from t1 where data = getcount("bar")|
-select * from t3|
-select getcount("zip")|
-select getcount("zip")|
-select * from t3|
-select getcount(id) from t1 where data = 3|
-select getcount(id) from t1 where data = 5|
-select * from t3|
-drop table t3|
-drop function getcount|
-
-
-# Test cases for different combinations of condition handlers in nested
-# begin-end blocks in stored procedures.
-#
-# Note that the standard specifies that the most specific handler should
-# be triggered even if it's an outer handler masked by a less specific
-# handler in an inner block.
-# Note also that '02000' is more specific than NOT FOUND; there might be
-# other '02xxx' states, even if we currently do not issue them in any
-# situation (e.g. '02001').
-#
-# The combinations we test are these:
-#
-# Inner
-# errcode sqlstate not found sqlwarning sqlexception
-# Outer +------------+------------+------------+------------+------------+
-#errcode | h_ee (i) | h_es (o) | h_en (o) | h_ew (o) | h_ex (o) |
-#sqlstate | h_se (i) | h_ss (i) | h_sn (o) | h_sw (o) | h_sx (o) |
-#not found | h_ne (i) | h_ns (i) | h_nn (i) | | |
-#sqlwarning | h_we (i) | h_ws (i) | | h_ww (i) | |
-#sqlexception | h_xe (i) | h_xs (i) | | | h_xx (i) |
-# +------------+---------------------------------------------------+
-#
-# (i) means that the inner handler is the one that should be invoked,
-# (o) means that the outer handler should be invoked.
-#
-# ('not found', 'sqlwarning' and 'sqlexception' are mutually exclusive, hence
-# no tests for those combinations.)
-#
-
---disable_warnings
-drop table if exists t3|
-drop procedure if exists h_ee|
-drop procedure if exists h_es|
-drop procedure if exists h_en|
-drop procedure if exists h_ew|
-drop procedure if exists h_ex|
-drop procedure if exists h_se|
-drop procedure if exists h_ss|
-drop procedure if exists h_sn|
-drop procedure if exists h_sw|
-drop procedure if exists h_sx|
-drop procedure if exists h_ne|
-drop procedure if exists h_ns|
-drop procedure if exists h_nn|
-drop procedure if exists h_we|
-drop procedure if exists h_ws|
-drop procedure if exists h_ww|
-drop procedure if exists h_xe|
-drop procedure if exists h_xs|
-drop procedure if exists h_xx|
---enable_warnings
-
-# smallint - to get out of range warnings
-# primary key - to get constraint errors
-create table t3 (a smallint primary key)|
-
-insert into t3 (a) values (1)|
-
-create procedure h_ee()
- deterministic
-begin
- declare continue handler for 1062 -- ER_DUP_ENTRY
- select 'Outer (bad)' as 'h_ee';
-
- begin
- declare continue handler for 1062 -- ER_DUP_ENTRY
- select 'Inner (good)' as 'h_ee';
-
- insert into t3 values (1);
- end;
-end|
-
-create procedure h_es()
- deterministic
-begin
- declare continue handler for 1062 -- ER_DUP_ENTRY
- select 'Outer (good)' as 'h_es';
-
- begin
- -- integrity constraint violation
- declare continue handler for sqlstate '23000'
- select 'Inner (bad)' as 'h_es';
-
- insert into t3 values (1);
- end;
-end|
-
-create procedure h_en()
- deterministic
-begin
- declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA
- select 'Outer (good)' as 'h_en';
-
- begin
- declare x int;
- declare continue handler for sqlstate '02000' -- no data
- select 'Inner (bad)' as 'h_en';
-
- select a into x from t3 where a = 42;
- end;
-end|
-
-create procedure h_ew()
- deterministic
-begin
- declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE
- select 'Outer (good)' as 'h_ew';
-
- begin
- declare continue handler for sqlwarning
- select 'Inner (bad)' as 'h_ew';
-
- insert into t3 values (123456789012);
- end;
- delete from t3;
- insert into t3 values (1);
-end|
-
-create procedure h_ex()
- deterministic
-begin
- declare continue handler for 1062 -- ER_DUP_ENTRY
- select 'Outer (good)' as 'h_ex';
-
- begin
- declare continue handler for sqlexception
- select 'Inner (bad)' as 'h_ex';
-
- insert into t3 values (1);
- end;
-end|
-
-create procedure h_se()
- deterministic
-begin
- -- integrity constraint violation
- declare continue handler for sqlstate '23000'
- select 'Outer (bad)' as 'h_se';
-
- begin
- declare continue handler for 1062 -- ER_DUP_ENTRY
- select 'Inner (good)' as 'h_se';
-
- insert into t3 values (1);
- end;
-end|
-
-create procedure h_ss()
- deterministic
-begin
- -- integrity constraint violation
- declare continue handler for sqlstate '23000'
- select 'Outer (bad)' as 'h_ss';
-
- begin
- -- integrity constraint violation
- declare continue handler for sqlstate '23000'
- select 'Inner (good)' as 'h_ss';
-
- insert into t3 values (1);
- end;
-end|
-
-create procedure h_sn()
- deterministic
-begin
- -- Note: '02000' is more specific than NOT FOUND ;
- -- there might be other not found states
- declare continue handler for sqlstate '02000' -- no data
- select 'Outer (good)' as 'h_sn';
-
- begin
- declare x int;
- declare continue handler for not found
- select 'Inner (bad)' as 'h_sn';
-
- select a into x from t3 where a = 42;
- end;
-end|
-
-create procedure h_sw()
- deterministic
-begin
- -- data exception - numeric value out of range
- declare continue handler for sqlstate '22003'
- select 'Outer (good)' as 'h_sw';
-
- begin
- declare continue handler for sqlwarning
- select 'Inner (bad)' as 'h_sw';
-
- insert into t3 values (123456789012);
- end;
- delete from t3;
- insert into t3 values (1);
-end|
-
-create procedure h_sx()
- deterministic
-begin
- -- integrity constraint violation
- declare continue handler for sqlstate '23000'
- select 'Outer (good)' as 'h_sx';
-
- begin
- declare continue handler for sqlexception
- select 'Inner (bad)' as 'h_sx';
-
- insert into t3 values (1);
- end;
-end|
-
-create procedure h_ne()
- deterministic
-begin
- declare continue handler for not found
- select 'Outer (bad)' as 'h_ne';
-
- begin
- declare x int;
- declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA
- select 'Inner (good)' as 'h_ne';
-
- select a into x from t3 where a = 42;
- end;
-end|
-
-create procedure h_ns()
- deterministic
-begin
- declare continue handler for not found
- select 'Outer (bad)' as 'h_ns';
-
- begin
- declare x int;
- declare continue handler for sqlstate '02000' -- no data
- select 'Inner (good)' as 'h_ns';
-
- select a into x from t3 where a = 42;
- end;
-end|
-
-create procedure h_nn()
- deterministic
-begin
- declare continue handler for not found
- select 'Outer (bad)' as 'h_nn';
-
- begin
- declare x int;
- declare continue handler for not found
- select 'Inner (good)' as 'h_nn';
-
- select a into x from t3 where a = 42;
- end;
-end|
-
-create procedure h_we()
- deterministic
-begin
- declare continue handler for sqlwarning
- select 'Outer (bad)' as 'h_we';
-
- begin
- declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE
- select 'Inner (good)' as 'h_we';
-
- insert into t3 values (123456789012);
- end;
- delete from t3;
- insert into t3 values (1);
-end|
-
-create procedure h_ws()
- deterministic
-begin
- declare continue handler for sqlwarning
- select 'Outer (bad)' as 'h_ws';
-
- begin
- -- data exception - numeric value out of range
- declare continue handler for sqlstate '22003'
- select 'Inner (good)' as 'h_ws';
-
- insert into t3 values (123456789012);
- end;
- delete from t3;
- insert into t3 values (1);
-end|
-
-create procedure h_ww()
- deterministic
-begin
- declare continue handler for sqlwarning
- select 'Outer (bad)' as 'h_ww';
-
- begin
- declare continue handler for sqlwarning
- select 'Inner (good)' as 'h_ww';
-
- insert into t3 values (123456789012);
- end;
- delete from t3;
- insert into t3 values (1);
-end|
-
-create procedure h_xe()
- deterministic
-begin
- declare continue handler for sqlexception
- select 'Outer (bad)' as 'h_xe';
-
- begin
- declare continue handler for 1062 -- ER_DUP_ENTRY
- select 'Inner (good)' as 'h_xe';
-
- insert into t3 values (1);
- end;
-end|
-
-create procedure h_xs()
- deterministic
-begin
- declare continue handler for sqlexception
- select 'Outer (bad)' as 'h_xs';
-
- begin
- -- integrity constraint violation
- declare continue handler for sqlstate '23000'
- select 'Inner (good)' as 'h_xs';
-
- insert into t3 values (1);
- end;
-end|
-
-create procedure h_xx()
- deterministic
-begin
- declare continue handler for sqlexception
- select 'Outer (bad)' as 'h_xx';
-
- begin
- declare continue handler for sqlexception
- select 'Inner (good)' as 'h_xx';
-
- insert into t3 values (1);
- end;
-end|
-
-call h_ee()|
-call h_es()|
-call h_en()|
-call h_ew()|
-call h_ex()|
-call h_se()|
-call h_ss()|
-call h_sn()|
-call h_sw()|
-call h_sx()|
-call h_ne()|
-call h_ns()|
-call h_nn()|
-call h_we()|
-call h_ws()|
-call h_ww()|
-call h_xe()|
-call h_xs()|
-call h_xx()|
-
-drop table t3|
-drop procedure h_ee|
-drop procedure h_es|
-drop procedure h_en|
-drop procedure h_ew|
-drop procedure h_ex|
-drop procedure h_se|
-drop procedure h_ss|
-drop procedure h_sn|
-drop procedure h_sw|
-drop procedure h_sx|
-drop procedure h_ne|
-drop procedure h_ns|
-drop procedure h_nn|
-drop procedure h_we|
-drop procedure h_ws|
-drop procedure h_ww|
-drop procedure h_xe|
-drop procedure h_xs|
-drop procedure h_xx|
-
-
-#
-# Test cases for old bugs
-#
-
-#
-# BUG#822
-#
---disable_warnings
-drop procedure if exists bug822|
---enable_warnings
-create procedure bug822(a_id char(16), a_data int)
-begin
- declare n int;
- select count(*) into n from t1 where id = a_id and data = a_data;
- if n = 0 then
- insert into t1 (id, data) values (a_id, a_data);
- end if;
-end|
-
-delete from t1|
-call bug822('foo', 42)|
-call bug822('foo', 42)|
-call bug822('bar', 666)|
-select * from t1|
-delete from t1|
-drop procedure bug822|
-
-#
-# BUG#1495
-#
---disable_warnings
-drop procedure if exists bug1495|
---enable_warnings
-create procedure bug1495()
-begin
- declare x int;
-
- select data into x from t1 order by id limit 1;
- if x > 10 then
- insert into t1 values ("less", x-10);
- else
- insert into t1 values ("more", x+10);
- end if;
-end|
-
-insert into t1 values ('foo', 12)|
-call bug1495()|
-delete from t1 where id='foo'|
-insert into t1 values ('bar', 7)|
-call bug1495()|
-delete from t1 where id='bar'|
-select * from t1|
-delete from t1|
-drop procedure bug1495|
-
-#
-# BUG#1547
-#
---disable_warnings
-drop procedure if exists bug1547|
---enable_warnings
-create procedure bug1547(s char(16))
-begin
- declare x int;
-
- select data into x from t1 where s = id limit 1;
- if x > 10 then
- insert into t1 values ("less", x-10);
- else
- insert into t1 values ("more", x+10);
- end if;
-end|
-
-insert into t1 values ("foo", 12), ("bar", 7)|
-call bug1547("foo")|
-call bug1547("bar")|
-select * from t1|
-delete from t1|
-drop procedure bug1547|
-
-#
-# BUG#1656
-#
---disable_warnings
-drop table if exists t70|
---enable_warnings
-create table t70 (s1 int,s2 int)|
-insert into t70 values (1,2)|
-
---disable_warnings
-drop procedure if exists bug1656|
---enable_warnings
-create procedure bug1656(out p1 int, out p2 int)
- select * into p1, p1 from t70|
-
-call bug1656(@1, @2)|
-select @1, @2|
-drop table t70|
-drop procedure bug1656|
-
-#
-# BUG#1862
-#
-create table t3(a int)|
-
---disable_warnings
-drop procedure if exists bug1862|
---enable_warnings
-create procedure bug1862()
-begin
- insert into t3 values(2);
- flush tables;
-end|
-
-call bug1862()|
-# the second call caused a segmentation
-call bug1862()|
-select * from t3|
-drop table t3|
-drop procedure bug1862|
-
-#
-# BUG#1874
-#
---disable_warnings
-drop procedure if exists bug1874|
---enable_warnings
-create procedure bug1874()
-begin
- declare x int;
- declare y double;
- select max(data) into x from t1;
- insert into t2 values ("max", x, 0);
- select min(data) into x from t1;
- insert into t2 values ("min", x, 0);
- select sum(data) into x from t1;
- insert into t2 values ("sum", x, 0);
- select avg(data) into y from t1;
- insert into t2 values ("avg", 0, y);
-end|
-
-insert into t1 (data) values (3), (1), (5), (9), (4)|
-call bug1874()|
-select * from t2|
-delete from t1|
-delete from t2|
-drop procedure bug1874|
-
-#
-# BUG#2260
-#
---disable_warnings
-drop procedure if exists bug2260|
---enable_warnings
-create procedure bug2260()
-begin
- declare v1 int;
- declare c1 cursor for select data from t1;
- declare continue handler for not found set @x2 = 1;
-
- open c1;
- fetch c1 into v1;
- set @x2 = 2;
- close c1;
-end|
-
-call bug2260()|
-select @x2|
-drop procedure bug2260|
-
-#
-# BUG#2267 "Lost connect if stored procedure has SHOW FUNCTION STATUS"
-#
---disable_warnings
-drop procedure if exists bug2267_1|
---enable_warnings
-create procedure bug2267_1()
-begin
- show procedure status;
-end|
-
---disable_warnings
-drop procedure if exists bug2267_2|
---enable_warnings
-create procedure bug2267_2()
-begin
- show function status;
-end|
-
---disable_warnings
-drop procedure if exists bug2267_3|
---enable_warnings
-create procedure bug2267_3()
-begin
- show create procedure bug2267_1;
-end|
-
---disable_warnings
-drop procedure if exists bug2267_4|
-drop function if exists bug2267_4|
---enable_warnings
-create procedure bug2267_4()
-begin
- show create function bug2267_4;
-end|
-create function bug2267_4() returns int return 100|
-
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
-call bug2267_1()|
---replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
-call bug2267_2()|
-call bug2267_3()|
-call bug2267_4()|
-
-drop procedure bug2267_1|
-drop procedure bug2267_2|
-drop procedure bug2267_3|
-drop procedure bug2267_4|
-drop function bug2267_4|
-
-#
-# BUG#2227
-#
---disable_warnings
-drop procedure if exists bug2227|
---enable_warnings
-create procedure bug2227(x int)
-begin
- declare y float default 2.6;
- declare z char(16) default "zzz";
-
- select 1.3, x, y, 42, z;
-end|
-
-call bug2227(9)|
-drop procedure bug2227|
-
-#
-# BUG#2614 "Stored procedure with INSERT ... SELECT that does not
-# contain any tables crashes server"
-#
---disable_warnings
-drop procedure if exists bug2614|
---enable_warnings
-create procedure bug2614()
-begin
- drop table if exists t3;
- create table t3 (id int default '0' not null);
- insert into t3 select 12;
- insert into t3 select * from t3;
-end|
-
---disable_warnings
-call bug2614()|
---enable_warnings
-call bug2614()|
-drop table t3|
-drop procedure bug2614|
-
-#
-# BUG#2674
-#
---disable_warnings
-drop function if exists bug2674|
---enable_warnings
-create function bug2674() returns int
- return @@sort_buffer_size|
-
-set @osbs = @@sort_buffer_size|
-set @@sort_buffer_size = 262000|
-select bug2674()|
-drop function bug2674|
-set @@sort_buffer_size = @osbs|
-
-#
-# BUG#3259
-#
---disable_warnings
-drop procedure if exists bug3259_1 |
---enable_warnings
-create procedure bug3259_1 () begin end|
---disable_warnings
-drop procedure if exists BUG3259_2 |
---enable_warnings
-create procedure BUG3259_2 () begin end|
---disable_warnings
-drop procedure if exists Bug3259_3 |
---enable_warnings
-create procedure Bug3259_3 () begin end|
-
-call BUG3259_1()|
-call BUG3259_1()|
-call bug3259_2()|
-call Bug3259_2()|
-call bug3259_3()|
-call bUG3259_3()|
-
-drop procedure bUg3259_1|
-drop procedure BuG3259_2|
-drop procedure BUG3259_3|
-
-#
-# BUG#2772
-#
---disable_warnings
-drop function if exists bug2772|
---enable_warnings
-create function bug2772() returns char(10) character set latin2
- return 'a'|
-
-select bug2772()|
-drop function bug2772|
-
-#
-# BUG#2776
-#
---disable_warnings
-drop procedure if exists bug2776_1|
---enable_warnings
-create procedure bug2776_1(out x int)
-begin
- declare v int;
-
- set v = default;
- set x = v;
-end|
-
---disable_warnings
-drop procedure if exists bug2776_2|
---enable_warnings
-create procedure bug2776_2(out x int)
-begin
- declare v int default 42;
-
- set v = default;
- set x = v;
-end|
-
-set @x = 1|
-call bug2776_1(@x)|
-select @x|
-call bug2776_2(@x)|
-select @x|
-drop procedure bug2776_1|
-drop procedure bug2776_2|
-
-#
-# BUG#2780
-#
-create table t3 (s1 smallint)|
-
-insert into t3 values (123456789012)|
-
---disable_warnings
-drop procedure if exists bug2780|
---enable_warnings
-create procedure bug2780()
-begin
- declare exit handler for sqlwarning set @x = 1;
-
- set @x = 0;
- insert into t3 values (123456789012);
- insert into t3 values (0);
-end|
-
-call bug2780()|
-select @x|
-select * from t3|
-
-drop procedure bug2780|
-drop table t3|
-
-#
-# BUG#1863
-#
-create table t3 (content varchar(10) )|
-insert into t3 values ("test1")|
-insert into t3 values ("test2")|
-create table t4 (f1 int, rc int, t3 int)|
-
---disable_warnings
-drop procedure if exists bug1863|
---enable_warnings
-create procedure bug1863(in1 int)
-begin
-
- declare ind int default 0;
- declare t1 int;
- declare t2 int;
- declare t3 int;
-
- declare rc int default 0;
- declare continue handler for 1065 set rc = 1;
-
- drop temporary table if exists temp_t1;
- create temporary table temp_t1 (
- f1 int auto_increment, f2 varchar(20), primary key (f1)
- );
-
- insert into temp_t1 (f2) select content from t3;
-
- select f2 into t3 from temp_t1 where f1 = 10;
-
- if (rc) then
- insert into t4 values (1, rc, t3);
- end if;
-
- insert into t4 values (2, rc, t3);
-
-end|
-
-call bug1863(10)|
-call bug1863(10)|
-select * from t4|
-
-drop procedure bug1863|
-drop temporary table temp_t1;
-drop table t3, t4|
-
-#
-# BUG#2656
-#
-
-create table t3 (
- OrderID int not null,
- MarketID int,
- primary key (OrderID)
-)|
-
-create table t4 (
- MarketID int not null,
- Market varchar(60),
- Status char(1),
- primary key (MarketID)
-)|
-
-insert t3 (OrderID,MarketID) values (1,1)|
-insert t3 (OrderID,MarketID) values (2,2)|
-insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")|
-insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")|
-
---disable_warnings
-drop procedure if exists bug2656_1|
---enable_warnings
-create procedure bug2656_1()
-begin
- select
- m.Market
- from t4 m JOIN t3 o
- ON o.MarketID != 1 and o.MarketID = m.MarketID;
-end |
-
---disable_warnings
-drop procedure if exists bug2656_2|
---enable_warnings
-create procedure bug2656_2()
-begin
- select
- m.Market
- from
- t4 m, t3 o
- where
- m.MarketID != 1 and m.MarketID = o.MarketID;
-
-end |
-
-call bug2656_1()|
-call bug2656_1()|
-call bug2656_2()|
-call bug2656_2()|
-drop procedure bug2656_1|
-drop procedure bug2656_2|
-drop table t3, t4|
-
-
-#
-# BUG#3426
-#
---disable_warnings
-drop procedure if exists bug3426|
---enable_warnings
-create procedure bug3426(in_time int unsigned, out x int)
-begin
- if in_time is null then
- set @stamped_time=10;
- set x=1;
- else
- set @stamped_time=in_time;
- set x=2;
- end if;
-end|
-
-call bug3426(1000, @i)|
-select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
-call bug3426(NULL, @i)|
-select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
-# Clear SP cache
-alter procedure bug3426 sql security invoker|
-call bug3426(NULL, @i)|
-select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
-call bug3426(1000, @i)|
-select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time|
-
-drop procedure bug3426|
-
-#
-# BUG#3448
-#
---disable_warnings
-create table t3 (
- a int primary key,
- ach char(1)
-) engine = innodb|
-
-create table t4 (
- b int primary key ,
- bch char(1)
-) engine = innodb|
---enable_warnings
-
-insert into t3 values (1 , 'aCh1' ) , ('2' , 'aCh2')|
-insert into t4 values (1 , 'bCh1' )|
-
---disable_warnings
-drop procedure if exists bug3448|
---enable_warnings
-create procedure bug3448()
- select * from t3 inner join t4 on t3.a = t4.b|
-
-select * from t3 inner join t4 on t3.a = t4.b|
-call bug3448()|
-call bug3448()|
-
-drop procedure bug3448|
-drop table t3, t4|
-
-
-#
-# BUG#3734
-#
-create table t3 (
- id int unsigned auto_increment not null primary key,
- title VARCHAR(200),
- body text,
- fulltext (title,body)
-)|
-
-insert into t3 (title,body) values
- ('MySQL Tutorial','DBMS stands for DataBase ...'),
- ('How To Use MySQL Well','After you went through a ...'),
- ('Optimizing MySQL','In this tutorial we will show ...'),
- ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
- ('MySQL vs. YourSQL','In the following database comparison ...'),
- ('MySQL Security','When configured properly, MySQL ...')|
-
---disable_warnings
-drop procedure if exists bug3734 |
---enable_warnings
-create procedure bug3734 (param1 varchar(100))
- select * from t3 where match (title,body) against (param1)|
-
-call bug3734('database')|
-call bug3734('Security')|
-
-drop procedure bug3734|
-drop table t3|
-
-#
-# BUG#3863
-#
---disable_warnings
-drop procedure if exists bug3863|
---enable_warnings
-create procedure bug3863()
-begin
- set @a = 0;
- while @a < 5 do
- set @a = @a + 1;
- end while;
-end|
-
-call bug3863()|
-select @a|
-call bug3863()|
-select @a|
-
-drop procedure bug3863|
-
-#
-# BUG#2460
-#
-
-create table t3 (
- id int(10) unsigned not null default 0,
- rid int(10) unsigned not null default 0,
- msg text not null,
- primary key (id),
- unique key rid (rid, id)
-)|
-
---disable_warnings
-drop procedure if exists bug2460_1|
---enable_warnings
-create procedure bug2460_1(in v int)
-begin
- ( select n0.id from t3 as n0 where n0.id = v )
- union
- ( select n0.id from t3 as n0, t3 as n1
- where n0.id = n1.rid and n1.id = v )
- union
- ( select n0.id from t3 as n0, t3 as n1, t3 as n2
- where n0.id = n1.rid and n1.id = n2.rid and n2.id = v );
-end|
-
-call bug2460_1(2)|
-call bug2460_1(2)|
-insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')|
-call bug2460_1(2)|
-call bug2460_1(2)|
-
---disable_warnings
-drop procedure if exists bug2460_2|
---enable_warnings
-create procedure bug2460_2()
-begin
- drop table if exists t3;
- create temporary table t3 (s1 int);
- insert into t3 select 1 union select 1;
-end|
-
-call bug2460_2()|
-call bug2460_2()|
-select * from t3|
-
-drop procedure bug2460_1|
-drop procedure bug2460_2|
-drop table t3|
-
-
-#
-# BUG#2564
-#
-set @@sql_mode = ''|
---disable_warnings
-drop procedure if exists bug2564_1|
---enable_warnings
-create procedure bug2564_1()
- comment 'Joe''s procedure'
- insert into `t1` values ("foo", 1)|
-
-set @@sql_mode = 'ANSI_QUOTES'|
---disable_warnings
-drop procedure if exists bug2564_2|
---enable_warnings
-create procedure bug2564_2()
- insert into "t1" values ('foo', 1)|
-
-delimiter $|
-set @@sql_mode = ''$
---disable_warnings
-drop function if exists bug2564_3$
---enable_warnings
-create function bug2564_3(x int, y int) returns int
- return x || y$
-
-set @@sql_mode = 'ANSI'$
---disable_warnings
-drop function if exists bug2564_4$
---enable_warnings
-create function bug2564_4(x int, y int) returns int
- return x || y$
-delimiter |$
-
-set @@sql_mode = ''|
-show create procedure bug2564_1|
-show create procedure bug2564_2|
-show create function bug2564_3|
-show create function bug2564_4|
-
-drop procedure bug2564_1|
-drop procedure bug2564_2|
-drop function bug2564_3|
-drop function bug2564_4|
-
-#
-# BUG#3132
-#
---disable_warnings
-drop function if exists bug3132|
---enable_warnings
-create function bug3132(s char(20)) returns char(50)
- return concat('Hello, ', s, '!')|
-
-select bug3132('Bob') union all select bug3132('Judy')|
-drop function bug3132|
-
-#
-# BUG#3843
-#
---disable_warnings
-drop procedure if exists bug3843|
---enable_warnings
-create procedure bug3843()
- analyze table t1|
-
-# Testing for packets out of order
-call bug3843()|
-call bug3843()|
-select 1+2|
-
-drop procedure bug3843|
-
-#
-# BUG#3368
-#
-create table t3 ( s1 char(10) )|
-insert into t3 values ('a'), ('b')|
-
---disable_warnings
-drop procedure if exists bug3368|
---enable_warnings
-create procedure bug3368(v char(10))
-begin
- select group_concat(v) from t3;
-end|
-
-call bug3368('x')|
-call bug3368('yz')|
-drop procedure bug3368|
-drop table t3|
-
-#
-# BUG#4579
-#
-create table t3 (f1 int, f2 int)|
-insert into t3 values (1,1)|
-
---disable_warnings
-drop procedure if exists bug4579_1|
---enable_warnings
-create procedure bug4579_1 ()
-begin
- declare sf1 int;
-
- select f1 into sf1 from t3 where f1=1 and f2=1;
- update t3 set f2 = f2 + 1 where f1=1 and f2=1;
- call bug4579_2();
-end|
-
---disable_warnings
-drop procedure if exists bug4579_2|
---enable_warnings
-create procedure bug4579_2 ()
-begin
-end|
-
-call bug4579_1()|
-call bug4579_1()|
-call bug4579_1()|
-
-drop procedure bug4579_1|
-drop procedure bug4579_2|
-drop table t3|
-
-#
-# BUG#2773: Function's data type ignored in stored procedures
-#
---disable_warnings
-drop procedure if exists bug2773|
---enable_warnings
-
-create function bug2773() returns int return null|
-create table t3 as select bug2773()|
-show create table t3|
-drop table t3|
-drop function bug2773|
-
-#
-# BUG#3788: Stored procedure packet error
-#
---disable_warnings
-drop procedure if exists bug3788|
---enable_warnings
-
-create function bug3788() returns date return cast("2005-03-04" as date)|
-select bug3788()|
-drop function bug3788|
-
-create function bug3788() returns binary(1) return 5|
-select bug3788()|
-drop function bug3788|
-
-
-#
-# BUG#4726
-#
-create table t3 (f1 int, f2 int, f3 int)|
-insert into t3 values (1,1,1)|
-
---disable_warnings
-drop procedure if exists bug4726|
---enable_warnings
-create procedure bug4726()
-begin
- declare tmp_o_id INT;
- declare tmp_d_id INT default 1;
-
- while tmp_d_id <= 2 do
- begin
- select f1 into tmp_o_id from t3 where f2=1 and f3=1;
- set tmp_d_id = tmp_d_id + 1;
- end;
- end while;
-end|
-
-call bug4726()|
-call bug4726()|
-call bug4726()|
-
-drop procedure bug4726|
-drop table t3|
-
-#
-# BUG#4318
-#
-
---disable_parsing # Don't know if HANDLER commands can work with SPs, or at all..
-create table t3 (s1 int)|
-insert into t3 values (3), (4)|
-
---disable_warnings
-drop procedure if exists bug4318|
---enable_warnings
-create procedure bug4318()
- handler t3 read next|
-
-handler t3 open|
-# Expect no results, as tables are closed, but there shouldn't be any errors
-call bug4318()|
-call bug4318()|
-handler t3 close|
-
-drop procedure bug4318|
-drop table t3|
---enable_parsing
-
-#
-# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error
-#
-# Added tests for most other show commands we could find too.
-# (Skipping those already tested, and the ones depending on optional handlers.)
-#
-# Note: This will return a large number of results of different formats,
-# which makes it impossible to filter with --replace_column.
-# It's possible that some of these are not deterministic across
-# platforms. If so, just remove the offending command.
-#
---disable_warnings
-drop procedure if exists bug4902|
---enable_warnings
-create procedure bug4902()
-begin
- show charset like 'foo';
- show collation like 'foo';
- show column types;
- show create table t1;
- show create database test;
- show databases like 'foo';
- show errors;
- show columns from t1;
- show grants for 'root'@'localhost';
- show keys from t1;
- show open tables like 'foo';
- show privileges;
- show status like 'foo';
- show tables like 'foo';
- show variables like 'foo';
- show warnings;
-end|
---disable_parsing
-show binlog events;
-show storage engines;
-show master status;
-show slave hosts;
-show slave status;
---enable_parsing
-
-call bug4902()|
-call bug4902()|
-
-drop procedure bug4902|
-
-# We need separate SP for SHOW PROCESSLIST since we want use replace_column
---disable_warnings
-drop procedure if exists bug4902_2|
---enable_warnings
-create procedure bug4902_2()
-begin
- show processlist;
-end|
---replace_column 1 # 6 # 3 localhost
-call bug4902_2()|
---replace_column 1 # 6 # 3 localhost
-call bug4902_2()|
-drop procedure bug4902_2|
-
-#
-# BUG#4904
-#
---disable_warnings
-drop procedure if exists bug4904|
---enable_warnings
-create procedure bug4904()
-begin
- declare continue handler for sqlstate 'HY000' begin end;
-
- create table t2 as select * from t3;
-end|
-
--- error 1146
-call bug4904()|
-
-drop procedure bug4904|
-
-create table t3 (s1 char character set latin1, s2 char character set latin2)|
-
---disable_warnings
-drop procedure if exists bug4904|
---enable_warnings
-create procedure bug4904 ()
-begin
- declare continue handler for sqlstate 'HY000' begin end;
-
- select s1 from t3 union select s2 from t3;
-end|
-
-call bug4904()|
-
-drop procedure bug4904|
-drop table t3|
-
-#
-# BUG#336
-#
---disable_warnings
-drop procedure if exists bug336|
---enable_warnings
-create procedure bug336(out y int)
-begin
- declare x int;
- set x = (select sum(t.data) from test.t1 t);
- set y = x;
-end|
-
-insert into t1 values ("a", 2), ("b", 3)|
-call bug336(@y)|
-select @y|
-delete from t1|
-drop procedure bug336|
-
-#
-# BUG#3157
-#
---disable_warnings
-drop procedure if exists bug3157|
---enable_warnings
-create procedure bug3157()
-begin
- if exists(select * from t1) then
- set @n= @n + 1;
- end if;
- if (select count(*) from t1) then
- set @n= @n + 1;
- end if;
-end|
-
-set @n = 0|
-insert into t1 values ("a", 1)|
-call bug3157()|
-select @n|
-delete from t1|
-drop procedure bug3157|
-
-#
-# BUG#5251: mysql changes creation time of a procedure/function when altering
-#
---disable_warnings
-drop procedure if exists bug5251|
---enable_warnings
-create procedure bug5251()
-begin
-end|
-
-select created into @c1 from mysql.proc
- where db='test' and name='bug5251'|
---sleep 2
-alter procedure bug5251 comment 'foobar'|
-select count(*) from mysql.proc
- where db='test' and name='bug5251' and created = @c1|
-
-drop procedure bug5251|
-
-#
-# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE
-#
---disable_warnings
-drop procedure if exists bug5251|
---enable_warnings
-create procedure bug5251()
- checksum table t1|
-
-call bug5251()|
-call bug5251()|
-drop procedure bug5251|
-
-#
-# BUG#5287: Stored procedure crash if leave outside loop
-#
---disable_warnings
-drop procedure if exists bug5287|
---enable_warnings
-create procedure bug5287(param1 int)
-label1:
- begin
- declare c cursor for select 5;
-
- loop
- if param1 >= 0 then
- leave label1;
- end if;
- end loop;
-end|
-call bug5287(1)|
-drop procedure bug5287|
-
-
-#
-# BUG#5307: Stored procedure allows statement after BEGIN ... END
-#
---disable_warnings
-drop procedure if exists bug5307|
---enable_warnings
-create procedure bug5307()
-begin
-end; set @x = 3|
-
-call bug5307()|
-select @x|
-drop procedure bug5307|
-
-#
-# BUG#5258: Stored procedure modified date is 0000-00-00
-# (This was a design flaw)
---disable_warnings
-drop procedure if exists bug5258|
---enable_warnings
-create procedure bug5258()
-begin
-end|
-
---disable_warnings
-drop procedure if exists bug5258_aux|
---enable_warnings
-create procedure bug5258_aux()
-begin
- declare c, m char(19);
-
- select created,modified into c,m from mysql.proc where name = 'bug5258';
- if c = m then
- select 'Ok';
- else
- select c, m;
- end if;
-end|
-
-call bug5258_aux()|
-
-drop procedure bug5258|
-drop procedure bug5258_aux|
-
-#
-# BUG#4487: Stored procedure connection aborted if uninitialized char
-#
---disable_warnings
-drop function if exists bug4487|
---enable_warnings
-create function bug4487() returns char
-begin
- declare v char;
- return v;
-end|
-
-select bug4487()|
-drop function bug4487|
-
-
-#
-# BUG#4941: Stored procedure crash fetching null value into variable.
-#
---disable_warnings
-drop procedure if exists bug4941|
---enable_warnings
---disable_warnings
-drop procedure if exists bug4941|
---enable_warnings
-create procedure bug4941(out x int)
-begin
- declare c cursor for select i from t2 limit 1;
- open c;
- fetch c into x;
- close c;
-end|
-
-insert into t2 values (null, null, null)|
-set @x = 42|
-call bug4941(@x)|
-select @x|
-delete from t1|
-drop procedure bug4941|
-
-
-#
-# BUG#3583: query cache doesn't work for stored procedures
-#
---disable_warnings
-drop procedure if exists bug3583|
---enable_warnings
---disable_warnings
-drop procedure if exists bug3583|
---enable_warnings
-create procedure bug3583()
-begin
- declare c int;
-
- select * from t1;
- select count(*) into c from t1;
- select c;
-end|
-
-insert into t1 values ("x", 3), ("y", 5)|
-set @x = @@query_cache_size|
-set global query_cache_size = 10*1024*1024|
-
-flush status|
-flush query cache|
-show status like 'Qcache_hits'|
-call bug3583()|
-show status like 'Qcache_hits'|
-call bug3583()|
-call bug3583()|
-show status like 'Qcache_hits'|
-
-set global query_cache_size = @x|
-flush status|
-flush query cache|
-delete from t1|
-drop procedure bug3583|
-
-#
-# BUG#4905: Stored procedure doesn't clear for "Rows affected"
-#
---disable_warnings
-drop procedure if exists bug4905|
---enable_warnings
-
-create table t3 (s1 int,primary key (s1))|
-
---disable_warnings
-drop procedure if exists bug4905|
---enable_warnings
-create procedure bug4905()
-begin
- declare v int;
- declare continue handler for sqlstate '23000' set v = 5;
-
- insert into t3 values (1);
-end|
-
-call bug4905()|
-select row_count()|
-call bug4905()|
-select row_count()|
-call bug4905()|
-select row_count()|
-select * from t3|
-
-drop procedure bug4905|
-drop table t3|
-
-#
-# BUG#6022: Stored procedure shutdown problem with self-calling function.
-#
-
---disable_parsing # until we implement support for recursive stored functions.
---disable_warnings
-drop function if exists bug6022|
---enable_warnings
-
---disable_warnings
-drop function if exists bug6022|
---enable_warnings
-create function bug6022(x int) returns int
-begin
- if x < 0 then
- return 0;
- else
- return bug6022(x-1);
- end if;
-end|
-
-select bug6022(5)|
-drop function bug6022|
---enable_parsing
-
-#
-# BUG#6029: Stored procedure specific handlers should have priority
-#
---disable_warnings
-drop procedure if exists bug6029|
---enable_warnings
-
---disable_warnings
-drop procedure if exists bug6029|
---enable_warnings
-create procedure bug6029()
-begin
- declare exit handler for 1136 select '1136';
- declare exit handler for sqlstate '23000' select 'sqlstate 23000';
- declare continue handler for sqlexception select 'sqlexception';
-
- insert into t3 values (1);
- insert into t3 values (1,2);
-end|
-
-create table t3 (s1 int, primary key (s1))|
-insert into t3 values (1)|
-call bug6029()|
-delete from t3|
-call bug6029()|
-
-drop procedure bug6029|
-drop table t3|
-
-#
-# BUG#8540: Local variable overrides an alias
-#
---disable_warnings
-drop procedure if exists bug8540|
---enable_warnings
-
-create procedure bug8540()
-begin
- declare x int default 1;
- select x as y, x+0 as z;
-end|
-
-call bug8540()|
-drop procedure bug8540|
-
-#
-# BUG#6642: Stored procedure crash if expression with set function
-#
-create table t3 (s1 int)|
-
---disable_warnings
-drop procedure if exists bug6642|
---enable_warnings
-
-create procedure bug6642()
- select abs(count(s1)) from t3|
-
-call bug6642()|
-call bug6642()|
-drop procedure bug6642|
-
-#
-# BUG#7013: Stored procedure crash if group by ... with rollup
-#
-insert into t3 values (0),(1)|
---disable_warnings
-drop procedure if exists bug7013|
---enable_warnings
-create procedure bug7013()
- select s1,count(s1) from t3 group by s1 with rollup|
-call bug7013()|
-call bug7013()|
-drop procedure bug7013|
-
-#
-# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure
-#
---disable_warnings
-drop table if exists t4|
---enable_warnings
-create table t4 (
- a mediumint(8) unsigned not null auto_increment,
- b smallint(5) unsigned not null,
- c char(32) not null,
- primary key (a)
-) engine=myisam default charset=latin1|
-insert into t4 values (1, 2, 'oneword')|
-insert into t4 values (2, 2, 'anotherword')|
-
---disable_warnings
-drop procedure if exists bug7743|
---enable_warnings
-create procedure bug7743 ( searchstring char(28) )
-begin
- declare var mediumint(8) unsigned;
- select a into var from t4 where b = 2 and c = binary searchstring limit 1;
- select var;
-end|
-
-call bug7743("oneword")|
-call bug7743("OneWord")|
-call bug7743("anotherword")|
-call bug7743("AnotherWord")|
-drop procedure bug7743|
-drop table t4|
-
-#
-# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes
-# the server
-#
-delete from t3|
-insert into t3 values(1)|
-drop procedure if exists bug7992_1|
-drop procedure if exists bug7992_2|
-create procedure bug7992_1()
-begin
- declare i int;
- select max(s1)+1 into i from t3;
-end|
-create procedure bug7992_2()
- insert into t3 (s1) select max(t4.s1)+1 from t3 as t4|
-
-call bug7992_1()|
-call bug7992_1()|
-call bug7992_2()|
-call bug7992_2()|
-
-drop procedure bug7992_1|
-drop procedure bug7992_2|
-drop table t3|
-
-#
-# BUG#8116: calling simple stored procedure twice in a row results
-# in server crash
-#
-create table t3 ( userid bigint(20) not null default 0 )|
-
---disable_warnings
-drop procedure if exists bug8116|
---enable_warnings
-create procedure bug8116(in _userid int)
- select * from t3 where userid = _userid|
-
-call bug8116(42)|
-call bug8116(42)|
-drop procedure bug8116|
-drop table t3|
-
-#
-# BUG#6857: current_time() in STORED PROCEDURES
-#
---disable_warnings
-drop procedure if exists bug6857|
---enable_warnings
-create procedure bug6857(counter int)
-begin
- declare t0, t1 int;
- declare plus bool default 0;
-
- set t0 = current_time();
- while counter > 0 do
- set counter = counter - 1;
- end while;
- set t1 = current_time();
- if t1 > t0 then
- set plus = 1;
- end if;
- select plus;
-end|
-
-# QQ: This is currently disabled. Not only does it slow down a normal test
-# run, it makes running with valgrind (or similar tools) extremely
-# painful.
-# Make sure this takes at least one second on all machines in all builds.
-# 30000 makes it about 3 seconds on an old 1.1GHz linux.
-#call bug6857(300000)|
-
-drop procedure bug6857|
-
-#
-# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not
-# work properly.
---disable_warnings
-drop procedure if exists bug8757|
---enable_warnings
-create procedure bug8757()
-begin
- declare x int;
- declare c1 cursor for select data from t1 limit 1;
-
- begin
- declare y int;
- declare c2 cursor for select i from t2 limit 1;
-
- open c2;
- fetch c2 into y;
- close c2;
- select 2,y;
- end;
- open c1;
- fetch c1 into x;
- close c1;
- select 1,x;
-end|
-
-delete from t1|
-delete from t2|
-insert into t1 values ("x", 1)|
-insert into t2 values ("y", 2, 0.0)|
-
-call bug8757()|
-
-delete from t1|
-delete from t2|
-drop procedure bug8757|
-
-
-#
-# BUG#8762: Stored Procedures: Inconsistent behavior
-# of DROP PROCEDURE IF EXISTS statement.
---disable_warnings
-drop procedure if exists bug8762|
---enable_warnings
-# Doesn't exist
-drop procedure if exists bug8762; create procedure bug8762() begin end|
-# Does exist
-drop procedure if exists bug8762; create procedure bug8762() begin end|
-drop procedure bug8762|
-
-
-#
-# BUG#5240: Stored procedure crash if function has cursor declaration
-#
---disable_warnings
-drop function if exists bug5240|
---enable_warnings
-create function bug5240 () returns int
-begin
- declare x int;
- declare c cursor for select data from t1 limit 1;
-
- open c;
- fetch c into x;
- close c;
- return x;
-end|
-
-delete from t1|
-insert into t1 values ("answer", 42)|
-select id, bug5240() from t1|
-drop function bug5240|
-
-#
-# BUG#5278: Stored procedure packets out of order if SET PASSWORD.
-#
---disable_warnings
-drop function if exists bug5278|
---enable_warnings
-create function bug5278 () returns char
-begin
- SET PASSWORD FOR 'bob'@'%.loc.gov' = PASSWORD('newpass');
- return 'okay';
-end|
-
---error 1133
-select bug5278()|
---error 1133
-select bug5278()|
-drop function bug5278|
-
-#
-# BUG#7992: rolling back temporary Item tree changes in SP
-#
---disable_warnings
-drop procedure if exists p1|
---enable_warnings
-create table t3(id int)|
-insert into t3 values(1)|
-create procedure bug7992()
-begin
- declare i int;
- select max(id)+1 into i from t3;
-end|
-
-call bug7992()|
-call bug7992()|
-drop procedure bug7992|
-drop table t3|
-delimiter ;|
-
-#
-# BUG#8849: problem with insert statement with table alias's
-#
-# Rolling back changes to AND/OR structure of ON and WHERE clauses in SP
-#
-
-delimiter |;
-create table t3 (
- lpitnumber int(11) default null,
- lrecordtype int(11) default null
-)|
-
-create table t4 (
- lbsiid int(11) not null default '0',
- ltradingmodeid int(11) not null default '0',
- ltradingareaid int(11) not null default '0',
- csellingprice decimal(19,4) default null,
- primary key (lbsiid,ltradingmodeid,ltradingareaid)
-)|
-
-create table t5 (
- lbsiid int(11) not null default '0',
- ltradingareaid int(11) not null default '0',
- primary key (lbsiid,ltradingareaid)
-)|
-
---disable_warnings
-drop procedure if exists bug8849|
---enable_warnings
-create procedure bug8849()
-begin
- insert into t5
- (
- t5.lbsiid,
- t5.ltradingareaid
- )
- select distinct t3.lpitnumber, t4.ltradingareaid
- from
- t4 join t3 on
- t3.lpitnumber = t4.lbsiid
- and t3.lrecordtype = 1
- left join t4 as price01 on
- price01.lbsiid = t4.lbsiid and
- price01.ltradingmodeid = 1 and
- t4.ltradingareaid = price01.ltradingareaid;
-end|
-
-call bug8849()|
-call bug8849()|
-call bug8849()|
-drop procedure bug8849|
-drop tables t3,t4,t5|
-
-#
-# BUG#8937: Stored Procedure: AVG() works as SUM() in SELECT ... INTO statement
-#
---disable_warnings
-drop procedure if exists bug8937|
---enable_warnings
-create procedure bug8937()
-begin
- declare s,x,y,z int;
- declare a float;
-
- select sum(data),avg(data),min(data),max(data) into s,x,y,z from t1;
- select s,x,y,z;
- select avg(data) into a from t1;
- select a;
-end|
-
-delete from t1|
-insert into t1 (data) values (1), (2), (3), (4), (6)|
-call bug8937()|
-
-drop procedure bug8937|
-delete from t1|
-
-
-#
-# BUG#6900: Stored procedure inner handler ignored
-# BUG#9074: STORED PROC: The scope of every handler declared is not
-# properly applied
-#
---disable_warnings
-drop procedure if exists bug6900|
-drop procedure if exists bug9074|
-drop procedure if exists bug6900_9074|
---enable_warnings
-
-create table t3 (w char unique, x char)|
-insert into t3 values ('a', 'b')|
-
-create procedure bug6900()
-begin
- declare exit handler for sqlexception select '1';
-
- begin
- declare exit handler for sqlexception select '2';
-
- insert into t3 values ('x', 'y', 'z');
- end;
-end|
-
-create procedure bug9074()
-begin
- declare x1, x2, x3, x4, x5, x6 int default 0;
-
- begin
- declare continue handler for sqlstate '23000' set x5 = 1;
-
- insert into t3 values ('a', 'b');
- set x6 = 1;
- end;
-
- begin1_label:
- begin
- declare continue handler for sqlstate '23000' set x1 = 1;
-
- insert into t3 values ('a', 'b');
- set x2 = 1;
-
- begin2_label:
- begin
- declare exit handler for sqlstate '23000' set x3 = 1;
-
- set x4= 1;
- insert into t3 values ('a','b');
- set x4= 0;
- end begin2_label;
- end begin1_label;
-
- select x1, x2, x3, x4, x5, x6;
-end|
-
-create procedure bug6900_9074(z int)
-begin
- declare exit handler for sqlstate '23000' select '23000';
-
- begin
- declare exit handler for sqlexception select 'sqlexception';
-
- if z = 1 then
- insert into t3 values ('a', 'b');
- else
- insert into t3 values ('x', 'y', 'z');
- end if;
- end;
-end|
-
-call bug6900()|
-call bug9074()|
-call bug6900_9074(0)|
-call bug6900_9074(1)|
-
-drop procedure bug6900|
-drop procedure bug9074|
-drop procedure bug6900_9074|
-drop table t3|
-
-
-#
-# BUG#7185: Stored procedure crash if identifier is AVG
-#
---disable_warnings
-drop procedure if exists avg|
---enable_warnings
-create procedure avg ()
-begin
-end|
-
-call avg ()|
-drop procedure avg|
-
-
-#
-# BUG#6129: Stored procedure won't display @@sql_mode value
-#
---disable_warnings
-drop procedure if exists bug6129|
---enable_warnings
-set @old_mode= @@sql_mode;
-set @@sql_mode= "ERROR_FOR_DIVISION_BY_ZERO";
-create procedure bug6129()
- select @@sql_mode|
-call bug6129()|
-set @@sql_mode= "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO"|
-call bug6129()|
-set @@sql_mode= "NO_ZERO_IN_DATE"|
-call bug6129()|
-set @@sql_mode=@old_mode;
-
-drop procedure bug6129|
-
-
-#
-# BUG#9856: Stored procedures: crash if handler for sqlexception, not found
-#
---disable_warnings
-drop procedure if exists bug9856|
---enable_warnings
-create procedure bug9856()
-begin
- declare v int;
- declare c cursor for select data from t1;
- declare exit handler for sqlexception, not found select '16';
-
- open c;
- fetch c into v;
- select v;
-end|
-
-delete from t1|
-call bug9856()|
-call bug9856()|
-drop procedure bug9856|
-
-
-#
-# BUG##9674: Stored Procs: Using declared vars in algebric operation causes
-# system crash.
-#
---disable_warnings
-drop procedure if exists bug9674_1|
-drop procedure if exists bug9674_2|
---enable_warnings
-create procedure bug9674_1(out arg int)
-begin
- declare temp_in1 int default 0;
- declare temp_fl1 int default 0;
-
- set temp_in1 = 100;
- set temp_fl1 = temp_in1/10;
- set arg = temp_fl1;
-end|
-
-create procedure bug9674_2()
-begin
- declare v int default 100;
-
- select v/10;
-end|
-
-call bug9674_1(@sptmp)|
-call bug9674_1(@sptmp)|
-select @sptmp|
-call bug9674_2()|
-call bug9674_2()|
-drop procedure bug9674_1|
-drop procedure bug9674_2|
-
-
-#
-# BUG#9598: stored procedure call within stored procedure overwrites IN variable
-#
---disable_warnings
-drop procedure if exists bug9598_1|
-drop procedure if exists bug9598_2|
---enable_warnings
-create procedure bug9598_1(in var_1 char(16),
- out var_2 integer, out var_3 integer)
-begin
- set var_2 = 50;
- set var_3 = 60;
-end|
-
-create procedure bug9598_2(in v1 char(16),
- in v2 integer,
- in v3 integer,
- in v4 integer,
- in v5 integer)
-begin
- select v1,v2,v3,v4,v5;
- call bug9598_1(v1,@tmp1,@tmp2);
- select v1,v2,v3,v4,v5;
-end|
-
-call bug9598_2('Test',2,3,4,5)|
-select @tmp1, @tmp2|
-
-drop procedure bug9598_1|
-drop procedure bug9598_2|
-
-
-#
-# BUG#9902: Crash with simple stored function using user defined variables
-#
---disable_warnings
-drop procedure if exists bug9902|
---enable_warnings
-create function bug9902() returns int(11)
-begin
- set @x = @x + 1;
- return @x;
-end|
-
-set @qcs1 = @@query_cache_size|
-set global query_cache_size = 100000|
-set @x = 1|
-insert into t1 values ("qc", 42)|
-select bug9902() from t1|
-select bug9902() from t1|
-select @x|
-
-set global query_cache_size = @qcs1|
-delete from t1|
-drop function bug9902|
-
-
-#
-# BUG#9102: Stored proccedures: function which returns blob causes crash
-#
---disable_warnings
-drop function if exists bug9102|
---enable_warnings
-create function bug9102() returns blob return 'a'|
-select bug9102()|
-drop function bug9102|
-
-
-#
-# BUG#7648: Stored procedure crash when invoking a function that returns a bit
-#
---disable_warnings
-drop function if exists bug7648|
---enable_warnings
-create function bug7648() returns bit(8) return 'a'|
-select bug7648()|
-drop function bug7648|
-
-
-#
-# BUG#9775: crash if create function that returns enum or set
-#
---disable_warnings
-drop function if exists bug9775|
---enable_warnings
-create function bug9775(v1 char(1)) returns enum('a','b') return v1|
-select bug9775('a'),bug9775('b'),bug9775('c')|
-drop function bug9775|
-create function bug9775(v1 int) returns enum('a','b') return v1|
-select bug9775(1),bug9775(2),bug9775(3)|
-drop function bug9775|
-
-create function bug9775(v1 char(1)) returns set('a','b') return v1|
-select bug9775('a'),bug9775('b'),bug9775('a,b'),bug9775('c')|
-drop function bug9775|
-create function bug9775(v1 int) returns set('a','b') return v1|
-select bug9775(1),bug9775(2),bug9775(3),bug9775(4)|
-drop function bug9775|
-
-
-#
-# BUG#8861: If Return is a YEAR data type, value is not shown in year format
-#
---disable_warnings
-drop function if exists bug8861|
---enable_warnings
-create function bug8861(v1 int) returns year return v1|
-select bug8861(05)|
-set @x = bug8861(05)|
-select @x|
-drop function bug8861|
-
-
-#
-# BUG#9004: Inconsistent behaviour of SP re. warnings
-#
---disable_warnings
-drop procedure if exists bug9004_1|
-drop procedure if exists bug9004_2|
---enable_warnings
-create procedure bug9004_1(x char(16))
-begin
- insert into t1 values (x, 42);
- insert into t1 values (x, 17);
-end|
-create procedure bug9004_2(x char(16))
- call bug9004_1(x)|
-
-# Truncation warnings expected...
-call bug9004_1('12345678901234567')|
-call bug9004_2('12345678901234567890')|
-
-delete from t1|
-drop procedure bug9004_1|
-drop procedure bug9004_2|
-
-#
-# BUG#7293: Stored procedure crash with soundex
-#
---disable_warnings
-drop procedure if exists bug7293|
---enable_warnings
-insert into t1 values ('secret', 0)|
-create procedure bug7293(p1 varchar(100))
-begin
- if exists (select id from t1 where soundex(p1)=soundex(id)) then
- select 'yes';
- end if;
-end;|
-call bug7293('secret')|
-call bug7293 ('secrete')|
-drop procedure bug7293|
-delete from t1|
-
-
-#
-# BUG#9841: Unexpected read lock when trying to update a view in a
-# stored procedure
-#
---disable_warnings
-drop procedure if exists bug9841|
-drop view if exists v1|
---enable_warnings
-
-create view v1 as select * from t1, t2 where id = s|
-create procedure bug9841 ()
- update v1 set data = 10|
-call bug9841()|
-
-drop view v1|
-drop procedure bug9841|
-
-
-#
-# BUG#5963 subqueries in SET/IF
-#
---disable_warnings
-drop procedure if exists bug5963|
---enable_warnings
-
-create procedure bug5963_1 () begin declare v int; set v = (select s1 from t3); select v; end;|
-create table t3 (s1 int)|
-insert into t3 values (5)|
-call bug5963_1()|
-call bug5963_1()|
-drop procedure bug5963_1|
-drop table t3|
-
-create procedure bug5963_2 (cfk_value int)
-begin
- if cfk_value in (select cpk from t3) then
- set @x = 5;
- end if;
- end;
-|
-create table t3 (cpk int)|
-insert into t3 values (1)|
-call bug5963_2(1)|
-call bug5963_2(1)|
-drop procedure bug5963_2|
-drop table t3|
-
-
-#
-# BUG#9559: Functions: Numeric Operations using -ve value gives incorrect
-# results.
-#
---disable_warnings
-drop function if exists bug9559|
---enable_warnings
-create function bug9559()
- returns int
-begin
- set @y = -6/2;
- return @y;
-end|
-
-select bug9559()|
-
-drop function bug9559|
-
-
-#
-# BUG#10961: Stored procedures: crash if select * from dual
-#
---disable_warnings
-drop procedure if exists bug10961|
---enable_warnings
-# "select * from dual" results in an error, so the cursor will not open
-create procedure bug10961()
-begin
- declare v char;
- declare x int;
- declare c cursor for select * from dual;
- declare continue handler for sqlexception select x;
-
- set x = 1;
- open c;
- set x = 2;
- fetch c into v;
- set x = 3;
- close c;
-end|
-
-call bug10961()|
-call bug10961()|
-
-drop procedure bug10961|
-
-#
-# BUG #6866: Second call of a stored procedure using a view with on expressions
-#
-
---disable_warnings
-DROP PROCEDURE IF EXISTS bug6866|
---enable_warnings
-
-DROP VIEW IF EXISTS tv|
-DROP TABLE IF EXISTS tt1,tt2,tt3|
-
-CREATE TABLE tt1 (a1 int, a2 int, a3 int, data varchar(10))|
-CREATE TABLE tt2 (a2 int, data2 varchar(10))|
-CREATE TABLE tt3 (a3 int, data3 varchar(10))|
-
-INSERT INTO tt1 VALUES (1, 1, 4, 'xx')|
-
-INSERT INTO tt2 VALUES (1, 'a')|
-INSERT INTO tt2 VALUES (2, 'b')|
-INSERT INTO tt2 VALUES (3, 'c')|
-
-INSERT INTO tt3 VALUES (4, 'd')|
-INSERT INTO tt3 VALUES (5, 'e')|
-INSERT INTO tt3 VALUES (6, 'f')|
-
-CREATE VIEW tv AS
-SELECT tt1.*, tt2.data2, tt3.data3
- FROM tt1 INNER JOIN tt2 ON tt1.a2 = tt2.a2
- LEFT JOIN tt3 ON tt1.a3 = tt3.a3
- ORDER BY tt1.a1, tt2.a2, tt3.a3|
-
-CREATE PROCEDURE bug6866 (_a1 int)
-BEGIN
-SELECT * FROM tv WHERE a1 = _a1;
-END|
-
-CALL bug6866(1)|
-CALL bug6866(1)|
-CALL bug6866(1)|
-
-DROP PROCEDURE bug6866;
-
-DROP VIEW tv|
-DROP TABLE tt1, tt2, tt3|
-
-#
-# BUG#10136: items cleunup
-#
---disable_warnings
-DROP PROCEDURE IF EXISTS bug10136|
---enable_warnings
-create table t3 ( name char(5) not null primary key, val float not null)|
-insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)|
-create procedure bug10136()
-begin
- declare done int default 3;
-
- repeat
- select * from t3;
- set done = done - 1;
- until done <= 0 end repeat;
-
-end|
-call bug10136()|
-call bug10136()|
-call bug10136()|
-drop procedure bug10136|
-drop table t3|
-
-#
-# BUG#11529: crash server after use stored procedure
-#
---disable_warnings
-drop procedure if exists bug11529|
---enable_warnings
-create procedure bug11529()
-begin
- declare c cursor for select id, data from t1 where data in (10,13);
-
- open c;
- begin
- declare vid char(16);
- declare vdata int;
- declare exit handler for not found begin end;
-
- while true do
- fetch c into vid, vdata;
- end while;
- end;
- close c;
-end|
-
-insert into t1 values
- ('Name1', 10),
- ('Name2', 11),
- ('Name3', 12),
- ('Name4', 13),
- ('Name5', 14)|
-
-call bug11529()|
-call bug11529()|
-delete from t1|
-drop procedure bug11529|
-
-
-#
-# BUG#6063: Stored procedure labels are subject to restrictions (partial)
-# BUG#7088: Stored procedures: labels won't work if character set is utf8
-#
---disable_warnings
-drop procedure if exists bug6063|
-drop procedure if exists bug7088_1|
-drop procedure if exists bug7088_2|
---enable_warnings
-
---disable_parsing # temporarily disabled until Bar fixes BUG#11986
-create procedure bug6063()
- lâbel: begin end|
-call bug6063()|
-# QQ Known bug: this will not show the label correctly.
-show create procedure bug6063|
-
-set character set utf8|
-create procedure bug7088_1()
- label1: begin end label1|
-create procedure bug7088_2()
- läbel1: begin end|
-call bug7088_1()|
-call bug7088_2()|
-set character set default|
-show create procedure bug7088_1|
-show create procedure bug7088_2|
-
-drop procedure bug6063|
-drop procedure bug7088_1|
-drop procedure bug7088_2|
---enable_parsing
-
-#
-# BUG#9565: "Wrong locking in stored procedure if a sub-sequent procedure
-# is called".
-#
---disable_warnings
-drop procedure if exists bug9565_sub|
-drop procedure if exists bug9565|
---enable_warnings
-create procedure bug9565_sub()
-begin
- select * from t1;
-end|
-create procedure bug9565()
-begin
- insert into t1 values ("one", 1);
- call bug9565_sub();
-end|
-call bug9565()|
-delete from t1|
-drop procedure bug9565_sub|
-drop procedure bug9565|
-
-
-#
-# BUG#9538: SProc: Creation fails if we try to SET system variable
-# using @@var_name in proc
-#
---disable_warnings
-drop procedure if exists bug9538|
---enable_warnings
-create procedure bug9538()
- set @@sort_buffer_size = 1000000|
-
-set @x = @@sort_buffer_size|
-set @@sort_buffer_size = 2000000|
-select @@sort_buffer_size|
-call bug9538()|
-select @@sort_buffer_size|
-set @@sort_buffer_size = @x|
-
-drop procedure bug9538|
-
-
-#
-# BUG#8692: Cursor fetch of empty string
-#
---disable_warnings
-drop procedure if exists bug8692|
---enable_warnings
-create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))|
-insert into t3 values ('', '', '', '', '', '', NULL)|
-
-create procedure bug8692()
-begin
- declare v1 VARCHAR(10);
- declare v2 VARCHAR(10);
- declare v3 VARCHAR(10);
- declare v4 VARCHAR(10);
- declare v5 VARCHAR(10);
- declare v6 VARCHAR(10);
- declare v7 VARCHAR(10);
- declare c8692 cursor for select c1,c2,c3,c4,c5,c6,c7 from t3;
- open c8692;
- fetch c8692 into v1,v2,v3,v4,v5,v6,v7;
- select v1, v2, v3, v4, v5, v6, v7;
-end|
-
-call bug8692()|
-drop procedure bug8692|
-drop table t3|
-
-#
-# Bug#10055 "Using stored function with information_schema causes empty
-# result set"
-#
---disable_warnings
-drop function if exists bug10055|
---enable_warnings
-create function bug10055(v char(255)) returns char(255) return lower(v)|
-# This select should not crash server and should return all fields in t1
-select t.column_name, bug10055(t.column_name)
-from information_schema.columns as t
-where t.table_schema = 'test' and t.table_name = 't1'|
-drop function bug10055|
-
-#
-# Bug #12297 "SP crashes the server if data inserted inside a lon loop"
-# The test for memleak bug, so actually there is no way to test it
-# from the suite. The test below could be used to check SP memory
-# consumption by passing large input parameter.
-#
-
---disable_warnings
-drop procedure if exists bug12297|
---enable_warnings
-
-create procedure bug12297(lim int)
-begin
- set @x = 0;
- repeat
- insert into t1(id,data)
- values('aa', @x);
- set @x = @x + 1;
- until @x >= lim
- end repeat;
-end|
-
-call bug12297(10)|
-drop procedure bug12297|
-
-#
-# Bug #11247 "Stored procedures: Function calls in long loops leak memory"
-# One more memleak bug test. One could use this test to check that the memory
-# isn't leaking by increasing the input value for p_bug11247.
-#
-
---disable_warnings
-drop function if exists f_bug11247|
-drop procedure if exists p_bug11247|
---enable_warnings
-
-create function f_bug11247(param int)
- returns int
-return param + 1|
-
-create procedure p_bug11247(lim int)
-begin
- declare v int default 0;
-
- while v < lim do
- set v= f_bug11247(v);
- end while;
-end|
-
-call p_bug11247(10)|
-drop function f_bug11247|
-drop procedure p_bug11247|
-#
-# BUG#12168: "'DECLARE CONTINUE HANDLER FOR NOT FOUND ...' in conditional
-# handled incorrectly"
-#
---disable_warnings
-drop procedure if exists bug12168|
-drop table if exists t3, t4|
---enable_warnings
-
-create table t3 (a int)|
-insert into t3 values (1),(2),(3),(4)|
-
-create table t4 (a int)|
-
-create procedure bug12168(arg1 char(1))
-begin
- declare b, c integer;
- if arg1 = 'a' then
- begin
- declare c1 cursor for select a from t3 where a % 2;
- declare continue handler for not found set b = 1;
- set b = 0;
- open c1;
- c1_repeat: repeat
- fetch c1 into c;
- if (b = 1) then
- leave c1_repeat;
- end if;
-
- insert into t4 values (c);
- until b = 1
- end repeat;
- end;
- end if;
- if arg1 = 'b' then
- begin
- declare c2 cursor for select a from t3 where not a % 2;
- declare continue handler for not found set b = 1;
- set b = 0;
- open c2;
- c2_repeat: repeat
- fetch c2 into c;
- if (b = 1) then
- leave c2_repeat;
- end if;
-
- insert into t4 values (c);
- until b = 1
- end repeat;
- end;
- end if;
-end|
-
-call bug12168('a')|
-select * from t4|
-truncate t4|
-call bug12168('b')|
-select * from t4|
-truncate t4|
-call bug12168('a')|
-select * from t4|
-truncate t4|
-call bug12168('b')|
-select * from t4|
-truncate t4|
-drop table t3, t4|
-drop procedure if exists bug12168|
-
-#
-# Bug #11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO
-# query"
-# One more memleak bug. Use the test to check memory consumption.
-#
-
---disable_warnings
-drop table if exists t3|
-drop procedure if exists bug11333|
---enable_warnings
-
-create table t3 (c1 char(128))|
-
-insert into t3 values
- ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')|
-
-
-create procedure bug11333(i int)
-begin
- declare tmp varchar(128);
- set @x = 0;
- repeat
- select c1 into tmp from t3
- where c1 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
- set @x = @x + 1;
- until @x >= i
- end repeat;
-end|
-
-call bug11333(10)|
-
-drop procedure bug11333|
-drop table t3|
-
-#
-# BUG#9048: Creating a function with char binary IN parameter fails
-#
---disable_warnings
-drop function if exists bug9048|
---enable_warnings
-create function bug9048(f1 char binary) returns char binary
-begin
- set f1= concat( 'hello', f1 );
- return f1;
-end|
-drop function bug9048|
-
-# Bug #12849 Stored Procedure: Crash on procedure call with CHAR type
-# 'INOUT' parameter
-#
-
---disable_warnings
-drop procedure if exists bug12849_1|
---enable_warnings
-create procedure bug12849_1(inout x char) select x into x|
-set @var='a'|
-call bug12849_1(@var)|
-select @var|
-drop procedure bug12849_1|
-
---disable_warnings
-drop procedure if exists bug12849_2|
---enable_warnings
-create procedure bug12849_2(inout foo varchar(15))
-begin
-select concat(foo, foo) INTO foo;
-end|
-set @var='abcd'|
-call bug12849_2(@var)|
-select @var|
-drop procedure bug12849_2|
-
-#
-# BUG#13133: Local variables in stored procedures are not initialized correctly.
-#
---disable_warnings
-drop procedure if exists bug131333|
-drop function if exists bug131333|
---enable_warnings
-create procedure bug131333()
-begin
- begin
- declare a int;
-
- select a;
- set a = 1;
- select a;
- end;
- begin
- declare b int;
-
- select b;
- end;
-end|
-
-create function bug131333()
- returns int
-begin
- begin
- declare a int;
-
- set a = 1;
- end;
- begin
- declare b int;
-
- return b;
- end;
-end|
-
-call bug131333()|
-select bug131333()|
-
-drop procedure bug131333|
-drop function bug131333|
-
-#
-# BUG#12379: PROCEDURE with HANDLER calling FUNCTION with error get
-# strange result
-#
---disable_warnings
-drop function if exists bug12379|
-drop procedure if exists bug12379_1|
-drop procedure if exists bug12379_2|
-drop procedure if exists bug12379_3|
-drop table if exists t3|
---enable_warnings
-
-create table t3 (c1 char(1) primary key not null)|
-
-create function bug12379()
- returns integer
-begin
- insert into t3 values('X');
- insert into t3 values('X');
- return 0;
-end|
-
-create procedure bug12379_1()
-begin
- declare exit handler for sqlexception select 42;
-
- select bug12379();
-END|
-create procedure bug12379_2()
-begin
- declare exit handler for sqlexception begin end;
-
- select bug12379();
-end|
-create procedure bug12379_3()
-begin
- select bug12379();
-end|
-
---error 1062
-select bug12379()|
-select 1|
-call bug12379_1()|
-select 2|
-call bug12379_2()|
-select 3|
---error 1062
-call bug12379_3()|
-select 4|
-
-drop function bug12379|
-drop procedure bug12379_1|
-drop procedure bug12379_2|
-drop procedure bug12379_3|
-drop table t3|
-
-#
-# Bug #13124 Stored Procedure using SELECT INTO crashes server
-#
-
---disable_warnings
-drop procedure if exists bug13124|
---enable_warnings
-create procedure bug13124()
-begin
- declare y integer;
- set @x=y;
-end|
-call bug13124()|
-drop procedure bug13124|
-
-#
-# Bug #12979 Stored procedures: crash if inout decimal parameter
-#
-
-# check NULL inout parameters processing
-
---disable_warnings
-drop procedure if exists bug12979_1|
---enable_warnings
-create procedure bug12979_1(inout d decimal(5)) set d = d / 2|
-set @bug12979_user_var = NULL|
-call bug12979_1(@bug12979_user_var)|
-drop procedure bug12979_1|
-
-# check NULL local variables processing
-
---disable_warnings
-drop procedure if exists bug12979_2|
---enable_warnings
-create procedure bug12979_2()
-begin
-declare internal_var decimal(5);
-set internal_var= internal_var / 2;
-select internal_var;
-end|
-call bug12979_2()|
-drop procedure bug12979_2|
-
-
-#
-# BUG#6127: Stored procedure handlers within handlers don't work
-#
---disable_warnings
-drop table if exists t3|
-drop procedure if exists bug6127|
---enable_warnings
-create table t3 (s1 int unique)|
-
-set @sm=@@sql_mode|
-set sql_mode='traditional'|
-
-create procedure bug6127()
-begin
- declare continue handler for sqlstate '23000'
- begin
- declare continue handler for sqlstate '22003'
- insert into t3 values (0);
-
- insert into t3 values (1000000000000000);
- end;
-
- insert into t3 values (1);
- insert into t3 values (1);
-end|
-
-call bug6127()|
-select * from t3|
---error ER_DUP_ENTRY
-call bug6127()|
-select * from t3|
-set sql_mode=@sm|
-drop table t3|
-drop procedure bug6127|
-
-
-#
-# BUG#12589: Assert when creating temp. table from decimal stored procedure
-# variable
-#
---disable_warnings
-drop procedure if exists bug12589_1|
-drop procedure if exists bug12589_2|
-drop procedure if exists bug12589_3|
---enable_warnings
-create procedure bug12589_1()
-begin
- declare spv1 decimal(3,3);
- set spv1= 123.456;
-
- set spv1 = 'test';
- create temporary table tm1 as select spv1;
- show create table tm1;
- drop temporary table tm1;
-end|
-
-create procedure bug12589_2()
-begin
- declare spv1 decimal(6,3);
- set spv1= 123.456;
-
- create temporary table tm1 as select spv1;
- show create table tm1;
- drop temporary table tm1;
-end|
-
-create procedure bug12589_3()
-begin
- declare spv1 decimal(6,3);
- set spv1= -123.456;
-
- create temporary table tm1 as select spv1;
- show create table tm1;
- drop temporary table tm1;
-end|
-
-# Note: The type of the field will match the value, not the declared
-# type of the variable. (This is a type checking issue which
-# might be changed later.)
-
-# Warning expected from "set spv1 = 'test'", the value is set to decimal "0".
-call bug12589_1()|
-# No warnings here
-call bug12589_2()|
-call bug12589_3()|
-drop procedure bug12589_1|
-drop procedure bug12589_2|
-drop procedure bug12589_3|
-
-#
-# BUG#7049: Stored procedure CALL errors are ignored
-#
---disable_warnings
-drop table if exists t3|
-drop procedure if exists bug7049_1|
-drop procedure if exists bug7049_2|
-drop procedure if exists bug7049_3|
-drop procedure if exists bug7049_4|
-drop function if exists bug7049_1|
-drop function if exists bug7049_2|
---enable_warnings
-
-create table t3 ( x int unique )|
-
-create procedure bug7049_1()
-begin
- insert into t3 values (42);
- insert into t3 values (42);
-end|
-
-create procedure bug7049_2()
-begin
- declare exit handler for sqlexception
- select 'Caught it' as 'Result';
-
- call bug7049_1();
- select 'Missed it' as 'Result';
-end|
-
-create procedure bug7049_3()
- call bug7049_1()|
-
-create procedure bug7049_4()
-begin
- declare exit handler for sqlexception
- select 'Caught it' as 'Result';
-
- call bug7049_3();
- select 'Missed it' as 'Result';
-end|
-
-create function bug7049_1()
- returns int
-begin
- insert into t3 values (42);
- insert into t3 values (42);
- return 42;
-end|
-
-create function bug7049_2()
- returns int
-begin
- declare x int default 0;
- declare continue handler for sqlexception
- set x = 1;
-
- set x = bug7049_1();
- return x;
-end|
-
-call bug7049_2()|
-select * from t3|
-delete from t3|
-call bug7049_4()|
-select * from t3|
-select bug7049_2()|
-
-drop table t3|
-drop procedure bug7049_1|
-drop procedure bug7049_2|
-drop procedure bug7049_3|
-drop procedure bug7049_4|
-drop function bug7049_1|
-drop function bug7049_2|
-
-
-#
-# BUG#13941: replace() string fuction behaves badly inside stored procedure
-# (BUG#13914: IFNULL is returning garbage in stored procedure)
-#
---disable_warnings
-drop function if exists bug13941|
-drop procedure if exists bug13941|
---enable_warnings
-
-create function bug13941(p_input_str text)
- returns text
-begin
- declare p_output_str text;
-
- set p_output_str = p_input_str;
-
- set p_output_str = replace(p_output_str, 'xyzzy', 'plugh');
- set p_output_str = replace(p_output_str, 'test', 'prova');
- set p_output_str = replace(p_output_str, 'this', 'questo');
- set p_output_str = replace(p_output_str, ' a ', 'una ');
- set p_output_str = replace(p_output_str, 'is', '');
-
- return p_output_str;
-end|
-
-create procedure bug13941(out sout varchar(128))
-begin
- set sout = 'Local';
- set sout = ifnull(sout, 'DEF');
-end|
-
-# Note: The bug showed different behaviour in different types of builds,
-# giving garbage results in some, and seemingly working in others.
-# Running with valgrind (or purify) is the safe way to check that it's
-# really working correctly.
-select bug13941('this is a test')|
-call bug13941(@a)|
-select @a|
-
-drop function bug13941|
-drop procedure bug13941|
-
-
-#
-# BUG#13095: Cannot create VIEWs in prepared statements
-#
-
-delimiter ;|
-
---disable_warnings
-DROP PROCEDURE IF EXISTS bug13095;
-DROP TABLE IF EXISTS bug13095_t1;
-DROP VIEW IF EXISTS bug13095_v1;
---enable_warnings
-
-delimiter |;
-
-CREATE PROCEDURE bug13095(tbl_name varchar(32))
-BEGIN
- SET @str =
- CONCAT("CREATE TABLE ", tbl_name, "(stuff char(15))");
- SELECT @str;
- PREPARE stmt FROM @str;
- EXECUTE stmt;
-
- SET @str =
- CONCAT("INSERT INTO ", tbl_name, " VALUES('row1'),('row2'),('row3')" );
- SELECT @str;
- PREPARE stmt FROM @str;
- EXECUTE stmt;
-
- SET @str =
- CONCAT("CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM ", tbl_name);
- SELECT @str;
- PREPARE stmt FROM @str;
- EXECUTE stmt;
-
- SELECT * FROM bug13095_v1;
-
- SET @str =
- "DROP VIEW bug13095_v1";
- SELECT @str;
- PREPARE stmt FROM @str;
- EXECUTE stmt;
-END|
-
-delimiter ;|
-
-CALL bug13095('bug13095_t1');
-
---disable_warnings
-DROP PROCEDURE IF EXISTS bug13095;
-DROP VIEW IF EXISTS bug13095_v1;
-DROP TABLE IF EXISTS bug13095_t1;
---enable_warnings
-
-delimiter |;
-
-#
-# BUG#14210: "Simple query with > operator on large table gives server
-# crash"
-# Check that cursors work in case when HEAP tables are converted to
-# MyISAM
-#
---disable_warnings
-drop procedure if exists bug14210|
---enable_warnings
-set @@session.max_heap_table_size=16384|
-select @@session.max_heap_table_size|
-# To trigger the memory corruption the original table must be InnoDB.
-# No harm if it's not, so don't warn if the suite is run with --skip-innodb
---disable_warnings
-create table t3 (a char(255)) engine=InnoDB|
---enable_warnings
-create procedure bug14210_fill_table()
-begin
- declare table_size, max_table_size int default 0;
- select @@session.max_heap_table_size into max_table_size;
- delete from t3;
- insert into t3 (a) values (repeat('a', 255));
- repeat
- insert into t3 select a from t3;
- select count(*)*255 from t3 into table_size;
- until table_size > max_table_size*2 end repeat;
-end|
-call bug14210_fill_table()|
-drop procedure bug14210_fill_table|
-create table t4 like t3|
-
-create procedure bug14210()
-begin
- declare a char(255);
- declare done int default 0;
- declare c cursor for select * from t3;
- declare continue handler for sqlstate '02000' set done = 1;
- open c;
- repeat
- fetch c into a;
- if not done then
- insert into t4 values (upper(a));
- end if;
- until done end repeat;
- close c;
-end|
-call bug14210()|
-select count(*) from t4|
-
-drop table t3, t4|
-drop procedure bug14210|
-set @@session.max_heap_table_size=default|
-
-
-#
-# BUG#1473: Dumping of stored functions seems to cause corruption in
-# the function body
-#
---disable_warnings
-drop function if exists bug14723|
-drop procedure if exists bug14723|
---enable_warnings
-
-delimiter ;;|
-/*!50003 create function bug14723()
- returns bigint(20)
-main_loop: begin
- return 42;
-end */;;
-show create function bug14723;;
-select bug14723();;
-
-/*!50003 create procedure bug14723()
-main_loop: begin
- select 42;
-end */;;
-show create procedure bug14723;;
-call bug14723();;
-
-delimiter |;;
-
-drop function bug14723|
-drop procedure bug14723|
-
-#
-# Bug#14845 "mysql_stmt_fetch returns MYSQL_NO_DATA when COUNT(*) is 0"
-# Check that when fetching from a cursor, COUNT(*) works properly.
-#
-create procedure bug14845()
-begin
- declare a char(255);
- declare done int default 0;
- declare c cursor for select count(*) from t1 where 1 = 0;
- declare continue handler for sqlstate '02000' set done = 1;
- open c;
- repeat
- fetch c into a;
- if not done then
- select a;
- end if;
- until done end repeat;
- close c;
-end|
-call bug14845()|
-drop procedure bug14845|
-
-#
-# BUG#13549 "Server crash with nested stored procedures".
-# Server should not crash when during execution of stored procedure
-# we have to parse trigger/function definition and this new trigger/
-# function has more local variables declared than invoking stored
-# procedure and last of these variables is used in argument of NOT
-# operator.
-#
---disable_warnings
-drop procedure if exists bug13549_1|
-drop procedure if exists bug13549_2|
---enable_warnings
-CREATE PROCEDURE `bug13549_2`()
-begin
- call bug13549_1();
-end|
-CREATE PROCEDURE `bug13549_1`()
-begin
- declare done int default 0;
- set done= not done;
-end|
-CALL bug13549_2()|
-drop procedure bug13549_2|
-drop procedure bug13549_1|
-
-#
-# BUG#10100: function (and stored procedure?) recursivity problem
-#
---disable_warnings
-drop function if exists bug10100f|
-drop procedure if exists bug10100p|
-drop procedure if exists bug10100t|
-drop procedure if exists bug10100pt|
-drop procedure if exists bug10100pv|
-drop procedure if exists bug10100pd|
-drop procedure if exists bug10100pc|
---enable_warnings
-# routines with simple recursion
-create function bug10100f(prm int) returns int
-begin
- if prm > 1 then
- return prm * bug10100f(prm - 1);
- end if;
- return 1;
-end|
-create procedure bug10100p(prm int, inout res int)
-begin
- set res = res * prm;
- if prm > 1 then
- call bug10100p(prm - 1, res);
- end if;
-end|
-create procedure bug10100t(prm int)
-begin
- declare res int;
- set res = 1;
- call bug10100p(prm, res);
- select res;
-end|
-
-# a procedure which use tables and recursion
-create table t3 (a int)|
-insert into t3 values (0)|
-create view v1 as select a from t3;
-create procedure bug10100pt(level int, lim int)
-begin
- if level < lim then
- update t3 set a=level;
- FLUSH TABLES;
- call bug10100pt(level+1, lim);
- else
- select * from t3;
- end if;
-end|
-# view & recursion
-create procedure bug10100pv(level int, lim int)
-begin
- if level < lim then
- update v1 set a=level;
- FLUSH TABLES;
- call bug10100pv(level+1, lim);
- else
- select * from v1;
- end if;
-end|
-# dynamic sql & recursion
-prepare stmt2 from "select * from t3;";
-create procedure bug10100pd(level int, lim int)
-begin
- if level < lim then
- select level;
- prepare stmt1 from "update t3 set a=a+2";
- execute stmt1;
- FLUSH TABLES;
- execute stmt1;
- FLUSH TABLES;
- execute stmt1;
- FLUSH TABLES;
- deallocate prepare stmt1;
- execute stmt2;
- select * from t3;
- call bug10100pd(level+1, lim);
- else
- execute stmt2;
- end if;
-end|
-# cursor & recursion
-create procedure bug10100pc(level int, lim int)
-begin
- declare lv int;
- declare c cursor for select a from t3;
- open c;
- if level < lim then
- select level;
- fetch c into lv;
- select lv;
- update t3 set a=level+lv;
- FLUSH TABLES;
- call bug10100pc(level+1, lim);
- else
- select * from t3;
- end if;
- close c;
-end|
-
-set @@max_sp_recursion_depth=4|
-select @@max_sp_recursion_depth|
--- error ER_SP_NO_RECURSION
-select bug10100f(3)|
--- error ER_SP_NO_RECURSION
-select bug10100f(6)|
-call bug10100t(5)|
-call bug10100pt(1,5)|
-call bug10100pv(1,5)|
-update t3 set a=1|
-call bug10100pd(1,5)|
-select * from t3|
-update t3 set a=1|
-call bug10100pc(1,5)|
-select * from t3|
-set @@max_sp_recursion_depth=0|
-select @@max_sp_recursion_depth|
--- error ER_SP_NO_RECURSION
-select bug10100f(5)|
--- error ER_SP_RECURSION_LIMIT
-call bug10100t(5)|
-
-#end of the stack checking
-set @@max_sp_recursion_depth=255|
-set @var=1|
-#disable log because error about stack overrun contains numbers which
-#depend on a system
--- disable_result_log
--- error ER_STACK_OVERRUN_NEED_MORE
-call bug10100p(255, @var)|
--- error ER_STACK_OVERRUN_NEED_MORE
-call bug10100pt(1,255)|
--- error ER_STACK_OVERRUN_NEED_MORE
-call bug10100pv(1,255)|
--- error ER_STACK_OVERRUN_NEED_MORE
-call bug10100pd(1,255)|
--- error ER_STACK_OVERRUN_NEED_MORE
-call bug10100pc(1,255)|
--- enable_result_log
-set @@max_sp_recursion_depth=0|
-
-deallocate prepare stmt2|
-
-drop function bug10100f|
-drop procedure bug10100p|
-drop procedure bug10100t|
-drop procedure bug10100pt|
-drop procedure bug10100pv|
-drop procedure bug10100pd|
-drop procedure bug10100pc|
-drop view v1|
-
-#
-# BUG#13729: Stored procedures: packet error after exception handled
-#
---disable_warnings
-drop procedure if exists bug13729|
-drop table if exists t3|
---enable_warnings
-
-create table t3 (s1 int, primary key (s1))|
-
-insert into t3 values (1),(2)|
-
-create procedure bug13729()
-begin
- declare continue handler for sqlexception select 55;
-
- update t3 set s1 = 1;
-end|
-
-call bug13729()|
-# Used to cause Packets out of order
-select * from t3|
-
-drop procedure bug13729|
-drop table t3|
-
-#
-# BUG#14643: Stored Procedure: Continuing after failed var. initialization
-# crashes server.
-#
---disable_warnings
-drop procedure if exists bug14643_1|
-drop procedure if exists bug14643_2|
---enable_warnings
-
-create procedure bug14643_1()
-begin
- declare continue handler for sqlexception select 'boo' as 'Handler';
-
- begin
- declare v int default undefined_var;
-
- if v = 1 then
- select 1;
- else
- select v, isnull(v);
- end if;
- end;
-end|
-
-create procedure bug14643_2()
-begin
- declare continue handler for sqlexception select 'boo' as 'Handler';
-
- case undefined_var
- when 1 then
- select 1;
- else
- select 2;
- end case;
-
- select undefined_var;
-end|
-
-call bug14643_1()|
-call bug14643_2()|
-
-drop procedure bug14643_1|
-drop procedure bug14643_2|
-
-#
-# BUG#14304: auto_increment field incorrect set in SP
-#
---disable_warnings
-drop procedure if exists bug14304|
-drop table if exists t3, t4|
---enable_warnings
-
-create table t3(a int primary key auto_increment)|
-create table t4(a int primary key auto_increment)|
-
-create procedure bug14304()
-begin
- insert into t3 set a=null;
- insert into t4 set a=null;
- insert into t4 set a=null;
- insert into t4 set a=null;
- insert into t4 set a=null;
- insert into t4 set a=null;
- insert into t4 select null as a;
-
- insert into t3 set a=null;
- insert into t3 set a=null;
-
- select * from t3;
-end|
-
-call bug14304()|
-
-drop procedure bug14304|
-drop table t3, t4|
-
-#
-# BUG#14376: MySQL crash on scoped variable (re)initialization
-#
---disable_warnings
-drop procedure if exists bug14376|
---enable_warnings
-
-create procedure bug14376()
-begin
- declare x int default x;
-end|
-
-# Not the error we want, but that's what we got for now...
---error ER_BAD_FIELD_ERROR
-call bug14376()|
-drop procedure bug14376|
-
-create procedure bug14376()
-begin
- declare x int default 42;
-
- begin
- declare x int default x;
-
- select x;
- end;
-end|
-
-call bug14376()|
-
-drop procedure bug14376|
-
-create procedure bug14376(x int)
-begin
- declare x int default x;
-
- select x;
-end|
-
-call bug14376(4711)|
-
-drop procedure bug14376|
-
-#
-# Bug#5967 "Stored procedure declared variable used instead of column"
-# The bug should be fixed later.
-# Test precedence of names of parameters, variable declarations,
-# variable declarations in nested compound statements, table columns,
-# table columns in cursor declarations.
-# According to the standard, table columns take precedence over
-# variable declarations. In MySQL 5.0 it's vice versa.
-#
-
---disable_warnings
-drop procedure if exists bug5967|
-drop table if exists t3|
---enable_warnings
-create table t3 (a varchar(255))|
-insert into t3 (a) values ("a - table column")|
-create procedure bug5967(a varchar(255))
-begin
- declare i varchar(255);
- declare c cursor for select a from t3;
- select a;
- select a from t3 into i;
- select i as 'Parameter takes precedence over table column'; open c;
- fetch c into i;
- close c;
- select i as 'Parameter takes precedence over table column in cursors';
- begin
- declare a varchar(255) default 'a - local variable';
- declare c1 cursor for select a from t3;
- select a as 'A local variable takes precedence over parameter';
- open c1;
- fetch c1 into i;
- close c1;
- select i as 'A local variable takes precedence over parameter in cursors';
- begin
- declare a varchar(255) default 'a - local variable in a nested compound statement';
- declare c2 cursor for select a from t3;
- select a as 'A local variable in a nested compound statement takes precedence over a local variable in the outer statement';
- select a from t3 into i;
- select i as 'A local variable in a nested compound statement takes precedence over table column';
- open c2;
- fetch c2 into i;
- close c2;
- select i as 'A local variable in a nested compound statement takes precedence over table column in cursors';
- end;
- end;
-end|
-call bug5967("a - stored procedure parameter")|
-drop procedure bug5967|
-
-#
-# Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server"
-#
---disable_warnings
-drop procedure if exists bug13012|
---enable_warnings
-create procedure bug13012()
-BEGIN
- REPAIR TABLE t1;
- BACKUP TABLE t1 to '../tmp';
- DROP TABLE t1;
- RESTORE TABLE t1 FROM '../tmp';
-END|
-call bug13012()|
-drop procedure bug13012|
-create view v1 as select * from t1|
-create procedure bug13012()
-BEGIN
- REPAIR TABLE t1,t2,t3,v1;
- OPTIMIZE TABLE t1,t2,t3,v1;
- ANALYZE TABLE t1,t2,t3,v1;
-END|
-call bug13012()|
-call bug13012()|
-call bug13012()|
-drop procedure bug13012|
-drop view v1;
-select * from t1|
-
-#
-# A test case for Bug#15392 "Server crashes during prepared statement
-# execute": make sure that stored procedure check for error conditions
-# properly and do not continue execution if an error has been set.
-#
-# It's necessary to use several DBs because in the original code
-# the successful return of mysql_change_db overrode the error from
-# execution.
-drop schema if exists mysqltest1|
-drop schema if exists mysqltest2|
-drop schema if exists mysqltest3|
-create schema mysqltest1|
-create schema mysqltest2|
-create schema mysqltest3|
-use mysqltest3|
-
-create procedure mysqltest1.p1 (out prequestid varchar(100))
-begin
- call mysqltest2.p2('call mysqltest3.p3(1, 2)');
-end|
-
-create procedure mysqltest2.p2(in psql text)
-begin
- declare lsql text;
- set @lsql= psql;
- prepare lstatement from @lsql;
- execute lstatement;
- deallocate prepare lstatement;
-end|
-
-create procedure mysqltest3.p3(in p1 int)
-begin
- select p1;
-end|
-
---error ER_SP_WRONG_NO_OF_ARGS
-call mysqltest1.p1(@rs)|
---error ER_SP_WRONG_NO_OF_ARGS
-call mysqltest1.p1(@rs)|
---error ER_SP_WRONG_NO_OF_ARGS
-call mysqltest1.p1(@rs)|
-drop schema if exists mysqltest1|
-drop schema if exists mysqltest2|
-drop schema if exists mysqltest3|
-use test|
-
-#
-# Bug#15441 "Running SP causes Server to Crash": check that an SP variable
-# can not be used in VALUES() function.
-#
---disable_warnings
-drop table if exists t3|
-drop procedure if exists bug15441|
---enable_warnings
-create table t3 (id int not null primary key, county varchar(25))|
-insert into t3 (id, county) values (1, 'York')|
-
-# First check that a stored procedure that refers to a parameter in VALUES()
-# function won't parse.
-
-create procedure bug15441(c varchar(25))
-begin
- update t3 set id=2, county=values(c);
-end|
---error ER_BAD_FIELD_ERROR
-call bug15441('county')|
-drop procedure bug15441|
-
-# Now check the case when there is an ambiguity between column names
-# and stored procedure parameters: the parser shall resolve the argument
-# of VALUES() function to the column name.
-
-# It's hard to deduce what county refers to in every case (INSERT statement):
-# 1st county refers to the column
-# 2nd county refers to the procedure parameter
-# 3d and 4th county refers to the column, again, but
-# for 4th county it has the value of SP parameter
-
-# In UPDATE statement, just check that values() function returns NULL for
-# non- INSERT...UPDATE statements, as stated in the manual.
-
-create procedure bug15441(county varchar(25))
-begin
- declare c varchar(25) default "hello";
-
- insert into t3 (id, county) values (1, county)
- on duplicate key update county= values(county);
- select * from t3;
-
- update t3 set id=2, county=values(id);
- select * from t3;
-end|
-call bug15441('Yale')|
-drop table t3|
-drop procedure bug15441|
-
-#
-# BUG#14498: Stored procedures: hang if undefined variable and exception
-#
---disable_warnings
-drop procedure if exists bug14498_1|
-drop procedure if exists bug14498_2|
-drop procedure if exists bug14498_3|
-drop procedure if exists bug14498_4|
-drop procedure if exists bug14498_5|
---enable_warnings
-
-create procedure bug14498_1()
-begin
- declare continue handler for sqlexception select 'error' as 'Handler';
-
- if v then
- select 'yes' as 'v';
- else
- select 'no' as 'v';
- end if;
- select 'done' as 'End';
-end|
-
-create procedure bug14498_2()
-begin
- declare continue handler for sqlexception select 'error' as 'Handler';
-
- while v do
- select 'yes' as 'v';
- end while;
- select 'done' as 'End';
-end|
-
-create procedure bug14498_3()
-begin
- declare continue handler for sqlexception select 'error' as 'Handler';
-
- repeat
- select 'maybe' as 'v';
- until v end repeat;
- select 'done' as 'End';
-end|
-
-create procedure bug14498_4()
-begin
- declare continue handler for sqlexception select 'error' as 'Handler';
-
- case v
- when 1 then
- select '1' as 'v';
- when 2 then
- select '2' as 'v';
- else
- select '?' as 'v';
- end case;
- select 'done' as 'End';
-end|
-
-create procedure bug14498_5()
-begin
- declare continue handler for sqlexception select 'error' as 'Handler';
-
- case
- when v = 1 then
- select '1' as 'v';
- when v = 2 then
- select '2' as 'v';
- else
- select '?' as 'v';
- end case;
- select 'done' as 'End';
-end|
-
-call bug14498_1()|
-call bug14498_2()|
-call bug14498_3()|
-call bug14498_4()|
-call bug14498_5()|
-
-drop procedure bug14498_1|
-drop procedure bug14498_2|
-drop procedure bug14498_3|
-drop procedure bug14498_4|
-drop procedure bug14498_5|
-
-#
-# BUG#15231: Stored procedure bug with not found condition handler
-#
---disable_warnings
-drop table if exists t3|
-drop procedure if exists bug15231_1|
-drop procedure if exists bug15231_2|
-drop procedure if exists bug15231_3|
-drop procedure if exists bug15231_4|
---enable_warnings
-
-create table t3 (id int not null)|
-
-create procedure bug15231_1()
-begin
- declare xid integer;
- declare xdone integer default 0;
- declare continue handler for not found set xdone = 1;
-
- set xid=null;
- call bug15231_2(xid);
- select xid, xdone;
-end|
-
-create procedure bug15231_2(inout ioid integer)
-begin
- select "Before NOT FOUND condition is triggered" as '1';
- select id into ioid from t3 where id=ioid;
- select "After NOT FOUND condtition is triggered" as '2';
-
- if ioid is null then
- set ioid=1;
- end if;
-end|
-
-create procedure bug15231_3()
-begin
- declare exit handler for sqlwarning
- select 'Caught it (wrong)' as 'Result';
-
- call bug15231_4();
-end|
-
-create procedure bug15231_4()
-begin
- declare x decimal(2,1);
-
- set x = 'zap';
- select 'Missed it (correct)' as 'Result';
-end|
-
-call bug15231_1()|
-call bug15231_3()|
-
-drop table if exists t3|
-drop procedure if exists bug15231_1|
-drop procedure if exists bug15231_2|
-drop procedure if exists bug15231_3|
-drop procedure if exists bug15231_4|
-
-
-#
-# BUG#15011: error handler in nested block not activated
-#
---disable_warnings
-drop procedure if exists bug15011|
---enable_warnings
-
-create table t3 (c1 int primary key)|
-
-insert into t3 values (1)|
-
-create procedure bug15011()
- deterministic
-begin
- declare continue handler for 1062
- select 'Outer' as 'Handler';
-
- begin
- declare continue handler for 1062
- select 'Inner' as 'Handler';
-
- insert into t3 values (1);
- end;
-end|
-
-call bug15011()|
-
-drop procedure bug15011|
-drop table t3|
-
-
-#
-# BUG#NNNN: New bug synopsis
-#
-#--disable_warnings
-#drop procedure if exists bugNNNN|
-#--enable_warnings
-#create procedure bugNNNN...
-
-# Add bugs above this line. Use existing tables t1 and t2 when
-# practical, or create table t3, t4 etc temporarily (and drop them).
-delimiter ;|
-drop table t1,t2;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 8bf8337714f..c9ed62f0e54 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -1851,6 +1851,24 @@ select 1 from dual where 2 > any (select 1);
select 1 from dual where 2 > all (select 1);
select 1 from dual where 1 < any (select 2 from dual);
select 1 from dual where 1 < all (select 2 from dual where 1!=1);
+
+# BUG#20975 Wrong query results for subqueries within NOT
+create table t1 (s1 char);
+insert into t1 values (1),(2);
+
+select * from t1 where (s1 < any (select s1 from t1));
+select * from t1 where not (s1 < any (select s1 from t1));
+
+select * from t1 where (s1 < ALL (select s1+1 from t1));
+select * from t1 where not(s1 < ALL (select s1+1 from t1));
+
+select * from t1 where (s1+1 = ANY (select s1 from t1));
+select * from t1 where NOT(s1+1 = ANY (select s1 from t1));
+
+select * from t1 where (s1 = ALL (select s1/s1 from t1));
+select * from t1 where NOT(s1 = ALL (select s1/s1 from t1));
+drop table t1;
+# End of 4.1 tests
# End of 4.1 tests
#
diff --git a/mysql-test/t/subselect2.test b/mysql-test/t/subselect2.test
index b21eda176b6..162bdd0d90a 100644
--- a/mysql-test/t/subselect2.test
+++ b/mysql-test/t/subselect2.test
@@ -150,3 +150,21 @@ EXPLAIN SELECT t2.*, t4.DOCTYPENAME, t1.CONTENTSIZE,t1.MIMETYPE FROM t2 INNER JO
drop table t1, t2, t3, t4;
# End of 4.1 tests
+
+#
+# Bug #20792: Incorrect results from aggregate subquery
+#
+CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t1 VALUES (1),(2);
+
+CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t2 VALUES (1);
+
+CREATE TABLE t3 (a int(10), b int(10), c int(10),
+ PRIMARY KEY (a)) Engine=InnoDB;
+INSERT INTO t3 VALUES (1,2,1);
+
+SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a
+ and t2.a='1' AND t1.a=t3.b) > 0;
+
+DROP TABLE t1,t2,t3;
diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test
index e0c2493c616..96e559f5c05 100644
--- a/mysql-test/t/udf.test
+++ b/mysql-test/t/udf.test
@@ -109,6 +109,24 @@ SELECT myfunc_double(n) AS f FROM bug19904;
SELECT metaphon(v) AS f FROM bug19904;
DROP TABLE bug19904;
+#
+# Bug#21269: DEFINER-clause is allowed for UDF-functions
+#
+
+--error ER_WRONG_USAGE
+CREATE DEFINER=CURRENT_USER() FUNCTION should_not_parse
+RETURNS STRING SONAME "should_not_parse.so";
+
+--error ER_WRONG_USAGE
+CREATE DEFINER=someone@somewhere FUNCTION should_not_parse
+RETURNS STRING SONAME "should_not_parse.so";
+#
+# Bug#19862: Sort with filesort by function evaluates function twice
+#
+create table t1(f1 int);
+insert into t1 values(1),(2);
+explain select myfunc_int(f1) from t1 order by 1;
+drop table t1;
--echo End of 5.0 tests.
#
diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test
index 7dfe4ac482f..fdb5f968589 100644
--- a/mysql-test/t/union.test
+++ b/mysql-test/t/union.test
@@ -390,8 +390,8 @@ create table t1 SELECT da from t2 UNION select dt from t2;
select * from t1;
show create table t1;
drop table t1;
-create table t1 SELECT dt from t2 UNION select sc from t2;
-select * from t1;
+create table t1 SELECT dt from t2 UNION select trim(sc) from t2;
+select trim(dt) from t1;
show create table t1;
drop table t1;
create table t1 SELECT dt from t2 UNION select sv from t2;
@@ -795,6 +795,14 @@ drop table t1;
# End of 4.1 tests
#
+# Bug#12185: Data type aggregation may produce wrong result
+#
+create table t1(f1 char(1), f2 char(5), f3 binary(1), f4 binary(5), f5 timestamp, f6 varchar(1) character set utf8 collate utf8_general_ci, f7 text);
+create table t2 as select *, f6 as f8 from t1 union select *, f7 from t1;
+show create table t2;
+drop table t1, t2;
+
+#
# Bug#18175: Union select over 129 tables with a sum function fails.
#
(select avg(1)) union (select avg(1)) union (select avg(1)) union
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 88a4d489039..5cb85ca6c9b 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -2643,3 +2643,78 @@ DESCRIBE t2;
DROP VIEW v1;
DROP TABLE t1,t2;
+
+#
+# Bug #17526: views with TRIM functions
+#
+
+CREATE TABLE t1 (s varchar(10));
+INSERT INTO t1 VALUES ('yadda'), ('yady');
+
+SELECT TRIM(BOTH 'y' FROM s) FROM t1;
+CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1;
+SELECT * FROM v1;
+DROP VIEW v1;
+
+SELECT TRIM(LEADING 'y' FROM s) FROM t1;
+CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1;
+SELECT * FROM v1;
+DROP VIEW v1;
+
+SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
+CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
+SELECT * FROM v1;
+DROP VIEW v1;
+
+DROP TABLE t1;
+
+#
+#Bug #21080: ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM
+#
+CREATE TABLE t1 (x INT, y INT);
+CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1;
+SHOW CREATE VIEW v1;
+
+ALTER VIEW v1 AS SELECT x, y FROM t1;
+SHOW CREATE VIEW v1;
+
+DROP VIEW v1;
+DROP TABLE t1;
+# Bug #21086: server crashes when VIEW defined with a SELECT with COLLATE
+# clause is called
+#
+CREATE TABLE t1 (s1 char);
+INSERT INTO t1 VALUES ('Z');
+
+CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1;
+
+CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1;
+
+# either of these statements will cause crash
+INSERT INTO v1 (col) VALUES ('b');
+INSERT INTO v2 (col) VALUES ('c');
+
+SELECT s1 FROM t1;
+DROP VIEW v1, v2;
+DROP TABLE t1;
+
+#
+# Bug #11551: Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE
+#
+CREATE TABLE t1 (id INT);
+CREATE VIEW v1 AS SELECT id FROM t1;
+SHOW TABLES;
+
+--error 1051
+DROP VIEW v2,v1;
+SHOW TABLES;
+
+CREATE VIEW v1 AS SELECT id FROM t1;
+--error 1347
+DROP VIEW t1,v1;
+SHOW TABLES;
+
+DROP TABLE t1;
+--disable_warnings
+DROP VIEW IF EXISTS v1;
+--enable_warnings
diff --git a/mysys/my_open.c b/mysys/my_open.c
index 6ed3cb5becf..a0168b23b16 100644
--- a/mysys/my_open.c
+++ b/mysys/my_open.c
@@ -335,7 +335,7 @@ File my_sopen(const char *path, int oflag, int shflag, int pmode)
* try to open/create the file
*/
if ((osfh= CreateFile(path, fileaccess, fileshare, &SecurityAttributes,
- filecreate, fileattrib, NULL)) == (HANDLE)0xffffffff)
+ filecreate, fileattrib, NULL)) == INVALID_HANDLE_VALUE)
{
/*
* OS call to open/create file failed! map the error, release
@@ -346,7 +346,7 @@ File my_sopen(const char *path, int oflag, int shflag, int pmode)
return -1; /* return error to caller */
}
- fh= _open_osfhandle((long)osfh, oflag & (_O_APPEND | _O_RDONLY | _O_TEXT));
+ fh= _open_osfhandle((intptr_t)osfh, oflag & (_O_APPEND | _O_RDONLY | _O_TEXT));
return fh; /* return handle */
}
diff --git a/scripts/make_win_src_distribution.sh b/scripts/make_win_src_distribution.sh
index d9333540ab8..6206ca64121 100644
--- a/scripts/make_win_src_distribution.sh
+++ b/scripts/make_win_src_distribution.sh
@@ -206,7 +206,7 @@ copy_dir_files()
for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def *.hpp *.yy *dsp *.dsw \
README INSTALL* LICENSE AUTHORS NEWS ChangeLog \
*.inc *.test *.result *.pem Moscow_leap des_key_file \
- *.vcproj *.sln *.dat *.000001 *.require *.opt
+ *.vcproj *.sln *.dat *.000001 *.require *.opt *.cnf
do
if [ -f $i ]
then
diff --git a/sql-common/client.c b/sql-common/client.c
index 45cd8befdf0..6819caddf35 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -584,7 +584,7 @@ err:
*****************************************************************************/
ulong
-net_safe_read(MYSQL *mysql)
+cli_safe_read(MYSQL *mysql)
{
NET *net= &mysql->net;
ulong len=0;
@@ -627,6 +627,16 @@ net_safe_read(MYSQL *mysql)
}
else
set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
+ /*
+ Cover a protocol design error: error packet does not
+ contain the server status. Therefore, the client has no way
+ to find out whether there are more result sets of
+ a multiple-result-set statement pending. Luckily, in 5.0 an
+ error always aborts execution of a statement, wherever it is
+ a multi-statement or a stored procedure, so it should be
+ safe to unconditionally turn off the flag here.
+ */
+ mysql->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
DBUG_PRINT("error",("Got error: %d/%s (%s)",
net->last_errno, net->sqlstate, net->last_error));
@@ -653,7 +663,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
NET *net= &mysql->net;
my_bool result= 1;
init_sigpipe_variables
- DBUG_ENTER("cli_advanced_command");
+ DBUG_ENTER("cli_advanced_command");
/* Don't give sigpipe errors if the client doesn't want them */
set_sigpipe(mysql);
@@ -663,7 +673,8 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
if (mysql_reconnect(mysql))
DBUG_RETURN(1);
}
- if (mysql->status != MYSQL_STATUS_READY)
+ if (mysql->status != MYSQL_STATUS_READY ||
+ mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
{
DBUG_PRINT("error",("state: %d", mysql->status));
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
@@ -702,7 +713,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
}
result=0;
if (!skip_check)
- result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ?
+ result= ((mysql->packet_length=cli_safe_read(mysql)) == packet_error ?
1 : 0);
end:
reset_sigpipe(mysql);
@@ -754,7 +765,7 @@ static void cli_flush_use_result(MYSQL *mysql)
for (;;)
{
ulong pkt_len;
- if ((pkt_len=net_safe_read(mysql)) == packet_error)
+ if ((pkt_len=cli_safe_read(mysql)) == packet_error)
break;
if (pkt_len <= 8 && mysql->net.read_pos[0] == 254)
{
@@ -1276,7 +1287,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
NET *net = &mysql->net;
DBUG_ENTER("cli_read_rows");
- if ((pkt_len= net_safe_read(mysql)) == packet_error)
+ if ((pkt_len= cli_safe_read(mysql)) == packet_error)
DBUG_RETURN(0);
if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA),
MYF(MY_WME | MY_ZEROFILL))))
@@ -1341,7 +1352,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
}
}
cur->data[field]=to; /* End of last field */
- if ((pkt_len=net_safe_read(mysql)) == packet_error)
+ if ((pkt_len=cli_safe_read(mysql)) == packet_error)
{
free_rows(result);
DBUG_RETURN(0);
@@ -1373,7 +1384,7 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
uchar *pos, *prev_pos, *end_pos;
NET *net= &mysql->net;
- if ((pkt_len=net_safe_read(mysql)) == packet_error)
+ if ((pkt_len=cli_safe_read(mysql)) == packet_error)
return -1;
if (pkt_len <= 8 && net->read_pos[0] == 254)
{
@@ -1650,23 +1661,23 @@ static MYSQL_RES *cli_use_result(MYSQL *mysql);
static MYSQL_METHODS client_methods=
{
- cli_read_query_result,
- cli_advanced_command,
- cli_read_rows,
- cli_use_result,
- cli_fetch_lengths,
- cli_flush_use_result
+ cli_read_query_result, /* read_query_result */
+ cli_advanced_command, /* advanced_command */
+ cli_read_rows, /* read_rows */
+ cli_use_result, /* use_result */
+ cli_fetch_lengths, /* fetch_lengths */
+ cli_flush_use_result /* flush_use_result */
#ifndef MYSQL_SERVER
- ,cli_list_fields,
- cli_read_prepare_result,
- cli_stmt_execute,
- cli_read_binary_rows,
- cli_unbuffered_fetch,
- NULL,
- cli_read_statistics,
- cli_read_query_result,
- cli_read_change_user_result,
- cli_read_binary_rows
+ ,cli_list_fields, /* list_fields */
+ cli_read_prepare_result, /* read_prepare_result */
+ cli_stmt_execute, /* stmt_execute */
+ cli_read_binary_rows, /* read_binary_rows */
+ cli_unbuffered_fetch, /* unbuffered_fetch */
+ NULL, /* free_embedded_thd */
+ cli_read_statistics, /* read_statistics */
+ cli_read_query_result, /* next_result */
+ cli_read_change_user_result, /* read_change_user_result */
+ cli_read_binary_rows /* read_rows_from_cursor */
#endif
};
@@ -2029,7 +2040,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
Part 1: Connection established, read and parse first packet
*/
- if ((pkt_length=net_safe_read(mysql)) == packet_error)
+ if ((pkt_length=cli_safe_read(mysql)) == packet_error)
goto error;
/* Check if version of protocol matches current one */
@@ -2253,7 +2264,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
OK-packet, or re-request scrambled password.
*/
- if ((pkt_length=net_safe_read(mysql)) == packet_error)
+ if ((pkt_length=cli_safe_read(mysql)) == packet_error)
goto error;
if (pkt_length == 1 && net->read_pos[0] == 254 &&
@@ -2270,7 +2281,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
goto error;
}
/* Read what server thinks about out new auth message report */
- if (net_safe_read(mysql) == packet_error)
+ if (cli_safe_read(mysql) == packet_error)
goto error;
}
@@ -2594,7 +2605,7 @@ static my_bool cli_read_query_result(MYSQL *mysql)
*/
mysql = mysql->last_used_con;
- if ((length = net_safe_read(mysql)) == packet_error)
+ if ((length = cli_safe_read(mysql)) == packet_error)
DBUG_RETURN(1);
free_old_query(mysql); /* Free old result */
#ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/
@@ -2629,7 +2640,7 @@ get_info:
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
{
int error=handle_local_infile(mysql,(char*) pos);
- if ((length=net_safe_read(mysql)) == packet_error || error)
+ if ((length= cli_safe_read(mysql)) == packet_error || error)
DBUG_RETURN(1);
goto get_info; /* Get info packet */
}
diff --git a/sql/field.cc b/sql/field.cc
index 98de224f900..921148e8f0f 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -4387,6 +4387,24 @@ Field_timestamp::Field_timestamp(char *ptr_arg, uint32 len_arg,
}
+Field_timestamp::Field_timestamp(bool maybe_null_arg,
+ const char *field_name_arg,
+ struct st_table *table_arg, CHARSET_INFO *cs)
+ :Field_str((char*) 0, 19, maybe_null_arg ? (uchar*) "": 0, 0,
+ NONE, field_name_arg, table_arg, cs)
+{
+ /* For 4.0 MYD and 4.0 InnoDB compatibility */
+ flags|= ZEROFILL_FLAG | UNSIGNED_FLAG;
+ if (table && !table->timestamp_field &&
+ unireg_check != NONE)
+ {
+ /* This timestamp has auto-update */
+ table->timestamp_field= this;
+ flags|=TIMESTAMP_FLAG;
+ }
+}
+
+
/*
Get auto-set type for TIMESTAMP field.
diff --git a/sql/field.h b/sql/field.h
index 09638b9a979..3306c4123db 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -780,6 +780,8 @@ public:
enum utype unireg_check_arg, const char *field_name_arg,
struct st_table *table_arg,
CHARSET_INFO *cs);
+ Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
+ struct st_table *table_arg, CHARSET_INFO *cs);
enum_field_types type() const { return FIELD_TYPE_TIMESTAMP;}
enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
enum Item_result cmp_type () const { return INT_RESULT; }
@@ -1128,6 +1130,21 @@ public:
{
flags|= BLOB_FLAG;
}
+ Field_blob(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
+ struct st_table *table_arg, CHARSET_INFO *cs, bool set_packlength)
+ :Field_longstr((char*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
+ NONE, field_name_arg, table_arg, cs)
+ {
+ flags|= BLOB_FLAG;
+ packlength= 4;
+ if (set_packlength)
+ {
+ uint32 char_length= len_arg/cs->mbmaxlen;
+ packlength= char_length <= 255 ? 1 :
+ char_length <= 65535 ? 2 :
+ char_length <= 16777215 ? 3 : 4;
+ }
+ }
enum_field_types type() const { return FIELD_TYPE_BLOB;}
enum ha_base_keytype key_type() const
{ return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 6aadce0191a..472506f9903 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -5943,14 +5943,6 @@ ha_innobase::start_stmt(
innobase_release_stat_resources(trx);
- if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
- && trx->global_read_view) {
- /* At low transaction isolation levels we let
- each consistent read set its own snapshot */
-
- read_view_close_for_mysql(trx);
- }
-
prebuilt->sql_stat_start = TRUE;
prebuilt->hint_need_to_fetch_extra_cols = 0;
prebuilt->read_just_key = 0;
@@ -6684,17 +6676,17 @@ ha_innobase::store_lock(
&& !thd->tablespace_op
&& thd->lex->sql_command != SQLCOM_TRUNCATE
&& thd->lex->sql_command != SQLCOM_OPTIMIZE
+
#ifdef __WIN__
- /*
- for alter table on win32 for succesfull operation
- completion it is used TL_WRITE(=10) lock instead of
- TL_WRITE_ALLOW_READ(=6), however here in innodb handler
- TL_WRITE is lifted to TL_WRITE_ALLOW_WRITE, which causes
- race condition when several clients do alter table
- simultaneously (bug #17264). This fix avoids the problem.
- */
- && thd->lex->sql_command != SQLCOM_ALTER_TABLE
+ /* For alter table on win32 for succesful operation
+ completion it is used TL_WRITE(=10) lock instead of
+ TL_WRITE_ALLOW_READ(=6), however here in innodb handler
+ TL_WRITE is lifted to TL_WRITE_ALLOW_WRITE, which causes
+ race condition when several clients do alter table
+ simultaneously (bug #17264). This fix avoids the problem. */
+ && thd->lex->sql_command != SQLCOM_ALTER_TABLE
#endif
+
&& thd->lex->sql_command != SQLCOM_CREATE_TABLE) {
lock_type = TL_WRITE_ALLOW_WRITE;
diff --git a/sql/item.cc b/sql/item.cc
index ad8b79182d4..95ff5462fad 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1424,7 +1424,8 @@ bool agg_item_charsets(DTCollation &coll, const char *fname,
In case we're in statement prepare, create conversion item
in its memory: it will be reused on each execute.
*/
- arena= thd->activate_stmt_arena_if_needed(&backup);
+ arena= thd->is_stmt_prepare() ? thd->activate_stmt_arena_if_needed(&backup)
+ : NULL;
for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
{
@@ -1459,7 +1460,7 @@ bool agg_item_charsets(DTCollation &coll, const char *fname,
been created in prepare. In this case register the change for
rollback.
*/
- if (arena && arena->is_conventional())
+ if (arena)
*arg= conv;
else
thd->change_item_tree(arg, conv);
@@ -3903,7 +3904,9 @@ Field *Item::make_string_field(TABLE *table)
if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
return new Field_blob(max_length, maybe_null, name, table,
collation.collation);
- if (max_length > 0)
+ /* Item_type_holder holds the exact type, do not change it */
+ if (max_length > 0 &&
+ (type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
return new Field_varstring(max_length, maybe_null, name, table,
collation.collation);
return new Field_string(max_length, maybe_null, name, table,
@@ -3967,6 +3970,7 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table)
case MYSQL_TYPE_TIME:
return new Field_time(maybe_null, name, table, &my_charset_bin);
case MYSQL_TYPE_TIMESTAMP:
+ return new Field_timestamp(maybe_null, name, table, &my_charset_bin);
case MYSQL_TYPE_DATETIME:
return new Field_datetime(maybe_null, name, table, &my_charset_bin);
case MYSQL_TYPE_YEAR:
@@ -3990,7 +3994,11 @@ Field *Item::tmp_table_field_from_field_type(TABLE *table)
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_GEOMETRY:
- return new Field_blob(max_length, maybe_null, name, table,
+ if (this->type() == Item::TYPE_HOLDER)
+ return new Field_blob(max_length, maybe_null, name, table,
+ collation.collation, 1);
+ else
+ return new Field_blob(max_length, maybe_null, name, table,
collation.collation);
break; // Blob handled outside of case
}
@@ -6151,7 +6159,7 @@ uint32 Item_type_holder::display_length(Item *item)
case MYSQL_TYPE_DOUBLE:
return 53;
case MYSQL_TYPE_NULL:
- return 4;
+ return 0;
case MYSQL_TYPE_LONGLONG:
return 20;
case MYSQL_TYPE_INT24:
diff --git a/sql/item.h b/sql/item.h
index 0f49145082f..514c31c2d74 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -752,6 +752,7 @@ public:
virtual bool find_item_in_field_list_processor(byte *arg) { return 0; }
virtual bool change_context_processor(byte *context) { return 0; }
virtual bool reset_query_id_processor(byte *query_id) { return 0; }
+ virtual bool is_expensive_processor(byte *arg) { return 0; }
virtual Item *equal_fields_propagator(byte * arg) { return this; }
virtual Item *set_no_const_sub(byte *arg) { return this; }
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 98453899375..34170124cd7 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -3656,6 +3656,28 @@ Item *Item_cond_or::neg_transformer(THD *thd) /* NOT(a OR b OR ...) -> */
}
+Item *Item_func_nop_all::neg_transformer(THD *thd)
+{
+ /* "NOT (e $cmp$ ANY (SELECT ...)) -> e $rev_cmp$" ALL (SELECT ...) */
+ Item_func_not_all *new_item= new Item_func_not_all(args[0]);
+ Item_allany_subselect *allany= (Item_allany_subselect*)args[0];
+ allany->func= allany->func_creator(FALSE);
+ allany->all= !allany->all;
+ allany->upper_item= new_item;
+ return new_item;
+}
+
+Item *Item_func_not_all::neg_transformer(THD *thd)
+{
+ /* "NOT (e $cmp$ ALL (SELECT ...)) -> e $rev_cmp$" ANY (SELECT ...) */
+ Item_func_nop_all *new_item= new Item_func_nop_all(args[0]);
+ Item_allany_subselect *allany= (Item_allany_subselect*)args[0];
+ allany->all= !allany->all;
+ allany->func= allany->func_creator(TRUE);
+ allany->upper_item= new_item;
+ return new_item;
+}
+
Item *Item_func_eq::negated_item() /* a = b -> a != b */
{
return new Item_func_ne(args[0], args[1]);
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index a2b10eacc79..47f9f2aa98f 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -311,6 +311,7 @@ public:
void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; };
void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; };
bool empty_underlying_subquery();
+ Item *neg_transformer(THD *thd);
};
@@ -321,6 +322,7 @@ public:
Item_func_nop_all(Item *a) :Item_func_not_all(a) {}
longlong val_int();
const char *func_name() const { return "<nop>"; }
+ Item *neg_transformer(THD *thd);
};
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 1d906b300b6..d3458103f6e 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -398,6 +398,13 @@ Field *Item_func::tmp_table_field(TABLE *t_arg)
return res;
}
+
+bool Item_func::is_expensive_processor(byte *arg)
+{
+ return is_expensive();
+}
+
+
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed);
@@ -4830,7 +4837,9 @@ Item_func_sp::execute_impl(THD *thd, Field *return_value_fld)
{
bool err_status= TRUE;
Sub_statement_state statement_state;
- Security_context *save_security_ctx= thd->security_ctx, *save_ctx_func;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ Security_context *save_security_ctx= thd->security_ctx;
+#endif
DBUG_ENTER("Item_func_sp::execute_impl");
@@ -4841,7 +4850,7 @@ Item_func_sp::execute_impl(THD *thd, Field *return_value_fld)
thd->security_ctx= context->security_ctx;
}
#endif
- if (find_and_check_access(thd, EXECUTE_ACL, &save_ctx_func))
+ if (find_and_check_access(thd))
goto error;
/*
@@ -4853,13 +4862,11 @@ Item_func_sp::execute_impl(THD *thd, Field *return_value_fld)
err_status= m_sp->execute_function(thd, args, arg_count, return_value_fld);
thd->restore_sub_statement_state(&statement_state);
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- sp_restore_security_context(thd, save_ctx_func);
error:
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
thd->security_ctx= save_security_ctx;
-#else
-error:
#endif
+
DBUG_RETURN(err_status);
}
@@ -4976,70 +4983,38 @@ Item_func_sp::tmp_table_field(TABLE *t_arg)
SYNOPSIS
find_and_check_access()
thd thread handler
- want_access requested access
- save backup of security context
RETURN
FALSE Access granted
TRUE Requested access can't be granted or function doesn't exists
- In this case security context is not changed and *save = 0
NOTES
Checks if requested access to function can be granted to user.
If function isn't found yet, it searches function first.
If function can't be found or user don't have requested access
error is raised.
- If security context sp_ctx is provided and access can be granted then
- switch back to previous context isn't performed.
- In case of access error or if context is not provided then
- find_and_check_access() switches back to previous security context.
*/
bool
-Item_func_sp::find_and_check_access(THD *thd, ulong want_access,
- Security_context **save)
+Item_func_sp::find_and_check_access(THD *thd)
{
- bool res= TRUE;
-
- *save= 0; // Safety if error
if (! m_sp && ! (m_sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, m_name,
&thd->sp_func_cache, TRUE)))
{
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname.str);
- goto error;
+ return TRUE;
}
#ifndef NO_EMBEDDED_ACCESS_CHECKS
- if (check_routine_access(thd, want_access,
+ if (check_routine_access(thd, EXECUTE_ACL,
m_sp->m_db.str, m_sp->m_name.str, 0, FALSE))
- goto error;
-
- sp_change_security_context(thd, m_sp, save);
- /*
- If we changed context to run as another user, we need to check the
- access right for the new context again as someone may have deleted
- this person the right to use the procedure
-
- TODO:
- Cache if the definer has the right to use the object on the first
- usage and only reset the cache if someone does a GRANT statement
- that 'may' affect this.
- */
- if (*save &&
- check_routine_access(thd, want_access,
- m_sp->m_db.str, m_sp->m_name.str, 0, FALSE))
- {
- sp_restore_security_context(thd, *save);
- *save= 0; // Safety
- goto error;
- }
+ return TRUE;
#endif
- res= FALSE; // no error
-error:
- return res;
+ return FALSE;
}
+
bool
Item_func_sp::fix_fields(THD *thd, Item **ref)
{
@@ -5050,19 +5025,23 @@ Item_func_sp::fix_fields(THD *thd, Item **ref)
{
/*
Here we check privileges of the stored routine only during view
- creation, in order to validate the view. A runtime check is perfomed
- in Item_func_sp::execute(), and this method is not called during
- context analysis. We do not need to restore the security context
- changed in find_and_check_access because all view structures created
- in CREATE VIEW are not used for execution. Notice, that during view
- creation we do not infer into stored routine bodies and do not check
- privileges of its statements, which would probably be a good idea
- especially if the view has SQL SECURITY DEFINER and the used stored
- procedure has SQL SECURITY DEFINER
+ creation, in order to validate the view. A runtime check is
+ perfomed in Item_func_sp::execute(), and this method is not
+ called during context analysis. Notice, that during view
+ creation we do not infer into stored routine bodies and do not
+ check privileges of its statements, which would probably be a
+ good idea especially if the view has SQL SECURITY DEFINER and
+ the used stored procedure has SQL SECURITY DEFINER.
*/
- Security_context *save_ctx;
- if (!(res= find_and_check_access(thd, EXECUTE_ACL, &save_ctx)))
- sp_restore_security_context(thd, save_ctx);
+ res= find_and_check_access(thd);
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ Security_context *save_secutiry_ctx;
+ if (!res && !(res= set_routine_security_ctx(thd, m_sp, false,
+ &save_secutiry_ctx)))
+ {
+ sp_restore_security_context(thd, save_secutiry_ctx);
+ }
+#endif /* ! NO_EMBEDDED_ACCESS_CHECKS */
}
return res;
}
diff --git a/sql/item_func.h b/sql/item_func.h
index c54fc701c53..da69b634aa5 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -55,7 +55,7 @@ public:
NOT_FUNC, NOT_ALL_FUNC,
NOW_FUNC, TRIG_COND_FUNC,
GUSERVAR_FUNC, COLLATE_FUNC,
- EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP };
+ EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC };
enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
OPTIMIZE_EQUAL };
enum Type type() const { return FUNC_ITEM; }
@@ -189,6 +189,8 @@ public:
Item *transform(Item_transformer transformer, byte *arg);
void traverse_cond(Cond_traverser traverser,
void * arg, traverse_order order);
+ bool is_expensive_processor(byte *arg);
+ virtual bool is_expensive() { return 0; }
};
@@ -933,6 +935,7 @@ public:
Item_udf_func(udf_func *udf_arg, List<Item> &list)
:Item_func(list), udf(udf_arg) {}
const char *func_name() const { return udf.name(); }
+ enum Functype functype() const { return UDF_FUNC; }
bool fix_fields(THD *thd, Item **ref)
{
DBUG_ASSERT(fixed == 0);
@@ -945,6 +948,7 @@ public:
void cleanup();
Item_result result_type () const { return udf.result_type(); }
table_map not_null_tables() const { return 0; }
+ bool is_expensive() { return 1; }
};
@@ -1468,11 +1472,11 @@ public:
{ context= (Name_resolution_context *)cntx; return FALSE; }
void fix_length_and_dec();
- bool find_and_check_access(THD * thd, ulong want_access,
- Security_context **backup);
+ bool find_and_check_access(THD * thd);
virtual enum Functype functype() const { return FUNC_SP; }
bool fix_fields(THD *thd, Item **ref);
+ bool is_expensive() { return 1; }
};
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 5ceb462385c..4fc7340a3b0 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1503,6 +1503,23 @@ void Item_func_trim::fix_length_and_dec()
}
}
+void Item_func_trim::print(String *str)
+{
+ if (arg_count == 1)
+ {
+ Item_func::print(str);
+ return;
+ }
+ str->append(Item_func_trim::func_name());
+ str->append('(');
+ str->append(mode_name());
+ str->append(' ');
+ args[1]->print(str);
+ str->append(STRING_WITH_LEN(" from "));
+ args[0]->print(str);
+ str->append(')');
+}
+
/* Item_func_password */
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 46b1b2fc248..488dc20b063 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -233,6 +233,8 @@ public:
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "trim"; }
+ void print(String *str);
+ virtual const char *mode_name() const { return "both"; }
};
@@ -243,6 +245,7 @@ public:
Item_func_ltrim(Item *a) :Item_func_trim(a) {}
String *val_str(String *);
const char *func_name() const { return "ltrim"; }
+ const char *mode_name() const { return "leading"; }
};
@@ -253,6 +256,7 @@ public:
Item_func_rtrim(Item *a) :Item_func_trim(a) {}
String *val_str(String *);
const char *func_name() const { return "rtrim"; }
+ const char *mode_name() const { return "trailing"; }
};
@@ -724,7 +728,7 @@ public:
void fix_length_and_dec();
bool eq(const Item *item, bool binary_cmp) const;
const char *func_name() const { return "collate"; }
- enum Functype func_type() const { return COLLATE_FUNC; }
+ enum Functype functype() const { return COLLATE_FUNC; }
void print(String *str);
Item_field *filed_for_view_update()
{
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 5404021a348..6675c9e7b25 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -572,14 +572,14 @@ Item_in_subselect::Item_in_subselect(Item * left_exp,
}
Item_allany_subselect::Item_allany_subselect(Item * left_exp,
- Comp_creator *fn,
+ chooser_compare_func_creator fc,
st_select_lex *select_lex,
bool all_arg)
- :Item_in_subselect(), all(all_arg)
+ :Item_in_subselect(), func_creator(fc), all(all_arg)
{
DBUG_ENTER("Item_in_subselect::Item_in_subselect");
left_expr= left_exp;
- func= fn;
+ func= func_creator(all_arg);
init(select_lex, new select_exists_subselect(this));
max_columns= 1;
abort_on_null= 0;
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 293408dc09e..45df4f3880d 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -269,14 +269,13 @@ public:
/* ALL/ANY/SOME subselect */
class Item_allany_subselect :public Item_in_subselect
{
-protected:
- Comp_creator *func;
-
public:
+ chooser_compare_func_creator func_creator;
+ Comp_creator *func;
bool all;
- Item_allany_subselect(Item * left_expr, Comp_creator *f,
- st_select_lex *select_lex, bool all);
+ Item_allany_subselect(Item * left_expr, chooser_compare_func_creator fc,
+ st_select_lex *select_lex, bool all);
// only ALL subquery has upper not
subs_type substype() { return all?ALL_SUBS:ANY_SUBS; }
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 4d70debb966..b0caa5e1810 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -377,7 +377,13 @@ Field *Item_sum::create_tmp_field(bool group, TABLE *table,
case INT_RESULT:
return new Field_longlong(max_length,maybe_null,name,table,unsigned_flag);
case STRING_RESULT:
- if (max_length/collation.collation->mbmaxlen > 255 && convert_blob_length)
+ /*
+ Make sure that the blob fits into a Field_varstring which has
+ 2-byte lenght.
+ */
+ if (max_length/collation.collation->mbmaxlen > 255 &&
+ max_length/collation.collation->mbmaxlen < UINT_MAX16 &&
+ convert_blob_length)
return new Field_varstring(convert_blob_length, maybe_null,
name, table,
collation.collation);
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 089bc965c8c..c776fc72b16 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -520,9 +520,11 @@ enum enum_var_type
OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
};
class sys_var;
+class Comp_creator;
+typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
#include "item.h"
extern my_decimal decimal_zero;
-typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
+
/* sql_parse.cc */
void free_items(Item *item);
void cleanup_items(Item *item);
@@ -865,8 +867,6 @@ bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
void mysqld_list_processes(THD *thd,const char *user,bool verbose);
int mysqld_show_status(THD *thd);
int mysqld_show_variables(THD *thd,const char *wild);
-int mysql_find_files(THD *thd,List<char> *files, const char *db,
- const char *path, const char *wild, bool dir);
bool mysqld_show_storage_engines(THD *thd);
bool mysqld_show_privileges(THD *thd);
bool mysqld_show_column_types(THD *thd);
@@ -1138,7 +1138,10 @@ uint check_word(TYPELIB *lib, const char *val, const char *end,
bool is_keyword(const char *name, uint len);
#define MY_DB_OPT_FILE "db.opt"
+bool check_db_dir_existence(const char *db_name);
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
+bool load_db_opt_by_name(THD *thd, const char *db_name,
+ HA_CREATE_INFO *db_create_info);
bool my_dbopt_init(void);
void my_dbopt_cleanup(void);
void my_dbopt_free(void);
diff --git a/sql/protocol.cc b/sql/protocol.cc
index 650bd8fc58f..f4efb8004ee 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -322,7 +322,7 @@ static char eof_buff[1]= { (char) 254 }; /* Marker for end of fields */
254 Marker (1 byte)
warning_count Stored in 2 bytes; New in 4.1 protocol
status_flag Stored in 2 bytes;
- For flags like SERVER_STATUS_MORE_RESULTS
+ For flags like SERVER_MORE_RESULTS_EXISTS
Note that the warning count will not be sent if 'no_flush' is set as
we don't want to report the warning count until all data is sent to the
diff --git a/sql/slave.cc b/sql/slave.cc
index 90e95e812bd..8bcaa6be102 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -3051,7 +3051,7 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings)
return packet_error;
#endif
- len = net_safe_read(mysql);
+ len = cli_safe_read(mysql);
if (len == packet_error || (long) len < 1)
{
if (mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
diff --git a/sql/sp.cc b/sql/sp.cc
index a7078da2f50..b7bf049cb1d 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -495,6 +495,13 @@ sp_returns_type(THD *thd, String &result, sp_head *sp)
table.s = &table.share_not_to_be_used;
field= sp->create_result_field(0, 0, &table);
field->sql_type(result);
+
+ if (field->has_charset())
+ {
+ result.append(STRING_WITH_LEN(" CHARSET "));
+ result.append(field->charset()->csname);
+ }
+
delete field;
}
@@ -626,7 +633,10 @@ db_create_routine(THD *thd, int type, sp_head *sp)
log_query.append(STRING_WITH_LEN("CREATE "));
append_definer(thd, &log_query, &thd->lex->definer->user,
&thd->lex->definer->host);
- log_query.append(thd->lex->stmt_definition_begin);
+ log_query.append(thd->lex->stmt_definition_begin,
+ (char *)sp->m_body_begin -
+ thd->lex->stmt_definition_begin +
+ sp->m_body.length);
/* Such a statement can always go directly to binlog, no trans cache */
Query_log_event qinfo(thd, log_query.c_ptr(), log_query.length(), 0,
@@ -974,6 +984,11 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp,
sp_head *new_sp;
const char *returns= "";
char definer[USER_HOST_BUFF_SIZE];
+
+ /*
+ String buffer for RETURNS data type must have system charset;
+ 64 -- size of "returns" column of mysql.proc.
+ */
String retstr(64);
DBUG_PRINT("info", ("found: 0x%lx", (ulong)sp));
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 9965c48935a..eec6e0fc3cd 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -470,7 +470,7 @@ sp_head::init(LEX *lex)
lex->trg_table_fields.empty();
my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
m_param_begin= m_param_end= m_body_begin= 0;
- m_qname.str= m_db.str= m_name.str= m_params.str=
+ m_qname.str= m_db.str= m_name.str= m_params.str=
m_body.str= m_defstr.str= 0;
m_qname.length= m_db.length= m_name.length= m_params.length=
m_body.length= m_defstr.length= 0;
@@ -478,29 +478,42 @@ sp_head::init(LEX *lex)
DBUG_VOID_RETURN;
}
+
+void
+sp_head::init_sp_name(THD *thd, sp_name *spname)
+{
+ DBUG_ENTER("sp_head::init_sp_name");
+
+ /* Must be initialized in the parser. */
+
+ DBUG_ASSERT(spname && spname->m_db.str && spname->m_db.length);
+
+ /* We have to copy strings to get them into the right memroot. */
+
+ m_db.length= spname->m_db.length;
+ m_db.str= strmake_root(thd->mem_root, spname->m_db.str, spname->m_db.length);
+
+ m_name.length= spname->m_name.length;
+ m_name.str= strmake_root(thd->mem_root, spname->m_name.str,
+ spname->m_name.length);
+
+ if (spname->m_qname.length == 0)
+ spname->init_qname(thd);
+
+ m_qname.length= spname->m_qname.length;
+ m_qname.str= strmake_root(thd->mem_root, spname->m_qname.str,
+ m_qname.length);
+}
+
+
void
-sp_head::init_strings(THD *thd, LEX *lex, sp_name *name)
+sp_head::init_strings(THD *thd, LEX *lex)
{
DBUG_ENTER("sp_head::init_strings");
uchar *endp; /* Used to trim the end */
/* During parsing, we must use thd->mem_root */
MEM_ROOT *root= thd->mem_root;
- DBUG_ASSERT(name);
- /* Must be initialized in the parser */
- DBUG_ASSERT(name->m_db.str && name->m_db.length);
-
- /* We have to copy strings to get them into the right memroot */
- m_db.length= name->m_db.length;
- m_db.str= strmake_root(root, name->m_db.str, name->m_db.length);
- m_name.length= name->m_name.length;
- m_name.str= strmake_root(root, name->m_name.str, name->m_name.length);
-
- if (name->m_qname.length == 0)
- name->init_qname(thd);
- m_qname.length= name->m_qname.length;
- m_qname.str= strmake_root(root, name->m_qname.str, m_qname.length);
-
if (m_param_begin && m_param_end)
{
m_params.length= m_param_end - m_param_begin;
@@ -514,10 +527,7 @@ sp_head::init_strings(THD *thd, LEX *lex, sp_name *name)
Trim "garbage" at the end. This is sometimes needed with the
"/ * ! VERSION... * /" wrapper in dump files.
*/
- while (m_body_begin < endp &&
- (endp[-1] <= ' ' || endp[-1] == '*' ||
- endp[-1] == '/' || endp[-1] == ';'))
- endp-= 1;
+ endp= skip_rear_comments(m_body_begin, endp);
m_body.length= endp - m_body_begin;
m_body.str= strmake_root(root, (char *)m_body_begin, m_body.length);
@@ -1097,6 +1107,7 @@ sp_head::execute(THD *thd)
thd->restore_active_arena(&execute_arena, &backup_arena);
+ thd->spcont->pop_all_cursors(); // To avoid memory leaks after an error
/* Restore all saved */
old_packet.swap(thd->packet);
@@ -1158,6 +1169,161 @@ sp_head::execute(THD *thd)
m_first_instance->m_first_free_instance->m_recursion_level ==
m_recursion_level + 1));
m_first_instance->m_first_free_instance= this;
+
+ DBUG_RETURN(err_status);
+}
+
+
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+/*
+ set_routine_security_ctx() changes routine security context, and
+ checks if there is an EXECUTE privilege in new context. If there is
+ no EXECUTE privilege, it changes the context back and returns a
+ error.
+
+ SYNOPSIS
+ set_routine_security_ctx()
+ thd thread handle
+ sp stored routine to change the context for
+ is_proc TRUE is procedure, FALSE if function
+ save_ctx pointer to an old security context
+
+ RETURN
+ TRUE if there was a error, and the context wasn't changed.
+ FALSE if the context was changed.
+*/
+
+bool
+set_routine_security_ctx(THD *thd, sp_head *sp, bool is_proc,
+ Security_context **save_ctx)
+{
+ *save_ctx= 0;
+ if (sp_change_security_context(thd, sp, save_ctx))
+ return TRUE;
+
+ /*
+ If we changed context to run as another user, we need to check the
+ access right for the new context again as someone may have revoked
+ the right to use the procedure from this user.
+
+ TODO:
+ Cache if the definer has the right to use the object on the
+ first usage and only reset the cache if someone does a GRANT
+ statement that 'may' affect this.
+ */
+ if (*save_ctx &&
+ check_routine_access(thd, EXECUTE_ACL,
+ sp->m_db.str, sp->m_name.str, is_proc, FALSE))
+ {
+ sp_restore_security_context(thd, *save_ctx);
+ *save_ctx= 0;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+#endif // ! NO_EMBEDDED_ACCESS_CHECKS
+
+
+/*
+ Execute a trigger:
+ - changes security context for triggers
+ - switch to new memroot
+ - call sp_head::execute
+ - restore old memroot
+ - restores security context
+
+ SYNOPSIS
+ sp_head::execute_trigger()
+ thd Thread handle
+ db database name
+ table table name
+ grant_info GRANT_INFO structure to be filled with
+ information about definer's privileges
+ on subject table
+
+ RETURN
+ FALSE on success
+ TRUE on error
+*/
+
+bool
+sp_head::execute_trigger(THD *thd, const char *db, const char *table,
+ GRANT_INFO *grant_info)
+{
+ sp_rcontext *octx = thd->spcont;
+ sp_rcontext *nctx = NULL;
+ bool err_status= FALSE;
+ MEM_ROOT call_mem_root;
+ Query_arena call_arena(&call_mem_root, Query_arena::INITIALIZED_FOR_SP);
+ Query_arena backup_arena;
+
+ DBUG_ENTER("sp_head::execute_trigger");
+ DBUG_PRINT("info", ("trigger %s", m_name.str));
+
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ Security_context *save_ctx;
+ if (sp_change_security_context(thd, this, &save_ctx))
+ DBUG_RETURN(TRUE);
+
+ /*
+ NOTE: TRIGGER_ACL should be used here.
+ */
+ if (check_global_access(thd, SUPER_ACL))
+ {
+ sp_restore_security_context(thd, save_ctx);
+ DBUG_RETURN(TRUE);
+ }
+
+ /*
+ Fetch information about table-level privileges to GRANT_INFO
+ structure for subject table. Check of privileges that will use it
+ and information about column-level privileges will happen in
+ Item_trigger_field::fix_fields().
+ */
+ fill_effective_table_privileges(thd, grant_info, db, table);
+#endif // NO_EMBEDDED_ACCESS_CHECKS
+
+ /*
+ Prepare arena and memroot for objects which lifetime is whole
+ duration of trigger call (sp_rcontext, it's tables and items,
+ sp_cursor and Item_cache holders for case expressions). We can't
+ use caller's arena/memroot for those objects because in this case
+ some fixed amount of memory will be consumed for each trigger
+ invocation and so statements which involve lot of them will hog
+ memory.
+
+ TODO: we should create sp_rcontext once per command and reuse it
+ on subsequent executions of a trigger.
+ */
+ init_sql_alloc(&call_mem_root, MEM_ROOT_BLOCK_SIZE, 0);
+ thd->set_n_backup_active_arena(&call_arena, &backup_arena);
+
+ if (!(nctx= new sp_rcontext(m_pcont, 0, octx)) ||
+ nctx->init(thd))
+ {
+ err_status= TRUE;
+ goto err_with_cleanup;
+ }
+
+#ifndef DBUG_OFF
+ nctx->sp= this;
+#endif
+
+ thd->spcont= nctx;
+
+ err_status= execute(thd);
+
+err_with_cleanup:
+ thd->restore_active_arena(&call_arena, &backup_arena);
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ sp_restore_security_context(thd, save_ctx);
+#endif // NO_EMBEDDED_ACCESS_CHECKS
+ delete nctx;
+ call_arena.free_items();
+ free_root(&call_mem_root, MYF(0));
+ thd->spcont= octx;
+
DBUG_RETURN(err_status);
}
@@ -1165,8 +1331,12 @@ sp_head::execute(THD *thd)
/*
Execute a function:
- evaluate parameters
+ - changes security context for SUID routines
+ - switch to new memroot
- call sp_head::execute
+ - restore old memroot
- evaluate the return value
+ - restores security context
SYNOPSIS
sp_head::execute_function()
@@ -1293,6 +1463,15 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount,
}
thd->spcont= nctx;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ Security_context *save_security_ctx;
+ if (set_routine_security_ctx(thd, this, FALSE, &save_security_ctx))
+ {
+ err_status= TRUE;
+ goto err_with_cleanup;
+ }
+#endif
+
binlog_save_options= thd->options;
if (need_binlog_call)
{
@@ -1333,7 +1512,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount,
reset_dynamic(&thd->user_var_events);
}
- if (m_type == TYPE_ENUM_FUNCTION && !err_status)
+ if (!err_status)
{
/* We need result only in function but not in trigger */
@@ -1344,8 +1523,9 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount,
}
}
-
- nctx->pop_all_cursors(); // To avoid memory leaks after an error
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ sp_restore_security_context(thd, save_security_ctx);
+#endif
err_with_cleanup:
delete nctx;
@@ -1368,8 +1548,10 @@ err_with_cleanup:
The function does the following steps:
- Set all parameters
+ - changes security context for SUID routines
- call sp_head::execute
- copy back values of INOUT and OUT parameters
+ - restores security context
RETURN
FALSE on success
@@ -1490,6 +1672,12 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
thd->spcont= nctx;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ Security_context *save_security_ctx= 0;
+ if (!err_status)
+ err_status= set_routine_security_ctx(thd, this, TRUE, &save_security_ctx);
+#endif
+
if (!err_status)
err_status= execute(thd);
@@ -1534,10 +1722,14 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
}
}
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+ if (save_security_ctx)
+ sp_restore_security_context(thd, save_security_ctx);
+#endif
+
if (!save_spcont)
delete octx;
- nctx->pop_all_cursors(); // To avoid memory leaks after an error
delete nctx;
thd->spcont= save_spcont;
@@ -1674,14 +1866,18 @@ sp_head::fill_field_definition(THD *thd, LEX *lex,
enum enum_field_types field_type,
create_field *field_def)
{
+ HA_CREATE_INFO sp_db_info;
LEX_STRING cmt = { 0, 0 };
uint unused1= 0;
int unused2= 0;
+ load_db_opt_by_name(thd, m_db.str, &sp_db_info);
+
if (field_def->init(thd, (char*) "", field_type, lex->length, lex->dec,
lex->type, (Item*) 0, (Item*) 0, &cmt, 0,
&lex->interval_list,
- (lex->charset ? lex->charset : default_charset_info),
+ (lex->charset ? lex->charset :
+ sp_db_info.default_table_charset),
lex->uint_geom_type))
return TRUE;
diff --git a/sql/sp_head.h b/sql/sp_head.h
index 073cca2cd12..4cd34bc9e20 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -193,9 +193,13 @@ public:
void
init(LEX *lex);
+ /* Copy sp name from parser. */
+ void
+ init_sp_name(THD *thd, sp_name *spname);
+
// Initialize strings after parsing header
void
- init_strings(THD *thd, LEX *lex, sp_name *name);
+ init_strings(THD *thd, LEX *lex);
int
create(THD *thd);
@@ -207,6 +211,10 @@ public:
destroy();
bool
+ execute_trigger(THD *thd, const char *db, const char *table,
+ GRANT_INFO *grant_onfo);
+
+ bool
execute_function(THD *thd, Item **args, uint argcount, Field *return_fld);
bool
@@ -1149,6 +1157,10 @@ sp_change_security_context(THD *thd, sp_head *sp,
Security_context **backup);
void
sp_restore_security_context(THD *thd, Security_context *backup);
+
+bool
+set_routine_security_ctx(THD *thd, sp_head *sp, bool is_proc,
+ Security_context **save_ctx);
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
TABLE_LIST *
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 5383bb52aaa..28edee5c729 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -4041,36 +4041,48 @@ store_top_level_join_columns(THD *thd, TABLE_LIST *table_ref,
if (table_ref->nested_join)
{
List_iterator_fast<TABLE_LIST> nested_it(table_ref->nested_join->join_list);
- TABLE_LIST *cur_left_neighbor= nested_it++;
- TABLE_LIST *cur_right_neighbor= NULL;
+ TABLE_LIST *same_level_left_neighbor= nested_it++;
+ TABLE_LIST *same_level_right_neighbor= NULL;
+ /* Left/right-most neighbors, possibly at higher levels in the join tree. */
+ TABLE_LIST *real_left_neighbor, *real_right_neighbor;
- while (cur_left_neighbor)
+ while (same_level_left_neighbor)
{
- TABLE_LIST *cur_table_ref= cur_left_neighbor;
- cur_left_neighbor= nested_it++;
+ TABLE_LIST *cur_table_ref= same_level_left_neighbor;
+ same_level_left_neighbor= nested_it++;
/*
The order of RIGHT JOIN operands is reversed in 'join list' to
transform it into a LEFT JOIN. However, in this procedure we need
the join operands in their lexical order, so below we reverse the
- join operands. Notice that this happens only in the first loop, and
- not in the second one, as in the second loop cur_left_neighbor == NULL.
- This is the correct behavior, because the second loop
- sets cur_table_ref reference correctly after the join operands are
+ join operands. Notice that this happens only in the first loop,
+ and not in the second one, as in the second loop
+ same_level_left_neighbor == NULL.
+ This is the correct behavior, because the second loop sets
+ cur_table_ref reference correctly after the join operands are
swapped in the first loop.
*/
- if (cur_left_neighbor &&
+ if (same_level_left_neighbor &&
cur_table_ref->outer_join & JOIN_TYPE_RIGHT)
{
/* This can happen only for JOIN ... ON. */
DBUG_ASSERT(table_ref->nested_join->join_list.elements == 2);
- swap_variables(TABLE_LIST*, cur_left_neighbor, cur_table_ref);
+ swap_variables(TABLE_LIST*, same_level_left_neighbor, cur_table_ref);
}
+ /*
+ Pick the parent's left and right neighbors if there are no immediate
+ neighbors at the same level.
+ */
+ real_left_neighbor= (same_level_left_neighbor) ?
+ same_level_left_neighbor : left_neighbor;
+ real_right_neighbor= (same_level_right_neighbor) ?
+ same_level_right_neighbor : right_neighbor;
+
if (cur_table_ref->nested_join &&
store_top_level_join_columns(thd, cur_table_ref,
- cur_left_neighbor, cur_right_neighbor))
+ real_left_neighbor, real_right_neighbor))
goto err;
- cur_right_neighbor= cur_table_ref;
+ same_level_right_neighbor= cur_table_ref;
}
}
@@ -4947,12 +4959,17 @@ fill_record(THD * thd, List<Item> &fields, List<Item> &values,
bool ignore_errors)
{
List_iterator_fast<Item> f(fields),v(values);
- Item *value;
+ Item *value, *fld;
Item_field *field;
DBUG_ENTER("fill_record");
- while ((field=(Item_field*) f++))
+ while ((fld= f++))
{
+ if (!(field= fld->filed_for_view_update()))
+ {
+ my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), fld->name);
+ DBUG_RETURN(TRUE);
+ }
value=v++;
Field *rfield= field->field;
TABLE *table= rfield->table;
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 902539dfdec..81508e4e9be 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -295,7 +295,6 @@ static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
create Where to store the read options
DESCRIPTION
- For now, only default-character-set is read.
RETURN VALUES
0 File found
@@ -384,6 +383,50 @@ err1:
/*
+ Retrieve database options by name. Load database options file or fetch from
+ cache.
+
+ SYNOPSIS
+ load_db_opt_by_name()
+ db_name Database name
+ db_create_info Where to store the database options
+
+ DESCRIPTION
+ load_db_opt_by_name() is a shortcut for load_db_opt().
+
+ NOTE
+ Although load_db_opt_by_name() (and load_db_opt()) returns status of
+ the operation, it is useless usually and should be ignored. The problem
+ is that there are 1) system databases ("mysql") and 2) virtual
+ databases ("information_schema"), which do not contain options file.
+ So, load_db_opt[_by_name]() returns FALSE for these databases, but this
+ is not an error.
+
+ load_db_opt[_by_name]() clears db_create_info structure in any case, so
+ even on failure it contains valid data. So, common use case is just
+ call load_db_opt[_by_name]() without checking return value and use
+ db_create_info right after that.
+
+ RETURN VALUES (read NOTE!)
+ FALSE Success
+ TRUE Failed to retrieve options
+*/
+
+bool load_db_opt_by_name(THD *thd, const char *db_name,
+ HA_CREATE_INFO *db_create_info)
+{
+ char db_opt_path[FN_REFLEN];
+
+ strxnmov(db_opt_path, sizeof (db_opt_path) - 1, mysql_data_home, "/",
+ db_name, "/", MY_DB_OPT_FILE, NullS);
+
+ unpack_filename(db_opt_path, db_opt_path);
+
+ return load_db_opt(thd, db_opt_path, db_create_info);
+}
+
+
+/*
Create a database
SYNOPSIS
@@ -1126,8 +1169,6 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check)
{
int path_length, db_length;
char *db_name;
- char path[FN_REFLEN];
- HA_CREATE_INFO create;
bool system_db= 0;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
ulong db_access;
@@ -1196,16 +1237,14 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check)
}
}
#endif
- (void) sprintf(path,"%s/%s", mysql_data_home, db_name);
- path_length= unpack_dirname(path, path); // Convert if not UNIX
- if (path_length && path[path_length-1] == FN_LIBCHAR)
- path[path_length-1]= '\0'; // remove ending '\'
- if (my_access(path,F_OK))
+
+ if (check_db_dir_existence(db_name))
{
my_error(ER_BAD_DB_ERROR, MYF(0), db_name);
my_free(db_name, MYF(0));
DBUG_RETURN(1);
}
+
end:
x_free(thd->db);
DBUG_ASSERT(db_name == NULL || db_name[0] != '\0');
@@ -1221,8 +1260,10 @@ end:
}
else
{
- strmov(path+unpack_dirname(path,path), MY_DB_OPT_FILE);
- load_db_opt(thd, path, &create);
+ HA_CREATE_INFO create;
+
+ load_db_opt_by_name(thd, db_name, &create);
+
thd->db_charset= create.default_table_charset ?
create.default_table_charset :
thd->variables.collation_server;
@@ -1230,3 +1271,36 @@ end:
}
DBUG_RETURN(0);
}
+
+
+/*
+ Check if there is directory for the database name.
+
+ SYNOPSIS
+ check_db_dir_existence()
+ db_name database name
+
+ RETURN VALUES
+ FALSE There is directory for the specified database name.
+ TRUE The directory does not exist.
+*/
+
+bool check_db_dir_existence(const char *db_name)
+{
+ char db_dir_path[FN_REFLEN];
+ uint db_dir_path_len;
+
+ strxnmov(db_dir_path, sizeof (db_dir_path) - 1, mysql_data_home, "/",
+ db_name, NullS);
+
+ db_dir_path_len= unpack_dirname(db_dir_path, db_dir_path);
+
+ /* Remove trailing '/' or '\' if exists. */
+
+ if (db_dir_path_len && db_dir_path[db_dir_path_len - 1] == FN_LIBCHAR)
+ db_dir_path[db_dir_path_len - 1]= 0;
+
+ /* Check access. */
+
+ return my_access(db_dir_path, F_OK);
+}
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 5a355cedca5..563ebce4ff7 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -126,6 +126,7 @@ void lex_start(THD *thd, uchar *buf,uint length)
lex->param_list.empty();
lex->view_list.empty();
lex->prepared_stmt_params.empty();
+ lex->auxiliary_table_list.empty();
lex->unit.next= lex->unit.master=
lex->unit.link_next= lex->unit.return_to= 0;
lex->unit.prev= lex->unit.link_prev= 0;
@@ -1050,6 +1051,30 @@ int MYSQLlex(void *arg, void *yythd)
}
}
+
+/*
+ Skip comment in the end of statement.
+
+ SYNOPSIS
+ skip_rear_comments()
+ begin pointer to the beginning of statement
+ end pointer to the end of statement
+
+ DESCRIPTION
+ The function is intended to trim comments at the end of the statement.
+
+ RETURN
+ Pointer to the last non-comment symbol of the statement.
+*/
+
+uchar *skip_rear_comments(uchar *begin, uchar *end)
+{
+ while (begin < end && (end[-1] <= ' ' || end[-1] == '*' ||
+ end[-1] == '/' || end[-1] == ';'))
+ end-= 1;
+ return end;
+}
+
/*
st_select_lex structures initialisations
*/
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index e5b087fc72a..17b95014c16 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -978,7 +978,7 @@ typedef struct st_lex : public Query_tables_list
/*
view created to be run from definer (standard behaviour)
*/
- bool create_view_suid;
+ uint8 create_view_suid;
/* Characterstics of trigger being created */
st_trg_chistics trg_chistics;
/*
@@ -1115,4 +1115,4 @@ extern void lex_free(void);
extern void lex_start(THD *thd, uchar *buf,uint length);
extern void lex_end(LEX *lex);
extern int MYSQLlex(void *arg, void *yythd);
-
+extern uchar *skip_rear_comments(uchar *begin, uchar *end);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 28ed3e25d57..72098fb83e4 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4413,9 +4413,6 @@ end_with_restore_list:
}
else
{
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- Security_context *save_ctx;
-#endif
ha_rows select_limit;
/* bits that should be cleared in thd->server_status */
uint bits_to_be_cleared= 0;
@@ -4457,21 +4454,11 @@ end_with_restore_list:
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (check_routine_access(thd, EXECUTE_ACL,
- sp->m_db.str, sp->m_name.str, TRUE, 0) ||
- sp_change_security_context(thd, sp, &save_ctx))
+ sp->m_db.str, sp->m_name.str, TRUE, FALSE))
{
thd->net.no_send_ok= nsok;
goto error;
}
- if (save_ctx &&
- check_routine_access(thd, EXECUTE_ACL,
- sp->m_db.str, sp->m_name.str, TRUE, 0))
- {
- thd->net.no_send_ok= nsok;
- sp_restore_security_context(thd, save_ctx);
- goto error;
- }
-
#endif
select_limit= thd->variables.select_limit;
thd->variables.select_limit= HA_POS_ERROR;
@@ -4495,9 +4482,6 @@ end_with_restore_list:
thd->total_warn_count= 0;
thd->variables.select_limit= select_limit;
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- sp_restore_security_context(thd, save_ctx);
-#endif
thd->net.no_send_ok= nsok;
thd->server_status&= ~bits_to_be_cleared;
@@ -7017,7 +7001,7 @@ Item * all_any_subquery_creator(Item *left_expr,
return new Item_func_not(new Item_in_subselect(left_expr, select_lex));
Item_allany_subselect *it=
- new Item_allany_subselect(left_expr, (*cmp)(all), select_lex, all);
+ new Item_allany_subselect(left_expr, cmp, select_lex, all);
if (all)
return it->upper_item= new Item_func_not_all(it); /* ALL */
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index ffe54310843..6d35c441368 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2128,29 +2128,21 @@ void reinit_stmt_before_use(THD *thd, LEX *lex)
they have their own table list).
*/
for (TABLE_LIST *tables= lex->query_tables;
- tables;
- tables= tables->next_global)
+ tables;
+ tables= tables->next_global)
+ {
+ tables->reinit_before_use(thd);
+ }
+ /*
+ Cleanup of the special case of DELETE t1, t2 FROM t1, t2, t3 ...
+ (multi-delete). We do a full clean up, although at the moment all we
+ need to clean in the tables of MULTI-DELETE list is 'table' member.
+ */
+ for (TABLE_LIST *tables= (TABLE_LIST*) lex->auxiliary_table_list.first;
+ tables;
+ tables= tables->next_global)
{
- /*
- Reset old pointers to TABLEs: they are not valid since the tables
- were closed in the end of previous prepare or execute call.
- */
tables->reinit_before_use(thd);
-
- /* Reset is_schema_table_processed value(needed for I_S tables */
- tables->is_schema_table_processed= FALSE;
-
- TABLE_LIST *embedded; /* The table at the current level of nesting. */
- TABLE_LIST *embedding= tables; /* The parent nested table reference. */
- do
- {
- embedded= embedding;
- if (embedded->prep_on_expr)
- embedded->on_expr= embedded->prep_on_expr->copy_andor_structure(thd);
- embedding= embedded->embedding;
- }
- while (embedding &&
- embedding->nested_join->join_list.head() == embedded);
}
lex->current_select= &lex->select_lex;
@@ -2165,7 +2157,7 @@ void reinit_stmt_before_use(THD *thd, LEX *lex)
}
lex->allow_sum_func= 0;
lex->in_sum_func= NULL;
- DBUG_VOID_RETURN;
+ DBUG_VOID_RETURN;
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 20512563f37..2f16b350d04 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -679,6 +679,25 @@ JOIN::optimize()
DBUG_PRINT("info",("Select tables optimized away"));
zero_result_cause= "Select tables optimized away";
tables_list= 0; // All tables resolved
+ /*
+ Extract all table-independent conditions and replace the WHERE
+ clause with them. All other conditions were computed by opt_sum_query
+ and the MIN/MAX/COUNT function(s) have been replaced by constants,
+ so there is no need to compute the whole WHERE clause again.
+ Notice that make_cond_for_table() will always succeed to remove all
+ computed conditions, because opt_sum_query() is applicable only to
+ conjunctions.
+ Preserve conditions for EXPLAIN.
+ */
+ if (conds && !(thd->lex->describe & DESCRIBE_EXTENDED))
+ {
+ COND *table_independent_conds=
+ make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0);
+ DBUG_EXECUTE("where",
+ print_where(table_independent_conds,
+ "where after opt_sum_query()"););
+ conds= table_independent_conds;
+ }
}
}
if (!tables_list)
@@ -1064,6 +1083,23 @@ JOIN::optimize()
{
need_tmp=1; simple_order=simple_group=0; // Force tmp table without sort
}
+ if (order)
+ {
+ /*
+ Force using of tmp table if sorting by a SP or UDF function due to
+ their expensive and probably non-deterministic nature.
+ */
+ for (ORDER *tmp_order= order; tmp_order ; tmp_order=tmp_order->next)
+ {
+ Item *item= *tmp_order->item;
+ if (item->walk(&Item::is_expensive_processor,(byte*)0))
+ {
+ /* Force tmp table without sort */
+ need_tmp=1; simple_order=simple_group=0;
+ break;
+ }
+ }
+ }
}
tmp_having= having;
@@ -2470,8 +2506,11 @@ merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end,
/* field = expression OR field IS NULL */
old->level= and_level;
old->optimize= KEY_OPTIMIZE_REF_OR_NULL;
- /* Remember the NOT NULL value */
- if (old->val->is_null())
+ /*
+ Remember the NOT NULL value unless the value does not depend
+ on other tables.
+ */
+ if (!old->val->used_tables() && old->val->is_null())
old->val= new_fields->val;
/* The referred expression can be NULL: */
old->null_rejecting= 0;
@@ -6174,10 +6213,16 @@ return_zero_rows(JOIN *join, select_result *result,TABLE_LIST *tables,
DBUG_RETURN(0);
}
-
+/*
+ used only in JOIN::clear
+*/
static void clear_tables(JOIN *join)
{
- for (uint i=0 ; i < join->tables ; i++)
+ /*
+ must clear only the non-const tables, as const tables
+ are not re-calculated.
+ */
+ for (uint i=join->const_tables ; i < join->tables ; i++)
mark_as_null_row(join->table[i]); // All fields are NULL
}
@@ -8034,7 +8079,12 @@ Field* create_tmp_field_from_field(THD *thd, Field* org_field,
{
Field *new_field;
- if (convert_blob_length && (org_field->flags & BLOB_FLAG))
+ /*
+ Make sure that the blob fits into a Field_varstring which has
+ 2-byte lenght.
+ */
+ if (convert_blob_length && convert_blob_length < UINT_MAX16 &&
+ (org_field->flags & BLOB_FLAG))
new_field= new Field_varstring(convert_blob_length,
org_field->maybe_null(),
org_field->field_name, table,
@@ -8116,8 +8166,13 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
if ((type= item->field_type()) == MYSQL_TYPE_DATETIME ||
type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE)
new_field= item->tmp_table_field_from_field_type(table);
+ /*
+ Make sure that the blob fits into a Field_varstring which has
+ 2-byte lenght.
+ */
else if (item->max_length/item->collation.collation->mbmaxlen > 255 &&
- convert_blob_length)
+ item->max_length/item->collation.collation->mbmaxlen < UINT_MAX16
+ && convert_blob_length)
new_field= new Field_varstring(convert_blob_length, maybe_null,
item->name, table,
item->collation.collation);
@@ -12810,7 +12865,7 @@ count_field_types(TMP_TABLE_PARAM *param, List<Item> &fields,
{
if (! field->const_item())
{
- Item_sum *sum_item=(Item_sum*) field;
+ Item_sum *sum_item=(Item_sum*) field->real_item();
if (!sum_item->quick_group)
param->quick_group=0; // UDF SUM function
param->sum_func_count++;
@@ -13070,10 +13125,11 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
param->copy_funcs.empty();
for (i= 0; (pos= li++); i++)
{
- if (pos->real_item()->type() == Item::FIELD_ITEM)
+ Item *real_pos= pos->real_item();
+ if (real_pos->type() == Item::FIELD_ITEM)
{
Item_field *item;
- pos= pos->real_item();
+ pos= real_pos;
if (!(item= new Item_field(thd, ((Item_field*) pos))))
goto err;
pos= item;
@@ -13112,12 +13168,13 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
}
}
}
- else if ((pos->type() == Item::FUNC_ITEM ||
- pos->type() == Item::SUBSELECT_ITEM ||
- pos->type() == Item::CACHE_ITEM ||
- pos->type() == Item::COND_ITEM) &&
- !pos->with_sum_func)
+ else if ((real_pos->type() == Item::FUNC_ITEM ||
+ real_pos->type() == Item::SUBSELECT_ITEM ||
+ real_pos->type() == Item::CACHE_ITEM ||
+ real_pos->type() == Item::COND_ITEM) &&
+ !real_pos->with_sum_func)
{ // Save for send fields
+ pos= real_pos;
/* TODO:
In most cases this result will be sent to the user.
This should be changed to use copy_int or copy_real depending
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 6e78596d679..433238cb853 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -250,9 +250,35 @@ bool mysqld_show_column_types(THD *thd)
}
-int
-mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
- const char *wild, bool dir)
+/*
+ find_files() - find files in a given directory.
+
+ SYNOPSIS
+ find_files()
+ thd thread handler
+ files put found files in this list
+ db database name to set in TABLE_LIST structure
+ path path to database
+ wild filter for found files
+ dir read databases in path if TRUE, read .frm files in
+ database otherwise
+
+ RETURN
+ FIND_FILES_OK success
+ FIND_FILES_OOM out of memory error
+ FIND_FILES_DIR no such directory, or directory can't be read
+*/
+
+enum find_files_result {
+ FIND_FILES_OK,
+ FIND_FILES_OOM,
+ FIND_FILES_DIR
+};
+
+static
+find_files_result
+find_files(THD *thd, List<char> *files, const char *db,
+ const char *path, const char *wild, bool dir)
{
uint i;
char *ext;
@@ -262,7 +288,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
uint col_access=thd->col_access;
#endif
TABLE_LIST table_list;
- DBUG_ENTER("mysql_find_files");
+ DBUG_ENTER("find_files");
if (wild && !wild[0])
wild=0;
@@ -275,7 +301,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), db);
else
my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), path, my_errno);
- DBUG_RETURN(-1);
+ DBUG_RETURN(FIND_FILES_DIR);
}
for (i=0 ; i < (uint) dirp->number_off_files ; i++)
@@ -337,7 +363,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
if (files->push_back(thd->strdup(file->name)))
{
my_dirend(dirp);
- DBUG_RETURN(-1);
+ DBUG_RETURN(FIND_FILES_OOM);
}
}
DBUG_PRINT("info",("found: %d files", files->elements));
@@ -345,7 +371,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
VOID(ha_find_files(thd,db,path,wild,dir,files));
- DBUG_RETURN(0);
+ DBUG_RETURN(FIND_FILES_OK);
}
@@ -439,13 +465,11 @@ bool mysqld_show_create_db(THD *thd, char *dbname,
{
Security_context *sctx= thd->security_ctx;
int length;
- char path[FN_REFLEN];
char buff[2048];
String buffer(buff, sizeof(buff), system_charset_info);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
uint db_access;
#endif
- bool found_libchar;
HA_CREATE_INFO create;
uint create_options = create_info ? create_info->options : 0;
Protocol *protocol=thd->protocol;
@@ -480,23 +504,13 @@ bool mysqld_show_create_db(THD *thd, char *dbname,
}
else
{
- (void) sprintf(path,"%s/%s",mysql_data_home, dbname);
- length=unpack_dirname(path,path); // Convert if not unix
- found_libchar= 0;
- if (length && path[length-1] == FN_LIBCHAR)
- {
- found_libchar= 1;
- path[length-1]=0; // remove ending '\'
- }
- if (access(path,F_OK))
+ if (check_db_dir_existence(dbname))
{
my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
DBUG_RETURN(TRUE);
}
- if (found_libchar)
- path[length-1]= FN_LIBCHAR;
- strmov(path+length, MY_DB_OPT_FILE);
- load_db_opt(thd, path, &create);
+
+ load_db_opt_by_name(thd, dbname, &create);
}
List<Item> field_list;
field_list.push_back(new Item_empty_string("Database",NAME_LEN));
@@ -2000,8 +2014,8 @@ enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table)
wild string otherwise it's db name;
RETURN
- 1 error
- 0 success
+ zero success
+ non-zero error
*/
int make_db_list(THD *thd, List<char> *files,
@@ -2027,8 +2041,8 @@ int make_db_list(THD *thd, List<char> *files,
if (files->push_back(thd->strdup(information_schema_name.str)))
return 1;
}
- return mysql_find_files(thd, files, NullS, mysql_data_home,
- idx_field_vals->db_value, 1);
+ return (find_files(thd, files, NullS, mysql_data_home,
+ idx_field_vals->db_value, 1) != FIND_FILES_OK);
}
/*
@@ -2055,7 +2069,8 @@ int make_db_list(THD *thd, List<char> *files,
if (files->push_back(thd->strdup(information_schema_name.str)))
return 1;
*with_i_schema= 1;
- return mysql_find_files(thd, files, NullS, mysql_data_home, NullS, 1);
+ return (find_files(thd, files, NullS,
+ mysql_data_home, NullS, 1) != FIND_FILES_OK);
}
@@ -2116,12 +2131,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
LINT_INIT(end);
LINT_INIT(len);
- /*
- Let us set fake sql_command so views won't try to merge
- themselves into main statement.
- */
- lex->sql_command= SQLCOM_SHOW_FIELDS;
-
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
/*
@@ -2144,8 +2153,16 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
I_S tables will be done.
*/
thd->temporary_tables= open_tables_state_backup.temporary_tables;
+ /*
+ Let us set fake sql_command so views won't try to merge
+ themselves into main statement. If we don't do this,
+ SELECT * from information_schema.xxxx will cause problems.
+ SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
+ */
+ lex->sql_command= SQLCOM_SHOW_FIELDS;
res= open_normal_and_derived_tables(thd, show_table_list,
MYSQL_LOCK_IGNORE_FLUSH);
+ lex->sql_command= save_sql_command;
/*
get_all_tables() returns 1 on failure and 0 on success thus
return only these and not the result code of ::process_table()
@@ -2204,9 +2221,28 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
strxmov(path, mysql_data_home, "/", base_name, NullS);
end= path + (len= unpack_dirname(path,path));
len= FN_LEN - len;
- if (mysql_find_files(thd, &files, base_name,
- path, idx_field_vals.table_value, 0))
- goto err;
+ find_files_result res= find_files(thd, &files, base_name,
+ path, idx_field_vals.table_value, 0);
+ if (res != FIND_FILES_OK)
+ {
+ /*
+ Downgrade errors about problems with database directory to
+ warnings if this is not a 'SHOW' command. Another thread
+ may have dropped database, and we may still have a name
+ for that directory.
+ */
+ if (res == FIND_FILES_DIR && lex->orig_sql_command == SQLCOM_END)
+ {
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ thd->net.last_errno, thd->net.last_error);
+ thd->clear_error();
+ continue;
+ }
+ else
+ {
+ goto err;
+ }
+ }
if (lower_case_table_names)
orig_base_name= thd->strdup(base_name);
}
@@ -2267,8 +2303,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
lex->all_selects_list= &sel;
lex->derived_tables= 0;
+ lex->sql_command= SQLCOM_SHOW_FIELDS;
res= open_normal_and_derived_tables(thd, show_table_list,
MYSQL_LOCK_IGNORE_FLUSH);
+ lex->sql_command= save_sql_command;
/*
We should use show_table_list->alias instead of
show_table_list->table_name because table_name
@@ -2319,8 +2357,11 @@ bool store_schema_shemata(THD* thd, TABLE *table, const char *db_name,
int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond)
{
- char path[FN_REFLEN];
- bool found_libchar;
+ /*
+ TODO: fill_schema_shemata() is called when new client is connected.
+ Returning error status in this case leads to client hangup.
+ */
+
INDEX_FIELD_VALUES idx_field_vals;
List<char> files;
char *file_name;
@@ -2352,20 +2393,9 @@ int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond)
(grant_option && !check_grant_db(thd, file_name)))
#endif
{
- strxmov(path, mysql_data_home, "/", file_name, NullS);
- length=unpack_dirname(path,path); // Convert if not unix
- found_libchar= 0;
- if (length && path[length-1] == FN_LIBCHAR)
- {
- found_libchar= 1;
- path[length-1]=0; // remove ending '\'
- }
+ load_db_opt_by_name(thd, file_name, &create);
- if (found_libchar)
- path[length-1]= FN_LIBCHAR;
- strmov(path+length, MY_DB_OPT_FILE);
- load_db_opt(thd, path, &create);
- if (store_schema_shemata(thd, table, file_name,
+ if (store_schema_shemata(thd, table, file_name,
create.default_table_charset))
DBUG_RETURN(1);
}
@@ -3950,13 +3980,19 @@ bool get_schema_tables_result(JOIN *join)
table_list->table->file->delete_all_rows();
free_io_cache(table_list->table);
filesort_free_buffers(table_list->table);
+ table_list->table->null_row= 0;
}
else
table_list->table->file->records= 0;
if (table_list->schema_table->fill_table(thd, table_list,
tab->select_cond))
+ {
result= 1;
+ join->error= 1;
+ table_list->is_schema_table_processed= TRUE;
+ break;
+ }
table_list->is_schema_table_processed= TRUE;
}
}
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 4772d64ad0a..e065a32c2e8 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1631,10 +1631,9 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
if (!create_info->default_table_charset)
{
HA_CREATE_INFO db_info;
- char path[FN_REFLEN];
- /* Abuse build_table_path() to build the path to the db.opt file */
- build_table_path(path, sizeof(path), db, MY_DB_OPT_FILE, "");
- load_db_opt(thd, path, &db_info);
+
+ load_db_opt_by_name(thd, db, &db_info);
+
create_info->default_table_charset= db_info.default_table_charset;
}
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 66a16f16d8c..e806dd4a3f3 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -295,7 +295,10 @@ end:
append_definer(thd, &log_query, &definer_user, &definer_host);
}
- log_query.append(thd->lex->stmt_definition_begin);
+ log_query.append(thd->lex->stmt_definition_begin,
+ (char *)thd->lex->sphead->m_body_begin -
+ thd->lex->stmt_definition_begin +
+ thd->lex->sphead->m_body.length);
}
/* Such a statement can always go directly to binlog, no trans cache. */
@@ -1503,40 +1506,11 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event,
old_field= table->field;
}
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- Security_context *save_ctx;
-
- if (sp_change_security_context(thd, sp_trigger, &save_ctx))
- return TRUE;
-
- /*
- NOTE: TRIGGER_ACL should be used below.
- */
-
- if (check_global_access(thd, SUPER_ACL))
- {
- sp_restore_security_context(thd, save_ctx);
- return TRUE;
- }
-
- /*
- Fetch information about table-level privileges to GRANT_INFO structure for
- subject table. Check of privileges that will use it and information about
- column-level privileges will happen in Item_trigger_field::fix_fields().
- */
-
- fill_effective_table_privileges(thd,
- &subject_table_grants[event][time_type],
- table->s->db, table->s->table_name);
-#endif // NO_EMBEDDED_ACCESS_CHECKS
-
thd->reset_sub_statement_state(&statement_state, SUB_STMT_TRIGGER);
- err_status= sp_trigger->execute_function(thd, 0, 0, 0);
+ err_status= sp_trigger->execute_trigger
+ (thd, table->s->db, table->s->table_name,
+ &subject_table_grants[event][time_type]);
thd->restore_sub_statement_state(&statement_state);
-
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
- sp_restore_security_context(thd, save_ctx);
-#endif // NO_EMBEDDED_ACCESS_CHECKS
}
return err_status;
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 90a6cba53f4..db55179f2dc 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -155,6 +155,54 @@ err:
DBUG_RETURN(TRUE);
}
+/*
+ Fill defined view parts
+
+ SYNOPSIS
+ fill_defined_view_parts()
+ thd current thread.
+ view view to operate on
+
+ DESCRIPTION
+ This function will initialize the parts of the view
+ definition that are not specified in ALTER VIEW
+ to their values from CREATE VIEW.
+ The view must be opened to get its definition.
+ We use a copy of the view when opening because we want
+ to preserve the original view instance.
+
+ RETURN VALUE
+ TRUE can't open table
+ FALSE success
+*/
+static bool
+fill_defined_view_parts (THD *thd, TABLE_LIST *view)
+{
+ LEX *lex= thd->lex;
+ bool not_used;
+ TABLE_LIST decoy;
+
+ memcpy (&decoy, view, sizeof (TABLE_LIST));
+ if (!open_table(thd, &decoy, thd->mem_root, &not_used, 0) &&
+ !decoy.view)
+ {
+ return TRUE;
+ }
+ if (!lex->definer)
+ {
+ view->definer.host= decoy.definer.host;
+ view->definer.user= decoy.definer.user;
+ lex->definer= &view->definer;
+ }
+ if (lex->create_view_algorithm == VIEW_ALGORITHM_UNDEFINED)
+ lex->create_view_algorithm= decoy.algorithm;
+ if (lex->create_view_suid == VIEW_SUID_DEFAULT)
+ lex->create_view_suid= decoy.view_suid ?
+ VIEW_SUID_DEFINER : VIEW_SUID_INVOKER;
+
+ return FALSE;
+}
+
/*
Creating/altering VIEW procedure
@@ -207,7 +255,15 @@ bool mysql_create_view(THD *thd,
}
if (mode != VIEW_CREATE_NEW)
+ {
+ if (mode == VIEW_ALTER &&
+ fill_defined_view_parts(thd, view))
+ {
+ res= TRUE;
+ goto err;
+ }
sp_cache_invalidate();
+ }
if (!lex->definer)
{
@@ -671,8 +727,10 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
view->query.str= (char*)str.ptr();
view->query.length= str.length()-1; // we do not need last \0
view->source.str= thd->query + thd->lex->create_view_select_start;
- view->source.length= (thd->query_length -
- thd->lex->create_view_select_start);
+ view->source.length= (char *)skip_rear_comments((uchar *)view->source.str,
+ (uchar *)thd->query +
+ thd->query_length) -
+ view->source.str;
view->file_version= 1;
view->calc_md5(md5);
view->md5.str= md5;
@@ -1227,8 +1285,11 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
DBUG_ENTER("mysql_drop_view");
char path[FN_REFLEN];
TABLE_LIST *view;
- bool type= 0;
+ frm_type_enum type;
db_type not_used;
+ String non_existant_views;
+ char *wrong_object_db= NULL, *wrong_object_name= NULL;
+ bool error= FALSE;
for (view= views; view; view= view->next_local)
{
@@ -1236,8 +1297,9 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
view->table_name, reg_ext, NullS);
(void) unpack_filename(path, path);
VOID(pthread_mutex_lock(&LOCK_open));
- if (access(path, F_OK) ||
- (type= (mysql_frm_type(thd, path, &not_used) != FRMTYPE_VIEW)))
+ type= FRMTYPE_ERROR;
+ if (access(path, F_OK) ||
+ FRMTYPE_VIEW != (type= mysql_frm_type(thd, path, &not_used)))
{
char name[FN_REFLEN];
my_snprintf(name, sizeof(name), "%s.%s", view->db, view->table_name);
@@ -1249,25 +1311,46 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
VOID(pthread_mutex_unlock(&LOCK_open));
continue;
}
- if (type)
- my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->table_name, "VIEW");
+ if (type == FRMTYPE_TABLE)
+ {
+ if (!wrong_object_name)
+ {
+ wrong_object_db= view->db;
+ wrong_object_name= view->table_name;
+ }
+ }
else
- my_error(ER_BAD_TABLE_ERROR, MYF(0), name);
- goto err;
+ {
+ if (non_existant_views.length())
+ non_existant_views.append(',');
+ non_existant_views.append(String(view->table_name,system_charset_info));
+ }
+ VOID(pthread_mutex_unlock(&LOCK_open));
+ continue;
}
if (my_delete(path, MYF(MY_WME)))
- goto err;
+ error= TRUE;
query_cache_invalidate3(thd, view, 0);
sp_cache_invalidate();
VOID(pthread_mutex_unlock(&LOCK_open));
}
+ if (error)
+ {
+ DBUG_RETURN(TRUE);
+ }
+ if (wrong_object_name)
+ {
+ my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name,
+ "VIEW");
+ DBUG_RETURN(TRUE);
+ }
+ if (non_existant_views.length())
+ {
+ my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr());
+ DBUG_RETURN(TRUE);
+ }
send_ok(thd);
DBUG_RETURN(FALSE);
-
-err:
- VOID(pthread_mutex_unlock(&LOCK_open));
- DBUG_RETURN(TRUE);
-
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 425945f525e..ccf4a9d6687 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1256,6 +1256,17 @@ create_function_tail:
RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys
{
LEX *lex=Lex;
+ if (lex->definer != NULL)
+ {
+ /*
+ DEFINER is a concept meaningful when interpreting SQL code.
+ UDF functions are compiled.
+ Using DEFINER with UDF has therefore no semantic,
+ and is considered a parsing error.
+ */
+ my_error(ER_WRONG_USAGE, MYF(0), "SONAME", "DEFINER");
+ YYABORT;
+ }
lex->sql_command = SQLCOM_CREATE_FUNCTION;
lex->udf.name = lex->spname->m_name;
lex->udf.returns=(Item_result) $2;
@@ -1285,6 +1296,7 @@ create_function_tail:
sp= new sp_head();
sp->reset_thd_mem_root(YYTHD);
sp->init(lex);
+ sp->init_sp_name(YYTHD, lex->spname);
sp->m_type= TYPE_ENUM_FUNCTION;
lex->sphead= sp;
@@ -1339,7 +1351,7 @@ create_function_tail:
YYABORT;
lex->sql_command= SQLCOM_CREATE_SPFUNCTION;
- sp->init_strings(YYTHD, lex, lex->spname);
+ sp->init_strings(YYTHD, lex);
if (!(sp->m_flags & sp_head::HAS_RETURN))
{
my_error(ER_SP_NORETURN, MYF(0), sp->m_qname.str);
@@ -1911,9 +1923,12 @@ sp_proc_stmt:
sp_instr_stmt *i=new sp_instr_stmt(sp->instructions(),
lex->spcont, lex);
- /* Extract the query statement from the tokenizer:
- The end is either lex->tok_end or tok->ptr. */
- if (lex->ptr - lex->tok_end > 1)
+ /*
+ Extract the query statement from the tokenizer. The
+ end is either lex->ptr, if there was no lookahead,
+ lex->tok_end otherwise.
+ */
+ if (yychar == YYEMPTY)
i->m_query.length= lex->ptr - sp->m_tmp_query;
else
i->m_query.length= lex->tok_end - sp->m_tmp_query;
@@ -7822,7 +7837,12 @@ option_type_value:
lex)))
YYABORT;
- if (lex->ptr - lex->tok_end > 1)
+ /*
+ Extract the query statement from the tokenizer. The
+ end is either lex->ptr, if there was no lookahead,
+ lex->tok_end otherwise.
+ */
+ if (yychar == YYEMPTY)
qbuff.length= lex->ptr - sp->m_tmp_query;
else
qbuff.length= lex->tok_end - sp->m_tmp_query;
@@ -8997,11 +9017,11 @@ view_algorithm_opt:
view_suid:
/* empty */
- { Lex->create_view_suid= TRUE; }
+ { Lex->create_view_suid= VIEW_SUID_DEFAULT; }
| SQL_SYM SECURITY_SYM DEFINER_SYM
- { Lex->create_view_suid= TRUE; }
+ { Lex->create_view_suid= VIEW_SUID_DEFINER; }
| SQL_SYM SECURITY_SYM INVOKER_SYM
- { Lex->create_view_suid= FALSE; }
+ { Lex->create_view_suid= VIEW_SUID_INVOKER; }
;
view_tail:
@@ -9092,6 +9112,7 @@ trigger_tail:
YYABORT;
sp->reset_thd_mem_root(YYTHD);
sp->init(lex);
+ sp->init_sp_name(YYTHD, $3);
lex->stmt_definition_begin= $2;
lex->ident.str= $7;
@@ -9120,7 +9141,7 @@ trigger_tail:
sp_head *sp= lex->sphead;
lex->sql_command= SQLCOM_CREATE_TRIGGER;
- sp->init_strings(YYTHD, lex, $3);
+ sp->init_strings(YYTHD, lex);
/* Restore flag if it was cleared above */
if (sp->m_old_cmq)
YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
@@ -9168,13 +9189,14 @@ sp_tail:
my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "PROCEDURE");
YYABORT;
}
-
+
lex->stmt_definition_begin= $2;
-
+
/* Order is important here: new - reset - init */
sp= new sp_head();
sp->reset_thd_mem_root(YYTHD);
sp->init(lex);
+ sp->init_sp_name(YYTHD, $3);
sp->m_type= TYPE_ENUM_PROCEDURE;
lex->sphead= sp;
@@ -9212,7 +9234,7 @@ sp_tail:
LEX *lex= Lex;
sp_head *sp= lex->sphead;
- sp->init_strings(YYTHD, lex, $3);
+ sp->init_strings(YYTHD, lex);
lex->sql_command= SQLCOM_CREATE_PROCEDURE;
/* Restore flag if it was cleared above */
if (sp->m_old_cmq)
diff --git a/sql/table.cc b/sql/table.cc
index e50b401df5f..b4c08729a79 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -2992,13 +2992,27 @@ Field_iterator_table_ref::get_natural_column_ref()
st_table_list::reinit_before_use()
*/
-void st_table_list::reinit_before_use(THD * /* thd */)
+void st_table_list::reinit_before_use(THD *thd)
{
/*
Reset old pointers to TABLEs: they are not valid since the tables
were closed in the end of previous prepare or execute call.
*/
table= 0;
+ /* Reset is_schema_table_processed value(needed for I_S tables */
+ is_schema_table_processed= FALSE;
+
+ TABLE_LIST *embedded; /* The table at the current level of nesting. */
+ TABLE_LIST *embedding= this; /* The parent nested table reference. */
+ do
+ {
+ embedded= embedding;
+ if (embedded->prep_on_expr)
+ embedded->on_expr= embedded->prep_on_expr->copy_andor_structure(thd);
+ embedding= embedded->embedding;
+ }
+ while (embedding &&
+ embedding->nested_join->join_list.head() == embedded);
}
diff --git a/sql/table.h b/sql/table.h
index 41ab7e7bec8..5136ac2c4db 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -360,6 +360,10 @@ typedef struct st_schema_table
#define VIEW_ALGORITHM_TMPTABLE 1
#define VIEW_ALGORITHM_MERGE 2
+#define VIEW_SUID_INVOKER 0
+#define VIEW_SUID_DEFINER 1
+#define VIEW_SUID_DEFAULT 2
+
/* view WITH CHECK OPTION parameter options */
#define VIEW_CHECK_NONE 0
#define VIEW_CHECK_LOCAL 1
@@ -678,6 +682,10 @@ typedef struct st_table_list
private:
bool prep_check_option(THD *thd, uint8 check_opt_type);
bool prep_where(THD *thd, Item **conds, bool no_where_clause);
+ /*
+ Cleanup for re-execution in a prepared statement or a stored
+ procedure.
+ */
} TABLE_LIST;
class Item;
diff --git a/sql/udf_example.c b/sql/udf_example.c
index 62995085599..a80fce81278 100644
--- a/sql/udf_example.c
+++ b/sql/udf_example.c
@@ -806,6 +806,7 @@ char *reverse_lookup(UDF_INIT *initid __attribute__((unused)), UDF_ARGS *args,
#if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
char name_buff[256];
struct hostent tmp_hostent;
+ int tmp_errno;
#endif
struct hostent *hp;
unsigned long taddr;
@@ -845,7 +846,6 @@ char *reverse_lookup(UDF_INIT *initid __attribute__((unused)), UDF_ARGS *args,
return 0;
}
#if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
- int tmp_errno;
if (!(hp=gethostbyaddr_r((char*) &taddr,sizeof(taddr), AF_INET,
&tmp_hostent, name_buff,sizeof(name_buff),
&tmp_errno)))
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 5ee63cb8738..e4b2374a698 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -50,7 +50,6 @@ static unsigned int opt_port;
static my_bool tty_password= 0, opt_silent= 0;
static MYSQL *mysql= 0;
-static char query[MAX_TEST_QUERY_LENGTH];
static char current_db[]= "client_test_db";
static unsigned int test_count= 0;
static unsigned int opt_count= 0;
@@ -270,6 +269,7 @@ mysql_simple_prepare(MYSQL *mysql, const char *query)
static void client_connect(ulong flag)
{
int rc;
+ static char query[MAX_TEST_QUERY_LENGTH];
myheader_r("client_connect");
if (!opt_silent)
@@ -327,6 +327,8 @@ static void client_connect(ulong flag)
static void client_disconnect()
{
+ static char query[MAX_TEST_QUERY_LENGTH];
+
myheader_r("client_disconnect");
if (mysql)
@@ -658,6 +660,7 @@ int my_stmt_result(const char *buff)
static void verify_col_data(const char *table, const char *col,
const char *exp_data)
{
+ static char query[MAX_TEST_QUERY_LENGTH];
MYSQL_RES *result;
MYSQL_ROW row;
int rc, field= 1;
@@ -1363,6 +1366,7 @@ static void test_prepare_insert_update()
for (cur_query= testcase; *cur_query; cur_query++)
{
+ char query[MAX_TEST_QUERY_LENGTH];
printf("\nRunning query: %s", *cur_query);
strmov(query, *cur_query);
stmt= mysql_simple_prepare(mysql, query);
@@ -1397,6 +1401,7 @@ static void test_prepare_simple()
{
MYSQL_STMT *stmt;
int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare_simple");
@@ -1467,6 +1472,7 @@ static void test_prepare_field_result()
MYSQL_STMT *stmt;
MYSQL_RES *result;
int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare_field_result");
@@ -1518,6 +1524,7 @@ static void test_prepare_syntax()
{
MYSQL_STMT *stmt;
int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare_syntax");
@@ -1559,6 +1566,7 @@ static void test_prepare()
my_bool is_null[7];
char llbuf[22];
MYSQL_BIND bind[7];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare");
@@ -1732,6 +1740,7 @@ static void test_double_compare()
MYSQL_RES *result;
MYSQL_BIND bind[3];
ulong length[3];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_double_compare");
@@ -1814,6 +1823,7 @@ static void test_null()
uint nData;
MYSQL_BIND bind[2];
my_bool is_null[2];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_null");
@@ -1960,6 +1970,7 @@ static void test_ps_null_param()
/* Execute several queries, all returning NULL in result. */
for(cur_query= queries; *cur_query; cur_query++)
{
+ char query[MAX_TEST_QUERY_LENGTH];
strmov(query, *cur_query);
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
@@ -1991,6 +2002,7 @@ static void test_fetch_null()
MYSQL_BIND bind[11];
ulong length[11];
my_bool is_null[11];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_fetch_null");
@@ -2219,6 +2231,7 @@ static void test_select()
int nData= 1;
MYSQL_BIND bind[2];
ulong length[2];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_select");
@@ -2290,6 +2303,7 @@ static void test_ps_conj_select()
int32 int_data;
char str_data[32];
unsigned long str_length;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_ps_conj_select");
rc= mysql_query(mysql, "drop table if exists t1");
@@ -2347,6 +2361,7 @@ static void test_bug1115()
MYSQL_BIND bind[1];
ulong length[1];
char szData[11];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_bug1115");
@@ -2458,6 +2473,7 @@ static void test_bug1180()
MYSQL_BIND bind[1];
ulong length[1];
char szData[11];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_select_bug");
@@ -2548,6 +2564,7 @@ static void test_bug1644()
int num;
my_bool isnull;
int rc, i;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_bug1644");
@@ -2647,6 +2664,7 @@ static void test_select_show()
{
MYSQL_STMT *stmt;
int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_select_show");
@@ -2715,6 +2733,7 @@ static void test_simple_update()
MYSQL_RES *result;
MYSQL_BIND bind[2];
ulong length[2];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_simple_update");
@@ -2792,6 +2811,7 @@ static void test_long_data()
char *data= NullS;
MYSQL_RES *result;
MYSQL_BIND bind[3];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_long_data");
@@ -2878,6 +2898,7 @@ static void test_long_data_str()
MYSQL_RES *result;
MYSQL_BIND bind[2];
my_bool is_null[2];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_long_data_str");
@@ -2970,6 +2991,7 @@ static void test_long_data_str1()
MYSQL_RES *result;
MYSQL_BIND bind[2];
MYSQL_FIELD *field;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_long_data_str1");
@@ -3125,6 +3147,7 @@ static void test_long_data_bin()
long length;
MYSQL_RES *result;
MYSQL_BIND bind[2];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_long_data_bin");
@@ -3204,6 +3227,7 @@ static void test_simple_delete()
MYSQL_RES *result;
MYSQL_BIND bind[2];
ulong length[2];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_simple_delete");
@@ -3286,6 +3310,7 @@ static void test_update()
MYSQL_RES *result;
MYSQL_BIND bind[2];
ulong length[2];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_update");
@@ -3382,6 +3407,7 @@ static void test_prepare_noparam()
MYSQL_STMT *stmt;
int rc;
MYSQL_RES *result;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare_noparam");
@@ -4238,6 +4264,7 @@ static void test_prepare_ext()
short sData= 10;
longlong bData= 20;
MYSQL_BIND bind[6];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare_ext");
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext");
@@ -4625,6 +4652,7 @@ static void test_stmt_close()
MYSQL_RES *result;
unsigned int count;
int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_stmt_close");
@@ -5271,6 +5299,7 @@ static void test_manual_sample()
ulonglong affected_rows;
MYSQL_BIND bind[3];
my_bool is_null;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_manual_sample");
@@ -5625,6 +5654,7 @@ static void test_prepare_multi_statements()
{
MYSQL *mysql_local;
MYSQL_STMT *stmt;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare_multi_statements");
if (!(mysql_local= mysql_init(NULL)))
@@ -5842,6 +5872,7 @@ static void test_store_result2()
int nData;
ulong length;
MYSQL_BIND bind[1];
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_store_result2");
@@ -7121,6 +7152,7 @@ static void test_set_option()
static void test_prepare_grant()
{
int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_prepare_grant");
@@ -8593,6 +8625,7 @@ static void test_sqlmode()
MYSQL_BIND bind[2];
char c1[5], c2[5];
int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_sqlmode");
@@ -8736,6 +8769,7 @@ static void test_ts()
ulong length;
int rc, field_count;
char name;
+ char query[MAX_TEST_QUERY_LENGTH];
myheader("test_ts");
@@ -15027,6 +15061,65 @@ static void test_bug20152()
}
}
+/* Bug#15752 "Lost connection to MySQL server when calling a SP from C API" */
+
+static void test_bug15752()
+{
+ MYSQL mysql_local;
+ int rc, i;
+ const int ITERATION_COUNT= 100;
+ char *query= "CALL p1()";
+
+ myheader("test_bug15752");
+
+ rc= mysql_query(mysql, "drop procedure if exists p1");
+ myquery(rc);
+ rc= mysql_query(mysql, "create procedure p1() select 1");
+ myquery(rc);
+
+ mysql_init(&mysql_local);
+ if (! mysql_real_connect(&mysql_local, opt_host, opt_user,
+ opt_password, current_db, opt_port,
+ opt_unix_socket,
+ CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS))
+ {
+ printf("Unable connect to MySQL server: %s\n", mysql_error(&mysql_local));
+ DIE_UNLESS(0);
+ }
+ rc= mysql_real_query(&mysql_local, query, strlen(query));
+ myquery(rc);
+ mysql_free_result(mysql_store_result(&mysql_local));
+
+ rc= mysql_real_query(&mysql_local, query, strlen(query));
+ DIE_UNLESS(rc && mysql_errno(&mysql_local) == CR_COMMANDS_OUT_OF_SYNC);
+
+ if (! opt_silent)
+ printf("Got error (as expected): %s\n", mysql_error(&mysql_local));
+
+ /* Check some other commands too */
+
+ DIE_UNLESS(mysql_next_result(&mysql_local) == 0);
+ mysql_free_result(mysql_store_result(&mysql_local));
+ DIE_UNLESS(mysql_next_result(&mysql_local) == -1);
+
+ /* The second problem is not reproducible: add the test case */
+ for (i = 0; i < ITERATION_COUNT; i++)
+ {
+ if (mysql_real_query(&mysql_local, query, strlen(query)))
+ {
+ printf("\ni=%d %s failed: %s\n", i, query, mysql_error(&mysql_local));
+ break;
+ }
+ mysql_free_result(mysql_store_result(&mysql_local));
+ DIE_UNLESS(mysql_next_result(&mysql_local) == 0);
+ mysql_free_result(mysql_store_result(&mysql_local));
+ DIE_UNLESS(mysql_next_result(&mysql_local) == -1);
+
+ }
+ mysql_close(&mysql_local);
+ rc= mysql_query(mysql, "drop procedure p1");
+ myquery(rc);
+}
/*
Bug#21206: memory corruption when too many cursors are opened at once
@@ -15342,7 +15435,8 @@ static struct my_tests_st my_tests[]= {
{ "test_bug20152", test_bug20152 },
{ "test_bug14169", test_bug14169 },
{ "test_bug17667", test_bug17667 },
- { "test_bug19671", test_bug19671},
+ { "test_bug19671", test_bug19671 },
+ { "test_bug15752", test_bug15752 },
{ "test_bug21206", test_bug21206},
{ 0, 0 }
};