Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
10.5
This was found as part of MDEV-33478 . See MDEV-33478 description for details.
This is fairly old code, why did new MSAN find it while valgrind didn't? It seems the cause was that the value was copied between Item objects but was not used.
If I add a printout:
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index f8fd28aebb5..7ec7a752875 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -5076,6 +5076,7 @@ Item_cond::fix_fields(THD *thd, Item **ref)
with_flags|= item->with_flags;
}
(void) eval_not_null_tables((void*) 0);
+ fprintf(stderr, "AAQ: not_null_tables_cache=%llx\n", not_null_tables_cache);
/*
We have to set fixed as some other items will check it and fail if we
the attached testcase (extract from include/common-tests.inc) starts to fail under valgrind:
==23601== Thread 6:
==23601== Use of uninitialised value of size 8
==23601== at 0x747F7E1: _itoa_word (_itoa.c:180)
==23601== by 0x7482EDD: vfprintf (vfprintf.c:1642)
==23601== by 0x748563F: buffered_vfprintf (vfprintf.c:2329)
==23601== by 0x74826F5: vfprintf (vfprintf.c:1301)
==23601== by 0x748BE13: fprintf (fprintf.c:32)
==23601== by 0xE9C878: Item_cond::fix_fields(THD*, Item**) (item_cmpfunc.cc:5079)
==23601== by 0xB18FC8: make_cond_for_table_from_pred(THD*, Item*, Item*, unsigned long long, unsigned long long, int, bool, bool, bool) (sql_select.cc:23938)
==23601== by 0xB18CBC: make_cond_for_table(THD*, Item*, unsigned long long, unsigned long long, int, bool, bool) (sql_select.cc:23869)
==23601== by 0xAFA17A: make_join_select(JOIN*, SQL_SELECT*, Item*) (sql_select.cc:12543)
==23601== by 0xADC64D: JOIN::optimize_stage2() (sql_select.cc:2855)
==23601== by 0xADB459: JOIN::optimize_inner() (sql_select.cc:2590)
==23601== by 0xAD8A6D: JOIN::optimize() (sql_select.cc:1888)
==23601== by 0xAE4A58: mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:5127)
==23601== by 0xAD3452: handle_select(THD*, LEX*, select_result*, unsigned long) (sql_select.cc:559)
==23601== by 0xA91440: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:6372)
is part of
MDEV-33478
Tests massively fail with clang-18 -fsanitize=memory
Closed
{"report":{"fcp":1331.8000001907349,"ttfb":311.69999980926514,"pageVisibility":"visible","entityId":128348,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"7950519a-844d-4871-8a2c-37063f41f34a","navigationType":0,"readyForUser":1471.4000000953674,"redirectCount":0,"resourceLoadedEnd":844,"resourceLoadedStart":320.40000009536743,"resourceTiming":[{"duration":39.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":320.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":320.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":360.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":39.80000019073486,"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":320.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":320.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":360.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":246.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":320.69999980926514,"connectEnd":320.69999980926514,"connectStart":320.69999980926514,"domainLookupEnd":320.69999980926514,"domainLookupStart":320.69999980926514,"fetchStart":320.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":363.19999980926514,"responseEnd":567.4000000953674,"responseStart":386.09999990463257,"secureConnectionStart":320.69999980926514},{"duration":523,"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":321,"connectEnd":321,"connectStart":321,"domainLookupEnd":321,"domainLookupStart":321,"fetchStart":321,"redirectEnd":0,"redirectStart":0,"requestStart":363.40000009536743,"responseEnd":844,"responseStart":380,"secureConnectionStart":321},{"duration":68,"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":321.19999980926514,"connectEnd":321.19999980926514,"connectStart":321.19999980926514,"domainLookupEnd":321.19999980926514,"domainLookupStart":321.19999980926514,"fetchStart":321.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":363.40000009536743,"responseEnd":389.19999980926514,"responseStart":384,"secureConnectionStart":321.19999980926514},{"duration":68.5,"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":321.30000019073486,"connectEnd":321.30000019073486,"connectStart":321.30000019073486,"domainLookupEnd":321.30000019073486,"domainLookupStart":321.30000019073486,"fetchStart":321.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":366.19999980926514,"responseEnd":389.80000019073486,"responseStart":385.30000019073486,"secureConnectionStart":321.30000019073486},{"duration":73.40000009536743,"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":321.40000009536743,"connectEnd":321.40000009536743,"connectStart":321.40000009536743,"domainLookupEnd":321.40000009536743,"domainLookupStart":321.40000009536743,"fetchStart":321.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":369.69999980926514,"responseEnd":394.80000019073486,"responseStart":391.80000019073486,"secureConnectionStart":321.40000009536743},{"duration":39.80000019073486,"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":321.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":321.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":361.30000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":73.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":321.69999980926514,"connectEnd":321.69999980926514,"connectStart":321.69999980926514,"domainLookupEnd":321.69999980926514,"domainLookupStart":321.69999980926514,"fetchStart":321.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":370.09999990463257,"responseEnd":395.09999990463257,"responseStart":392.30000019073486,"secureConnectionStart":321.69999980926514},{"duration":50.799999713897705,"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":321.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":321.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":372.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":88.40000009536743,"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":322.09999990463257,"connectEnd":322.09999990463257,"connectStart":322.09999990463257,"domainLookupEnd":322.09999990463257,"domainLookupStart":322.09999990463257,"fetchStart":322.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":379.80000019073486,"responseEnd":410.5,"responseStart":400,"secureConnectionStart":322.09999990463257},{"duration":511.90000009536743,"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":327.59999990463257,"connectEnd":327.59999990463257,"connectStart":327.59999990463257,"domainLookupEnd":327.59999990463257,"domainLookupStart":327.59999990463257,"fetchStart":327.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":433.80000019073486,"responseEnd":839.5,"responseStart":834.9000000953674,"secureConnectionStart":327.59999990463257},{"duration":512.2000002861023,"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":327.69999980926514,"connectEnd":327.69999980926514,"connectStart":327.69999980926514,"domainLookupEnd":327.69999980926514,"domainLookupStart":327.69999980926514,"fetchStart":327.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":599.8000001907349,"responseEnd":839.9000000953674,"responseStart":836.5999999046326,"secureConnectionStart":327.69999980926514},{"duration":338.7999997138977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":743.4000000953674,"connectEnd":743.4000000953674,"connectStart":743.4000000953674,"domainLookupEnd":743.4000000953674,"domainLookupStart":743.4000000953674,"fetchStart":743.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1031.1999998092651,"responseEnd":1082.1999998092651,"responseStart":1078.6999998092651,"secureConnectionStart":743.4000000953674},{"duration":411.40000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1238.1999998092651,"connectEnd":1238.1999998092651,"connectStart":1238.1999998092651,"domainLookupEnd":1238.1999998092651,"domainLookupStart":1238.1999998092651,"fetchStart":1238.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1611.8000001907349,"responseEnd":1649.5999999046326,"responseStart":1648.5999999046326,"secureConnectionStart":1238.1999998092651}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":137,"responseStart":312,"responseEnd":324,"domLoading":315,"domInteractive":1681,"domContentLoadedEventStart":1681,"domContentLoadedEventEnd":1753,"domComplete":2319,"loadEventStart":2319,"loadEventEnd":2319,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1599.9000000953674},{"name":"bigPipe.sidebar-id.end","time":1600.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1600.8000001907349},{"name":"bigPipe.activity-panel-pipe-id.end","time":1602.5},{"name":"activityTabFullyLoaded","time":1769.8000001907349}],"measures":[],"correlationId":"87ed74257b2b8d","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":93,"dbReadsTimeInMs":12,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Previously suggested fix
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 0973d0c2c82..54f7eb222bf 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -397,6 +397,7 @@ Item_func::quick_fix_field()
}
}
base_flags|= item_base_t::FIXED;
+ eval_not_null_tables(NULL);
}
removes the error, but is it correct? quick_fix_field() just marks the item as fixed, without updating any fields (like e.g. used_tables). Why should we single out not_null_tables_cache and just update it?
Some callers update some fields after quick_fix_field() call:
new_cond->quick_fix_field();
new_cond->used_tables_cache=
((Item_cond_and*) cond)->used_tables_cache &
tables;