Commit 126375b1 authored by unknown's avatar unknown

Merge bk-internal.mysql.com:/home/bk/mysql-5.0

into  bodhi.local:/opt/local/work/mysql-5.1-runtime-merge


libmysql/libmysql.c:
  Auto merged
libmysqld/lib_sql.cc:
  Auto merged
mysql-test/lib/mtr_io.pl:
  Auto merged
mysql-test/r/im_daemon_life_cycle.result:
  Auto merged
mysql-test/r/im_life_cycle.result:
  Auto merged
mysql-test/r/rpl_trigger.result:
  Auto merged
mysql-test/r/trigger.result:
  Auto merged
mysql-test/t/im_daemon_life_cycle.imtest:
  Auto merged
mysql-test/t/im_life_cycle.imtest:
  Auto merged
mysql-test/t/im_utils.imtest:
  Auto merged
mysql-test/t/rpl_trigger.test:
  Auto merged
mysql-test/t/trigger.test:
  Auto merged
sql/item_cmpfunc.cc:
  Auto merged
sql/item_func.cc:
  Auto merged
sql/item_strfunc.cc:
  Auto merged
sql/item_sum.cc:
  Auto merged
sql/mysqld.cc:
  Auto merged
sql/sql_cache.cc:
  Auto merged
tests/mysql_client_test.c:
  Auto merged
mysql-test/lib/mtr_process.pl:
  Use local.
mysql-test/r/func_str.result:
  SCCS merged
mysql-test/t/func_str.test:
  Manual merge.
sql/sql_trigger.cc:
  Manual merge.
sql/sql_yacc.yy:
  Manual merge.
