| 4374 | |
| 4375 | |
| 4376 | bool |
| 4377 | JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields, |
| 4378 | ORDER *table_group, |
| 4379 | bool save_sum_fields, |
| 4380 | bool distinct, |
| 4381 | bool keep_row_order) |
| 4382 | { |
| 4383 | DBUG_ENTER("JOIN::create_postjoin_aggr_table"); |
| 4384 | THD_STAGE_INFO(thd, stage_creating_tmp_table); |
| 4385 | |
| 4386 | /* |
| 4387 | Pushing LIMIT to the post-join temporary table creation is not applicable |
| 4388 | when there is ORDER BY or GROUP BY or there is no GROUP BY, but |
| 4389 | there are aggregate functions, because in all these cases we need |
| 4390 | all result rows. |
| 4391 | |
| 4392 | We also can not push limit if the limit is WITH TIES, as we do not know |
| 4393 | how many rows we will actually have. This can happen if ORDER BY was |
| 4394 | a constant and removed (during remove_const), thus we have an "unlimited" |
| 4395 | WITH TIES. |
| 4396 | */ |
| 4397 | ha_rows table_rows_limit= ((order == NULL || skip_sort_order) && |
| 4398 | !table_group && |
| 4399 | !select_lex->with_sum_func && |
| 4400 | !unit->lim.is_with_ties()) ? select_limit |
| 4401 | : HA_POS_ERROR; |
| 4402 | |
| 4403 | if (!(tab->tmp_table_param= new TMP_TABLE_PARAM(tmp_table_param))) |
| 4404 | DBUG_RETURN(true); |
| 4405 | if (tmp_table_keep_current_rowid) |
| 4406 | add_fields_for_current_rowid(tab, table_fields); |
| 4407 | tab->tmp_table_param->skip_create_table= true; |
| 4408 | TABLE* table= create_tmp_table(thd, tab->tmp_table_param, *table_fields, |
| 4409 | table_group, distinct, |
| 4410 | save_sum_fields, select_options, |
| 4411 | table_rows_limit, |
| 4412 | &empty_clex_str, true, keep_row_order); |
| 4413 | if (!table) |
| 4414 | DBUG_RETURN(true); |
| 4415 | tmp_table_param.using_outer_summary_function= |
| 4416 | tab->tmp_table_param->using_outer_summary_function; |
| 4417 | tab->join= this; |
| 4418 | DBUG_ASSERT(tab > tab->join->join_tab || !top_join_tab_count || |
| 4419 | !tables_list); |
| 4420 | tab->table= table; |
| 4421 | if (tab > join_tab) |
| 4422 | (tab - 1)->next_select= sub_select_postjoin_aggr; |
| 4423 | |
| 4424 | /* if group or order on first table, sort first */ |
| 4425 | if ((group_list && simple_group) || |
| 4426 | (implicit_grouping && select_lex->have_window_funcs())) |
| 4427 | { |
| 4428 | DBUG_PRINT("info",("Sorting for group")); |
| 4429 | THD_STAGE_INFO(thd, stage_sorting_for_group); |
| 4430 | |
| 4431 | if (ordered_index_usage != ordered_index_group_by && |
| 4432 | !only_const_tables() && |
| 4433 | (join_tab + const_tables)->type != JT_CONST && // Don't sort 1 row |
nothing calls this directly
no test coverage detected