Bug #72318 | Stored function throws error 1137 if temporary table was not created right then | ||
---|---|---|---|
Submitted: | 11 Apr 2014 17:36 | Modified: | 14 Apr 2014 17:54 |
Reporter: | Dillon Sadofsky | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S3 (Non-critical) |
Version: | 5.6.14-log | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | error 1137, stored procedure, temporary table |
[11 Apr 2014 17:36]
Dillon Sadofsky
[11 Apr 2014 19:13]
Dillon Sadofsky
Just an additional interesting detail. If I add DROP TEMPORARY TABLE IF EXISTS to the start of the function (so that it will be dropped and recreated within the function). It does NOT help. The behavior seems to be that the table gets successfully dropped, recreated, repopulated, then the SELECT fails. If the SELECT is commented out, execution progresses correctly, without error. This is somewhat critical for my users because, if I have an error when populating the temp table, I enter a state where the function will continue to fail until the user establishes a new connection.
[11 Apr 2014 20:16]
Dillon Sadofsky
Also, maybe I should submit another bug for this, but I thought I could work around the issue with: DECLARE CONTINUE HANDLER FOR 1137 BEGIN [my code] END; DECLARE CONTINUE HANDLER FOR SQLSTATE 'HY000' BEGIN [my code] END; However, [my code] never seems to execute. Is this a known issue in functions? I'm able to successfully trap error 1051, but for some reason 1137 seems to be untrappable. This really makes this bug terrible for my situation, as I cannot create a self-contained function that is guaranteed to perform the task I need. Please advise. I would prefer not to move to a permanent table, as that would require serious retooling and introduce inter-connection locking since I have multi-user concurrency to worry about.
[14 Apr 2014 17:03]
MySQL Verification Team
Regarding the behavior of the temporary tables within the stored routines, this is expected behavior, but totally undocumented. Hence, I verify this bug as a documentation bug that needs to be addressed. Regarding the error 1137 not being caught by a CONTINUE HANDLER, this is a server bug. Would you be so kind to create a new bug for that this problem so that it could be handled as a bug in stored routines within the server. After you do it, please be kind to report its number in this entry. Thanks in advance.
[14 Apr 2014 17:54]
Dillon Sadofsky
As per your request, bug # 72347 has been created. However, before we close this, I just wanted to make sure we're on the same page. What we have here is inconsistent behavior. TEMPORARY TABLEs *can* be used inside of functions and subfunctions (they can even be created in one and modified in another), but a different set of rules apply if the TABLE was created outside the function execution? Something that seems strange about this is in my own testing (not necessarily in the sample functions I gave), calling the topmost function with a pre-existing temp table would work, so long as I commented out the SELECT statement in the topmost function (the subfunctions still ran DELETE/INSERT on the temp table without error). I did not create test cases for this because I assumed the issue I reported would be considered inconsistent and counter-intuitive behavior (and therefore something worth changing). I hope that something can be done about this or at least bug 72347 because it is now difficult for me to move forward. I didn't really want to use a TEMPORARY TABLE for this purpose, but since I cannot use prepared statements to execute dynamic SQL inside a stored function, it was the only way I could build up a complex result set. A non-temporary table would require session variables, truncating nightly EVENTs, synchronization locks, slower indices, and is generally going to hurt my use case of executing this function many thousands of times in a row, performance wise. Any suggestions for workarounds are appreciated.
[15 Apr 2014 12:56]
MySQL Verification Team
Changing the category , after deeper analysis of the problem.