Bug #30660 Stored routines do not work following downgrade from 5.1 to 5.0
Submitted: 28 Aug 2007 1:52 Modified: 6 Sep 2007 13:16
Reporter: Omer Barnir (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S1 (Critical)
Version:5.1.21+, 5.0.46- OS:Any
Assigned to: Jon Stephens CPU Architecture:Any
Tags: 5.0, 5.1, downgrade, mysql.proc, stored routines

[28 Aug 2007 1:52] Omer Barnir
Description:
Following a downgrade from 5.1 to 5.0 (regardless if the system was created in 5.1 or was originaly upgraded from 5.0), all stored procedures and function fail to operate in the downgraded system. This applies to SP/functions that were created in 5.1 or were created in 5.0 prioir to upgrade. This also causes any object that referances SP/functions -- such as a view that includes a function call (e.g. CREATE VIEW V1 AS SELECT f(...) ... ) to fail being loaded when the mysqldump dump file is imported to the 5.0 system.

The problem is a result of the fact that the upgrade to 5.1 adds four columns to the mysql.proc table. 
 - character_set_client
 - collation_connection
 - db_collation
 - body_utf8

Once the system is downgraded, these four extra columns cause the 5.0 server to view the mysql.proc table as corrupted. 

As a result, SP/functions cannot be 
 - created
 - executed
 - used in other objects
 - displayed 
 - droped 
 - etc.

If the four columns are manualy removed after downgrade (using ALTER TABLE mysql.proc COLUMN <col_name>), the SP/functions will function as expected. However this cannot be considered a workaround since some of the 'damage' has already happened during the import stage (as described above.

How to repeat:
1) Create a 5.0 system
2) Using the client create a function, for example
   USE TEST;
   CREATE FUNCTION f50() RETURNS INT RETURN 42;
3) Verify the function works
4) Upgrade the system to 5.1 
5) run the mysql_upgrade utility
6) Using the 5.1 client 
   a. check that the function stil works
      USE TEST;
      SELECT f50();
   b. create similar function
      CREATE FUNCTION f51() RETURNS INT RETURN 7;
      and verify that it works
   c. create a view referancing one of the functions:
      CREATE VIEW v51 AS SELECT f51();
      and verify that it works
7) Export the database using the 5.1 version of mysqldump (include 
   the --all-databases oprion)
8) Downgrade the system and import the dump file created in #7.
>> The import will fail to load the view with: 
   ERROR 1457 (HY000) at line xxx: Failed to load routine test.f51. The table
   mysql.proc is missing, corrupt, or contains bad data (internal code -5)
9) Log into the 5.0 client
>> Trying to execute either function (e.g SELECT test.f50() ) will result in
   the same error as above.
>> Trying to create a new function will return
   ERROR 1307 (HY000): Failed to CREATE FUNCTION
>> Performing a SHOW CREATE FUNCTION test.f50 will return:
   FUNCTION f50 does not exis
>> SELECT * from mysql.proc wil show the two function definitions
10) Altering the proc table and dropping the 5.1 added columns will cause the checkes mentioned in #9 to work properly.
  
 

      
   Downgrade the system to the original 

Suggested fix:
Either add a mechanizm that prevents the extra column definition and data from being loaded from the dump file if the server version in less than 5.1 (51000) or change the 5.0 server to ignore extra columns if exist in the mysql.proc table.
[2 Sep 2007 6:50] Konstantin Osipov
Omer, this has  been already fixed in the latest 5.0
Could you please confirm you have been using the latest bk version?
If not, could you please re-verify?
[4 Sep 2007 20:15] Omer Barnir
The bug was observed with 5.0.46 and is not observed with 5.0.48
[6 Sep 2007 13:16] Jon Stephens
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.

Updated synopsis, tags, set Category to Docs and assigned to myself.

Now documented in downgrading-to-5-0 section of 5.1 Manual.