Commit 111a752b authored by Weijun-H's avatar Weijun-H

MDEV-19160 JSON_DETAILED output unnecessarily verbose

parent fb0808c4
...@@ -1133,3 +1133,129 @@ DROP TABLE t1; ...@@ -1133,3 +1133,129 @@ DROP TABLE t1;
# #
# End of 10.4 tests # End of 10.4 tests
# #
#
# MDEV-19160 JSON_DETAILED output unnecessarily verbose
#
create table t200 (a text);
insert into t200 values
('{
"steps": [
{
"join_optimization": {
"select_id": 1,
"steps": [
{
"rows_estimation": [
{
"table": "t1",
"range_analysis": {
"table_scan": {
"rows": 1000,
"cost": 2e308
},
"potential_range_indexes": [
{
"index": "a_b",
"usable": true,
"key_parts": ["a", "b"]
}
],
"best_covering_index_scan": {
"index": "a_b",
"cost": 52.195,
"chosen": true
},
"setup_range_conditions": [],
"group_index_range": {
"chosen": false,
"cause": "no group by or distinct"
},
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "a_b",
"ranges": ["2 <= a <= 2 AND 4 <= b <= 4", "123"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 1,
"cost": 1.1752,
"chosen": true
}
],
"analyzing_roworder_intersect": {
"cause": "too few roworder scans"
},
"analyzing_index_merge_union": [],
"test_one_line_array":["123"]
},
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "a_b",
"rows": 1,
"ranges": ["2 <= a <= 2 AND 4 <= b <= 4"]
},
"rows_for_plan": 1,
"cost_for_plan": 1.1752,
"chosen": true
}
}
},
{
"selectivity_for_indexes": [
{
"index_name": "a_b",
"selectivity_from_index": 0.001
}
],
"selectivity_for_columns": [],
"cond_selectivity": 0.001
}
]
}
]
}
},
{
"join_execution": {
"select_id": 1,
"steps": []
}
}
]
}');
select JSON_DETAILED(JSON_EXTRACT(a, '$**.analyzing_range_alternatives')) from t200;
JSON_DETAILED(JSON_EXTRACT(a, '$**.analyzing_range_alternatives'))
[
{
"range_scan_alternatives":
[
{
"index": "a_b",
"ranges":
[
"2 <= a <= 2 AND 4 <= b <= 4",
"123"
],
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 1,
"cost": 1.1752,
"chosen": true
}
],
"analyzing_roworder_intersect":
{
"cause": "too few roworder scans"
},
"analyzing_index_merge_union":
[],
"test_one_line_array":
["123"]
}
]
select JSON_LOOSE(JSON_EXTRACT(a, '$**.analyzing_range_alternatives')) from t200;
JSON_LOOSE(JSON_EXTRACT(a, '$**.analyzing_range_alternatives'))
[{"range_scan_alternatives": [{"index": "a_b", "ranges": ["2 <= a <= 2 AND 4 <= b <= 4", "123"], "rowid_ordered": true, "using_mrr": false, "index_only": true, "rows": 1, "cost": 1.1752, "chosen": true}], "analyzing_roworder_intersect": {"cause": "too few roworder scans"}, "analyzing_index_merge_union": [], "test_one_line_array": ["123"]}]
...@@ -718,3 +718,103 @@ DROP TABLE t1; ...@@ -718,3 +718,103 @@ DROP TABLE t1;
--echo # --echo #
--echo # End of 10.4 tests --echo # End of 10.4 tests
--echo # --echo #
--echo #
--echo # MDEV-19160 JSON_DETAILED output unnecessarily verbose
--echo #
create table t200 (a text);
insert into t200 values
('{
"steps": [
{
"join_optimization": {
"select_id": 1,
"steps": [
{
"rows_estimation": [
{
"table": "t1",
"range_analysis": {
"table_scan": {
"rows": 1000,
"cost": 2e308
},
"potential_range_indexes": [
{
"index": "a_b",
"usable": true,
"key_parts": ["a", "b"]
}
],
"best_covering_index_scan": {
"index": "a_b",
"cost": 52.195,
"chosen": true
},
"setup_range_conditions": [],
"group_index_range": {
"chosen": false,
"cause": "no group by or distinct"
},
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "a_b",
"ranges": ["2 <= a <= 2 AND 4 <= b <= 4", "123"],
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 1,
"cost": 1.1752,
"chosen": true
}
],
"analyzing_roworder_intersect": {
"cause": "too few roworder scans"
},
"analyzing_index_merge_union": [],
"test_one_line_array":["123"]
},
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "a_b",
"rows": 1,
"ranges": ["2 <= a <= 2 AND 4 <= b <= 4"]
},
"rows_for_plan": 1,
"cost_for_plan": 1.1752,
"chosen": true
}
}
},
{
"selectivity_for_indexes": [
{
"index_name": "a_b",
"selectivity_from_index": 0.001
}
],
"selectivity_for_columns": [],
"cond_selectivity": 0.001
}
]
}
]
}
},
{
"join_execution": {
"select_id": 1,
"steps": []
}
}
]
}');
select JSON_DETAILED(JSON_EXTRACT(a, '$**.analyzing_range_alternatives')) from t200;
select JSON_LOOSE(JSON_EXTRACT(a, '$**.analyzing_range_alternatives')) from t200;
This diff is collapsed.
...@@ -23,17 +23,13 @@ EXPLAIN ...@@ -23,17 +23,13 @@ EXPLAIN
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[ [
{ {
"range_scan_alternatives": "range_scan_alternatives":
[ [
{ {
"index": "col1", "index": "col1",
"ranges": "ranges":
[ ["(a) <= (col1)"],
"(a) <= (col1)"
],
"rowid_ordered": false, "rowid_ordered": false,
"using_mrr": false, "using_mrr": false,
"index_only": false, "index_only": false,
...@@ -47,8 +43,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) ...@@ -47,8 +43,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "too few roworder scans" "cause": "too few roworder scans"
}, },
"analyzing_index_merge_union": "analyzing_index_merge_union":
[ []
]
} }
] ]
drop table t1; drop table t1;
...@@ -20,7 +20,6 @@ select json_detailed(JSON_EXTRACT(trace, '$**.ranges')) ...@@ -20,7 +20,6 @@ select json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
from information_schema.optimizer_trace; from information_schema.optimizer_trace;
json_detailed(JSON_EXTRACT(trace, '$**.ranges')) json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
[ [
[ [
"(1) <= (key1) <= (1)", "(1) <= (key1) <= (1)",
"(2) <= (key1) <= (2)", "(2) <= (key1) <= (2)",
......
...@@ -110,16 +110,13 @@ json_detailed(priv) ...@@ -110,16 +110,13 @@ json_detailed(priv)
"authentication_string": "*7D8C3DF236D9163B6C274A9D47704BC496988460", "authentication_string": "*7D8C3DF236D9163B6C274A9D47704BC496988460",
"auth_or": "auth_or":
[ [
{ {
"plugin": "ed25519", "plugin": "ed25519",
"authentication_string": "F4aF8bw7130VaRbdLCl4f/P/wkjDmgJXwWvpJ5gmsZc" "authentication_string": "F4aF8bw7130VaRbdLCl4f/P/wkjDmgJXwWvpJ5gmsZc"
}, },
{ {
"plugin": "unix_socket" "plugin": "unix_socket"
}, },
{ {
} }
], ],
......
...@@ -257,16 +257,22 @@ static int json_nice(json_engine_t *je, String *nice_js, ...@@ -257,16 +257,22 @@ static int json_nice(json_engine_t *je, String *nice_js,
Item_func_json_format::formats mode, int tab_size=4) Item_func_json_format::formats mode, int tab_size=4)
{ {
int depth= 0; int depth= 0;
const char *comma, *colon; static const char *comma= ", ", *colon= "\": ";
uint comma_len, colon_len; uint comma_len, colon_len;
int first_value= 1; int first_value= 1;
int value_size = 0;
DBUG_ASSERT(je->s.cs == nice_js->charset()); int curr_state= -1;
int64_t value_len= 0;
String curr_str{};
nice_js->length(0);
nice_js->set_charset(je->s.cs);
nice_js->alloc(je->s.str_end - je->s.c_str + 32);
DBUG_ASSERT(mode != Item_func_json_format::DETAILED || DBUG_ASSERT(mode != Item_func_json_format::DETAILED ||
(tab_size >= 0 && tab_size <= TAB_SIZE_LIMIT)); (tab_size >= 0 && tab_size <= TAB_SIZE_LIMIT));
comma= ", ";
colon= "\": ";
if (mode == Item_func_json_format::LOOSE) if (mode == Item_func_json_format::LOOSE)
{ {
comma_len= 2; comma_len= 2;
...@@ -285,6 +291,7 @@ static int json_nice(json_engine_t *je, String *nice_js, ...@@ -285,6 +291,7 @@ static int json_nice(json_engine_t *je, String *nice_js,
do do
{ {
curr_state= je->state;
switch (je->state) switch (je->state)
{ {
case JST_KEY: case JST_KEY:
...@@ -307,7 +314,7 @@ static int json_nice(json_engine_t *je, String *nice_js, ...@@ -307,7 +314,7 @@ static int json_nice(json_engine_t *je, String *nice_js,
append_tab(nice_js, depth, tab_size)) append_tab(nice_js, depth, tab_size))
goto error; goto error;
nice_js->append("\"", 1); nice_js->append('"');
append_simple(nice_js, key_start, key_end - key_start); append_simple(nice_js, key_start, key_end - key_start);
nice_js->append(colon, colon_len); nice_js->append(colon, colon_len);
} }
...@@ -332,17 +339,23 @@ static int json_nice(json_engine_t *je, String *nice_js, ...@@ -332,17 +339,23 @@ static int json_nice(json_engine_t *je, String *nice_js,
if (append_simple(nice_js, je->value_begin, if (append_simple(nice_js, je->value_begin,
je->value_end - je->value_begin)) je->value_end - je->value_begin))
goto error; goto error;
curr_str.copy((const char *)je->value_begin,
je->value_end - je->value_begin, je->s.cs);
value_len= je->value_end - je->value_begin;
first_value= 0; first_value= 0;
if (value_size != -1)
value_size++;
} }
else else
{ {
if (mode == Item_func_json_format::DETAILED && if (mode == Item_func_json_format::DETAILED &&
depth > 0 && depth > 0 && !(curr_state != JST_KEY) &&
append_tab(nice_js, depth, tab_size)) append_tab(nice_js, depth, tab_size))
goto error; goto error;
nice_js->append((je->value_type == JSON_VALUE_OBJECT) ? "{" : "[", 1); nice_js->append((je->value_type == JSON_VALUE_OBJECT) ? "{" : "[", 1);
first_value= 1; first_value= 1;
value_size= (je->value_type == JSON_VALUE_OBJECT) ? -1: 0;
depth++; depth++;
} }
...@@ -351,11 +364,27 @@ static int json_nice(json_engine_t *je, String *nice_js, ...@@ -351,11 +364,27 @@ static int json_nice(json_engine_t *je, String *nice_js,
case JST_OBJ_END: case JST_OBJ_END:
case JST_ARRAY_END: case JST_ARRAY_END:
depth--; depth--;
if (mode == Item_func_json_format::DETAILED && if (mode == Item_func_json_format::DETAILED && (value_size > 1 || value_size == -1) &&
append_tab(nice_js, depth, tab_size)) append_tab(nice_js, depth, tab_size))
goto error; goto error;
if (mode == Item_func_json_format::DETAILED &&
value_size == 1 && je->state != JST_OBJ_END)
{
for (auto i = 0; i < value_len; i++)
{
nice_js->chop();
}
for (auto i = 0; i < (depth + 1) * tab_size + 1; i++)
{
nice_js->chop();
}
nice_js->append(curr_str);
}
nice_js->append((je->state == JST_OBJ_END) ? "}": "]", 1); nice_js->append((je->state == JST_OBJ_END) ? "}": "]", 1);
first_value= 0; first_value= 0;
value_size= -1;
break; break;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment