Commit a118c20c authored by Varun Gupta's avatar Varun Gupta

MDEV-10844: EXPLAIN FORMAT=JSON doesn't show order direction for filesort

Currently explain format=json does not show the order direction of fields used during filesort.
This patch would remove this limitation
parent 8bcbcac0
......@@ -1582,3 +1582,63 @@ EXPLAIN
}
}
drop table t0,t1;
#
# MDEV-10844: EXPLAIN FORMAT=JSON doesn't show order direction for filesort
#
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(2,3);
explain format=json select * from t1 order by a, b desc;
EXPLAIN
{
"query_block": {
"select_id": 1,
"read_sorted_file": {
"filesort": {
"sort_key": "t1.a, t1.b desc",
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100
}
}
}
}
}
explain format=json select * from t1 order by a desc, b desc;
EXPLAIN
{
"query_block": {
"select_id": 1,
"read_sorted_file": {
"filesort": {
"sort_key": "t1.a desc, t1.b desc",
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100
}
}
}
}
}
explain format=json select * from t1 order by a desc, b ;
EXPLAIN
{
"query_block": {
"select_id": 1,
"read_sorted_file": {
"filesort": {
"sort_key": "t1.a desc, t1.b",
"table": {
"table_name": "t1",
"access_type": "ALL",
"rows": 3,
"filtered": 100
}
}
}
}
}
drop table t1;
......@@ -1779,7 +1779,7 @@ EXPLAIN
"query_block": {
"select_id": 1,
"filesort": {
"sort_key": "row_number() over ( order by t1.s1,t1.s2)",
"sort_key": "row_number() over ( order by t1.s1,t1.s2) desc",
"window_functions_computation": {
"sorts": {
"filesort": {
......
......@@ -406,3 +406,14 @@ explain format=json
select a, (select max(a) from t1 where t0.a<5 and t1.b<t0.a) from t0;
drop table t0,t1;
--echo #
--echo # MDEV-10844: EXPLAIN FORMAT=JSON doesn't show order direction for filesort
--echo #
create table t1 (a int, b int);
insert into t1 values (1,2),(3,4),(2,3);
explain format=json select * from t1 order by a, b desc;
explain format=json select * from t1 order by a desc, b desc;
explain format=json select * from t1 order by a desc, b ;
drop table t1;
......@@ -927,6 +927,7 @@ Explain_aggr_filesort::Explain_aggr_filesort(MEM_ROOT *mem_root,
for (ORDER *ord= filesort->order; ord; ord= ord->next)
{
sort_items.push_back(ord->item[0], mem_root);
sort_directions.push_back(&ord->direction, mem_root);
}
filesort->tracker= &tracker;
}
......@@ -940,10 +941,13 @@ void Explain_aggr_filesort::print_json_members(Json_writer *writer,
str.length(0);
List_iterator_fast<Item> it(sort_items);
Item *item;
List_iterator_fast<ORDER::enum_order> it_dir(sort_directions);
Item* item;
ORDER::enum_order *direction;
bool first= true;
while ((item= it++))
{
direction= it_dir++;
if (first)
first= false;
else
......@@ -951,6 +955,8 @@ void Explain_aggr_filesort::print_json_members(Json_writer *writer,
str.append(", ");
}
append_item_to_str(&str, item);
if (*direction == ORDER::ORDER_DESC)
str.append(" desc");
}
writer->add_member("sort_key").add_str(str.c_ptr_safe());
......
......@@ -282,6 +282,7 @@ class Explain_aggr_node : public Sql_alloc
class Explain_aggr_filesort : public Explain_aggr_node
{
List<Item> sort_items;
List<ORDER::enum_order> sort_directions;
public:
enum_explain_aggr_node_type get_type() { return AGGR_OP_FILESORT; }
Filesort_tracker tracker;
......
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