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":960.4000000953674,"ttfb":177.90000009536743,"pageVisibility":"visible","entityId":128348,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"76d48a03-2c91-42fe-95e0-63530c80281b","navigationType":0,"readyForUser":1041,"redirectCount":0,"resourceLoadedEnd":715.5,"resourceLoadedStart":183.30000019073486,"resourceTiming":[{"duration":164.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":183.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":183.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":347.5,"responseStart":0,"secureConnectionStart":0},{"duration":164.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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":183.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":183.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":347.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":390.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/c54b129276d75dc2a3460e1d78f37913-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":183.59999990463257,"connectEnd":183.59999990463257,"connectStart":183.59999990463257,"domainLookupEnd":183.59999990463257,"domainLookupStart":183.59999990463257,"fetchStart":183.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":352.7000002861023,"responseEnd":574.2000002861023,"responseStart":378.5,"secureConnectionStart":183.59999990463257},{"duration":200,"initiatorType":"script","name":"https://jira.mariadb.org/s/ffdb17665775c5b4d6f097f3974ee359-CDN/lu2bsh/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":183.7000002861023,"connectEnd":183.7000002861023,"connectStart":183.7000002861023,"domainLookupEnd":183.7000002861023,"domainLookupStart":183.7000002861023,"fetchStart":183.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":353.30000019073486,"responseEnd":383.7000002861023,"responseStart":382.40000009536743,"secureConnectionStart":183.7000002861023},{"duration":501.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/f867843cd2fdb209d4d1d4f760f86346-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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":183.7000002861023,"connectEnd":183.7000002861023,"connectStart":183.7000002861023,"domainLookupEnd":183.7000002861023,"domainLookupStart":183.7000002861023,"fetchStart":183.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":352.90000009536743,"responseEnd":685.5,"responseStart":376.5,"secureConnectionStart":183.7000002861023},{"duration":202.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":183.80000019073486,"connectEnd":183.80000019073486,"connectStart":183.80000019073486,"domainLookupEnd":183.80000019073486,"domainLookupStart":183.80000019073486,"fetchStart":183.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":353.5,"responseEnd":386.2000002861023,"responseStart":384,"secureConnectionStart":183.80000019073486},{"duration":168.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bsh/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":184,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":184,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":352.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":202.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":184,"connectEnd":184,"connectStart":184,"domainLookupEnd":184,"domainLookupStart":184,"fetchStart":184,"redirectEnd":0,"redirectStart":0,"requestStart":353.7000002861023,"responseEnd":386.5,"responseStart":384.5,"secureConnectionStart":184},{"duration":169.2999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bsh/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":184.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":184.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":353.5,"responseStart":0,"secureConnectionStart":0},{"duration":224.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":184.2000002861023,"connectEnd":184.2000002861023,"connectStart":184.2000002861023,"domainLookupEnd":184.2000002861023,"domainLookupStart":184.2000002861023,"fetchStart":184.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":355.2000002861023,"responseEnd":408.80000019073486,"responseStart":405.5,"secureConnectionStart":184.2000002861023},{"duration":209.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/81b5d7c27af3ebc078cc4a36383678ba-CDN/lu2bsh/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":184.30000019073486,"connectEnd":184.30000019073486,"connectStart":184.30000019073486,"domainLookupEnd":184.30000019073486,"domainLookupStart":184.30000019073486,"fetchStart":184.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":355.90000009536743,"responseEnd":393.7000002861023,"responseStart":385.09999990463257,"secureConnectionStart":184.30000019073486},{"duration":525.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":189.59999990463257,"connectEnd":189.59999990463257,"connectStart":189.59999990463257,"domainLookupEnd":189.59999990463257,"domainLookupStart":189.59999990463257,"fetchStart":189.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":381.40000009536743,"responseEnd":715.5,"responseStart":710.5,"secureConnectionStart":189.59999990463257},{"duration":525,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":189.7000002861023,"connectEnd":189.7000002861023,"connectStart":189.7000002861023,"domainLookupEnd":189.7000002861023,"domainLookupStart":189.7000002861023,"fetchStart":189.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":413.2000002861023,"responseEnd":714.7000002861023,"responseStart":708.4000000953674,"secureConnectionStart":189.7000002861023},{"duration":116,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":721.5999999046326,"connectEnd":721.5999999046326,"connectStart":721.5999999046326,"domainLookupEnd":721.5999999046326,"domainLookupStart":721.5999999046326,"fetchStart":721.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":807.4000000953674,"responseEnd":837.5999999046326,"responseStart":836.8000001907349,"secureConnectionStart":721.5999999046326},{"duration":118.90000009536743,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":953.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":953.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1072.5,"responseStart":0,"secureConnectionStart":0},{"duration":152.30000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":960,"connectEnd":960,"connectStart":960,"domainLookupEnd":960,"domainLookupStart":960,"fetchStart":960,"redirectEnd":0,"redirectStart":0,"requestStart":1076.4000000953674,"responseEnd":1112.3000001907349,"responseStart":1111.7000002861023,"secureConnectionStart":960}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":42,"responseStart":178,"responseEnd":185,"domLoading":181,"domInteractive":1139,"domContentLoadedEventStart":1139,"domContentLoadedEventEnd":1183,"domComplete":1386,"loadEventStart":1386,"loadEventEnd":1386,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1115.2000002861023},{"name":"bigPipe.sidebar-id.end","time":1115.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1116.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":1117.5999999046326},{"name":"activityTabFullyLoaded","time":1201.8000001907349}],"measures":[],"correlationId":"681899c77b2b64","effectiveType":"4g","downlink":9,"rtt":0,"serverDuration":70,"dbReadsTimeInMs":11,"dbConnsTimeInMs":17,"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;