Skip to content

Commit eaba1ba

Browse files
committed
Re-commit in git:
MDEV-406: ANALYZE $stmt - Ported the old patch to new explain code - New SQL syntax (ANALYZE $stmt) - ANALYZE UPDATE/DELETE is now supported (because EXPLAIN UPDATE/DELETE is supported) - Basic counters are calculated for basic kinds of queries (still need to see what happens with join buffer, ORDER BY...LIMIT queries, etc)
1 parent 5a61516 commit eaba1ba

File tree

13 files changed

+239
-58
lines changed

13 files changed

+239
-58
lines changed

sql/sql_class.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,9 @@ int THD::send_explain_fields(select_result *result)
22822282
/*
22832283
Populate the provided field_list with EXPLAIN output columns.
22842284
this->lex->describe has the EXPLAIN flags
2285+
2286+
The set/order of columns must be kept in sync with
2287+
Explain_query::print_explain and co.
22852288
*/
22862289

22872290
void THD::make_explain_field_list(List<Item> &field_list)
@@ -2317,11 +2320,25 @@ void THD::make_explain_field_list(List<Item> &field_list)
23172320
item->maybe_null=1;
23182321
field_list.push_back(item= new Item_return_int("rows", 10,
23192322
MYSQL_TYPE_LONGLONG));
2320-
if (lex->describe & DESCRIBE_EXTENDED)
2323+
if (lex->analyze_stmt)
2324+
{
2325+
field_list.push_back(item= new Item_return_int("r_rows", 10,
2326+
MYSQL_TYPE_LONGLONG));
2327+
item->maybe_null=1;
2328+
}
2329+
2330+
if (lex->analyze_stmt || lex->describe & DESCRIBE_EXTENDED)
23212331
{
23222332
field_list.push_back(item= new Item_float("filtered", 0.1234, 2, 4));
23232333
item->maybe_null=1;
23242334
}
2335+
2336+
if (lex->analyze_stmt)
2337+
{
2338+
field_list.push_back(item= new Item_float("r_filtered", 0.1234, 2, 4));
2339+
item->maybe_null=1;
2340+
}
2341+
23252342
item->maybe_null= 1;
23262343
field_list.push_back(new Item_empty_string("Extra", 255, cs));
23272344
}

sql/sql_class.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,6 +3959,18 @@ class select_send :public select_result {
39593959
virtual void cleanup();
39603960
};
39613961

3962+
class select_send_analyze : public select_send
3963+
{
3964+
bool discard_data;
3965+
bool send_result_set_metadata(List<Item> &list, uint flags) { return 0; }
3966+
/*
3967+
ANALYZE-todo: we should call val_int() (or val_str() or whatever) to
3968+
compute the columns. If we don't, it's not full execution.
3969+
*/
3970+
int send_data(List<Item> &items) { return 0; }
3971+
bool send_eof() { return 0; }
3972+
void abort_result_set() {}
3973+
};
39623974

39633975
class select_to_file :public select_result_interceptor {
39643976
protected:

sql/sql_delete.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
223223
killed_state killed_status= NOT_KILLED;
224224
THD::enum_binlog_query_type query_type= THD::ROW_QUERY_TYPE;
225225
bool with_select= !select_lex->item_list.is_empty();
226+
Explain_delete *explain;
226227
Delete_plan query_plan(thd->mem_root);
227228
query_plan.index= MAX_KEY;
228229
query_plan.using_filesort= FALSE;
@@ -538,9 +539,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
538539
goto cleanup;
539540
}
540541

542+
explain= (Explain_delete*)thd->lex->explain->get_upd_del_plan();
541543
while (!(error=info.read_record(&info)) && !thd->killed &&
542544
! thd->is_error())
543545
{
546+
explain->on_record_read();
544547
if (table->vfield)
545548
update_virtual_fields(thd, table,
546549
table->triggers ? VCOL_UPDATE_ALL :
@@ -549,6 +552,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
549552
// thd->is_error() is tested to disallow delete row on error
550553
if (!select || select->skip_record(thd) > 0)
551554
{
555+
explain->on_record_after_where();
552556
if (table->triggers &&
553557
table->triggers->process_triggers(thd, TRG_EVENT_DELETE,
554558
TRG_ACTION_BEFORE, FALSE))
@@ -666,6 +670,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
666670
}
667671
DBUG_ASSERT(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table);
668672
free_underlaid_joins(thd, select_lex);
673+
if (thd->lex->analyze_stmt)
674+
{
675+
error= thd->lex->explain->send_explain(thd);
676+
}
677+
else
669678
if (error < 0 ||
670679
(thd->lex->ignore && !thd->is_error() && !thd->is_fatal_error))
671680
{

0 commit comments

Comments
 (0)