I don't have a testcase, I only have a customer's core file.
As far as I was able to investigate, the following has happened:
1. There is a big query with nested SELECTs and non-recursive CTEs. Some CTEs are used multiple times.
2. The query is submitted to server as a Prepared Statement. The prepared statement has many '?' parameters.
3. [At least] one of the parameters is inside in a CTE that's reused and it used like so:
We crash in optimize_keyuse(), when we are trying to process a KEYUSE element created from the above equality.
We crash somewhere here:
|
if (keyuse->used_tables &
|
(map= (keyuse->used_tables & ~join->const_table_map &
|
~OUTER_REF_TABLE_BIT)))
|
{
|
uint n_tables= my_count_bits(map);
|
if (n_tables == 1) // Only one table
|
{
|
Table_map_iterator it(map);
|
int tablenr= it.next_bit();
|
DBUG_ASSERT(tablenr != Table_map_iterator::BITMAP_END);
|
TABLE *tmp_table=join->table[tablenr];
|
if (tmp_table) // already created
|
keyuse->ref_table_rows= MY_MAX(tmp_table->file->stats.records, 100);
|
}
|
The cause is that the keyuse has:
keyuse->used_tables = PARAM_TABLE_BIT
|
keyuse->val = Item_param
|
With PARAM_TABLE_BIT, the "if (n_tables == 1)" branch is taken, and we get a tablenr value, but join->table[tablenr] is not pointing to a valid TABLE object hence we get a poorly-reproducible crash.
We should not get {{ keyuse->used_tables = PARAM_TABLE_BIT}}. We do, because
$keyuse->val->state == Item_param::NO_VALUE
|
(which also shouldn't be happening).
There is Prepared_statement::param_array which is an array of "primary" parameter instances, and
$keyuse->val != $prepared_statement->param_array[$i] for any value of $i.
|
However, I can find $keyuse->val in
$prepared_statement->param_array[$a].m_clones.m_array[$b]
|
That is, it is a "secondary" Item_param object that was created for a CTE.
Further, I observe that
- The "primary" Item_param objects from $prepared_statement->param_array[i] all have state=Item_param::SHORT_DATA_VALUE or other similar states
- The "secondary" Item_param objects from "m_clones" arrays all have state=Item_param::NO_VALUE.
{"report":{"fcp":1657,"ttfb":471,"pageVisibility":"visible","entityId":87717,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"7f7b2b7d-a5a6-4be2-8237-9f85fc48f9c8","navigationType":0,"readyForUser":1755.3000001907349,"redirectCount":0,"resourceLoadedEnd":1785.1999998092651,"resourceLoadedStart":478.4000005722046,"resourceTiming":[{"duration":652.7999992370605,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":478.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":478.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1131.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":652.9000005722046,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":478.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":478.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1131.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":706.2999992370605,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":478.9000005722046,"connectEnd":478.9000005722046,"connectStart":478.9000005722046,"domainLookupEnd":478.9000005722046,"domainLookupStart":478.9000005722046,"fetchStart":478.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":478.9000005722046,"responseEnd":1185.1999998092651,"responseStart":1185.1999998092651,"secureConnectionStart":478.9000005722046},{"duration":759.8999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":479.1000003814697,"connectEnd":479.1000003814697,"connectStart":479.1000003814697,"domainLookupEnd":479.1000003814697,"domainLookupStart":479.1000003814697,"fetchStart":479.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":479.1000003814697,"responseEnd":1239,"responseStart":1239,"secureConnectionStart":479.1000003814697},{"duration":763.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":479.4000005722046,"connectEnd":479.4000005722046,"connectStart":479.4000005722046,"domainLookupEnd":479.4000005722046,"domainLookupStart":479.4000005722046,"fetchStart":479.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":479.4000005722046,"responseEnd":1243.1000003814697,"responseStart":1243.1000003814697,"secureConnectionStart":479.4000005722046},{"duration":763.8999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":479.6000003814697,"connectEnd":479.6000003814697,"connectStart":479.6000003814697,"domainLookupEnd":479.6000003814697,"domainLookupStart":479.6000003814697,"fetchStart":479.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":479.6000003814697,"responseEnd":1243.5,"responseStart":1243.5,"secureConnectionStart":479.6000003814697},{"duration":764.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":479.69999980926514,"connectEnd":479.69999980926514,"connectStart":479.69999980926514,"domainLookupEnd":479.69999980926514,"domainLookupStart":479.69999980926514,"fetchStart":479.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":479.69999980926514,"responseEnd":1244,"responseStart":1244,"secureConnectionStart":479.69999980926514},{"duration":851.7999992370605,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":479.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":479.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1331.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":764.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":480.1000003814697,"connectEnd":480.1000003814697,"connectStart":480.1000003814697,"domainLookupEnd":480.1000003814697,"domainLookupStart":480.1000003814697,"fetchStart":480.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":480.1000003814697,"responseEnd":1244.5,"responseStart":1244.5,"secureConnectionStart":480.1000003814697},{"duration":851.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/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":480.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":480.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1331.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":764.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/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":480.5,"connectEnd":480.5,"connectStart":480.5,"domainLookupEnd":480.5,"domainLookupStart":480.5,"fetchStart":480.5,"redirectEnd":0,"redirectStart":0,"requestStart":480.5,"responseEnd":1245.1000003814697,"responseStart":1245.1000003814697,"secureConnectionStart":480.5},{"duration":1064.7000007629395,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":481.19999980926514,"connectEnd":481.19999980926514,"connectStart":481.19999980926514,"domainLookupEnd":481.19999980926514,"domainLookupStart":481.19999980926514,"fetchStart":481.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":481.19999980926514,"responseEnd":1545.9000005722046,"responseStart":1545.9000005722046,"secureConnectionStart":481.19999980926514},{"duration":1270.2999992370605,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":481.4000005722046,"connectEnd":481.4000005722046,"connectStart":481.4000005722046,"domainLookupEnd":481.4000005722046,"domainLookupStart":481.4000005722046,"fetchStart":481.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":481.4000005722046,"responseEnd":1751.6999998092651,"responseStart":1751.6999998092651,"secureConnectionStart":481.4000005722046},{"duration":214.30000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1343.6000003814697,"connectEnd":1343.6000003814697,"connectStart":1343.6000003814697,"domainLookupEnd":1343.6000003814697,"domainLookupStart":1343.6000003814697,"fetchStart":1343.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":1343.6000003814697,"responseEnd":1557.9000005722046,"responseStart":1557.9000005722046,"secureConnectionStart":1343.6000003814697},{"duration":177.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1607.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1607.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1785.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":177.39999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/50bc9be5bfead1a25e72c1a9338c94f6-CDN/lu2cib/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/css/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1607.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1607.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1785.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":154,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1608.6999998092651,"connectEnd":1608.6999998092651,"connectStart":1608.6999998092651,"domainLookupEnd":1608.6999998092651,"domainLookupStart":1608.6999998092651,"fetchStart":1608.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1608.6999998092651,"responseEnd":1762.6999998092651,"responseStart":1762.6999998092651,"secureConnectionStart":1608.6999998092651},{"duration":160.89999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":1609.1000003814697,"connectEnd":1609.1000003814697,"connectStart":1609.1000003814697,"domainLookupEnd":1609.1000003814697,"domainLookupStart":1609.1000003814697,"fetchStart":1609.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":1609.1000003814697,"responseEnd":1770,"responseStart":1770,"secureConnectionStart":1609.1000003814697},{"duration":161.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/e0bf5781d46ea69fb123572974cf39de-CDN/lu2cib/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/js/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":1609.5,"connectEnd":1609.5,"connectStart":1609.5,"domainLookupEnd":1609.5,"domainLookupStart":1609.5,"fetchStart":1609.5,"redirectEnd":0,"redirectStart":0,"requestStart":1609.5,"responseEnd":1771.3000001907349,"responseStart":1771.3000001907349,"secureConnectionStart":1609.5},{"duration":188.89999961853027,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1650.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1650.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1839.1999998092651,"responseStart":0,"secureConnectionStart":0}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":286,"responseStart":472,"responseEnd":475,"domLoading":476,"domInteractive":1890,"domContentLoadedEventStart":1890,"domContentLoadedEventEnd":1943,"domComplete":2068,"loadEventStart":2068,"loadEventEnd":2069,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1840.3000001907349},{"name":"bigPipe.sidebar-id.end","time":1845.6000003814697},{"name":"bigPipe.activity-panel-pipe-id.start","time":1845.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":1851},{"name":"activityTabFullyLoaded","time":1969.4000005722046}],"measures":[],"correlationId":"c554324cea384e","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":116,"dbReadsTimeInMs":11,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Documentation about Execute in the protocol: https://mariadb.com/kb/en/com_stmt_execute/
According to Diego,