Very strange situation to create and use temporary tables in procedures.
In some procedures, it runs normally at first, but when it is re-executed in the same session the error happens. we found that this happens whenever we have a CREATE TABLE SELECT and SELECT is used any function. If you do not function being used, the error does not happen.
example:
DELIMITER $$
|
|
DROP PROCEDURE IF EXISTS `sp_fail_temp_table`$$
|
|
CREATE DEFINER=`xpto`@`%` PROCEDURE `sp_fail_temp_table`()
|
BEGIN
|
/**
|
* Creating temporary table
|
*/
|
DROP TEMPORARY TABLE IF EXISTS tbl_temporary;
|
|
CREATE TEMPORARY TABLE IF NOT EXISTS tbl_temporary
|
(
|
`a` VARCHAR(64)
|
)
|
;
|
|
/**
|
* Creating second temporary table
|
* the call to a function makes it fail on the second time
|
* this stored procedure is called
|
*/
|
DROP TEMPORARY TABLE IF EXISTS tbl_second_temp;
|
|
CREATE TEMPORARY TABLE tbl_second_temp
|
SELECT
|
fn_return_zero() AS temp_amount
|
FROM
|
(
|
SELECT
|
a
|
FROM
|
tbl_temporary tt
|
) tt
|
ORDER BY
|
a
|
;
|
|
END$$
|
|
DELIMITER ;
|
|
|
DELIMITER $$
|
DROP FUNCTION IF EXISTS fn_return_zero$$
|
CREATE DEFINER=`xpto`@`%` FUNCTION fn_return_zero() RETURNS FLOAT(10,2)
|
READS SQL DATA
|
BEGIN
|
RETURN 0;
|
END $$
|
|
DELIMITER ;
|
|
CALL sp_fail_temp_table();
|
Run the procedure twice.
- duplicates
-
MDEV-9084
Calling a stored function from a nested select from temporary table causes unpredictable behavior
-
-
Closed
- links to
-
{"report":{"fcp":857.3000001907349,"ttfb":235,"pageVisibility":"visible","entityId":58469,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"f2e37bd0-2b66-43f9-a8b6-c801e1f04da0","navigationType":0,"readyForUser":944,"redirectCount":0,"resourceLoadedEnd":600.7000000476837,"resourceLoadedStart":247.20000004768372,"resourceTiming":[{"duration":12.200000047683716,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":247.20000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":247.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":259.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":12.100000143051147,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":247.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":247.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":259.60000014305115,"responseStart":0,"secureConnectionStart":0},{"duration":206.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":247.70000004768372,"connectEnd":247.70000004768372,"connectStart":247.70000004768372,"domainLookupEnd":247.70000004768372,"domainLookupStart":247.70000004768372,"fetchStart":247.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":267,"responseEnd":454,"responseStart":283.90000009536743,"secureConnectionStart":247.70000004768372},{"duration":352.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":248.5,"connectEnd":248.5,"connectStart":248.5,"domainLookupEnd":248.5,"domainLookupStart":248.5,"fetchStart":248.5,"redirectEnd":0,"redirectStart":0,"requestStart":273.7000000476837,"responseEnd":600.7000000476837,"responseStart":291.5,"secureConnectionStart":248.5},{"duration":47,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":248.60000014305115,"connectEnd":248.60000014305115,"connectStart":248.60000014305115,"domainLookupEnd":248.60000014305115,"domainLookupStart":248.60000014305115,"fetchStart":248.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":274.7000000476837,"responseEnd":295.60000014305115,"responseStart":292.90000009536743,"secureConnectionStart":248.60000014305115},{"duration":48.89999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":248.60000014305115,"connectEnd":248.60000014305115,"connectStart":248.60000014305115,"domainLookupEnd":248.60000014305115,"domainLookupStart":248.60000014305115,"fetchStart":248.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":275,"responseEnd":297.5,"responseStart":296.10000014305115,"secureConnectionStart":248.60000014305115},{"duration":51.799999952316284,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":248.70000004768372,"connectEnd":248.70000004768372,"connectStart":248.70000004768372,"domainLookupEnd":248.70000004768372,"domainLookupStart":248.70000004768372,"fetchStart":248.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":275.90000009536743,"responseEnd":300.5,"responseStart":297.90000009536743,"secureConnectionStart":248.70000004768372},{"duration":22,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":248.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":248.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":270.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":23.600000143051147,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":249,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":249,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":272.60000014305115,"responseStart":0,"secureConnectionStart":0},{"duration":51.700000047683716,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":249,"connectEnd":249,"connectStart":249,"domainLookupEnd":249,"domainLookupStart":249,"fetchStart":249,"redirectEnd":0,"redirectStart":0,"requestStart":276.10000014305115,"responseEnd":300.7000000476837,"responseStart":298.7000000476837,"secureConnectionStart":249},{"duration":54.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":249.20000004768372,"connectEnd":249.20000004768372,"connectStart":249.20000004768372,"domainLookupEnd":249.20000004768372,"domainLookupStart":249.20000004768372,"fetchStart":249.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":277.7000000476837,"responseEnd":303.60000014305115,"responseStart":301.10000014305115,"secureConnectionStart":249.20000004768372},{"duration":252.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":295.10000014305115,"connectEnd":295.10000014305115,"connectStart":295.10000014305115,"domainLookupEnd":295.10000014305115,"domainLookupStart":295.10000014305115,"fetchStart":295.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":303.80000019073486,"responseEnd":547.6000001430511,"responseStart":541,"secureConnectionStart":295.10000014305115},{"duration":236.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":311.60000014305115,"connectEnd":311.60000014305115,"connectStart":311.60000014305115,"domainLookupEnd":311.60000014305115,"domainLookupStart":311.60000014305115,"fetchStart":311.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":329.80000019073486,"responseEnd":548.1000001430511,"responseStart":543.7000000476837,"secureConnectionStart":311.60000014305115},{"duration":115.90000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":594,"connectEnd":594,"connectStart":594,"domainLookupEnd":594,"domainLookupStart":594,"fetchStart":594,"redirectEnd":0,"redirectStart":0,"requestStart":679.6000001430511,"responseEnd":709.9000000953674,"responseStart":709.1000001430511,"secureConnectionStart":594},{"duration":158.39999985694885,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":814.1000001430511,"connectEnd":814.1000001430511,"connectStart":814.1000001430511,"domainLookupEnd":814.1000001430511,"domainLookupStart":814.1000001430511,"fetchStart":814.1000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":938,"responseEnd":972.5,"responseStart":970.8000001907349,"secureConnectionStart":814.1000001430511},{"duration":88.20000004768372,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":850.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":850.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":939.1000001430511,"responseStart":0,"secureConnectionStart":0}],"fetchStart":1,"domainLookupStart":20,"domainLookupEnd":39,"connectStart":39,"connectEnd":57,"secureConnectionStart":47,"requestStart":59,"responseStart":235,"responseEnd":312,"domLoading":239,"domInteractive":1051,"domContentLoadedEventStart":1051,"domContentLoadedEventEnd":1109,"domComplete":1283,"loadEventStart":1283,"loadEventEnd":1284,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1024.2000000476837},{"name":"bigPipe.sidebar-id.end","time":1025},{"name":"bigPipe.activity-panel-pipe-id.start","time":1025.1000001430511},{"name":"bigPipe.activity-panel-pipe-id.end","time":1027.5},{"name":"activityTabFullyLoaded","time":1125.3000001907349}],"measures":[],"correlationId":"6e1260999bd6a6","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":88,"dbReadsTimeInMs":12,"dbConnsTimeInMs":25,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
diegohellas, thanks for the report and test case.
Reproducible on all 10.x versions.
The problem existed in 5.6/5.7 too, but is fixed in the latest releases. apparently in the scope of
https://bugs.mysql.com/bug.php?id=68972