Bug #34252 MySql server crashes on show create trigger statement after dropping the table
Submitted: 2 Feb 2008 19:36 Modified: 12 Feb 2008 17:33
Reporter: Rakesh Kumar Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S2 (Serious)
Version:5.1.22-rc-community OS:Any (I tested on windows XP and Ubuntu gutsy 7.10)
Assigned to: CPU Architecture:Any
Tags: drop table, triggers

[2 Feb 2008 19:36] Rakesh Kumar
Description:
When a table, for which some triggers are defined, is dropped, then executing the statement "show create trigger `trigger name`" crashes the server.

This happens every time, even after the server has got restarted.

Here is a dump of my error log from Ubuntu 7.10:

080203  0:13:00 - mysqld got signal 11;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=16777216
read_buffer_size=258048
max_used_connections=1
max_threads=151
threads_connected=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 132594 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x9c83c40
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
Cannot determine thread, fp=0x21ead9d8, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
0x822ba2c
0x8339af8
0x823b730
0x8243fe9
0x824454c
0x82459b7
0x823481f
0xb7fa246b
0xb7da26de
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/refman/5.1/en/resolve-stack-dump.html
and follow instructions on how to resolve the stack trace.
Resolved stack trace is much more helpful in diagnosing the
problem, so please do resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x9cd2270 = show create trigger mytrigger
thd->thread_id=2
The manual page at http://www.mysql.com/doc/en/Crashing.html contains
information that should help you find out what is causing the crash.
080203 00:13:00 mysqld_safe Number of processes running now: 0
080203 00:13:00 mysqld_safe mysqld restarted
InnoDB: Log scan progressed past the checkpoint lsn 0 1635207184
080203  0:13:01  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 1635209622
080203  0:13:01  InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 
InnoDB: Apply batch completed
InnoDB: Last MySQL binlog file position 0 307, file name ./mysql-bin.000076
080203  0:13:03  InnoDB: Started; log sequence number 0 1635209622
080203  0:13:03 [Note] Recovering after a crash using mysql-bin
080203  0:13:03 [Note] Starting crash recovery...
080203  0:13:03 [Note] Crash recovery finished.
080203  0:13:03 [Note] Event Scheduler: Loaded 0 events
080203  0:13:03 [Note] /usr/local/mysql/libexec/mysqld: ready for connections.
Version: '5.1.22-rc-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  Source distribution

How to repeat:
1) create any trigger on a table.
2) drop the table
3) run show create trigger `triggername`

This crashes the server.
[2 Feb 2008 21:46] MySQL Verification Team
Thank you for the bug report. Could you please provide the complete script
test case just with the description isn't possible to repeat the behavior
reported. Thanks in advance.
[3 Feb 2008 14:43] MySQL Verification Team
This crashed my 5.1.22 but *not* 5.1.24BK build:

delimiter ;
drop table if exists `t1`;
create table `t1`(`a` int)engine=myisam;
drop trigger `trig`;
delimiter //
create trigger `trig` before insert on `t1` for each row begin end//
delimiter ;
show create trigger `trig`;
drop table if exists `t1`;
show create trigger `trig`;
[4 Feb 2008 8:00] Rakesh Kumar
Here is a sequence of commands to reproduce the error. I have used City table as example (created using database dump world.sql available from http://dev.mysql.com/doc/ "example database" section):

mysql> use world;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_world |
+-----------------+
| City            | 
| Country         | 
| CountryLanguage | 
+-----------------+
3 rows in set (0.00 sec)

mysql> show create table City;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                              |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| City  | CREATE TABLE `City` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` char(35) NOT NULL DEFAULT '',
  `CountryCode` char(3) NOT NULL DEFAULT '',
  `District` char(20) NOT NULL DEFAULT '',
  `Population` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1 | 
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> create table city_deleted like City;
Query OK, 0 rows affected (0.00 sec)

mysql> create trigger city_backup after delete on City for each row insert into city_deleted values(old.id, old.name,old.countrycode,old.district,old.population);
Query OK, 0 rows affected (0.00 sec)

mysql> show create trigger city_backup\G
*************************** 1. row ***************************
               Trigger: city_backup
              sql_mode: 
SQL Original Statement: CREATE DEFINER=`root`@`localhost` trigger city_backup after delete on City for each row insert into city_deleted values(old.id, old.name,old.countrycode,old.district,old.population)
  character_set_client: latin1
  collation_connection: latin1_swedish_ci
    Database Collation: latin1_swedish_ci
1 row in set (0.00 sec)

mysql> select * from city_deleted;
Empty set (0.00 sec)

mysql> delete from City where name='delhi';
Query OK, 1 row affected (0.01 sec)

mysql> select * from city_deleted;
+------+-------+-------------+----------+------------+
| ID   | Name  | CountryCode | District | Population |
+------+-------+-------------+----------+------------+
| 1025 | Delhi | IND         | Delhi    |    7206704 | 
+------+-------+-------------+----------+------------+
1 row in set (0.00 sec)

mysql> drop table City;
Query OK, 0 rows affected (0.00 sec)

mysql> show create trigger city_backup;
ERROR 2013 (HY000): Lost connection to MySQL server during query

mysql> show tables;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1
Current database: world

+-----------------+
| Tables_in_world |
+-----------------+
| Country         | 
| CountryLanguage | 
| city_deleted    | 
+-----------------+
3 rows in set (27.18 sec)
[4 Feb 2008 10:18] Valeriy Kravchuk
Verified using Shane's simple test case.
[4 Feb 2008 11:27] Valeriy Kravchuk
And yes, in latest 5.1.24-BK I do not have a crash, just proper error message. Looks like trigger is gropped with table now.
[12 Feb 2008 17:33] Valeriy Kravchuk
Actually, not repetable with 5.1.24-BK. Just needs a test case to prevent future regressions.