mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
EXPLAIN FORMAT=JSON: produce the 'ref' column.
This commit is contained in:
@ -64,6 +64,7 @@ EXPLAIN
|
|||||||
"key": "a",
|
"key": "a",
|
||||||
"used_key_parts": "TODO",
|
"used_key_parts": "TODO",
|
||||||
"key_length": "5",
|
"key_length": "5",
|
||||||
|
"ref": ["test.t0.a"],
|
||||||
"rows": 1,
|
"rows": 1,
|
||||||
"filtered": 100
|
"filtered": 100
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ static void push_string(List<Item> *item_list, String *str)
|
|||||||
system_charset_info));
|
system_charset_info));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void push_string_list(List<Item> *item_list, List<char> &lines,
|
static void push_string_list(List<Item> *item_list, String_list &lines,
|
||||||
String *buf)
|
String *buf)
|
||||||
{
|
{
|
||||||
List_iterator_fast<char> it(lines);
|
List_iterator_fast<char> it(lines);
|
||||||
@ -677,10 +677,11 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
|
|||||||
item_list.push_back(item_null);
|
item_list.push_back(item_null);
|
||||||
|
|
||||||
/* `ref` */
|
/* `ref` */
|
||||||
if (ref_set)
|
StringBuffer<64> ref_list_buf;
|
||||||
push_string(&item_list, &ref);
|
if (ref_list.is_empty())
|
||||||
else
|
|
||||||
item_list.push_back(item_null);
|
item_list.push_back(item_null);
|
||||||
|
else
|
||||||
|
push_string_list(&item_list, ref_list, &ref_list_buf);
|
||||||
|
|
||||||
/* `rows` */
|
/* `rows` */
|
||||||
if (rows_set)
|
if (rows_set)
|
||||||
@ -772,6 +773,18 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool String_list::append_str(MEM_ROOT *mem_root, const char *str)
|
||||||
|
{
|
||||||
|
size_t len= strlen(str);
|
||||||
|
char *cp;
|
||||||
|
if (!(cp = (char*)alloc_root(mem_root, len)))
|
||||||
|
return 1;
|
||||||
|
memcpy(cp, str, len+1);
|
||||||
|
push_back(cp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void write_item(Json_writer *writer, Item *item)
|
static void write_item(Json_writer *writer, Item *item)
|
||||||
{
|
{
|
||||||
THD *thd= current_thd;
|
THD *thd= current_thd;
|
||||||
@ -857,12 +870,26 @@ void Explain_table_access::print_explain_json(Json_writer *writer,
|
|||||||
/* `used_key_parts` */
|
/* `used_key_parts` */
|
||||||
if (key_str.length())
|
if (key_str.length())
|
||||||
writer->add_member("used_key_parts").add_str("TODO");
|
writer->add_member("used_key_parts").add_str("TODO");
|
||||||
|
|
||||||
|
/* `key_length` */
|
||||||
StringBuffer<64> key_len_str;
|
StringBuffer<64> key_len_str;
|
||||||
fill_key_len_str(&key_len_str);
|
fill_key_len_str(&key_len_str);
|
||||||
if (key_len_str.length())
|
if (key_len_str.length())
|
||||||
writer->add_member("key_length").add_str(key_len_str);
|
writer->add_member("key_length").add_str(key_len_str);
|
||||||
|
|
||||||
|
/* `ref` */
|
||||||
|
// TODO: need to print this as an array.
|
||||||
|
if (!ref_list.is_empty())
|
||||||
|
{
|
||||||
|
List_iterator_fast<char> it(ref_list);
|
||||||
|
const char *str;
|
||||||
|
writer->add_member("ref").start_array();
|
||||||
|
while ((str= it++))
|
||||||
|
writer->add_str(str);
|
||||||
|
writer->end_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* `rows` */
|
||||||
if (rows_set)
|
if (rows_set)
|
||||||
writer->add_member("rows").add_ll(rows);
|
writer->add_member("rows").add_ll(rows);
|
||||||
|
|
||||||
@ -873,6 +900,7 @@ void Explain_table_access::print_explain_json(Json_writer *writer,
|
|||||||
writer->add_member("r_rows").add_ll(avg_rows);
|
writer->add_member("r_rows").add_ll(avg_rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* `filtered` */
|
||||||
if (filtered_set)
|
if (filtered_set)
|
||||||
writer->add_member("filtered").add_double(filtered);
|
writer->add_member("filtered").add_double(filtered);
|
||||||
|
|
||||||
|
@ -464,6 +464,13 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class String_list: public List<char>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool append_str(MEM_ROOT *mem_root, const char *str);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
EXPLAIN data structure for a single JOIN_TAB.
|
EXPLAIN data structure for a single JOIN_TAB.
|
||||||
*/
|
*/
|
||||||
@ -489,9 +496,8 @@ public:
|
|||||||
StringBuffer<32> used_partitions;
|
StringBuffer<32> used_partitions;
|
||||||
bool used_partitions_set;
|
bool used_partitions_set;
|
||||||
|
|
||||||
/* Empty string means "NULL" will be printed */
|
/* Empty means "NULL" will be printed */
|
||||||
List<char> possible_keys;
|
String_list possible_keys;
|
||||||
//StringBuffer<32> possible_keys_str;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Index use: key name and length.
|
Index use: key name and length.
|
||||||
@ -509,8 +515,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
Explain_index_use hash_next_key;
|
Explain_index_use hash_next_key;
|
||||||
|
|
||||||
bool ref_set; /* not set means 'NULL' should be printed */
|
String_list ref_list;
|
||||||
StringBuffer<32> ref;
|
|
||||||
|
|
||||||
bool rows_set; /* not set means 'NULL' should be printed */
|
bool rows_set; /* not set means 'NULL' should be printed */
|
||||||
ha_rows rows;
|
ha_rows rows;
|
||||||
|
@ -23261,23 +23261,14 @@ void explain_append_mrr_info(QUICK_RANGE_SELECT *quick, String *res)
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// TODO: join with make_possible_keys_line ?
|
int append_possible_keys(MEM_ROOT *alloc, String_list &list, TABLE *table,
|
||||||
int append_possible_keys(MEM_ROOT *alloc, List<char> &list, TABLE *table,
|
|
||||||
key_map possible_keys)
|
key_map possible_keys)
|
||||||
{
|
{
|
||||||
uint j;
|
uint j;
|
||||||
for (j=0 ; j < table->s->keys ; j++)
|
for (j=0 ; j < table->s->keys ; j++)
|
||||||
{
|
{
|
||||||
if (possible_keys.is_set(j))
|
if (possible_keys.is_set(j))
|
||||||
{
|
list.append_str(alloc, table->key_info[j].name);
|
||||||
const char *key_name= table->key_info[j].name;
|
|
||||||
size_t len= strlen(key_name);
|
|
||||||
char *cp;
|
|
||||||
if (!(cp = (char*)alloc_root(alloc, len)))
|
|
||||||
return 1;
|
|
||||||
memcpy(cp, key_name, len+1);
|
|
||||||
list.push_back(cp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -23312,13 +23303,10 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab
|
|||||||
|
|
||||||
TABLE *table=tab->table;
|
TABLE *table=tab->table;
|
||||||
TABLE_LIST *table_list= tab->table->pos_in_table_list;
|
TABLE_LIST *table_list= tab->table->pos_in_table_list;
|
||||||
char buff4[512];
|
|
||||||
my_bool key_read;
|
my_bool key_read;
|
||||||
char table_name_buffer[SAFE_NAME_LEN];
|
char table_name_buffer[SAFE_NAME_LEN];
|
||||||
String tmp4(buff4,sizeof(buff4),cs);
|
|
||||||
KEY *key_info= 0;
|
KEY *key_info= 0;
|
||||||
uint key_len= 0;
|
uint key_len= 0;
|
||||||
tmp4.length(0);
|
|
||||||
quick_type= -1;
|
quick_type= -1;
|
||||||
QUICK_SELECT_I *quick= NULL;
|
QUICK_SELECT_I *quick= NULL;
|
||||||
|
|
||||||
@ -23456,14 +23444,11 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab
|
|||||||
store_key **ref=tab->ref.key_copy;
|
store_key **ref=tab->ref.key_copy;
|
||||||
for (uint kp= 0; kp < tab->ref.key_parts; kp++)
|
for (uint kp= 0; kp < tab->ref.key_parts; kp++)
|
||||||
{
|
{
|
||||||
if (tmp4.length())
|
|
||||||
tmp4.append(',');
|
|
||||||
|
|
||||||
if ((key_part_map(1) << kp) & tab->ref.const_ref_part_map)
|
if ((key_part_map(1) << kp) & tab->ref.const_ref_part_map)
|
||||||
tmp4.append("const");
|
eta->ref_list.append_str(thd->mem_root, "const");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp4.append((*ref)->name(), strlen((*ref)->name()), cs);
|
eta->ref_list.append_str(thd->mem_root, (*ref)->name());
|
||||||
ref++;
|
ref++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23477,17 +23462,7 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab
|
|||||||
table->key_info[tab->index].key_length);
|
table->key_info[tab->index].key_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key_info)
|
if (!key_info)
|
||||||
{
|
|
||||||
if (key_info && tab_type != JT_NEXT)
|
|
||||||
{
|
|
||||||
eta->ref.copy(tmp4);
|
|
||||||
eta->ref_set= true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
eta->ref_set= false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (table_list && /* SJM bushes don't have table_list */
|
if (table_list && /* SJM bushes don't have table_list */
|
||||||
table_list->schema_table &&
|
table_list->schema_table &&
|
||||||
@ -23517,7 +23492,6 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab
|
|||||||
if (key_name_buf.length())
|
if (key_name_buf.length())
|
||||||
eta->key.set(thd->mem_root, key_name_buf.c_ptr_safe(), -1);
|
eta->key.set(thd->mem_root, key_name_buf.c_ptr_safe(), -1);
|
||||||
}
|
}
|
||||||
eta->ref_set= false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* "rows" */
|
/* "rows" */
|
||||||
|
Reference in New Issue
Block a user