mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
1fea8c1b90
SYNTAX TRIGGERS IN ANY WAY Table with triggers which were using deprecated (5.0-only) syntax became unavailable for any DML and DDL after upgrade to 5.1 version of server. Attempt to execute any statement on such a table resulted in parsing error reported. Since this included DROP TRIGGER and DROP TABLE statements (actually, the latter was allowed but was not functioning properly for such tables) it was impossible to fix the problem without manual operations on .TRG and .TRN files in data directory. The problem was that failure to parse trigger body (due to 5.0-only syntax) when opening trigger file for a table prevented the table from being open. This made all operations on the table impossible (except DROP TABLE which due to peculiarity in its implementation dropped the table but left trigger files around). This patch solves this problem by silencing error which occurs when we parse trigger body during table open. Error message is preserved for the future use and table is marked as having a broken trigger. We also try to analyze parse tree to recover trigger name, which will be needed in order to drop the broken trigger. DML statements which invoke triggers on the table marked as having broken trigger are prohibited and emit saved error message. The same happens for DDL which change triggers except DROP TRIGGER and DROP TABLE which try their best to do what was requested. Table becomes no longer marked as having broken trigger when last such trigger is dropped. mysql-test/r/trigger-compat.result: Add results for test case for bug#45235 mysql-test/t/trigger-compat.test: Add test case for bug#45235. sql/sp_head.cc: Added protection against MEM_ROOT double restoring to sp_head::restore_thd_mem_root() method. Since this method can be sometimes called twice during parsing of stored routine (the first time during normal flow of parsing, and the second time when a syntax error is detected) we need to shortcut execution of the method to avoid damaging MEM_ROOT by the second consecutive call to this method. sql/sql_trigger.cc: Added error handler Deprecated_trigger_syntax_handler to catch non-OOM errors during parsing of trigger body. Added handling of parse errors into method Table_triggers_list::check_n_load(). sql/sql_trigger.h: Added new members to handle broken triggers and error messages.
143 lines
8.2 KiB
Text
143 lines
8.2 KiB
Text
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;
|
|
DROP DATABASE IF EXISTS mysqltest_db1;
|
|
CREATE DATABASE mysqltest_db1;
|
|
CREATE USER mysqltest_dfn@localhost;
|
|
CREATE USER mysqltest_inv@localhost;
|
|
GRANT CREATE, TRIGGER ON mysqltest_db1.* TO mysqltest_dfn@localhost;
|
|
|
|
---> connection: wl2818_definer_con
|
|
CREATE TABLE t1(num_value INT);
|
|
CREATE TABLE t2(user_str TEXT);
|
|
CREATE TRIGGER wl2818_trg1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES(CURRENT_USER());
|
|
|
|
---> patching t1.TRG...
|
|
|
|
CREATE TRIGGER wl2818_trg2 AFTER INSERT ON t1
|
|
FOR EACH ROW
|
|
INSERT INTO t2 VALUES(CURRENT_USER());
|
|
Warnings:
|
|
Warning 1454 No definer attribute for trigger 'mysqltest_db1'.'wl2818_trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
|
|
|
|
SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
|
|
trigger_name definer
|
|
wl2818_trg1
|
|
wl2818_trg2 mysqltest_dfn@localhost
|
|
Warnings:
|
|
Warning 1454 No definer attribute for trigger 'mysqltest_db1'.'wl2818_trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
|
|
|
|
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
|
|
TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION
|
|
NULL mysqltest_db1 wl2818_trg1 INSERT NULL mysqltest_db1 t1 0 NULL INSERT INTO t2 VALUES(CURRENT_USER()) ROW BEFORE NULL NULL OLD NEW NULL latin1 latin1_swedish_ci latin1_swedish_ci
|
|
NULL mysqltest_db1 wl2818_trg2 INSERT NULL mysqltest_db1 t1 0 NULL INSERT INTO t2 VALUES(CURRENT_USER()) ROW AFTER NULL NULL OLD NEW NULL mysqltest_dfn@localhost latin1 latin1_swedish_ci latin1_swedish_ci
|
|
DROP TRIGGER wl2818_trg1;
|
|
Warnings:
|
|
Warning 1454 No definer attribute for trigger 'mysqltest_db1'.'wl2818_trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
|
|
DROP TRIGGER wl2818_trg2;
|
|
use mysqltest_db1;
|
|
DROP TABLE t1;
|
|
DROP TABLE t2;
|
|
DROP USER mysqltest_dfn@localhost;
|
|
DROP USER mysqltest_inv@localhost;
|
|
DROP DATABASE mysqltest_db1;
|
|
USE test;
|
|
#
|
|
# Bug#45235: 5.1 does not support 5.0-only syntax triggers in any way
|
|
#
|
|
DROP TABLE IF EXISTS t1, t2, t3;
|
|
CREATE TABLE t1 ( a INT );
|
|
CREATE TABLE t2 ( a INT );
|
|
CREATE TABLE t3 ( a INT );
|
|
INSERT INTO t1 VALUES (1), (2), (3);
|
|
INSERT INTO t2 VALUES (1), (2), (3);
|
|
INSERT INTO t3 VALUES (1), (2), (3);
|
|
# We simulate importing a trigger from 5.0 by writing a .TRN file for
|
|
# each trigger plus a .TRG file the way MySQL 5.0 would have done it,
|
|
# with syntax allowed in 5.0 only.
|
|
#
|
|
# Note that in 5.0 the following lines are missing from t1.TRG:
|
|
#
|
|
# client_cs_names='latin1'
|
|
# connection_cl_names='latin1_swedish_ci'
|
|
# db_cl_names='latin1_swedish_ci'
|
|
# We will get parse errors for most DDL and DML statements when the table
|
|
# has broken triggers. The parse error refers to the first broken
|
|
# trigger.
|
|
CREATE TRIGGER tr16 AFTER UPDATE ON t1 FOR EACH ROW INSERT INTO t1 VALUES (1);
|
|
ERROR 42000: Trigger 'tr13' has an error in its body: '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 'a USING t1 a' at line 1'
|
|
CREATE TRIGGER tr22 BEFORE INSERT ON t2 FOR EACH ROW DELETE FROM non_existing_table;
|
|
ERROR 42000: Unknown trigger has an error in its body: '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 'Not allowed syntax here, and trigger name cant be extracted either.' at line 1'
|
|
SHOW TRIGGERS;
|
|
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
|
|
tr11 INSERT t1 DELETE FROM t3 BEFORE NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
|
|
tr12 INSERT t1 DELETE FROM t3 AFTER NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
|
|
tr14 DELETE t1 DELETE FROM non_existing_table AFTER NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
|
|
Warnings:
|
|
Warning 1603 Triggers for table `test`.`t1` have no creation context
|
|
Warning 1603 Triggers for table `test`.`t2` have no creation context
|
|
INSERT INTO t1 VALUES (1);
|
|
ERROR 42000: Trigger 'tr13' has an error in its body: '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 'a USING t1 a' at line 1'
|
|
INSERT INTO t2 VALUES (1);
|
|
ERROR 42000: Unknown trigger has an error in its body: '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 'Not allowed syntax here, and trigger name cant be extracted either.' at line 1'
|
|
DELETE FROM t1;
|
|
ERROR 42000: Trigger 'tr13' has an error in its body: '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 'a USING t1 a' at line 1'
|
|
UPDATE t1 SET a = 1 WHERE a = 1;
|
|
ERROR 42000: Trigger 'tr13' has an error in its body: '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 'a USING t1 a' at line 1'
|
|
SELECT * FROM t1;
|
|
a
|
|
1
|
|
2
|
|
3
|
|
RENAME TABLE t1 TO t1_2;
|
|
ERROR 42000: Trigger 'tr13' has an error in its body: '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 'a USING t1 a' at line 1'
|
|
SHOW TRIGGERS;
|
|
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
|
|
tr11 INSERT t1 DELETE FROM t3 BEFORE NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
|
|
tr12 INSERT t1 DELETE FROM t3 AFTER NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
|
|
tr14 DELETE t1 DELETE FROM non_existing_table AFTER NULL root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
|
|
Warnings:
|
|
Warning 1603 Triggers for table `test`.`t1` have no creation context
|
|
DROP TRIGGER tr11;
|
|
Warnings:
|
|
Warning 1603 Triggers for table `test`.`t1` have no creation context
|
|
DROP TRIGGER tr12;
|
|
DROP TRIGGER tr13;
|
|
DROP TRIGGER tr14;
|
|
DROP TRIGGER tr15;
|
|
SHOW TRIGGERS;
|
|
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
|
|
# Make sure there is no trigger file left.
|
|
# We write the same trigger files one more time to test DROP TABLE.
|
|
DROP TABLE t1;
|
|
Warnings:
|
|
Warning 1603 Triggers for table `test`.`t1` have no creation context
|
|
DROP TABLE t2;
|
|
Warnings:
|
|
Warning 1603 Triggers for table `test`.`t2` have no creation context
|
|
DROP TABLE t3;
|
|
# Make sure there is no trigger file left.
|
|
CREATE TABLE t1 ( a INT );
|
|
CREATE TABLE t2 ( a INT );
|
|
INSERT INTO t1 VALUES (1), (2), (3);
|
|
INSERT INTO t2 VALUES (1), (2), (3);
|
|
# We write three trigger files. First trigger is syntaxically incorrect, next trigger is correct
|
|
# and last trigger is broken.
|
|
# Next we try to execute SHOW CREATE TRGGIR command for broken trigger and then try to drop one.
|
|
FLUSH TABLE t1;
|
|
SHOW CREATE TRIGGER tr12;
|
|
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation
|
|
tr12 CREATE DEFINER=`root`@`localhost` TRIGGER tr12 BEFORE INSERT ON t1 FOR EACH ROW DELETE FROM t2 latin1 latin1_swedish_ci latin1_swedish_ci
|
|
Warnings:
|
|
Warning 1603 Triggers for table `test`.`t1` have no creation context
|
|
SHOW CREATE TRIGGER tr11;
|
|
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation
|
|
tr11 CREATE DEFINER=`root`@`localhost` TRIGGER tr11 BEFORE DELETE ON t1 FOR EACH ROW DELETE FROM t1 a USING t1 a latin1 latin1_swedish_ci latin1_swedish_ci
|
|
DROP TRIGGER tr12;
|
|
Warnings:
|
|
Warning 1603 Triggers for table `test`.`t1` have no creation context
|
|
DROP TRIGGER tr11;
|
|
DROP TABLE t1;
|
|
DROP TABLE t2;
|