Commit d2ea53aa authored by Sergey Petrunya's avatar Sergey Petrunya

[SHOW] EXPLAIN UPDATE/DELETE, code re-architecting

- Pass more tests
- select with subselects is now shown with type=PRIMARY where it used to be (incorrectly) 'SIMPLE' 
parent 1ec99931
...@@ -386,7 +386,7 @@ materialized derived in merged derived ...@@ -386,7 +386,7 @@ materialized derived in merged derived
explain extended select * from (select * from explain extended select * from (select * from
(select * from t1 where f1 < 7 group by f1) tt where f1 > 2) zz; (select * from t1 where f1 < 7 group by f1) tt where f1 > 2) zz;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where 1 PRIMARY <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort 3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort
Warnings: Warnings:
Note 1003 select `tt`.`f1` AS `f1`,`tt`.`f11` AS `f11` from (select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f11` AS `f11` from `test`.`t1` where (`test`.`t1`.`f1` < 7) group by `test`.`t1`.`f1`) `tt` where (`tt`.`f1` > 2) Note 1003 select `tt`.`f1` AS `f1`,`tt`.`f11` AS `f11` from (select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f11` AS `f11` from `test`.`t1` where (`test`.`t1`.`f1` < 7) group by `test`.`t1`.`f1`) `tt` where (`tt`.`f1` > 2)
...@@ -429,8 +429,8 @@ join ...@@ -429,8 +429,8 @@ join
(select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2) z (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2) z
on x.f1 = z.f1; on x.f1 = z.f1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where 1 PRIMARY <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where
1 SIMPLE <derived5> ref key0 key0 5 tt.f1 2 100.00 1 PRIMARY <derived5> ref key0 key0 5 tt.f1 2 100.00
5 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort 5 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort
3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort 3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort
Warnings: Warnings:
...@@ -522,7 +522,7 @@ materialized view in merged derived ...@@ -522,7 +522,7 @@ materialized view in merged derived
explain extended explain extended
select * from ( select * from v1 where f1 < 7) tt; select * from ( select * from v1 where f1 < 7) tt;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where 1 PRIMARY <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using temporary; Using filesort 3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using temporary; Using filesort
Warnings: Warnings:
Note 1003 select `v1`.`f1` AS `f1`,`v1`.`f11` AS `f11` from `test`.`v1` where (`v1`.`f1` < 7) Note 1003 select `v1`.`f1` AS `f1`,`v1`.`f11` AS `f11` from `test`.`v1` where (`v1`.`f1` < 7)
...@@ -568,8 +568,8 @@ f1 f11 ...@@ -568,8 +568,8 @@ f1 f11
join of above two join of above two
explain extended select * from v6 join v7 on f2=f1; explain extended select * from v6 join v7 on f2=f1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 11 100.00 Using where 1 PRIMARY t2 ALL NULL NULL NULL NULL 11 100.00 Using where
1 SIMPLE <derived5> ref key0 key0 5 test.t2.f2 2 100.00 1 PRIMARY <derived5> ref key0 key0 5 test.t2.f2 2 100.00
5 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using temporary; Using filesort 5 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using temporary; Using filesort
Warnings: Warnings:
Note 1003 select `test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f22` AS `f22`,`v1`.`f1` AS `f1`,`v1`.`f11` AS `f11` from `test`.`t2` join `test`.`v1` where ((`v1`.`f1` = `test`.`t2`.`f2`) and (`test`.`t2`.`f2` < 7) and (`test`.`t2`.`f2` in (2,3))) Note 1003 select `test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f22` AS `f22`,`v1`.`f1` AS `f1`,`v1`.`f11` AS `f11` from `test`.`t2` join `test`.`v1` where ((`v1`.`f1` = `test`.`t2`.`f2`) and (`test`.`t2`.`f2` < 7) and (`test`.`t2`.`f2` in (2,3)))
...@@ -1220,7 +1220,7 @@ Note 1003 select `test`.`t1`.`b` AS `b` from `test`.`t1` where 0 ...@@ -1220,7 +1220,7 @@ Note 1003 select `test`.`t1`.`b` AS `b` from `test`.`t1` where 0
EXPLAIN EXTENDED EXPLAIN EXTENDED
SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b; SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
3 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort 3 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort
Warnings: Warnings:
Note 1003 select `v2`.`b` AS `b` from `test`.`v2` where 0 Note 1003 select `v2`.`b` AS `b` from `test`.`v2` where 0
......
...@@ -393,7 +393,7 @@ and not exists (select * from orders where o_custkey = c_custkey) ...@@ -393,7 +393,7 @@ and not exists (select * from orders where o_custkey = c_custkey)
group by cntrycode group by cntrycode
order by cntrycode; order by cntrycode;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort 1 PRIMARY customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort
4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index 4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index
3 SUBQUERY customer ALL NULL NULL NULL NULL 150 100.00 Using where 3 SUBQUERY customer ALL NULL NULL NULL NULL 150 100.00 Using where
Warnings: Warnings:
...@@ -434,7 +434,7 @@ and not exists (select * from orders where o_custkey = c_custkey) ...@@ -434,7 +434,7 @@ and not exists (select * from orders where o_custkey = c_custkey)
group by cntrycode group by cntrycode
order by cntrycode; order by cntrycode;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort 1 PRIMARY customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort
4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index 4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index
3 SUBQUERY customer ALL NULL NULL NULL NULL 150 91.00 Using where 3 SUBQUERY customer ALL NULL NULL NULL NULL 150 91.00 Using where
Warnings: Warnings:
......
...@@ -396,7 +396,7 @@ and not exists (select * from orders where o_custkey = c_custkey) ...@@ -396,7 +396,7 @@ and not exists (select * from orders where o_custkey = c_custkey)
group by cntrycode group by cntrycode
order by cntrycode; order by cntrycode;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort 1 PRIMARY customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort
4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index 4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index
3 SUBQUERY customer ALL NULL NULL NULL NULL 150 100.00 Using where 3 SUBQUERY customer ALL NULL NULL NULL NULL 150 100.00 Using where
Warnings: Warnings:
...@@ -437,7 +437,7 @@ and not exists (select * from orders where o_custkey = c_custkey) ...@@ -437,7 +437,7 @@ and not exists (select * from orders where o_custkey = c_custkey)
group by cntrycode group by cntrycode
order by cntrycode; order by cntrycode;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort 1 PRIMARY customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort
4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index 4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index
3 SUBQUERY customer ALL NULL NULL NULL NULL 150 91.00 Using where 3 SUBQUERY customer ALL NULL NULL NULL NULL 150 91.00 Using where
Warnings: Warnings:
......
...@@ -258,7 +258,7 @@ WHERE date < '2012-12-12 12:12:12' ...@@ -258,7 +258,7 @@ WHERE date < '2012-12-12 12:12:12'
ORDER BY mirror_date ASC ORDER BY mirror_date ASC
) AS calculated_result; ) AS calculated_result;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE <derived2> ALL NULL NULL NULL NULL 2 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
2 DERIVED t1 range date date 9 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using filesort 2 DERIVED t1 range date date 9 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using filesort
SELECT * FROM ( SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result SELECT node_uid, date, mirror_date, @result := 0 AS result
...@@ -281,7 +281,7 @@ WHERE date < '2012-12-12 12:12:12' ...@@ -281,7 +281,7 @@ WHERE date < '2012-12-12 12:12:12'
ORDER BY mirror_date ASC ORDER BY mirror_date ASC
) AS calculated_result; ) AS calculated_result;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE <derived2> ALL NULL NULL NULL NULL 2 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
2 DERIVED t1 range date date 9 NULL 2 Using index condition; Using where; Using filesort 2 DERIVED t1 range date date 9 NULL 2 Using index condition; Using where; Using filesort
SELECT * FROM ( SELECT * FROM (
SELECT node_uid, date, mirror_date, @result := 0 AS result SELECT node_uid, date, mirror_date, @result := 0 AS result
......
...@@ -13,7 +13,7 @@ select (select 2); ...@@ -13,7 +13,7 @@ select (select 2);
2 2
explain extended select (select 2); explain extended select (select 2);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1249 Select 2 was reduced during optimization Note 1249 Select 2 was reduced during optimization
Note 1003 select 2 AS `(select 2)` Note 1003 select 2 AS `(select 2)`
...@@ -737,7 +737,7 @@ id ...@@ -737,7 +737,7 @@ id
1 1
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ref id id 5 const 1 100.00 Using index 1 SIMPLE t2 ref id id 5 const 1 100.00 Using index
Warnings: Warnings:
Note 1249 Select 2 was reduced during optimization Note 1249 Select 2 was reduced during optimization
Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1) Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1)
...@@ -749,7 +749,7 @@ id ...@@ -749,7 +749,7 @@ id
2 2
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ref id id 5 const 1 100.00 Using where; Using index 1 SIMPLE t2 ref id id 5 const 1 100.00 Using where; Using index
Warnings: Warnings:
Note 1249 Select 3 was reduced during optimization Note 1249 Select 3 was reduced during optimization
Note 1249 Select 2 was reduced during optimization Note 1249 Select 2 was reduced during optimization
...@@ -883,7 +883,7 @@ select 10.5 > ANY (SELECT * from t1); ...@@ -883,7 +883,7 @@ select 10.5 > ANY (SELECT * from t1);
1 1
explain extended select (select a+1) from t1; explain extended select (select a+1) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
Note 1249 Select 2 was reduced during optimization Note 1249 Select 2 was reduced during optimization
...@@ -4552,7 +4552,7 @@ int_nokey int_key ...@@ -4552,7 +4552,7 @@ int_nokey int_key
0 0 0 0
EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`); EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY C ALL NULL NULL NULL NULL 20 100.00 Using where 1 SIMPLE C ALL NULL NULL NULL NULL 20 100.00 Using where
DROP TABLE C; DROP TABLE C;
# End of test for bug#45061. # End of test for bug#45061.
# #
...@@ -6107,7 +6107,7 @@ FROM t1 AS sq4_alias1 ...@@ -6107,7 +6107,7 @@ FROM t1 AS sq4_alias1
WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR
sq4_alias1.col_varchar_key = @var3 ) AS alias3; sq4_alias1.col_varchar_key = @var3 ) AS alias3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE <derived2> system NULL NULL NULL NULL 0 const row not found 1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found
2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
SELECT * FROM ( SELECT @var3:=12, sq4_alias1.* SELECT * FROM ( SELECT @var3:=12, sq4_alias1.*
FROM t1 AS sq4_alias1 FROM t1 AS sq4_alias1
...@@ -6152,7 +6152,7 @@ FROM t2 AS c_sq1_alias1 ...@@ -6152,7 +6152,7 @@ FROM t2 AS c_sq1_alias1
WHERE (c_sq1_alias1.col_int_nokey != @var2 WHERE (c_sq1_alias1.col_int_nokey != @var2
OR c_sq1_alias1.pk != @var3)) ) AS alias3; OR c_sq1_alias1.pk != @var3)) ) AS alias3;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1 3 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1
SELECT * FROM ( SELECT sq4_alias1.* SELECT * FROM ( SELECT sq4_alias1.*
FROM t1 AS sq4_alias1 FROM t1 AS sq4_alias1
......
...@@ -99,9 +99,9 @@ int QPF_union::print_explain(QPF_query *query, select_result_sink *output, ...@@ -99,9 +99,9 @@ int QPF_union::print_explain(QPF_query *query, select_result_sink *output,
uint8 explain_flags) uint8 explain_flags)
{ {
// print all children, in order // print all children, in order
for (int i= 0; i < (int) children.elements(); i++) for (int i= 0; i < (int) union_members.elements(); i++)
{ {
QPF_select *sel= query->get_select(children.at(i)); QPF_select *sel= query->get_select(union_members.at(i));
sel->print_explain(query, output, explain_flags); sel->print_explain(query, output, explain_flags);
} }
...@@ -123,15 +123,15 @@ int QPF_union::print_explain(QPF_query *query, select_result_sink *output, ...@@ -123,15 +123,15 @@ int QPF_union::print_explain(QPF_query *query, select_result_sink *output,
uint len= 6, lastop= 0; uint len= 6, lastop= 0;
memcpy(table_name_buffer, STRING_WITH_LEN("<union")); memcpy(table_name_buffer, STRING_WITH_LEN("<union"));
for (; childno < children.elements() && len + lastop + 5 < NAME_LEN; for (; childno < union_members.elements() && len + lastop + 5 < NAME_LEN;
childno++) childno++)
{ {
len+= lastop; len+= lastop;
lastop= my_snprintf(table_name_buffer + len, NAME_LEN - len, lastop= my_snprintf(table_name_buffer + len, NAME_LEN - len,
"%u,", children.at(childno)); "%u,", union_members.at(childno));
} }
if (childno < children.elements() || len + lastop >= NAME_LEN) if (childno < union_members.elements() || len + lastop >= NAME_LEN)
{ {
memcpy(table_name_buffer + len, STRING_WITH_LEN("...>") + 1); memcpy(table_name_buffer + len, STRING_WITH_LEN("...>") + 1);
len+= 4; len+= 4;
...@@ -184,6 +184,13 @@ int QPF_union::print_explain(QPF_query *query, select_result_sink *output, ...@@ -184,6 +184,13 @@ int QPF_union::print_explain(QPF_query *query, select_result_sink *output,
if (output->send_data(item_list)) if (output->send_data(item_list))
return 1; return 1;
for (int i= 0; i < (int) children.elements(); i++)
{
QPF_node *node= query->get_node(children.at(i));
node->print_explain(query, output, explain_flags);
}
return 0; return 0;
} }
...@@ -222,7 +229,6 @@ int QPF_select::print_explain(QPF_query *query, select_result_sink *output, ...@@ -222,7 +229,6 @@ int QPF_select::print_explain(QPF_query *query, select_result_sink *output,
if (output->send_data(item_list)) if (output->send_data(item_list))
return 1; return 1;
return 0;
} }
else else
{ {
...@@ -244,7 +250,6 @@ int QPF_select::print_explain(QPF_query *query, select_result_sink *output, ...@@ -244,7 +250,6 @@ int QPF_select::print_explain(QPF_query *query, select_result_sink *output,
} }
} }
//psergey-TODO: print children here...
for (int i= 0; i < (int) children.elements(); i++) for (int i= 0; i < (int) children.elements(); i++)
{ {
QPF_node *node= query->get_node(children.at(i)); QPF_node *node= query->get_node(children.at(i));
...@@ -262,11 +267,17 @@ int QPF_table_access::print_explain(select_result_sink *output, uint8 explain_fl ...@@ -262,11 +267,17 @@ int QPF_table_access::print_explain(select_result_sink *output, uint8 explain_fl
Item *item_null= new Item_null(); Item *item_null= new Item_null();
//const CHARSET_INFO *cs= system_charset_info; //const CHARSET_INFO *cs= system_charset_info;
if (sjm_nest_select_id)
select_id= sjm_nest_select_id;
/* `id` column */ /* `id` column */
item_list.push_back(new Item_int((int32) select_id)); item_list.push_back(new Item_int((int32) select_id));
/* `select_type` column */ /* `select_type` column */
push_str(&item_list, select_type); if (sjm_nest_select_id)
push_str(&item_list, "MATERIALIZED");
else
push_str(&item_list, select_type);
/* `table` column */ /* `table` column */
push_string(&item_list, &table_name); push_string(&item_list, &table_name);
...@@ -440,6 +451,18 @@ void QPF_table_access::append_tag_name(String *str, enum Extra_tag tag) ...@@ -440,6 +451,18 @@ void QPF_table_access::append_tag_name(String *str, enum Extra_tag tag)
str->append(join_buffer_type); str->append(join_buffer_type);
break; break;
} }
case ET_FIRST_MATCH:
{
if (firstmatch_table_name.length())
{
str->append("FirstMatch(");
str->append(firstmatch_table_name);
str->append(")");
}
else
str->append(extra_tag_text[tag]);
break;
}
default: default:
str->append(extra_tag_text[tag]); str->append(extra_tag_text[tag]);
} }
......
...@@ -23,6 +23,14 @@ class QPF_node : public Sql_alloc ...@@ -23,6 +23,14 @@ class QPF_node : public Sql_alloc
virtual enum qpf_node_type get_type()= 0; virtual enum qpf_node_type get_type()= 0;
virtual int print_explain(QPF_query *query, select_result_sink *output, virtual int print_explain(QPF_query *query, select_result_sink *output,
uint8 explain_flags)=0; uint8 explain_flags)=0;
Dynamic_array<int> children;
void add_child(int select_no)
{
children.append(select_no);
}
virtual ~QPF_node(){} virtual ~QPF_node(){}
}; };
...@@ -90,13 +98,6 @@ class QPF_select : public QPF_node ...@@ -90,13 +98,6 @@ class QPF_select : public QPF_node
bool using_temporary; bool using_temporary;
bool using_filesort; bool using_filesort;
/* Child selects. TODO: join this with QPF_union's children? */
Dynamic_array<int> children;
void add_child(int select_no)
{
children.append(select_no);
}
void print_tabular(select_result_sink *output, uint8 explain_flags//, void print_tabular(select_result_sink *output, uint8 explain_flags//,
//bool *printed_anything //bool *printed_anything
); );
...@@ -113,15 +114,26 @@ class QPF_union : public QPF_node ...@@ -113,15 +114,26 @@ class QPF_union : public QPF_node
int get_select_id() int get_select_id()
{ {
DBUG_ASSERT(children.elements() > 0); DBUG_ASSERT(union_members.elements() > 0);
return children.at(0); return union_members.at(0);
} }
// This has QPF_select children /*
Dynamic_array<int> children; Members of the UNION. Note: these are disjoint from UNION's "children".
Example:
(select * from t1) union
(select * from t2) order by (select col1 from t3 ...)
here
- select-from-t1 and select-from-t2 are "union members"
- select-from-t3 is the only "child".
*/
Dynamic_array<int> union_members;
void add_select(int select_no) void add_select(int select_no)
{ {
children.append(select_no); union_members.append(select_no);
} }
void push_table_name(List<Item> *item_list); void push_table_name(List<Item> *item_list);
int print_explain(QPF_query *query, select_result_sink *output, int print_explain(QPF_query *query, select_result_sink *output,
...@@ -204,56 +216,66 @@ class QPF_table_access : public Sql_alloc ...@@ -204,56 +216,66 @@ class QPF_table_access : public Sql_alloc
/* Internals */ /* Internals */
public: public:
/*
0 means this tab is not inside SJM nest and should use QPF_select's id
other value means the tab is inside an SJM nest.
*/
int sjm_nest_select_id;
/* id and 'select_type' are cared-of by the parent QPF_select */ /* id and 'select_type' are cared-of by the parent QPF_select */
TABLE *table; TABLE *table;
StringBuffer<256> table_name; StringBuffer<64> table_name;
enum join_type type; enum join_type type;
StringBuffer<256> used_partitions; StringBuffer<64> used_partitions;
bool used_partitions_set; bool used_partitions_set;
key_map possible_keys; key_map possible_keys;
StringBuffer<256> possible_keys_str; StringBuffer<64> possible_keys_str;
/* Not used? */
uint key_no; uint key_no;
uint key_length; uint key_length;
Dynamic_array<enum Extra_tag> extra_tags; Dynamic_array<enum Extra_tag> extra_tags;
//temporary: //temporary:
StringBuffer<256> key; bool key_set; /* not set means 'NULL' should be printed */
StringBuffer<256> key_len; StringBuffer<64> key;
StringBuffer<256> ref;
bool key_set; bool key_len_set; /* not set means 'NULL' should be printed */
bool key_len_set; StringBuffer<64> key_len;
bool ref_set;
bool ref_set; /* not set means 'NULL' should be printed */
StringBuffer<64> ref;
bool rows_set; bool rows_set;
ha_rows rows; ha_rows rows;
double filtered;
bool filtered_set; bool filtered_set;
double filtered;
/* Various stuff for 'Extra' column*/ /* Various stuff for 'Extra' column*/
uint join_cache_level; uint join_cache_level;
// Valid if ET_USING tag is present // Valid if ET_USING tag is present
StringBuffer<256> quick_info; StringBuffer<64> quick_info;
// Valid if ET_USING_INDEX_FOR_GROUP_BY is present // Valid if ET_USING_INDEX_FOR_GROUP_BY is present
StringBuffer<256> loose_scan_type; StringBuffer<64> loose_scan_type;
// valid with ET_RANGE_CHECKED_FOR_EACH_RECORD // valid with ET_RANGE_CHECKED_FOR_EACH_RECORD
key_map range_checked_map; key_map range_checked_map;
// valid with ET_USING_MRR // valid with ET_USING_MRR
StringBuffer <256> mrr_type; StringBuffer <64> mrr_type;
// valid with ET_USING_JOIN_BUFFER // valid with ET_USING_JOIN_BUFFER
StringBuffer <256> join_buffer_type; StringBuffer <64> join_buffer_type;
TABLE *firstmatch_table; //TABLE *firstmatch_table;
StringBuffer<64> firstmatch_table_name;
int print_explain(select_result_sink *output, uint8 explain_flags, int print_explain(select_result_sink *output, uint8 explain_flags,
uint select_id, const char *select_type, uint select_id, const char *select_type,
......
...@@ -22308,7 +22308,7 @@ void explain_append_mrr_info(QUICK_RANGE_SELECT *quick, String *res) ...@@ -22308,7 +22308,7 @@ void explain_append_mrr_info(QUICK_RANGE_SELECT *quick, String *res)
sizeof(mrr_str_buf)); sizeof(mrr_str_buf));
if (len > 0) if (len > 0)
{ {
res->append(STRING_WITH_LEN("; ")); //res->append(STRING_WITH_LEN("; "));
res->append(mrr_str_buf, len); res->append(mrr_str_buf, len);
} }
} }
...@@ -22929,7 +22929,7 @@ void append_possible_keys(String *str, TABLE *table, key_map possible_keys) ...@@ -22929,7 +22929,7 @@ void append_possible_keys(String *str, TABLE *table, key_map possible_keys)
int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
bool distinct, const char *message) bool distinct, const char *message)
{ {
QPF_select *qp_sel= NULL; QPF_node *qp_node;
const bool on_the_fly= true; const bool on_the_fly= true;
JOIN *join= this; /* Legacy: this code used to be a non-member function */ JOIN *join= this; /* Legacy: this code used to be a non-member function */
...@@ -22951,7 +22951,8 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -22951,7 +22951,8 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
*/ */
if (message) if (message)
{ {
qp_sel= new QPF_select; QPF_select *qp_sel;
qp_node= qp_sel= new QPF_select;
join->select_lex->set_explain_type(on_the_fly); join->select_lex->set_explain_type(on_the_fly);
qp_sel->select_id= join->select_lex->select_number; qp_sel->select_id= join->select_lex->select_number;
...@@ -22964,6 +22965,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -22964,6 +22965,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
{ {
select_lex->set_explain_type(on_the_fly); select_lex->set_explain_type(on_the_fly);
QPF_union *qp_union= new QPF_union; QPF_union *qp_union= new QPF_union;
qp_node= qp_union;
SELECT_LEX *child; SELECT_LEX *child;
for (child= select_lex->master_unit()->first_select(); child; for (child= select_lex->master_unit()->first_select(); child;
...@@ -22981,13 +22983,14 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -22981,13 +22983,14 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
else if (!join->select_lex->master_unit()->derived || else if (!join->select_lex->master_unit()->derived ||
join->select_lex->master_unit()->derived->is_materialized_derived()) join->select_lex->master_unit()->derived->is_materialized_derived())
{ {
qp_sel= new QPF_select; QPF_select *qp_sel;
qp_node= qp_sel= new QPF_select;
table_map used_tables=0; table_map used_tables=0;
if (on_the_fly) if (on_the_fly)
join->select_lex->set_explain_type(on_the_fly); join->select_lex->set_explain_type(on_the_fly);
bool printing_materialize_nest= FALSE; //bool printing_materialize_nest= FALSE;
uint select_id= join->select_lex->select_number; uint select_id= join->select_lex->select_number;
qp_sel->select_id= join->select_lex->select_number; qp_sel->select_id= join->select_lex->select_number;
...@@ -23002,7 +23005,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -23002,7 +23005,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
{ {
JOIN_TAB *first_sibling= tab->bush_root_tab->bush_children->start; JOIN_TAB *first_sibling= tab->bush_root_tab->bush_children->start;
select_id= first_sibling->emb_sj_nest->sj_subq_pred->get_identifier(); select_id= first_sibling->emb_sj_nest->sj_subq_pred->get_identifier();
printing_materialize_nest= TRUE; //printing_materialize_nest= TRUE;
} }
TABLE *table=tab->table; TABLE *table=tab->table;
...@@ -23042,10 +23045,12 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -23042,10 +23045,12 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
QPF_table_access *qpt= new QPF_table_access; QPF_table_access *qpt= new QPF_table_access;
qp_sel->add_table(qpt); qp_sel->add_table(qpt);
/* id */ /* id */
// TODO: this can be '2' in case of SJM nests.. if (tab->bush_root_tab)
//qp_sel->select_id= select_id; qpt->sjm_nest_select_id= select_id;
else
qpt->sjm_nest_select_id= 0;
/* select_type */ /* select_type */
//const char* stype= printing_materialize_nest? "MATERIALIZED" : //const char* stype= printing_materialize_nest? "MATERIALIZED" :
...@@ -23060,7 +23065,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -23060,7 +23065,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
int len= my_snprintf(table_name_buffer, sizeof(table_name_buffer)-1, int len= my_snprintf(table_name_buffer, sizeof(table_name_buffer)-1,
"<derived%u>", "<derived%u>",
table->derived_select_number); table->derived_select_number);
qpt->table_name.append(table_name_buffer, len, cs); qpt->table_name.copy(table_name_buffer, len, cs);
} }
else if (tab->bush_children) else if (tab->bush_children)
{ {
...@@ -23070,12 +23075,12 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -23070,12 +23075,12 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
sizeof(table_name_buffer)-1, sizeof(table_name_buffer)-1,
"<subquery%d>", "<subquery%d>",
ctab->emb_sj_nest->sj_subq_pred->get_identifier()); ctab->emb_sj_nest->sj_subq_pred->get_identifier());
qpt->table_name.set(table_name_buffer, len, cs); qpt->table_name.copy(table_name_buffer, len, cs);
} }
else else
{ {
TABLE_LIST *real_table= table->pos_in_table_list; TABLE_LIST *real_table= table->pos_in_table_list;
qpt->table_name.append(real_table->alias, strlen(real_table->alias), cs); qpt->table_name.copy(real_table->alias, strlen(real_table->alias), cs);
} }
/* "partitions" column */ /* "partitions" column */
...@@ -23433,13 +23438,12 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -23433,13 +23438,12 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
else else
{ {
qpt->push_extra(ET_FIRST_MATCH); qpt->push_extra(ET_FIRST_MATCH);
//TABLE *prev_table=tab->do_firstmatch->table; TABLE *prev_table=tab->do_firstmatch->table;
/* /*
TODO: qpt->firstmatch_table... TODO: qpt->firstmatch_table...
This must be a reference to another QPF element. Or, its index. This must be a reference to another QPF element. Or, its index.
*/ */
#if 0 // extra.append(STRING_WITH_LEN("; FirstMatch("));
extra.append(STRING_WITH_LEN("; FirstMatch("));
if (prev_table->derived_select_number) if (prev_table->derived_select_number)
{ {
char namebuf[NAME_LEN]; char namebuf[NAME_LEN];
...@@ -23447,12 +23451,11 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -23447,12 +23451,11 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
int len= my_snprintf(namebuf, sizeof(namebuf)-1, int len= my_snprintf(namebuf, sizeof(namebuf)-1,
"<derived%u>", "<derived%u>",
prev_table->derived_select_number); prev_table->derived_select_number);
extra.append(namebuf, len); qpt->firstmatch_table_name.append(namebuf, len);
} }
else else
extra.append(prev_table->pos_in_table_list->alias); qpt->firstmatch_table_name.append(prev_table->pos_in_table_list->alias);
extra.append(STRING_WITH_LEN(")")); //extra.append(STRING_WITH_LEN(")"));
#endif
} }
} }
...@@ -23484,20 +23487,17 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, ...@@ -23484,20 +23487,17 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
//TODO: can a UNION have subquery children that are not union members? yes, //TODO: can a UNION have subquery children that are not union members? yes,
//perhaps... //perhaps...
if (qp_sel) for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit();
unit;
unit= unit->next_unit())
{ {
for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit(); /*
unit; Display subqueries only if they are not parts of eliminated WHERE/ON
unit= unit->next_unit()) clauses.
*/
if (!(unit->item && unit->item->eliminated))
{ {
/* qp_node->add_child(unit->first_select()->select_number);
Display subqueries only if they are not parts of eliminated WHERE/ON
clauses.
*/
if (!(unit->item && unit->item->eliminated))
{
qp_sel->add_child(unit->first_select()->select_number);
}
} }
} }
......
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