测试时发现一个有趣的问题,更新表A,确报表B不存在。这是为什么呢?
【实验】
会不会是触发器捣的鬼呢?检查发现mgc表上果然有三个触发器。
检查了这三个触发器的内容,发现并不是开发创建的。删除这三个触发器后,update能正常进行。
那么mgc表上的三个触发器是怎么来的呢?
【实验】
MariaDB [test]> update test.mgc set c1='xxx1' where id=4;
ERROR 1146 (42S02): Table 'test._mgc_new' doesn't exist
检查发现_mgc_new表确实不存在。
MariaDB [test]> show tables like '%mgc%';
+------------------------+
| Tables_in_test (%mgc%) |
+------------------------+
| mgc |
+------------------------+
1 row in set (0.00 sec)
会不会是触发器捣的鬼呢?检查发现mgc表上果然有三个触发器。
MariaDB [test]> select concat(TRIGGER_SCHEMA,'.',TRIGGER_NAME) from information_schema.TRIGGERS where EVENT_OBJECT_TABLE like '%mgc%';
+-----------------------------------------+
| concat(TRIGGER_SCHEMA,'.',TRIGGER_NAME) |
+-----------------------------------------+
| test.pt_osc_test_mgc_ins |
| test.pt_osc_test_mgc_upd |
| test.pt_osc_test_mgc_del |
+-----------------------------------------+
3 rows in set (0.00 sec)
检查了这三个触发器的内容,发现并不是开发创建的。删除这三个触发器后,update能正常进行。
MMariaDB [test]> select concat('DROP TRIGGER ',TRIGGER_SCHEMA,'.',TRIGGER_NAME,' ;') from information_schema.TRIGGERS where EVENT_OBJECT_TABLE like '%mgc%';
+---------------------------------------------------------------+
| concat('DROP TRIGGER ',TRIGGER_SCHEMA,'.',TRIGGER_NAME,' ;') |
+---------------------------------------------------------------+
| DROP TRIGGER test.pt_osc_test_mgc_ins ; |
| DROP TRIGGER test.pt_osc_test_mgc_upd ; |
| DROP TRIGGER test.pt_osc_test_mgc_del ; |
+---------------------------------------------------------------+
MariaDB [test]> DROP TRIGGER test.pt_osc_test_mgc_ins ;
MariaDB [test]> DROP TRIGGER test.pt_osc_test_mgc_upd ;
MariaDB [test]> DROP TRIGGER test.pt_osc_test_mgc_del ;
MariaDB [test]> update test.mgc set c1='xxx1' where id=4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
至此不能update的问题已经解决。
那么mgc表上的三个触发器是怎么来的呢?
从触发器的名字的前缀来看,发现三个触发器都是以pt_osc_开始的,使用过pt-online-schema-change的都知道,这是pt-online-schema-change在做DDL时要创建的insert,update,delete触发器。正常情况下这三个触发器在pt-online-schema-change完成了DDL操作时,会删除这三个触发器的。如果pt-online-schema-change异常退出,这三个触发器没有被正常删除,就会出现上述情况。