For i48579, the massif output showed that add_derived_key()/update_derived_keys() function had an increased memory consumption for the most part. Thus, the customer changed a query in the stored procedure to use temporary table instead of subquery(using derived table). The stress test on a small test server showed stable memory usage for over 12+ hours. The max used memory by this function was 30M in the massif output. Due to the small scale of the test, we know now that this function is part of the problem but unknown yet if it is the main problem. Here is the related massif output for reference: | | | ->17.34% (29,906,400B) 0x88509D: add_derived_key(List&, Field*, unsigned long long) (table.cc:6153) | | | | ->11.57% (19,951,200B) 0x885342: TABLE_LIST::update_derived_keys(Field*, Item**, unsigned int) (table.cc:6217) | | | | | ->11.57% (19,951,200B) 0x9B64DE: add_key_field(Key_field**, unsigned int, Item_func*, Field*, bool, Item**, unsigned int, unsigned long long, st_sargable_param**) (sql_optimizer.cc:4885) | | | | | ->11.57% (19,951,200B) 0x9B6BD8: add_key_equal_fields(Key_field**, unsigned int, Item_func*, Item_field*, bool, Item**, unsigned int, unsigned long long, st_sargable_param**) (sql_optimizer.cc:5068) | | | | | ->11.57% (19,951,200B) 0x9B76F3: add_key_fields(JOIN*, Key_field**, unsigned int*, Item*, unsigned long long, st_sargable_param**) (sql_optimizer.cc:5280) | | | | | ->11.57% (19,951,200B) 0x9B7F5D: update_ref_and_keys(THD*, Mem_root_array*, st_join_table*, unsigned int, Item*, COND_EQUAL*, unsigned long long, st_select_lex*, st_sargable_param**) (sql_optimizer.cc:5891) | | | | | ->11.57% (19,951,200B) 0x9B9243: make_join_statistics(JOIN*, TABLE_LIST*, Item*, Mem_root_array*, bool) (sql_optimizer.cc:3329) | | | | | ->11.57% (19,951,200B) 0x9BF50B: JOIN::optimize() (sql_optimizer.cc:363) | | | | | ->11.57% (19,951,200B) 0x7FF5E2: mysql_execute_select(THD*, st_select_lex*, bool) (sql_select.cc:1086) | | | | | ->11.57% (19,951,200B) 0x7FFFE9: mysql_select(THD*, TABLE_LIST*, unsigned int, List&, Item*, SQL_I_List*, SQL_I_List*, Item*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:1221) | | | | | ->11.57% (19,951,200B) 0x8001E5: handle_select(THD*, select_result*, unsigned long) (sql_select.cc:110) | | | | | ->11.57% (19,951,200B) 0x7C63BA: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5103) | | | | | ->11.57% (19,951,200B) 0x7C78E5: mysql_execute_command(THD*) (sql_parse.cc:2649) | | | | | ->11.57% (19,951,200B) 0x789EF8: mysql_open_cursor(THD*, select_result*, Server_side_cursor**) (sql_cursor.cc:118) | | | | | ->11.57% (19,951,200B) 0x725EFD: sp_cursor::open(THD*) (sp_rcontext.cc:493) | | | | | ->11.57% (19,951,200B) 0x97FAB8: sp_instr_cpush::exec_core(THD*, unsigned int*) (sp_instr.cc:1471) | | | | | ->11.57% (19,951,200B) 0x981657: sp_lex_instr::reset_lex_and_exec_core(THD*, unsigned int*, bool) (sp_instr.cc:390) | | | | | ->11.57% (19,951,200B) 0x981926: sp_lex_instr::validate_lex_and_execute_core(THD*, unsigned int*, bool) (sp_instr.cc:638) | | | | | ->11.57% (19,951,200B) 0x981AB8: sp_instr_copen::execute(THD*, unsigned int*) (sp_instr.cc:1554) | | | | | ->11.57% (19,951,200B) 0x71E428: sp_head::execute(THD*, bool) (sp_head.cc:645) | | | | | ->11.57% (19,951,200B) 0x71F3B6: sp_head::execute_procedure(THD*, List*) (sp_head.cc:1315) | | | | | ->11.57% (19,951,200B) 0x7CD2E6: mysql_execute_command(THD*) (sql_parse.cc:4569) | | | | | ->11.57% (19,951,200B) 0x980394: sp_instr_stmt::exec_core(THD*, unsigned int*) (sp_instr.cc:901) | | | | | ->11.57% (19,951,200B) 0x981657: sp_lex_instr::reset_lex_and_exec_core(THD*, unsigned int*, bool) (sp_instr.cc:390) | | | | | ->11.57% (19,951,200B) 0x981926: sp_lex_instr::validate_lex_and_execute_core(THD*, unsigned int*, bool) (sp_instr.cc:638) | | | | | ->11.57% (19,951,200B) 0x981D20: sp_instr_stmt::execute(THD*, unsigned int*) (sp_instr.cc:808) | | | | | ->11.57% (19,951,200B) 0x71E428: sp_head::execute(THD*, bool) (sp_head.cc:645) | | | | | | | | | ->05.77% (9,955,200B) 0x885386: TABLE_LIST::update_derived_keys(Field*, Item**, unsigned int) (table.cc:6222) | | | | |-> ....