Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
10.4(EOL), 10.5
Description
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.
Attachments
Issue Links
- is blocked by
-
MDEV-26929 Make the main testsuite runnable with optimizer trace enabled
- Closed
- relates to
-
MDEV-27036 Json_writer allows one to create duplicate object members
- Closed