Bug #107559 Why Switch_ref_item_slice in TemptableAggregateIterator::Init
Submitted: 14 Jun 8:45 Modified: 14 Jun 12:23
Reporter: lou shuai (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[14 Jun 8:45] lou shuai
Description:
Hi,

I'd ask for an help to understand the code When i read the TemptableAggregateIterator::Init code:

```code
TemptableAggregateIterator::Init {
    for {
         m_subquery_iterator->Read(); 
         copy_fields(m_temp_table_param, thd())
         for (ORDER *group = table()->group; group; group = group->next) { 
             item->save_org_in_field(group->field_in_tmp_table);
         }
         group_found = !table()->file->ha_index_read_map
         if (group_found) {
             restore_record(table(), record[1]);  
             update_tmptable_sum_func(m_join->sum_funcs, table());
             table()->file->ha_update_row
             continue;
         }
         Switch_ref_item_slice slice_switch(m_join, m_ref_slice); 
         copy_funcs(m_temp_table_param, thd())
         init_tmptable_sum_functions(m_join->sum_funcs); 
         table()->file->ha_write_row  
    }
}
```
after the group by items are evaluated and saved into temp table's field,
Why change current_ref_item_slice to the temp table ?
I tried some example, but find copy_funcs rely on the base table's field instead of temp table's field result.
Can you give me an example?

How to repeat:
None
[14 Jun 8:53] lou shuai
the version is mysql8.0.25
[14 Jun 12:23] MySQL Verification Team
Hi Mr. shuai,

Thank you for your bug report.

However, it is not a bug.

We accept bug reports with test cases and bug reports based on code analysis. This is not a forum where we are explaining the code or the functionality of our software, hence, you are on the wrong site.

Regarding your question, this is an initialisation function which does many things, including initialising all columns in the temporary table.

Not a bug.