Consider this example patch
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
|
index f0d42c32dd0..9fbae781274 100644
|
--- a/sql/sql_select.cc
|
+++ b/sql/sql_select.cc
|
@@ -1797,6 +1797,15 @@ JOIN::optimize_inner()
|
trace_prepare.add_select_number(select_lex->select_number);
|
Json_writer_array trace_steps(thd, "steps");
|
|
+ {
|
+ Json_writer_object trace_wrapper(thd);
|
+ Json_writer_object trace_conv(thd, "new_rewrite");
|
+ trace_conv.add("member", "member-value");
|
+ {
|
+ Json_writer_object obj(thd);
|
+ obj.add("rewrite_done", true);
|
+ }
|
+ }
|
/*
|
Needed in case optimizer short-cuts,
|
set properly in make_aggr_tables_info()
|
It will silently produce invalid trace:
create table t1(a int);
|
insert into t1 values (1),(2);
|
set optimizer_trace=1;
|
explain select * from t1;
|
select * from information_schema.optimizer_trace\G
|
will show this:
...
|
"join_optimization": {
|
"select_id": 1,
|
"steps": [
|
{
|
"new_rewrite": {
|
"member": "member-value",
|
{
|
"rewrite_done": true
|
}
|
}
|
},
|
new_rewrite is an object, while it has an un-named object inside it.
How to solve this
In ideal world, one would want that JSON writer API doesn't allow to construct call sequences that produce invalid JSON. However this will require passing around a "write context" object which would be either "array member context" (which one can use to add unnamed members) or "object member context" (which one can use to add named members).
Passing the context around is inconvenient. We want to be able to write things like
Json_writer_object trace_conv(thd);
|
at arbitrary place in the code.
Perhaps what we need is:
- A convention that by default the Optimizer trace writer is left in an unnamed context.
- Assert statements that will fire if one attempts to produce invalid JSON.
This MDEV is about adding the latter.
{"report":{"fcp":1085.5999994277954,"ttfb":189.30000019073486,"pageVisibility":"visible","entityId":91878,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"ccbe95ab-bc51-435e-99d2-e41978955540","navigationType":0,"readyForUser":1226.1999998092651,"redirectCount":0,"resourceLoadedEnd":1390.0999994277954,"resourceLoadedStart":194.80000019073486,"resourceTiming":[{"duration":51.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":194.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":194.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":246.30000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":51.59999942779541,"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":195,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":195,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":246.5999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":78.89999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":195.19999980926514,"connectEnd":195.19999980926514,"connectStart":195.19999980926514,"domainLookupEnd":195.19999980926514,"domainLookupStart":195.19999980926514,"fetchStart":195.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":195.19999980926514,"responseEnd":274.0999994277954,"responseStart":274.0999994277954,"secureConnectionStart":195.19999980926514},{"duration":246.60000038146973,"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":195.39999961853027,"connectEnd":195.39999961853027,"connectStart":195.39999961853027,"domainLookupEnd":195.39999961853027,"domainLookupStart":195.39999961853027,"fetchStart":195.39999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":195.39999961853027,"responseEnd":442,"responseStart":442,"secureConnectionStart":195.39999961853027},{"duration":250,"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":195.5999994277954,"connectEnd":195.5999994277954,"connectStart":195.5999994277954,"domainLookupEnd":195.5999994277954,"domainLookupStart":195.5999994277954,"fetchStart":195.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":195.5999994277954,"responseEnd":445.5999994277954,"responseStart":445.5999994277954,"secureConnectionStart":195.5999994277954},{"duration":250.69999980926514,"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":195.80000019073486,"connectEnd":195.80000019073486,"connectStart":195.80000019073486,"domainLookupEnd":195.80000019073486,"domainLookupStart":195.80000019073486,"fetchStart":195.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":195.80000019073486,"responseEnd":446.5,"responseStart":446.5,"secureConnectionStart":195.80000019073486},{"duration":379,"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":195.89999961853027,"connectEnd":195.89999961853027,"connectStart":195.89999961853027,"domainLookupEnd":195.89999961853027,"domainLookupStart":195.89999961853027,"fetchStart":195.89999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":195.89999961853027,"responseEnd":574.8999996185303,"responseStart":574.8999996185303,"secureConnectionStart":195.89999961853027},{"duration":698.8999996185303,"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":196.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":196.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":895.0999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":379,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":196.39999961853027,"connectEnd":196.39999961853027,"connectStart":196.39999961853027,"domainLookupEnd":196.39999961853027,"domainLookupStart":196.39999961853027,"fetchStart":196.39999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":196.39999961853027,"responseEnd":575.3999996185303,"responseStart":575.3999996185303,"secureConnectionStart":196.39999961853027},{"duration":698.5999994277954,"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":196.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":196.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":895.0999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":379.3999996185303,"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":196.69999980926514,"connectEnd":196.69999980926514,"connectStart":196.69999980926514,"domainLookupEnd":196.69999980926514,"domainLookupStart":196.69999980926514,"fetchStart":196.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":196.69999980926514,"responseEnd":576.0999994277954,"responseStart":576.0999994277954,"secureConnectionStart":196.69999980926514},{"duration":1177.6999998092651,"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":205.39999961853027,"connectEnd":205.39999961853027,"connectStart":205.39999961853027,"domainLookupEnd":205.39999961853027,"domainLookupStart":205.39999961853027,"fetchStart":205.39999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":205.39999961853027,"responseEnd":1383.0999994277954,"responseStart":1383.0999994277954,"secureConnectionStart":205.39999961853027},{"duration":1178.5,"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":205.5999994277954,"connectEnd":205.5999994277954,"connectStart":205.5999994277954,"domainLookupEnd":205.5999994277954,"domainLookupStart":205.5999994277954,"fetchStart":205.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":205.5999994277954,"responseEnd":1384.0999994277954,"responseStart":1384.0999994277954,"secureConnectionStart":205.5999994277954},{"duration":327.80000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":473.19999980926514,"connectEnd":473.19999980926514,"connectStart":473.19999980926514,"domainLookupEnd":473.19999980926514,"domainLookupStart":473.19999980926514,"fetchStart":473.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":473.19999980926514,"responseEnd":801,"responseStart":801,"secureConnectionStart":473.19999980926514},{"duration":286.6000003814697,"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":900.1999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":900.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1186.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":484.19999980926514,"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":901.1999998092651,"connectEnd":901.1999998092651,"connectStart":901.1999998092651,"domainLookupEnd":901.1999998092651,"domainLookupStart":901.1999998092651,"fetchStart":901.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":901.1999998092651,"responseEnd":1385.3999996185303,"responseStart":1385.3999996185303,"secureConnectionStart":901.1999998092651},{"duration":488.5999994277954,"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":901.5,"connectEnd":901.5,"connectStart":901.5,"domainLookupEnd":901.5,"domainLookupStart":901.5,"fetchStart":901.5,"redirectEnd":0,"redirectStart":0,"requestStart":901.5,"responseEnd":1390.0999994277954,"responseStart":1390.0999994277954,"secureConnectionStart":901.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":4,"responseStart":190,"responseEnd":205,"domLoading":193,"domInteractive":1426,"domContentLoadedEventStart":1426,"domContentLoadedEventEnd":1490,"domComplete":2662,"loadEventStart":2662,"loadEventEnd":2664,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1401},{"name":"bigPipe.sidebar-id.end","time":1402},{"name":"bigPipe.activity-panel-pipe-id.start","time":1402},{"name":"bigPipe.activity-panel-pipe-id.end","time":1405.1999998092651},{"name":"activityTabFullyLoaded","time":1508}],"measures":[],"correlationId":"9830cbe4ba7a9c","effectiveType":"4g","downlink":9.8,"rtt":0,"serverDuration":105,"dbReadsTimeInMs":12,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}