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;
#
# 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;
--echo #
--echo # End of 10.4 tests
--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
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[
{
"range_scan_alternatives":
[
{
"index": "col1",
"ranges":
[
"(a) <= (col1)"
],
["(a) <= (col1)"],
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
......@@ -47,8 +43,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "too few roworder scans"
},
"analyzing_index_merge_union":
[
]
[]
}
]
drop table t1;
......@@ -20,7 +20,6 @@ select json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
from information_schema.optimizer_trace;
json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
[
[
"(1) <= (key1) <= (1)",
"(2) <= (key1) <= (2)",
......
......@@ -110,16 +110,13 @@ json_detailed(priv)
"authentication_string": "*7D8C3DF236D9163B6C274A9D47704BC496988460",
"auth_or":
[
{
"plugin": "ed25519",
"authentication_string": "F4aF8bw7130VaRbdLCl4f/P/wkjDmgJXwWvpJ5gmsZc"
},
{
"plugin": "unix_socket"
},
{
}
],
......
......@@ -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)
{
int depth= 0;
const char *comma, *colon;
static const char *comma= ", ", *colon= "\": ";
uint comma_len, colon_len;
int first_value= 1;
DBUG_ASSERT(je->s.cs == nice_js->charset());
int value_size = 0;
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 ||
(tab_size >= 0 && tab_size <= TAB_SIZE_LIMIT));
comma= ", ";
colon= "\": ";
if (mode == Item_func_json_format::LOOSE)
{
comma_len= 2;
......@@ -285,6 +291,7 @@ static int json_nice(json_engine_t *je, String *nice_js,
do
{
curr_state= je->state;
switch (je->state)
{
case JST_KEY:
......@@ -307,7 +314,7 @@ static int json_nice(json_engine_t *je, String *nice_js,
append_tab(nice_js, depth, tab_size))
goto error;
nice_js->append("\"", 1);
nice_js->append('"');
append_simple(nice_js, key_start, key_end - key_start);
nice_js->append(colon, colon_len);
}
......@@ -332,17 +339,23 @@ static int json_nice(json_engine_t *je, String *nice_js,
if (append_simple(nice_js, je->value_begin,
je->value_end - je->value_begin))
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;
if (value_size != -1)
value_size++;
}
else
{
if (mode == Item_func_json_format::DETAILED &&
depth > 0 &&
depth > 0 && !(curr_state != JST_KEY) &&
append_tab(nice_js, depth, tab_size))
goto error;
nice_js->append((je->value_type == JSON_VALUE_OBJECT) ? "{" : "[", 1);
first_value= 1;
value_size= (je->value_type == JSON_VALUE_OBJECT) ? -1: 0;
depth++;
}
......@@ -351,11 +364,27 @@ static int json_nice(json_engine_t *je, String *nice_js,
case JST_OBJ_END:
case JST_ARRAY_END:
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))
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);
first_value= 0;
value_size= -1;
break;
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