Bug #33563 Backup: crash if restore in procedure
Submitted: 28 Dec 2007 23:49 Modified: 14 Mar 2008 1:43
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:6.0.5-alpha-debug OS:Linux (SUSE 10 64-bit)
Assigned to: Rafal Somla CPU Architecture:Any
Triage: D1 (Critical) / R3 (Medium) / E3 (Medium)

[28 Dec 2007 23:49] Peter Gulutzan
Description:
I create a procedure containing a RESTORE statement.
I call the procedure.
Crash.

Built from mysql-6.0-backup source with BUILD/compile-pentium-debug-max.
Last changeset = "ChangeSet@1.2753, 2007-12-20 15:32:22-05:00".

How to repeat:
mysql> create database x;
Query OK, 1 row affected (0.01 sec)

mysql> use x
Database changed

mysql> backup database x to '/usr/local/mysql/var/x3';
+-----------+
| backup_id |
+-----------+
| 7         |
+-----------+
1 row in set (1.68 sec)

mysql> restore from '/usr/local/mysql/var/x3';
+-----------+
| backup_id |
+-----------+
| 8         |
+-----------+
1 row in set (1.42 sec)

mysql> use x
Database changed
mysql> create procedure p () restore from '/usr/local/mysql/var/x3';
Query OK, 0 rows affected (0.01 sec)

mysql> call p();
ERROR 2013 (HY000): Lost connection to MySQL server during query
[29 Dec 2007 5:14] Miguel Solorzano
Thank you for the bug report. Verified as described:

mysql> create procedure p () restore from '/home/miguel/dbs/6.0b/x3';
Query OK, 0 rows affected (0.00 sec)

mysql> call p();
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql>
[23 Jan 2008 18:39] Rafal Somla
REFINED PROBLEM DESCRIPTION

Internally, RESTORE statement re-creates objects by executing CRATE ... statements, passing them to mysql_parse() function. This function is not intended to be called from inside stored routine. At the beginning it calls mysql_reset_thd_for_next_command(thd) which contains assertion  

DBUG_ASSERT(!thd->spcont)

This assertion fails and causes server to crash if mysql_parse() is executed from inside stored procedure.
[23 Jan 2008 18:43] Rafal Somla
Backup kernel is now being refactored to use object services (WL#3574 and WL#4205). When this happens, explicit execution of CREATE statements will be replaced by a call to service function which creates an object. This problem should be handled in the implementation of that function.
[24 Jan 2008 13:52] Rafal Somla
PROPOSED SOLUTION

It was decided (ask Lars) that in the first version BACKUP/RESTORE commands
will be disabled inside stored routines, triggers and events. We will work on enabling this functionality in later versions.

The bug will be fixed by disabling BACKUP/RESTORE statements inside stored routines. This should behave identical as for other statements which are not allowed there, that is error will be reported when stored procedure is created.
[24 Jan 2008 14:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/41212

ChangeSet@1.2784, 2008-01-24 15:25:32+01:00, rafal@quant.(none) +3 -0
  Bug #33563  (Backup: crash if restore in procedure)
  
  This patch disables BACKUP/RESTORE statements inside stored routines thus avoiding 
  the crash.
[28 Jan 2008 14:02] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/41307

ChangeSet@1.2784, 2008-01-28 15:01:12+01:00, rafal@quant.(none) +3 -0
  Bug #33563  (Backup: crash if restore in procedure)
  
  This patch disables BACKUP/RESTORE statements inside stored routines thus avoiding 
  the crash.
[28 Jan 2008 14:41] Chuck Bell
Patch approved.
[30 Jan 2008 20:33] Rafal Somla
Pushed into 6.0-backup tree.
[25 Feb 2008 20:19] Bugs System
Pushed into 6.0.5-alpha
[14 Mar 2008 1:43] Paul Dubois
No changelog entry needed; this bug did not appear in any released version.

Noted the restriction against BACKUP DATABASE or RESTORE appearing in stored programs in the restrictions appendix.