parents 66b53b16 4ec84721
...@@ -582,7 +582,7 @@ sub mtr_im_start($$) { ...@@ -582,7 +582,7 @@ sub mtr_im_start($$) {
mtr_add_arg($args, $opt); mtr_add_arg($args, $opt);
} }
$im->{'pid'} = $im->{'spawner_pid'} =
mtr_spawn( mtr_spawn(
$::exe_im, # path to the executable $::exe_im, # path to the executable
$args, # cmd-line args $args, # cmd-line args
...@@ -593,7 +593,7 @@ sub mtr_im_start($$) { ...@@ -593,7 +593,7 @@ sub mtr_im_start($$) {
{ append_log_file => 1 } # append log files { append_log_file => 1 } # append log files
); );
unless ( $im->{'pid'} ) unless ( $im->{'spawner_pid'} )
{ {
mtr_error('Could not start Instance Manager.') mtr_error('Could not start Instance Manager.')
} }
......
...@@ -39,6 +39,7 @@ sub mtr_get_pid_from_file ($) { ...@@ -39,6 +39,7 @@ sub mtr_get_pid_from_file ($) {
# Read pid number from file # Read pid number from file
my $pid= <FILE>; my $pid= <FILE>;
chomp $pid;
close FILE; close FILE;
return $pid if $pid=~ /^(\d+)/; return $pid if $pid=~ /^(\d+)/;
......
...@@ -6,7 +6,7 @@ instance_name state ...@@ -6,7 +6,7 @@ instance_name state
mysqld1 XXXXX mysqld1 XXXXX
mysqld2 offline mysqld2 offline
Killing the process... Killing the process...
Sleeping... Waiting...
Success: the process was restarted. Success: the process was restarted.
Success: server is ready to accept connection on socket. Success: server is ready to accept connection on socket.
...@@ -16,7 +16,7 @@ Success: server is ready to accept connection on socket. ...@@ -16,7 +16,7 @@ Success: server is ready to accept connection on socket.
START INSTANCE mysqld2; START INSTANCE mysqld2;
Success: the process has been started. Success: the process has been started.
Killing the process... Killing the process...
Sleeping... Waiting...
Success: the process was restarted. Success: the process was restarted.
Success: server is ready to accept connection on socket. Success: server is ready to accept connection on socket.
SHOW INSTANCE STATUS mysqld1; SHOW INSTANCE STATUS mysqld1;
......
...@@ -39,7 +39,7 @@ ERROR HY000: Unknown instance name ...@@ -39,7 +39,7 @@ ERROR HY000: Unknown instance name
-- 1.1.6. -- 1.1.6.
-------------------------------------------------------------------- --------------------------------------------------------------------
Killing the process... Killing the process...
Sleeping... Waiting...
Success: the process was restarted. Success: the process was restarted.
SHOW INSTANCES; SHOW INSTANCES;
instance_name state instance_name state
...@@ -52,7 +52,7 @@ mysqld2 offline ...@@ -52,7 +52,7 @@ mysqld2 offline
START INSTANCE mysqld2; START INSTANCE mysqld2;
Success: the process has been started. Success: the process has been started.
Killing the process... Killing the process...
Sleeping... Waiting...
Success: the process was killed. Success: the process was killed.
-------------------------------------------------------------------- --------------------------------------------------------------------
......
...@@ -944,3 +944,30 @@ c ...@@ -944,3 +944,30 @@ c
---> Cleaning up... ---> Cleaning up...
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
drop table if exists t1;
create table t1(a int, b varchar(50));
drop trigger not_a_trigger;
ERROR HY000: Trigger does not exist
drop trigger if exists not_a_trigger;
Warnings:
Note 1360 Trigger does not exist
create trigger t1_bi before insert on t1
for each row set NEW.b := "In trigger t1_bi";
insert into t1 values (1, "a");
drop trigger if exists t1_bi;
insert into t1 values (2, "b");
drop trigger if exists t1_bi;
Warnings:
Note 1360 Trigger does not exist
insert into t1 values (3, "c");
select * from t1;
a b
1 In trigger t1_bi
2 b
3 c
select * from t1;
a b
1 In trigger t1_bi
2 b
3 c
drop table t1;
...@@ -1256,4 +1256,26 @@ select @a; ...@@ -1256,4 +1256,26 @@ select @a;
20 20
drop table t1; drop table t1;
drop function f1; drop function f1;
drop table if exists t1;
create table t1(a int, b varchar(50));
drop trigger not_a_trigger;
ERROR HY000: Trigger does not exist
drop trigger if exists not_a_trigger;
Warnings:
Note 1360 Trigger does not exist
create trigger t1_bi before insert on t1
for each row set NEW.b := "In trigger t1_bi";
insert into t1 values (1, "a");
drop trigger if exists t1_bi;
insert into t1 values (2, "b");
drop trigger if exists t1_bi;
Warnings:
Note 1360 Trigger does not exist
insert into t1 values (3, "c");
select * from t1;
a b
1 In trigger t1_bi
2 b
3 c
drop table t1;
End of 5.0 tests End of 5.0 tests
...@@ -895,4 +895,208 @@ select benchmark(5+5, pi()); ...@@ -895,4 +895,208 @@ select benchmark(5+5, pi());
select benchmark((select 10 from dual), pi()); select benchmark((select 10 from dual), pi());
select benchmark(@bench_count, pi()); select benchmark(@bench_count, pi());
#
# Bug #10963
# 4294967296 18446744073709551616
select locate('he','hello',-2);
select locate('lo','hello',-4294967295);
select locate('lo','hello',4294967295);
select locate('lo','hello',-4294967296);
select locate('lo','hello',4294967296);
select locate('lo','hello',-4294967297);
select locate('lo','hello',4294967297);
select locate('lo','hello',-18446744073709551615);
select locate('lo','hello',18446744073709551615);
select locate('lo','hello',-18446744073709551616);
select locate('lo','hello',18446744073709551616);
select locate('lo','hello',-18446744073709551617);
select locate('lo','hello',18446744073709551617);
select left('hello', 10);
select left('hello', 0);
select left('hello', -1);
select left('hello', -4294967295);
select left('hello', 4294967295);
select left('hello', -4294967296);
select left('hello', 4294967296);
select left('hello', -4294967297);
select left('hello', 4294967297);
select left('hello', -18446744073709551615);
select left('hello', 18446744073709551615);
select left('hello', -18446744073709551616);
select left('hello', 18446744073709551616);
select left('hello', -18446744073709551617);
select left('hello', 18446744073709551617);
select right('hello', 10);
select right('hello', 0);
select right('hello', -1);
select right('hello', -4294967295);
select right('hello', 4294967295);
select right('hello', -4294967296);
select right('hello', 4294967296);
select right('hello', -4294967297);
select right('hello', 4294967297);
select right('hello', -18446744073709551615);
select right('hello', 18446744073709551615);
select right('hello', -18446744073709551616);
select right('hello', 18446744073709551616);
select right('hello', -18446744073709551617);
select right('hello', 18446744073709551617);
select substring('hello', 2, -1);
select substring('hello', -1, 1);
select substring('hello', -2, 1);
select substring('hello', -4294967295, 1);
select substring('hello', 4294967295, 1);
select substring('hello', -4294967296, 1);
select substring('hello', 4294967296, 1);
select substring('hello', -4294967297, 1);
select substring('hello', 4294967297, 1);
select substring('hello', -18446744073709551615, 1);
select substring('hello', 18446744073709551615, 1);
select substring('hello', -18446744073709551616, 1);
select substring('hello', 18446744073709551616, 1);
select substring('hello', -18446744073709551617, 1);
select substring('hello', 18446744073709551617, 1);
select substring('hello', 1, -1);
select substring('hello', 1, -4294967295);
select substring('hello', 1, 4294967295);
select substring('hello', 1, -4294967296);
select substring('hello', 1, 4294967296);
select substring('hello', 1, -4294967297);
select substring('hello', 1, 4294967297);
select substring('hello', 1, -18446744073709551615);
select substring('hello', 1, 18446744073709551615);
select substring('hello', 1, -18446744073709551616);
select substring('hello', 1, 18446744073709551616);
select substring('hello', 1, -18446744073709551617);
select substring('hello', 1, 18446744073709551617);
select substring('hello', -1, -1);
select substring('hello', -4294967295, -4294967295);
select substring('hello', 4294967295, 4294967295);
select substring('hello', -4294967296, -4294967296);
select substring('hello', 4294967296, 4294967296);
select substring('hello', -4294967297, -4294967297);
select substring('hello', 4294967297, 4294967297);
select substring('hello', -18446744073709551615, -18446744073709551615);
select substring('hello', 18446744073709551615, 18446744073709551615);
select substring('hello', -18446744073709551616, -18446744073709551616);
select substring('hello', 18446744073709551616, 18446744073709551616);
select substring('hello', -18446744073709551617, -18446744073709551617);
select substring('hello', 18446744073709551617, 18446744073709551617);
select insert('hello', -1, 1, 'hi');
select insert('hello', -4294967295, 1, 'hi');
select insert('hello', 4294967295, 1, 'hi');
select insert('hello', -4294967296, 1, 'hi');
select insert('hello', 4294967296, 1, 'hi');
select insert('hello', -4294967297, 1, 'hi');
select insert('hello', 4294967297, 1, 'hi');
select insert('hello', -18446744073709551615, 1, 'hi');
select insert('hello', 18446744073709551615, 1, 'hi');
select insert('hello', -18446744073709551616, 1, 'hi');
select insert('hello', 18446744073709551616, 1, 'hi');
select insert('hello', -18446744073709551617, 1, 'hi');
select insert('hello', 18446744073709551617, 1, 'hi');
select insert('hello', 1, -1, 'hi');
select insert('hello', 1, -4294967295, 'hi');
select insert('hello', 1, 4294967295, 'hi');
select insert('hello', 1, -4294967296, 'hi');
select insert('hello', 1, 4294967296, 'hi');
select insert('hello', 1, -4294967297, 'hi');
select insert('hello', 1, 4294967297, 'hi');
select insert('hello', 1, -18446744073709551615, 'hi');
select insert('hello', 1, 18446744073709551615, 'hi');
select insert('hello', 1, -18446744073709551616, 'hi');
select insert('hello', 1, 18446744073709551616, 'hi');
select insert('hello', 1, -18446744073709551617, 'hi');
select insert('hello', 1, 18446744073709551617, 'hi');
select insert('hello', -1, -1, 'hi');
select insert('hello', -4294967295, -4294967295, 'hi');
select insert('hello', 4294967295, 4294967295, 'hi');
select insert('hello', -4294967296, -4294967296, 'hi');
select insert('hello', 4294967296, 4294967296, 'hi');
select insert('hello', -4294967297, -4294967297, 'hi');
select insert('hello', 4294967297, 4294967297, 'hi');
select insert('hello', -18446744073709551615, -18446744073709551615, 'hi');
select insert('hello', 18446744073709551615, 18446744073709551615, 'hi');
select insert('hello', -18446744073709551616, -18446744073709551616, 'hi');
select insert('hello', 18446744073709551616, 18446744073709551616, 'hi');
select insert('hello', -18446744073709551617, -18446744073709551617, 'hi');
select insert('hello', 18446744073709551617, 18446744073709551617, 'hi');
select repeat('hello', -1);
select repeat('hello', -4294967295);
select repeat('hello', 4294967295);
select repeat('hello', -4294967296);
select repeat('hello', 4294967296);
select repeat('hello', -4294967297);
select repeat('hello', 4294967297);
select repeat('hello', -18446744073709551615);
select repeat('hello', 18446744073709551615);
select repeat('hello', -18446744073709551616);
select repeat('hello', 18446744073709551616);
select repeat('hello', -18446744073709551617);
select repeat('hello', 18446744073709551617);
select space(-1);
select space(-4294967295);
select space(4294967295);
select space(-4294967296);
select space(4294967296);
select space(-4294967297);
select space(4294967297);
select space(-18446744073709551615);
select space(18446744073709551615);
select space(-18446744073709551616);
select space(18446744073709551616);
select space(-18446744073709551617);
select space(18446744073709551617);
select rpad('hello', -1, '1');
select rpad('hello', -4294967295, '1');
select rpad('hello', 4294967295, '1');
select rpad('hello', -4294967296, '1');
select rpad('hello', 4294967296, '1');
select rpad('hello', -4294967297, '1');
select rpad('hello', 4294967297, '1');
select rpad('hello', -18446744073709551615, '1');
select rpad('hello', 18446744073709551615, '1');
select rpad('hello', -18446744073709551616, '1');
select rpad('hello', 18446744073709551616, '1');
select rpad('hello', -18446744073709551617, '1');
select rpad('hello', 18446744073709551617, '1');
select lpad('hello', -1, '1');
select lpad('hello', -4294967295, '1');
select lpad('hello', 4294967295, '1');
select lpad('hello', -4294967296, '1');
select lpad('hello', 4294967296, '1');
select lpad('hello', -4294967297, '1');
select lpad('hello', 4294967297, '1');
select lpad('hello', -18446744073709551615, '1');
select lpad('hello', 18446744073709551615, '1');
select lpad('hello', -18446744073709551616, '1');
select lpad('hello', 18446744073709551616, '1');
select lpad('hello', -18446744073709551617, '1');
select lpad('hello', 18446744073709551617, '1');
#
# BUG#17047: CHAR() and IN() can return NULL without signaling NULL
# result
#
SET @orig_sql_mode = @@SQL_MODE;
SET SQL_MODE=traditional;
SELECT CHAR(0xff,0x8f USING utf8);
SELECT CHAR(0xff,0x8f USING utf8) IS NULL;
SET SQL_MODE=@orig_sql_mode;
--echo End of 5.0 tests --echo End of 5.0 tests
...@@ -6,59 +6,73 @@ ...@@ -6,59 +6,73 @@
# #
########################################################################### ###########################################################################
--exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle im_daemon_life_cycle.imtest started.
###########################################################################
--source include/im_check_env.inc --source include/im_check_env.inc
# Turn on reconnect, not on by default anymore # Turn on reconnect, not on by default anymore.
--enable_reconnect --enable_reconnect
###########################################################################
#
# The main daemon-life-cycle test case -- check that IM-angel will restart
# IM-main if it got killed:
# - kill IM-main and check that IM-angel will restart it;
# - wait for IM-main to start accepting connections before continue test
# case;
#
########################################################################### ###########################################################################
# Kill the IM main process and check that the IM Angel will restart the main --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle Main-test: starting...
# process.
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30
########################################################################### --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle Killing IM-main...
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30 im_daemon_life_cycle
# Wait for IM to start accepting connections. --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle Waiting for IM-main to start accepting connections...
--exec $MYSQL_TEST_DIR/t/wait_for_socket.sh $EXE_MYSQL $IM_PATH_SOCK $IM_USERNAME $IM_PASSWORD '' 30 im_daemon_life_cycle
--exec $MYSQL_TEST_DIR/t/wait_for_socket.sh $EXE_MYSQL $IM_PATH_SOCK $IM_USERNAME $IM_PASSWORD '' 30 --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle Main-test: done.
########################################################################### ###########################################################################
# #
# BUG#12751: Instance Manager: client hangs # BUG#12751: Instance Manager: client hangs
# - start nonguarded instance (mysqld2);
# - kill IM-main and get it restarted by IM-angel;
# - check that guarded instance (mysqld1) is accepting connections.
# - check that non-guarded instance (mysqld2) were not stopped.
# #
###########################################################################
--echo --echo
--echo -------------------------------------------------------------------- --echo --------------------------------------------------------------------
--echo -- Test for BUG#12751 --echo -- Test for BUG#12751
--echo -------------------------------------------------------------------- --echo --------------------------------------------------------------------
# Give some time to begin accepting connections after restart. --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle BUG12751: starting...
# FIXME: race condition here.
--sleep 3
# 1. Start mysqld; # 1. Start mysqld;
--exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle mysqld2: starting...
START INSTANCE mysqld2; START INSTANCE mysqld2;
# FIXME: START INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started
# 2. Restart IM-main: kill it and IM-angel will restart it; wait for IM to --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle mysqld2: waiting to start...
# start accepting connections again. --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started im_daemon_life_cycle
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30 --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle mysqld2: started.
--exec $MYSQL_TEST_DIR/t/wait_for_socket.sh $EXE_MYSQL $IM_PATH_SOCK $IM_USERNAME $IM_PASSWORD '' 30 # 2. Restart IM-main;
# 3. Issue some statement -- connection should be re-established. --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle Killing IM-main...
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30 im_daemon_life_cycle
# Give some time to begin accepting connections after restart. --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle Waiting for IM-main to start accepting connections...
# FIXME: race condition here. --exec $MYSQL_TEST_DIR/t/wait_for_socket.sh $EXE_MYSQL $IM_PATH_SOCK $IM_USERNAME $IM_PASSWORD '' 30 im_daemon_life_cycle
# 3. Issue some statement -- connection should be re-established.
--sleep 3 --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle Checking that IM-main processing commands...
--replace_column 3 VERSION_NUMBER 4 VERSION --replace_column 3 VERSION_NUMBER 4 VERSION
SHOW INSTANCE STATUS mysqld1; SHOW INSTANCE STATUS mysqld1;
...@@ -67,6 +81,13 @@ SHOW INSTANCE STATUS mysqld1; ...@@ -67,6 +81,13 @@ SHOW INSTANCE STATUS mysqld1;
# So, if it we do not stop it, it will be stopped by mysql-test-run.pl with # So, if it we do not stop it, it will be stopped by mysql-test-run.pl with
# warning. # warning.
--exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle mysqld2: stopping...
STOP INSTANCE mysqld2; STOP INSTANCE mysqld2;
# FIXME: STOP INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped --exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle mysqld2: waiting to stop...
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped im_daemon_life_cycle
--exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle mysqld2: stopped.
###########################################################################
--exec $MYSQL_TEST_DIR/t/log.sh im_daemon_life_cycle BUG12751: done.
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
START INSTANCE mysqld2; START INSTANCE mysqld2;
# FIXME: START INSTANCE should be synchronous. # FIXME: START INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started im_life_cycle
# FIXME: Result of SHOW INSTANCES here is not deterministic unless START # FIXME: Result of SHOW INSTANCES here is not deterministic unless START
# INSTANCE is synchronous. Even waiting for mysqld to start by looking at # INSTANCE is synchronous. Even waiting for mysqld to start by looking at
...@@ -58,7 +58,7 @@ SHOW VARIABLES LIKE 'port'; ...@@ -58,7 +58,7 @@ SHOW VARIABLES LIKE 'port';
STOP INSTANCE mysqld2; STOP INSTANCE mysqld2;
# FIXME: STOP INSTANCE should be synchronous. # FIXME: STOP INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped im_life_cycle
# FIXME: Result of SHOW INSTANCES here is not deterministic unless START # FIXME: Result of SHOW INSTANCES here is not deterministic unless START
# INSTANCE is synchronous. Even waiting for mysqld to start by looking at # INSTANCE is synchronous. Even waiting for mysqld to start by looking at
...@@ -121,7 +121,7 @@ STOP INSTANCE mysqld3; ...@@ -121,7 +121,7 @@ STOP INSTANCE mysqld3;
--echo -- 1.1.6. --echo -- 1.1.6.
--echo -------------------------------------------------------------------- --echo --------------------------------------------------------------------
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30 --exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30 im_life_cycle
# Give some time to IM to detect that mysqld was restarted. It should be # Give some time to IM to detect that mysqld was restarted. It should be
# longer than monitoring interval. # longer than monitoring interval.
...@@ -143,7 +143,7 @@ SHOW INSTANCES; ...@@ -143,7 +143,7 @@ SHOW INSTANCES;
START INSTANCE mysqld2; START INSTANCE mysqld2;
# FIXME: START INSTANCE should be synchronous. # FIXME: START INSTANCE should be synchronous.
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started im_life_cycle
# FIXME: Result of SHOW INSTANCES here is not deterministic unless START # FIXME: Result of SHOW INSTANCES here is not deterministic unless START
# INSTANCE is synchronous. Even waiting for mysqld to start by looking at # INSTANCE is synchronous. Even waiting for mysqld to start by looking at
...@@ -151,7 +151,7 @@ START INSTANCE mysqld2; ...@@ -151,7 +151,7 @@ START INSTANCE mysqld2;
# mysqld has started. # mysqld has started.
# SHOW INSTANCES; # SHOW INSTANCES;
--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10 --exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10 im_life_cycle
# FIXME: Result of SHOW INSTANCES here is not deterministic unless START # FIXME: Result of SHOW INSTANCES here is not deterministic unless START
# INSTANCE is synchronous. Even waiting for mysqld to start by looking at # INSTANCE is synchronous. Even waiting for mysqld to start by looking at
......
...@@ -31,10 +31,10 @@ SHOW INSTANCE OPTIONS mysqld2; ...@@ -31,10 +31,10 @@ SHOW INSTANCE OPTIONS mysqld2;
# #
START INSTANCE mysqld2; START INSTANCE mysqld2;
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started im_utils
STOP INSTANCE mysqld2; STOP INSTANCE mysqld2;
--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped --exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped im_utils
# #
# Check 'SHOW LOG FILES' command: # Check 'SHOW LOG FILES' command:
......
...@@ -2,74 +2,101 @@ ...@@ -2,74 +2,101 @@
########################################################################### ###########################################################################
# NOTE: this script returns 0 (success) even in case of failure. This is # NOTE: this script returns 0 (success) even in case of failure (except for
# because this script is executed under mysql-test-run[.pl] and it's better to # usage-error). This is because this script is executed under
# examine particular problem in log file, than just having said that the test # mysql-test-run[.pl] and it's better to examine particular problem in log
# case has failed. # file, than just having said that the test case has failed.
###########################################################################
basename=`basename "$0"`
dirname=`dirname "$0"`
###########################################################################
. "$dirname/utils.sh"
########################################################################### ###########################################################################
check_restart() check_restart()
{ {
if [ ! -r "$pid_path" ]; then if [ ! -r "$pid_path" ]; then
log_debug "No '$pid_path' found."
user_msg='the process was killed' user_msg='the process was killed'
return 1 return 1
fi fi
new_pid=`cat "$pid_path" 2>/dev/null` new_pid=`cat "$pid_path" 2>/dev/null`
err_code=$?
if [ $? -eq 0 -a "$original_pid" = "$new_pid" ]; then log_debug "err_code: $err_code; original_pid: $original_pid; new_pid: $new_pid."
if [ $err_code -eq 0 -a "$original_pid" = "$new_pid" ]; then
log_debug "The process was not restarted."
user_msg='the process was not restarted' user_msg='the process was not restarted'
return 1 return 1
fi fi
log_debug "The process was restarted."
user_msg='the process was restarted' user_msg='the process was restarted'
return 0 return 0
} }
########################################################################### ###########################################################################
if [ $# -ne 3 ]; then if [ $# -ne 4 ]; then
echo "Usage: kill_n_check.sh <pid file path> killed|restarted <timeout>" echo "Usage: $basename <pid file path> killed|restarted <timeout> <test id>"
exit 0 exit 1
fi fi
pid_path="$1" pid_path="$1"
expected_result="$2" expected_result="$2"
total_timeout="$3" total_timeout="$3"
test_id="$4"
log_file="$MYSQLTEST_VARDIR/log/$test_id.log"
log_debug "-- $basename: starting --"
log_debug "pid_path: '$pid_path'"
log_debug "expected_result: '$expected_result'"
log_debug "total_timeout: '$total_timeout'"
log_debug "test_id: '$test_id'"
log_debug "log_file: '$log_file'"
###########################################################################
if [ "$expected_result" != 'killed' -a \ if [ "$expected_result" != 'killed' -a \
"$expected_result" != 'restarted' ]; then "$expected_result" != 'restarted' ]; then
echo "Error: invalid second argument ('killed' or 'restarted' expected)." log_error "Invalid second argument ($expected_result): 'killed' or 'restarted' expected."
exit 0 quit 0
fi fi
if [ -z "$pid_path" ]; then if [ -z "$pid_path" ]; then
echo "Error: invalid PID path ($pid_path)." log_error "Invalid PID path ($pid_path)."
exit 0 quit 0
fi fi
if [ ! -r "$pid_path" ]; then if [ ! -r "$pid_path" ]; then
echo "Error: PID file ($pid_path) does not exist." log_error "PID file ($pid_path) does not exist."
exit 0 quit 0
fi fi
if [ -z "$total_timeout" ]; then if [ -z "$total_timeout" ]; then
echo "Error: timeout is not specified." log_error "Timeout is not specified."
exit 0 quit 0
fi fi
########################################################################### ###########################################################################
original_pid=`cat "$pid_path"` original_pid=`cat "$pid_path"`
log_debug "original_pid: $original_pid."
echo "Killing the process..." log_info "Killing the process..."
kill -9 $original_pid kill -9 $original_pid
########################################################################### ###########################################################################
echo "Sleeping..." log_info "Waiting..."
if [ "$expected_result" = "restarted" ]; then if [ "$expected_result" = "restarted" ]; then
...@@ -79,37 +106,42 @@ if [ "$expected_result" = "restarted" ]; then ...@@ -79,37 +106,42 @@ if [ "$expected_result" = "restarted" ]; then
while true; do while true; do
log_debug "cur_attempt: $cur_attempt."
if check_restart; then if check_restart; then
echo "Success: $user_msg." log_info "Success: $user_msg."
exit 0 quit 0
fi fi
[ $cur_attempt -ge $total_timeout ] && break [ $cur_attempt -ge $total_timeout ] && break
log_debug "Sleeping for 1 second..."
sleep 1 sleep 1
cur_attempt=`expr $cur_attempt + 1` cur_attempt=`expr $cur_attempt + 1`
done done
echo "Error: $user_msg." log_error "$user_msg."
exit 0 quit 0
else # $expected_result == killed else # $expected_result == killed
# Here we have to sleep for some long time to ensure that the process will # Here we have to sleep for some long time to ensure that the process will
# not be restarted. # not be restarted.
log_debug "Sleeping for $total_timeout seconds..."
sleep $total_timeout sleep $total_timeout
new_pid=`cat "$pid_path" 2>/dev/null` new_pid=`cat "$pid_path" 2>/dev/null`
log_debug "new_pid: $new_pid."
if [ "$new_pid" -a "$new_pid" -ne "$original_pid" ]; then if [ "$new_pid" -a "$new_pid" -ne "$original_pid" ]; then
echo "Error: the process was restarted." log_error "The process was restarted."
else else
echo "Success: the process was killed." log_info "Success: the process was killed."
fi fi
exit 0 quit 0
fi fi
#!/bin/bash
###########################################################################
basename=`basename "$0"`
dirname=`dirname "$0"`
###########################################################################
. "$dirname/utils.sh"
###########################################################################
if [ $# -lt 2 ]; then
echo "Usage: $basename <test id> log message ..."
exit 1
fi
test_id="$1"
log_file="$MYSQLTEST_VARDIR/log/$test_id.log"
shift
log_debug "$*"
...@@ -431,6 +431,43 @@ DROP TABLE t2; ...@@ -431,6 +431,43 @@ DROP TABLE t2;
--sync_with_master --sync_with_master
--connection master --connection master
#
# BUG#23703: DROP TRIGGER needs an IF EXISTS
#
connection master;
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1(a int, b varchar(50));
-- error ER_TRG_DOES_NOT_EXIST
drop trigger not_a_trigger;
drop trigger if exists not_a_trigger;
create trigger t1_bi before insert on t1
for each row set NEW.b := "In trigger t1_bi";
insert into t1 values (1, "a");
drop trigger if exists t1_bi;
insert into t1 values (2, "b");
drop trigger if exists t1_bi;
insert into t1 values (3, "c");
select * from t1;
save_master_pos;
connection slave;
sync_with_master;
select * from t1;
connection master;
drop table t1;
# #
# End of tests # End of tests
......
...@@ -1519,4 +1519,32 @@ connection default; ...@@ -1519,4 +1519,32 @@ connection default;
drop table t1; drop table t1;
drop function f1; drop function f1;
#
# Bug#23703: DROP TRIGGER needs an IF EXISTS
#
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1(a int, b varchar(50));
-- error ER_TRG_DOES_NOT_EXIST
drop trigger not_a_trigger;
drop trigger if exists not_a_trigger;
create trigger t1_bi before insert on t1
for each row set NEW.b := "In trigger t1_bi";
insert into t1 values (1, "a");
drop trigger if exists t1_bi;
insert into t1 values (2, "b");
drop trigger if exists t1_bi;
insert into t1 values (3, "c");
select * from t1;
drop table t1;
--echo End of 5.0 tests --echo End of 5.0 tests
###########################################################################
#
# This file provides utility functions and is included by other scripts.
#
# The following global variables must be set before calling functions from this
# file:
# - basename -- base name of the calling script (main application);
# - log_file -- where to store log records;
#
###########################################################################
log()
{
[ -z "$log_file" ] && return;
log_level="$1"
log_msg="$2"
ts=`date`
echo "[$ts] [$basename] [$log_level] $log_msg" >> "$log_file";
}
###########################################################################
log_debug()
{
log 'DEBUG' "$1"
}
###########################################################################
log_info()
{
log 'INFO' "$1"
echo "$1"
}
###########################################################################
log_error()
{
log 'ERROR' "$1"
echo "Error: $1"
}
###########################################################################
quit()
{
exit_status="$1"
log_debug "-- $basename: finished (exit_status: $exit_status) --"
exit $exit_status
}
...@@ -2,34 +2,40 @@ ...@@ -2,34 +2,40 @@
########################################################################### ###########################################################################
pid_path="$1" # NOTE: this script returns 0 (success) even in case of failure (except for
total_attempts="$2" # usage-error). This is because this script is executed under
event="$3" # mysql-test-run[.pl] and it's better to examine particular problem in log
# file, than just having said that the test case has failed.
case "$3" in ###########################################################################
started)
check_fn='check_started';
;;
stopped) basename=`basename "$0"`
check_fn='check_stopped'; dirname=`dirname "$0"`
;;
*) ###########################################################################
echo "Error: invalid third argument ('started' or 'stopped' expected)."
exit 0 . "$dirname/utils.sh"
esac
########################################################################### ###########################################################################
check_started() check_started()
{ {
[ ! -r "$pid_path" ] && return 1 if [ ! -r "$pid_path" ]; then
log_debug "No PID-file ($pid_path) found -- not started."
return 1
fi
new_pid=`cat "$pid_path" 2>/dev/null` new_pid=`cat "$pid_path" 2>/dev/null`
err_code=$?
log_debug "err_code: $err_code; new_pid: $new_pid."
[ $? -eq 0 -a "$original_pid" = "$new_pid" ] && return 1 if [ $? -ne 0 -o -z "$new_pid" ]; then
log_debug "The process was not started."
return 1
fi
log_debug "The process was started."
return 0 return 0
} }
...@@ -37,30 +43,72 @@ check_started() ...@@ -37,30 +43,72 @@ check_started()
check_stopped() check_stopped()
{ {
[ -r "$pid_path" ] && return 1 if [ -r "$pid_path" ]; then
log_debug "PID-file '$pid_path' exists -- not stopped."
return 1
fi
log_debug "No PID-file ($pid_path) found -- stopped."
return 0 return 0
} }
########################################################################### ###########################################################################
if [ $# -ne 4 ]; then
echo "Usage: $basename <pid file path> <total attempts> started|stopped <test id>"
exit 1
fi
pid_path="$1"
total_attempts="$2"
event="$3"
test_id="$4"
log_file="$MYSQLTEST_VARDIR/log/$test_id.log"
log_debug "-- $basename: starting --"
log_debug "pid_path: '$pid_path'"
log_debug "total_attempts: '$total_attempts'"
log_debug "event: '$event'"
log_debug "test_id: '$test_id'"
log_debug "log_file: '$log_file'"
###########################################################################
case "$event" in
started)
check_fn='check_started';
;;
stopped)
check_fn='check_stopped';
;;
*)
log_error "Invalid third argument ('started' or 'stopped' expected)."
quit 0
esac
###########################################################################
cur_attempt=1 cur_attempt=1
while true; do while true; do
log_debug "cur_attempt: $cur_attempt."
if ( eval $check_fn ); then if ( eval $check_fn ); then
echo "Success: the process has been $event." log_info "Success: the process has been $event."
exit 0 quit 0
fi fi
[ $cur_attempt -ge $total_attempts ] && break [ $cur_attempt -ge $total_attempts ] && break
log_debug "Sleeping for 1 second..."
sleep 1 sleep 1
cur_attempt=`expr $cur_attempt + 1` cur_attempt=`expr $cur_attempt + 1`
done done
echo "Error: the process has not been $event in $total_attempts secs." log_error "The process has not been $event in $total_attempts secs."
exit 0 quit 0
...@@ -2,9 +2,25 @@ ...@@ -2,9 +2,25 @@
########################################################################### ###########################################################################
if [ $# -ne 6 ]; then # NOTE: this script returns 0 (success) even in case of failure (except for
echo "Usage: wait_for_socket.sh <executable path> <socket path> <username> <password> <db> <timeout>" # usage-error). This is because this script is executed under
exit 0 # mysql-test-run[.pl] and it's better to examine particular problem in log
# file, than just having said that the test case has failed.
###########################################################################
basename=`basename "$0"`
dirname=`dirname "$0"`
###########################################################################
. "$dirname/utils.sh"
###########################################################################
if [ $# -ne 7 ]; then
echo "Usage: wait_for_socket.sh <executable path> <socket path> <username> <password> <db> <timeout> <test id>"
exit 1
fi fi
client_exe="$1" client_exe="$1"
...@@ -13,22 +29,34 @@ username="$3" ...@@ -13,22 +29,34 @@ username="$3"
password="$4" password="$4"
db="$5" db="$5"
total_timeout="$6" total_timeout="$6"
test_id="$7"
log_file="$MYSQLTEST_VARDIR/log/$test_id.log"
log_debug "-- $basename: starting --"
log_debug "client_exe: '$client_exe'"
log_debug "socket_path: '$socket_path'"
log_debug "username: '$username'"
log_debug "password: '$password'"
log_debug "db: '$db'"
log_debug "total_timeout: '$total_timeout'"
log_debug "test_id: '$test_id'"
log_debug "log_file: '$log_file'"
########################################################################### ###########################################################################
if [ -z "$client_exe" ]; then if [ -z "$client_exe" ]; then
echo "Error: invalid path to client executable ($client_exe)." log_error "Invalid path to client executable ($client_exe)."
exit 0; quit 0;
fi fi
if [ ! -x "$client_exe" ]; then if [ ! -x "$client_exe" ]; then
echo "Error: client by path '$client_exe' is not available." log_error "Client by path '$client_exe' is not available."
exit 0; quit 0;
fi fi
if [ -z "$socket_path" ]; then if [ -z "$socket_path" ]; then
echo "Error: invalid socket patch." log_error "Invalid socket patch ($socket_path)."
exit 0 quit 0
fi fi
########################################################################### ###########################################################################
...@@ -39,15 +67,19 @@ client_args="--silent --socket=$socket_path --connect_timeout=1 " ...@@ -39,15 +67,19 @@ client_args="--silent --socket=$socket_path --connect_timeout=1 "
[ -n "$password" ] && client_args="$client_args --password=$password " [ -n "$password" ] && client_args="$client_args --password=$password "
[ -n "$db" ] && client_args="$client_args $db" [ -n "$db" ] && client_args="$client_args $db"
log_debug "client_args: '$client_args'"
########################################################################### ###########################################################################
cur_attempt=1 cur_attempt=1
while true; do while true; do
log_debug "cur_attempt: $cur_attempt."
if ( echo 'quit' | "$client_exe" $client_args >/dev/null 2>&1 ); then if ( echo 'quit' | "$client_exe" $client_args >/dev/null 2>&1 ); then
echo "Success: server is ready to accept connection on socket." log_info "Success: server is ready to accept connection on socket."
exit 0 quit 0
fi fi
[ $cur_attempt -ge $total_timeout ] && break [ $cur_attempt -ge $total_timeout ] && break
...@@ -58,5 +90,5 @@ while true; do ...@@ -58,5 +90,5 @@ while true; do
done done
echo "Error: server does not accept connections after $total_timeout seconds." log_error "Server does not accept connections after $total_timeout seconds."
exit 0 quit 0
...@@ -737,7 +737,11 @@ void query_cache_end_of_result(THD *thd) ...@@ -737,7 +737,11 @@ void query_cache_end_of_result(THD *thd)
header->query())); header->query()));
query_cache.wreck(__LINE__, ""); query_cache.wreck(__LINE__, "");
BLOCK_UNLOCK_WR(query_block); /*
We do not need call of BLOCK_UNLOCK_WR(query_block); here because
query_cache.wreck() switched query cache off but left content
untouched for investigation (it is debugging method).
*/
goto end; goto end;
} }
#endif #endif
...@@ -3523,7 +3527,7 @@ uint Query_cache::filename_2_table_key (char *key, const char *path, ...@@ -3523,7 +3527,7 @@ uint Query_cache::filename_2_table_key (char *key, const char *path,
#if defined(DBUG_OFF) && !defined(USE_QUERY_CACHE_INTEGRITY_CHECK) #if defined(DBUG_OFF) && !defined(USE_QUERY_CACHE_INTEGRITY_CHECK)
void wreck(uint line, const char *message) {} void wreck(uint line, const char *message) { query_cache_size = 0; }
void bins_dump() {} void bins_dump() {}
void cache_dump() {} void cache_dump() {}
void queries_dump() {} void queries_dump() {}
...@@ -3535,6 +3539,17 @@ my_bool in_blocks(Query_cache_block * point) { return 0; } ...@@ -3535,6 +3539,17 @@ my_bool in_blocks(Query_cache_block * point) { return 0; }
#else #else
/*
Debug method which switch query cache off but left content for
investigation.
SYNOPSIS
Query_cache::wreck()
line line of the wreck() call
message message for logging
*/
void Query_cache::wreck(uint line, const char *message) void Query_cache::wreck(uint line, const char *message)
{ {
THD *thd=current_thd; THD *thd=current_thd;
......
...@@ -107,7 +107,9 @@ const LEX_STRING trg_event_type_names[]= ...@@ -107,7 +107,9 @@ const LEX_STRING trg_event_type_names[]=
}; };
static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig); static int
add_table_for_trigger(THD *thd, sp_name *trig, bool if_exists,
TABLE_LIST ** table);
class Handle_old_incorrect_sql_modes_hook: public Unknown_key_hook class Handle_old_incorrect_sql_modes_hook: public Unknown_key_hook
{ {
...@@ -156,6 +158,13 @@ class Handle_old_incorrect_trigger_table_hook: public Unknown_key_hook ...@@ -156,6 +158,13 @@ class Handle_old_incorrect_trigger_table_hook: public Unknown_key_hook
*/ */
bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
{ {
/*
FIXME: The code below takes too many different paths depending on the
'create' flag, so that the justification for a single function
'mysql_create_or_drop_trigger', compared to two separate functions
'mysql_create_trigger' and 'mysql_drop_trigger' is not apparent.
This is a good candidate for a minor refactoring.
*/
TABLE *table; TABLE *table;
bool result= TRUE; bool result= TRUE;
String stmt_query; String stmt_query;
...@@ -181,10 +190,6 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) ...@@ -181,10 +190,6 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
if (!create &&
!(tables= add_table_for_trigger(thd, thd->lex->spname)))
DBUG_RETURN(TRUE);
/* /*
We don't allow creating triggers on tables in the 'mysql' schema We don't allow creating triggers on tables in the 'mysql' schema
*/ */
...@@ -194,9 +199,6 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) ...@@ -194,9 +199,6 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
/* We should have only one table in table list. */
DBUG_ASSERT(tables->next_global == 0);
/* /*
Check that the user has TRIGGER privilege on the subject table. Check that the user has TRIGGER privilege on the subject table.
*/ */
...@@ -216,8 +218,10 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) ...@@ -216,8 +218,10 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
/* /*
There is no DETERMINISTIC clause for triggers, so can't check it. There is no DETERMINISTIC clause for triggers, so can't check it.
But a trigger can in theory be used to do nasty things (if it supported But a trigger can in theory be used to do nasty things (if it supported
DROP for example) so we do the check for privileges. Triggers have the DROP for example) so we do the check for privileges. For now there is
same nature as functions regarding binlogging: their body is implicitely already a stronger test right above; but when this stronger test will
be removed, the test below will hold. Because triggers have the same
nature as functions regarding binlogging: their body is implicitly
binlogged, so they share the same danger, so trust_function_creators binlogged, so they share the same danger, so trust_function_creators
applies to them too. applies to them too.
*/ */
...@@ -228,24 +232,52 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) ...@@ -228,24 +232,52 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
/* We do not allow creation of triggers on temporary tables. */
if (create && find_temporary_table(thd, tables))
{
my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias);
DBUG_RETURN(TRUE);
}
/* /*
We don't want perform our operations while global read lock is held We don't want perform our operations while global read lock is held
so we have to wait until its end and then prevent it from occuring so we have to wait until its end and then prevent it from occurring
again until we are done. (Acquiring LOCK_open is not enough because again until we are done. (Acquiring LOCK_open is not enough because
global read lock is held without helding LOCK_open). global read lock is held without holding LOCK_open).
*/ */
if (wait_if_global_read_lock(thd, 0, 1)) if (wait_if_global_read_lock(thd, 0, 1))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
if (!create)
{
bool if_exists= thd->lex->drop_if_exists;
if (add_table_for_trigger(thd, thd->lex->spname, if_exists, & tables))
goto end;
if (!tables)
{
DBUG_ASSERT(if_exists);
/*
Since the trigger does not exist, there is no associated table,
and therefore :
- no TRIGGER privileges to check,
- no trigger to drop,
- no table to lock/modify,
so the drop statement is successful.
*/
result= FALSE;
/* Still, we need to log the query ... */
stmt_query.append(thd->query, thd->query_length);
goto end;
}
}
/* We should have only one table in table list. */
DBUG_ASSERT(tables->next_global == 0);
/* We do not allow creation of triggers on temporary tables. */
if (create && find_temporary_table(thd, tables->db, tables->table_name))
{
my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias);
goto end;
}
if (lock_table_names(thd, tables)) if (lock_table_names(thd, tables))
goto end; goto end;
...@@ -1141,13 +1173,17 @@ bool Table_triggers_list::get_trigger_info(THD *thd, trg_event_type event, ...@@ -1141,13 +1173,17 @@ bool Table_triggers_list::get_trigger_info(THD *thd, trg_event_type event,
mysql_table_for_trigger() mysql_table_for_trigger()
thd - current thread context thd - current thread context
trig - identifier for trigger trig - identifier for trigger
if_exists - treat a not existing trigger as a warning if TRUE
table - pointer to TABLE_LIST object for the table trigger (output)
RETURN VALUE RETURN VALUE
0 - error 0 Success
# - pointer to TABLE_LIST object for the table 1 Error
*/ */
static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig) static int
add_table_for_trigger(THD *thd, sp_name *trig, bool if_exists,
TABLE_LIST **table)
{ {
LEX *lex= thd->lex; LEX *lex= thd->lex;
char path_buff[FN_REFLEN]; char path_buff[FN_REFLEN];
...@@ -1158,6 +1194,7 @@ static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig) ...@@ -1158,6 +1194,7 @@ static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig)
path_buff, &trigname.trigger_table); path_buff, &trigname.trigger_table);
DBUG_ENTER("add_table_for_trigger"); DBUG_ENTER("add_table_for_trigger");
DBUG_ASSERT(table != NULL);
path.length= build_table_filename(path_buff, FN_REFLEN-1, path.length= build_table_filename(path_buff, FN_REFLEN-1,
trig->m_db.str, trig->m_name.str, trig->m_db.str, trig->m_name.str,
...@@ -1166,30 +1203,45 @@ static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig) ...@@ -1166,30 +1203,45 @@ static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig)
if (access(path_buff, F_OK)) if (access(path_buff, F_OK))
{ {
my_error(ER_TRG_DOES_NOT_EXIST, MYF(0)); if (if_exists)
{
push_warning_printf(thd,
MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_TRG_DOES_NOT_EXIST,
ER(ER_TRG_DOES_NOT_EXIST));
*table= NULL;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
my_error(ER_TRG_DOES_NOT_EXIST, MYF(0));
DBUG_RETURN(1);
}
if (!(parser= sql_parse_prepare(&path, thd->mem_root, 1))) if (!(parser= sql_parse_prepare(&path, thd->mem_root, 1)))
DBUG_RETURN(0); DBUG_RETURN(1);
if (!is_equal(&trigname_file_type, parser->type())) if (!is_equal(&trigname_file_type, parser->type()))
{ {
my_error(ER_WRONG_OBJECT, MYF(0), trig->m_name.str, trigname_file_ext+1, my_error(ER_WRONG_OBJECT, MYF(0), trig->m_name.str, trigname_file_ext+1,
"TRIGGERNAME"); "TRIGGERNAME");
DBUG_RETURN(0); DBUG_RETURN(1);
} }
if (parser->parse((gptr)&trigname, thd->mem_root, if (parser->parse((gptr)&trigname, thd->mem_root,
trigname_file_parameters, 1, trigname_file_parameters, 1,
&trigger_table_hook)) &trigger_table_hook))
DBUG_RETURN(0); DBUG_RETURN(1);
/* We need to reset statement table list to be PS/SP friendly. */ /* We need to reset statement table list to be PS/SP friendly. */
lex->query_tables= 0; lex->query_tables= 0;
lex->query_tables_last= &lex->query_tables; lex->query_tables_last= &lex->query_tables;
DBUG_RETURN(sp_add_to_query_tables(thd, lex, trig->m_db.str, *table= sp_add_to_query_tables(thd, lex, trig->m_db.str,
trigname.trigger_table.str, TL_IGNORE)); trigname.trigger_table.str, TL_IGNORE);
if (! *table)
DBUG_RETURN(1);
DBUG_RETURN(0);
} }
......
...@@ -7741,11 +7741,12 @@ drop: ...@@ -7741,11 +7741,12 @@ drop:
Lex->spname= $4; Lex->spname= $4;
Lex->sql_command = SQLCOM_DROP_EVENT; Lex->sql_command = SQLCOM_DROP_EVENT;
} }
| DROP TRIGGER_SYM sp_name | DROP TRIGGER_SYM if_exists sp_name
{ {
LEX *lex= Lex; LEX *lex= Lex;
lex->sql_command= SQLCOM_DROP_TRIGGER; lex->sql_command= SQLCOM_DROP_TRIGGER;
lex->spname= $3; lex->drop_if_exists= $3;
lex->spname= $4;
} }
| DROP TABLESPACE tablespace_name opt_ts_engine opt_ts_wait | DROP TABLESPACE tablespace_name opt_ts_engine opt_ts_wait
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment