| 23997 | */ |
| 23998 | |
| 23999 | void set_postjoin_aggr_write_func(JOIN_TAB *tab) |
| 24000 | { |
| 24001 | JOIN *join= tab->join; |
| 24002 | TABLE *table= tab->table; |
| 24003 | AGGR_OP *aggr= tab->aggr; |
| 24004 | TMP_TABLE_PARAM *tmp_tbl= tab->tmp_table_param; |
| 24005 | |
| 24006 | DBUG_ASSERT(table && aggr); |
| 24007 | |
| 24008 | if (table->group && tmp_tbl->sum_func_count && |
| 24009 | !tmp_tbl->precomputed_group_by) |
| 24010 | { |
| 24011 | /* |
| 24012 | Note for MyISAM tmp tables: if uniques is true keys won't be |
| 24013 | created. |
| 24014 | */ |
| 24015 | if (table->s->keys && !table->s->have_unique_constraint()) |
| 24016 | { |
| 24017 | DBUG_PRINT("info",("Using end_update")); |
| 24018 | aggr->set_write_func(end_update); |
| 24019 | } |
| 24020 | else |
| 24021 | { |
| 24022 | DBUG_PRINT("info",("Using end_unique_update")); |
| 24023 | aggr->set_write_func(end_unique_update); |
| 24024 | } |
| 24025 | } |
| 24026 | else if (join->sort_and_group && !tmp_tbl->precomputed_group_by && |
| 24027 | !join->sort_and_group_aggr_tab && join->tables_list && |
| 24028 | join->top_join_tab_count) |
| 24029 | { |
| 24030 | DBUG_PRINT("info",("Using end_write_group")); |
| 24031 | aggr->set_write_func(end_write_group); |
| 24032 | join->sort_and_group_aggr_tab= tab; |
| 24033 | } |
| 24034 | else |
| 24035 | { |
| 24036 | DBUG_PRINT("info",("Using end_write")); |
| 24037 | aggr->set_write_func(end_write); |
| 24038 | if (tmp_tbl->precomputed_group_by) |
| 24039 | { |
| 24040 | /* |
| 24041 | A preceding call to create_tmp_table in the case when loose |
| 24042 | index scan is used guarantees that |
| 24043 | TMP_TABLE_PARAM::items_to_copy has enough space for the group |
| 24044 | by functions. It is OK here to use memcpy since we copy |
| 24045 | Item_sum pointers into an array of Item pointers. |
| 24046 | */ |
| 24047 | memcpy(tmp_tbl->items_to_copy + tmp_tbl->func_count, |
| 24048 | join->sum_funcs, |
| 24049 | sizeof(Item*)*tmp_tbl->sum_func_count); |
| 24050 | tmp_tbl->items_to_copy[tmp_tbl->func_count+tmp_tbl->sum_func_count]= 0; |
| 24051 | } |
| 24052 | } |
| 24053 | } |
| 24054 | |
| 24055 | |
| 24056 | /** |
no test coverage detected