@@ -3546,7 +3546,8 @@ bool JOIN::make_aggr_tables_info()
35463546
35473547 if (gbh)
35483548 {
3549- if (!(pushdown_query= new (thd->mem_root) Pushdown_query(select_lex, gbh)))
3549+ if (!(pushdown_query= new (thd->mem_root) Pushdown_query(select_lex,
3550+ gbh)))
35503551 DBUG_RETURN(1);
35513552 /*
35523553 We must store rows in the tmp table if we need to do an ORDER BY
@@ -3566,6 +3567,7 @@ bool JOIN::make_aggr_tables_info()
35663567
35673568 if (!(curr_tab->tmp_table_param= new TMP_TABLE_PARAM(tmp_table_param)))
35683569 DBUG_RETURN(1);
3570+ curr_tab->tmp_table_param->func_count= all_fields.elements;
35693571 TABLE* table= create_tmp_table(thd, curr_tab->tmp_table_param,
35703572 all_fields,
35713573 NULL, distinct,
@@ -19600,6 +19602,7 @@ TABLE *Create_tmp_table::start(THD *thd,
1960019602 */
1960119603 if (param->precomputed_group_by)
1960219604 copy_func_count+= param->sum_func_count;
19605+ param->copy_func_count= copy_func_count;
1960319606
1960419607 init_sql_alloc(key_memory_TABLE, &own_root, TABLE_ALLOC_BLOCK_SIZE, 0,
1960519608 MYF(MY_THREAD_SPECIFIC));
@@ -19805,8 +19808,9 @@ bool Create_tmp_table::add_fields(THD *thd,
1980519808 We here distinguish between UNION and multi-table-updates by the fact
1980619809 that in the later case group is set to the row pointer.
1980719810
19808- The test for item->marker == 4 is ensure we don't create a group-by
19809- key over a bit field as heap tables can't handle that.
19811+ The test for item->marker == MARKER_NULL_KEY is ensure we
19812+ don't create a group-by key over a bit field as heap tables
19813+ can't handle that.
1981019814 */
1981119815 DBUG_ASSERT(!param->schema_table);
1981219816 Field *new_field=
@@ -19873,6 +19877,7 @@ bool Create_tmp_table::add_fields(THD *thd,
1987319877 new_field->flags|= FIELD_PART_OF_TMP_UNIQUE;
1987419878 }
1987519879 }
19880+
1987619881 DBUG_ASSERT(fieldnr == m_field_count[other] + m_field_count[distinct]);
1987719882 DBUG_ASSERT(m_blob_count == m_blobs_count[other] + m_blobs_count[distinct]);
1987819883 share->fields= fieldnr;
@@ -19881,6 +19886,8 @@ bool Create_tmp_table::add_fields(THD *thd,
1988119886 share->blob_field[m_blob_count]= 0; // End marker
1988219887 copy_func[0]= 0; // End marker
1988319888 param->func_count= (uint) (copy_func - param->items_to_copy);
19889+ DBUG_ASSERT(param->func_count <= param->copy_func_count);
19890+
1988419891 share->column_bitmap_size= bitmap_buffer_size(share->fields);
1988519892
1988619893 thd->mem_root= mem_root_save;
@@ -27337,6 +27344,11 @@ bool JOIN::rollup_init()
2733727344 Item **ref_array;
2733827345
2733927346 tmp_table_param.quick_group= 0; // Can't create groups in tmp table
27347+ /*
27348+ Each group can potentially be replaced with Item_func_rollup_const() which
27349+ needs a copy_func placeholder.
27350+ */
27351+ tmp_table_param.func_count+= send_group_parts;
2734027352 rollup.state= ROLLUP::STATE_INITED;
2734127353
2734227354 /*
@@ -27361,7 +27373,6 @@ bool JOIN::rollup_init()
2736127373
2736227374 ref_array= (Item**) (rollup.ref_pointer_arrays+send_group_parts);
2736327375
27364-
2736527376 /*
2736627377 Prepare space for field list for the different levels
2736727378 These will be filled up in rollup_make_fields()
@@ -27525,7 +27536,6 @@ bool JOIN::rollup_make_fields(List<Item> &fields_arg, List<Item> &sel_fields,
2752527536 /* Point to first hidden field */
2752627537 uint ref_array_ix= fields_arg.elements-1;
2752727538
27528-
2752927539 /* Remember where the sum functions ends for the previous level */
2753027540 sum_funcs_end[pos+1]= *func;
2753127541
0 commit comments