Repository navigation
MDEV-30645: Generalized triggers - #3296
andremralves wants to merge 9 commits into
Conversation
cf904cb to
d3db901
Compare
|
Looks good, but please add a test for a syntax error, like CREATE OR REPLACE TRIGGER IF NOT EXISTS ev1 IN SCHEDULE EVERY 1 SECOND DO DROP DATABASE db1; |
d3db901 to
8abc2af
Compare
|
@vuvova I added some more tests like the one you suggested. |
a8b655a to
38180c9
Compare
38180c9 to
3e6df94
Compare
vuvova
left a comment
There was a problem hiding this comment.
Looks good, thanks.
It's a bit inconsistent that error messages still say "event", like in
CREATE TRIGGER ev1 ON SCHEDULE EVERY 1 SECOND DO INSERT INTO t1 VALUES (11);
ERROR HY000: Event 'ev1' already exists
but let's not spend time on it now. You can get back to it after the main GSoC project is done.
|
Note, this won't be pushed into 11.6 right now, it would just be seen as a strange and redundant alias of an existing feature. We'll push everything together, then it'll be a logical part of the "generalized triggers" |
That is something I was thinking about. After we use |
|
I think it'll be the same object, so no need to differentiate. But it should be done in steps. |
|
Thanks for the explanation. I thought that since they will be the same object (event), maybe the error message saying that is an event is good, but, on the other hand, it could confuse the user. |
6471ec5 to
a2374d8
Compare
a2374d8 to
70d1018
Compare
2b408a8 to
d4a387d
Compare
66a62e8 to
b7dcdb7
Compare
b7dcdb7 to
f2780cf
Compare
856df15 to
1dee305
Compare
1dee305 to
7f8bd63
Compare
7f8bd63 to
e82d4ef
Compare
| # restart | ||
| SELECT * FROM t1; | ||
| inc | ||
| 1 |
There was a problem hiding this comment.
add show triggers and show create trigger here, please.
| build_trn_path(thd, lex->spname, (LEX_STRING*) &trn_path); | ||
| if (check_trn_exists(&trn_path) && !opt_bootstrap) | ||
| lex->set_command(SQLCOM_DROP_EVENT, $3); | ||
| #endif |
There was a problem hiding this comment.
eh, no, this kind of decision cannot be done in the parser. it should be done later during execution. Consider, for example, a stored procedure:
create procedure drop_trigger_foo
begin
drop trigger foo;
endit's parsed once but can executed many times. you cannot decide during the parsing whether it'll be event or trigger, this might change between executions.
this should be fixed. and a test case added.
There was a problem hiding this comment.
What do you suggest? Maybe make this decision in mysql_create_or_drop_trigger()?
There was a problem hiding this comment.
The idea is to execute drop event if a trigger isn't found, right?
There was a problem hiding this comment.
What do you think about handling it in sql_parser.cc? First, DROP TRIGGER is executed, and then, if it returns an error, we try to execute DROP EVENT. Like this:
case SQLCOM_DROP_TRIGGER:
{
if (thd->variables.option_bits & OPTION_IF_EXISTS)
lex->create_info.set(DDL_options_st::OPT_IF_EXISTS);
/* Conditionally writes to binlog. */
res= mysql_create_or_drop_trigger(thd, all_tables, 0);
/*
If there is an error or error level warning
try to drop from mysql.event.
*/
if(!opt_bootstrap &&
(thd->get_stmt_da()->sql_errno() + thd->get_stmt_da()->error_count()))
{
/* Clear errors and warnings */
thd->clear_error();
thd->get_stmt_da()->clear_warning_info(thd->query_id);
if (!(res= Events::drop_event(thd,
&lex->spname->m_db, &lex->spname->m_name,
lex->if_exists())))
my_ok(thd);
}
break;
}If that’s not the appropriate place to handle that decision, please let me know where it should be.
There was a problem hiding this comment.
What do you suggest? Maybe make this decision in
mysql_create_or_drop_trigger()?
I think this is a good idea. add_table_for_trigger_internal starts from
if (check_trn_exists(&trn_path)) {
if (if_exists) {
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_TRG_DOES_NOT_EXIST,
ER_THD(thd, ER_TRG_DOES_NOT_EXIST));
*table= NULL;
DBUG_RETURN(FALSE);
}
my_error(ER_TRG_DOES_NOT_EXIST, MYF(0));
DBUG_RETURN(TRUE);
}you can, for example, move error reporting to the caller and mysql_create_or_drop_trigger can call drop_event.
Please, add tests for CREATE OR REPLACE, CREATE IF NOT EXISTS, and DROP IF EXISTS. Particularly, when a trigger of one type exists, but you create (with OR REPLACE or IF NOT EXISTS) a trigger of a different type
e353d5f to
64dcb76
Compare
64dcb76 to
1d73ccd
Compare
Description
TL;DR
This PR implements some Generalized Triggers. It contains:
CREATE TRIGGERas a synonym forCREATE EVENT.CREATE TRIGGER .. AFTER STARTUP DO ..CREATE TRIGGER .. BEFORE SHUTDOWN DO ..Making
CREATE TRIGGERa synonym forCREATE EVENTImplementation:
I changed the rule
trigger_tailto be either atrigger_tailor aevent_tail.I had to change some tests since the syntax now accepts the prefix
create trigger [trigger_name] on.Implementing
CREATE TRIGGER .. AFTER STARTUPandCREATE TRIGGER .. BEFORE SHUTDOWN.To run those triggers, I took advantage of the event scheduler infrastructure, and for storing them, I used the mysql.event table.
Startup trigger example:
Will run right after the server startup starts.
Shutdown trigger example:
Will run right before the server shutdown starts.
Last GSoC commit: Fixup: some rpl and embedded test errors and other minor issues
Release Notes
TODO: What should the release notes say about this change?
Include any changed system variables, status variables or behaviour. Optionally list any https://mariadb.com/kb/ pages that need changing.
How can this PR be tested?
You can use the automated test:
or manually try to create an event using
CREATE TRIGGERand then check if there is any corner case.Basing the PR against the correct MariaDB version
PR quality check