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":968.4000000953674,"ttfb":339.2999999523163,"pageVisibility":"visible","entityId":87717,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"87c9e336-acd8-4c44-ac9b-610ee30cdd83","navigationType":0,"readyForUser":1045.7000000476837,"redirectCount":0,"resourceLoadedEnd":697.7000000476837,"resourceLoadedStart":347,"resourceTiming":[{"duration":83.20000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":347,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":347,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":430.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":83.10000014305115,"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":347.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":347.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":430.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":204.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":347.40000009536743,"connectEnd":347.40000009536743,"connectStart":347.40000009536743,"domainLookupEnd":347.40000009536743,"domainLookupStart":347.40000009536743,"fetchStart":347.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":432.2000000476837,"responseEnd":552,"responseStart":453.5,"secureConnectionStart":347.40000009536743},{"duration":350,"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":347.7000000476837,"connectEnd":347.7000000476837,"connectStart":347.7000000476837,"domainLookupEnd":347.7000000476837,"domainLookupStart":347.7000000476837,"fetchStart":347.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":433.5,"responseEnd":697.7000000476837,"responseStart":457.2000000476837,"secureConnectionStart":347.7000000476837},{"duration":111.39999985694885,"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":347.90000009536743,"connectEnd":347.90000009536743,"connectStart":347.90000009536743,"domainLookupEnd":347.90000009536743,"domainLookupStart":347.90000009536743,"fetchStart":347.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":434.59999990463257,"responseEnd":459.2999999523163,"responseStart":458,"secureConnectionStart":347.90000009536743},{"duration":109.09999990463257,"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":348,"connectEnd":348,"connectStart":348,"domainLookupEnd":348,"domainLookupStart":348,"fetchStart":348,"redirectEnd":0,"redirectStart":0,"requestStart":434.40000009536743,"responseEnd":457.09999990463257,"responseStart":455.7000000476837,"secureConnectionStart":348},{"duration":113.20000004768372,"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":348.2000000476837,"connectEnd":348.2000000476837,"connectStart":348.2000000476837,"domainLookupEnd":348.2000000476837,"domainLookupStart":348.2000000476837,"fetchStart":348.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":435.5,"responseEnd":461.40000009536743,"responseStart":460.09999990463257,"secureConnectionStart":348.2000000476837},{"duration":86.5,"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":348.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":348.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":435,"responseStart":0,"secureConnectionStart":0},{"duration":115.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":348.59999990463257,"connectEnd":348.59999990463257,"connectStart":348.59999990463257,"domainLookupEnd":348.59999990463257,"domainLookupStart":348.59999990463257,"fetchStart":348.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":437.59999990463257,"responseEnd":464.5,"responseStart":461.90000009536743,"secureConnectionStart":348.59999990463257},{"duration":87.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":348.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":348.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":436.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":117.29999995231628,"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":348.90000009536743,"connectEnd":348.90000009536743,"connectStart":348.90000009536743,"domainLookupEnd":348.90000009536743,"domainLookupStart":348.90000009536743,"fetchStart":348.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":438.5,"responseEnd":466.2000000476837,"responseStart":464.90000009536743,"secureConnectionStart":348.90000009536743},{"duration":341.40000009536743,"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":353.5,"connectEnd":353.5,"connectStart":353.5,"domainLookupEnd":353.5,"domainLookupStart":353.5,"fetchStart":353.5,"redirectEnd":0,"redirectStart":0,"requestStart":530.4000000953674,"responseEnd":694.9000000953674,"responseStart":690.5,"secureConnectionStart":353.5},{"duration":335.59999990463257,"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":360.7000000476837,"connectEnd":360.7000000476837,"connectStart":360.7000000476837,"domainLookupEnd":360.7000000476837,"domainLookupStart":360.7000000476837,"fetchStart":360.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":590,"responseEnd":696.2999999523163,"responseStart":693.4000000953674,"secureConnectionStart":360.7000000476837},{"duration":144.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":714.2999999523163,"connectEnd":714.2999999523163,"connectStart":714.2999999523163,"domainLookupEnd":714.2999999523163,"domainLookupStart":714.2999999523163,"fetchStart":714.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":823,"responseEnd":858.7999999523163,"responseStart":857.7000000476837,"secureConnectionStart":714.2999999523163},{"duration":223.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":925,"connectEnd":925,"connectStart":925,"domainLookupEnd":925,"domainLookupStart":925,"fetchStart":925,"redirectEnd":0,"redirectStart":0,"requestStart":1115.2999999523163,"responseEnd":1148.5,"responseStart":1147.5,"secureConnectionStart":925},{"duration":195,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":961.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":961.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1156.7000000476837,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":78,"domainLookupEnd":124,"connectStart":124,"connectEnd":143,"secureConnectionStart":132,"requestStart":144,"responseStart":339,"responseEnd":361,"domLoading":343,"domInteractive":1157,"domContentLoadedEventStart":1157,"domContentLoadedEventEnd":1216,"domComplete":1352,"loadEventStart":1352,"loadEventEnd":1352,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1117},{"name":"bigPipe.sidebar-id.end","time":1117.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.start","time":1117.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":1122},{"name":"activityTabFullyLoaded","time":1233.9000000953674}],"measures":[],"correlationId":"c01c5b29d3fbb3","effectiveType":"4g","downlink":9.8,"rtt":0,"serverDuration":130,"dbReadsTimeInMs":12,"dbConnsTimeInMs":25,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Documentation about Execute in the protocol: https://mariadb.com/kb/en/com_stmt_execute/
According to Diego,