Type:
Task
Priority:
Major
Resolution:
Fixed
As of 11.3.0, the server code uses two ways to put a Field::val_str() value to MEM_ROOT :
char *get_field(MEM_ROOT *mem, Field *field);
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
In many cases the value is further needed as a LEX_CSTRING , but both versions of get_field() are inconvenient and inefficient to initialize a LEX_CSTRING .
The first version requires an strlen() call. This is an example from udf_init() in sql_udf.cc :
LEX_CSTRING name;
name.str=get_field(&mem, table->field[0]);
name.length = (uint) safe_strlen(name.str);
char *dl_name= get_field(&mem, table->field[2]);
...
if (!name.str || !dl_name || check_valid_path(dl_name, strlen (dl_name)) ||
Notice safe_strlen() and strlen() calls.
The second version of get_field() requires a String buffer for every LEX_CSTRING . This is an example from plugin_load() in sql_plugin.cc :
String str_name, str_dl;
get_field(tmp_root, table->field[0], &str_name);
get_field(tmp_root, table->field[1], &str_dl);
LEX_CSTRING name= {str_name.ptr(), str_name.length()};
LEX_CSTRING dl= {str_dl.ptr(), str_dl.length()};
Notice two String buffers.
Let's add a native method in Field which will overcome both problems:
LEX_STRING Field::val_lex_string_strmake(MEM_ROOT *mem)
{
StringBuffer<MAX_FIELD_WIDTH> str;
val_str(&str);
char *to= strmake_root(mem, str.ptr(), str.length());
return to ? LEX_STRING{to, str.length()} : LEX_STRING{NULL, 0};
}
It won't need neither strlen() calls nor String buffers.
Also let's move this version of get_field():
bool get_field(MEM_ROOT *mem, Field *field, String *res)
as a static function to sql_help.cc , as it's only used in this file. This will help to avoid reincarnation of its calls around the code in the future and encorage the use of the new method Field::val_lex_string_strmake() .
{"report":{"fcp":2033.1999998092651,"ttfb":1019.0999999046326,"pageVisibility":"visible","entityId":124619,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"d0784940-e7d7-467d-b4bf-845db210fa37","navigationType":0,"readyForUser":2113.0999999046326,"redirectCount":0,"resourceLoadedEnd":2933.0999999046326,"resourceLoadedStart":1059.2999999523163,"resourceTiming":[{"duration":479.2999999523163,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":1059.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1059.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1538.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":479.30000019073486,"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":1059.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1059.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1539,"responseStart":0,"secureConnectionStart":0},{"duration":486.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":1059.8999998569489,"connectEnd":1059.8999998569489,"connectStart":1059.8999998569489,"domainLookupEnd":1059.8999998569489,"domainLookupStart":1059.8999998569489,"fetchStart":1059.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":1059.8999998569489,"responseEnd":1546.5999999046326,"responseStart":1546.5999999046326,"secureConnectionStart":1059.8999998569489},{"duration":576.1999998092651,"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":1060.5,"connectEnd":1060.5,"connectStart":1060.5,"domainLookupEnd":1060.5,"domainLookupStart":1060.5,"fetchStart":1060.5,"redirectEnd":0,"redirectStart":0,"requestStart":1060.5,"responseEnd":1636.6999998092651,"responseStart":1636.6999998092651,"secureConnectionStart":1060.5},{"duration":579.5999999046326,"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":1060.7999999523163,"connectEnd":1060.7999999523163,"connectStart":1060.7999999523163,"domainLookupEnd":1060.7999999523163,"domainLookupStart":1060.7999999523163,"fetchStart":1060.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1060.7999999523163,"responseEnd":1640.3999998569489,"responseStart":1640.3999998569489,"secureConnectionStart":1060.7999999523163},{"duration":580,"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":1060.8999998569489,"connectEnd":1060.8999998569489,"connectStart":1060.8999998569489,"domainLookupEnd":1060.8999998569489,"domainLookupStart":1060.8999998569489,"fetchStart":1060.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":1060.8999998569489,"responseEnd":1640.8999998569489,"responseStart":1640.8999998569489,"secureConnectionStart":1060.8999998569489},{"duration":578.5999999046326,"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":1062.7999999523163,"connectEnd":1062.7999999523163,"connectStart":1062.7999999523163,"domainLookupEnd":1062.7999999523163,"domainLookupStart":1062.7999999523163,"fetchStart":1062.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1062.7999999523163,"responseEnd":1641.3999998569489,"responseStart":1641.2999999523163,"secureConnectionStart":1062.7999999523163},{"duration":629.6999998092651,"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":1063,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1063,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1692.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":578.6000001430511,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":1063.1999998092651,"connectEnd":1063.1999998092651,"connectStart":1063.1999998092651,"domainLookupEnd":1063.1999998092651,"domainLookupStart":1063.1999998092651,"fetchStart":1063.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1063.1999998092651,"responseEnd":1641.7999999523163,"responseStart":1641.7999999523163,"secureConnectionStart":1063.1999998092651},{"duration":629.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":1063.3999998569489,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1063.3999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1692.8999998569489,"responseStart":0,"secureConnectionStart":0},{"duration":578.7000000476837,"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":1063.5999999046326,"connectEnd":1063.5999999046326,"connectStart":1063.5999999046326,"domainLookupEnd":1063.5999999046326,"domainLookupStart":1063.5999999046326,"fetchStart":1063.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1063.5999999046326,"responseEnd":1642.2999999523163,"responseStart":1642.2999999523163,"secureConnectionStart":1063.5999999046326},{"duration":1792.7999999523163,"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":1136.2999999523163,"connectEnd":1136.2999999523163,"connectStart":1136.2999999523163,"domainLookupEnd":1136.2999999523163,"domainLookupStart":1136.2999999523163,"fetchStart":1136.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1136.2999999523163,"responseEnd":2929.0999999046326,"responseStart":2929,"secureConnectionStart":1136.2999999523163},{"duration":1775.2999999523163,"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":1157.7999999523163,"connectEnd":1157.7999999523163,"connectStart":1157.7999999523163,"domainLookupEnd":1157.7999999523163,"domainLookupStart":1157.7999999523163,"fetchStart":1157.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1157.7999999523163,"responseEnd":2933.0999999046326,"responseStart":2933.0999999046326,"secureConnectionStart":1157.7999999523163},{"duration":339.90000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1704.6999998092651,"connectEnd":1704.6999998092651,"connectStart":1704.6999998092651,"domainLookupEnd":1704.6999998092651,"domainLookupStart":1704.6999998092651,"fetchStart":1704.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1704.6999998092651,"responseEnd":2044.5999999046326,"responseStart":2044.5999999046326,"secureConnectionStart":1704.6999998092651}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":841,"responseStart":1019,"responseEnd":1160,"domLoading":1022,"domInteractive":2970,"domContentLoadedEventStart":2970,"domContentLoadedEventEnd":3035,"domComplete":3755,"loadEventStart":3755,"loadEventEnd":3756,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2942.199999809265},{"name":"bigPipe.sidebar-id.end","time":2943.199999809265},{"name":"bigPipe.activity-panel-pipe-id.start","time":2943.399999856949},{"name":"bigPipe.activity-panel-pipe-id.end","time":2944.7999999523163},{"name":"activityTabFullyLoaded","time":3049.899999856949}],"measures":[],"correlationId":"2d1600ed730c1d","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":104,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Suggest to not have the final strmake suffix. Just val_lex_string should suffice.