commit d792fd2664cdbf87237253f96c96d94e833e822c from: Vladimir Davydov date: Fri Oct 26 20:19:45 2018 UTC alter: install space commit/rollback triggers before preparing sql view sql_compile_view() may fail, in which case the space will never be deleted from (in case of space creation) or inserted back into (in case of space drop) the space cache, because commit/rollback triggers, which are supposed to do the job, are only installed after preparing a view. Fix this by installing triggers before sql_compile_view(). No need to write a test as without this commit sql/view test will crash after applying the next commit (the one that introduces space name cache). Fixes commit dc358cb01428 ("sql: rework VIEW internals"). commit - 9975ed0655aed0f1f48a632a2264e4d737b8cb94 commit + d792fd2664cdbf87237253f96c96d94e833e822c blob - 986d4daf7f85fe96bcf59c1b5f4b117d516496aa blob + a6bb5a0f02c57a4a961d8d62d8d6211a794cf607 --- src/box/alter.cc +++ src/box/alter.cc @@ -1702,6 +1702,12 @@ on_replace_dd_space(struct trigger * /* trigger */, vo * so it's safe to simply drop the space on * rollback. */ + struct trigger *on_commit = + txn_alter_trigger_new(on_create_space_commit, space); + txn_on_commit(txn, on_commit); + struct trigger *on_rollback = + txn_alter_trigger_new(on_create_space_rollback, space); + txn_on_rollback(txn, on_rollback); if (def->opts.is_view) { struct Select *select = sql_view_compile(sql_get(), def->opts.sql); @@ -1732,12 +1738,6 @@ on_replace_dd_space(struct trigger * /* trigger */, vo txn_on_rollback(txn, on_rollback_view); select_guard.is_active = false; } - struct trigger *on_commit = - txn_alter_trigger_new(on_create_space_commit, space); - txn_on_commit(txn, on_commit); - struct trigger *on_rollback = - txn_alter_trigger_new(on_create_space_rollback, space); - txn_on_rollback(txn, on_rollback); } else if (new_tuple == NULL) { /* DELETE */ access_check_ddl(old_space->def->name, old_space->def->id, old_space->def->uid, SC_SPACE, PRIV_D, true); @@ -1788,6 +1788,9 @@ on_replace_dd_space(struct trigger * /* trigger */, vo struct trigger *on_commit = txn_alter_trigger_new(on_drop_space_commit, old_space); txn_on_commit(txn, on_commit); + struct trigger *on_rollback = + txn_alter_trigger_new(on_drop_space_rollback, old_space); + txn_on_rollback(txn, on_rollback); if (old_space->def->opts.is_view) { struct Select *select = sql_view_compile(sql_get(), @@ -1807,10 +1810,6 @@ on_replace_dd_space(struct trigger * /* trigger */, vo txn_on_rollback(txn, on_rollback_view); select_guard.is_active = false; } - struct trigger *on_rollback = - txn_alter_trigger_new(on_drop_space_rollback, - old_space); - txn_on_rollback(txn, on_rollback); } else { /* UPDATE, REPLACE */ assert(old_space != NULL && new_tuple != NULL); struct space_def *def =