| 4832 | |
| 4833 | |
| 4834 | bool JOIN::save_explain_data(Explain_query *output, bool can_overwrite, |
| 4835 | bool need_tmp_table, bool need_order, |
| 4836 | bool distinct) |
| 4837 | { |
| 4838 | DBUG_ENTER("JOIN::save_explain_data"); |
| 4839 | DBUG_PRINT("enter", ("Save explain Select_lex: %u (%p) parent lex: %p stmt_lex: %p present select: %u (%p)", |
| 4840 | select_lex->select_number, select_lex, |
| 4841 | select_lex->parent_lex, thd->lex->stmt_lex, |
| 4842 | (output->get_select(select_lex->select_number) ? |
| 4843 | select_lex->select_number : 0), |
| 4844 | (output->get_select(select_lex->select_number) ? |
| 4845 | output->get_select(select_lex->select_number) |
| 4846 | ->select_lex : NULL))); |
| 4847 | /* |
| 4848 | If there is SELECT in this statement with the same number it must be the |
| 4849 | same SELECT |
| 4850 | */ |
| 4851 | DBUG_ASSERT(select_lex->select_number == FAKE_SELECT_LEX_ID || !output || |
| 4852 | !output->get_select(select_lex->select_number) || |
| 4853 | output->get_select(select_lex->select_number)->select_lex == |
| 4854 | select_lex); |
| 4855 | |
| 4856 | if (select_lex->select_number != FAKE_SELECT_LEX_ID && |
| 4857 | have_query_plan != JOIN::QEP_NOT_PRESENT_YET && |
| 4858 | have_query_plan != JOIN::QEP_DELETED && // this happens when there was |
| 4859 | // no QEP ever, but then |
| 4860 | //cleanup() is called multiple times |
| 4861 | output && // for "SET" command in SPs. |
| 4862 | (can_overwrite? true: !output->get_select(select_lex->select_number))) |
| 4863 | { |
| 4864 | const char *message= NULL; |
| 4865 | if (!table_count || !tables_list || zero_result_cause) |
| 4866 | { |
| 4867 | /* It's a degenerate join */ |
| 4868 | message= zero_result_cause ? zero_result_cause : "No tables used"; |
| 4869 | } |
| 4870 | bool rc= save_explain_data_intern(thd->lex->explain, need_tmp_table, |
| 4871 | need_order, distinct, message); |
| 4872 | DBUG_RETURN(rc); |
| 4873 | } |
| 4874 | |
| 4875 | /* |
| 4876 | Can have join_tab==NULL for degenerate cases (e.g. SELECT .. UNION ... SELECT LIMIT 0) |
| 4877 | */ |
| 4878 | if (select_lex == select_lex->master_unit()->fake_select_lex && join_tab) |
| 4879 | { |
| 4880 | /* |
| 4881 | This is fake_select_lex. It has no query plan, but we need to set up a |
| 4882 | tracker for ANALYZE |
| 4883 | */ |
| 4884 | uint nr= select_lex->master_unit()->first_select()->select_number; |
| 4885 | Explain_union *eu= output->get_union(nr); |
| 4886 | explain= &eu->fake_select_lex_explain; |
| 4887 | join_tab[0].tracker= eu->get_fake_select_lex_tracker(); |
| 4888 | for (uint i=0 ; i < exec_join_tab_cnt() + aggr_tables; i++) |
| 4889 | { |
| 4890 | if (join_tab[i].filesort) |
| 4891 | { |
no test coverage detected