We're updating the issue view to help you get more done. 

Statistics: ANALYZE TABLE failure and memory loss warnings after deleting records from a table

Description

With statistics enabled, If I create a table, insert a few records and then delete some, the following ANALYZE TABLE statement fails and memory loss warnings are thrown. The memory leak is for real, if I run a similar test for several minutes, the server ends up with "out of memory".

1 2 3 4 5 6 7 SET use_stat_tables = PREFERABLY; CREATE TABLE t1 (a INT) ENGINE=MyISAM; INSERT INTO t1 VALUES (1),(2); DELETE FROM t1 WHERE a=1; ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status Operation failed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 Warning: 65536 bytes lost, allocated at mysys/mf_iocache.c:231, mysys/mf_cache.c:69, sql/uniques.cc:98, sql/sql_statistics.cc:1254, sql/sql_statistics.cc:1822, sql/sql_statistics.cc:2038, sql/sql_admin.cc:721, sql/sql_admin.cc:1088 Warning: 3 bytes lost, allocated at mysys/my_malloc.c:137, mysys/mf_cache.c:65, sql/uniques.cc:98, sql/sql_statistics.cc:1254, sql/sql_statistics.cc:1822, sql/sql_statistics.cc:2038, sql/sql_admin.cc:721, sql/sql_admin.cc:1088 Warning: 58 bytes lost, allocated at mysys/my_malloc.c:137, mysys/mf_cache.c:64, sql/uniques.cc:98, sql/sql_statistics.cc:1254, sql/sql_statistics.cc:1822, sql/sql_statistics.cc:2038, sql/sql_admin.cc:721, sql/sql_admin.cc:1088 Warning: 768 bytes lost, allocated at mysys/array.c:65, sql/uniques.cc:95, sql/sql_statistics.cc:1254, sql/sql_statistics.cc:1822, sql/sql_statistics.cc:2038, sql/sql_admin.cc:721, sql/sql_admin.cc:1088, sql/sql_parse.cc:4459 ==11324== 103 bytes in 1 blocks are still reachable in loss record 2 of 6 ==11324== at 0x4C26C3A: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==11324== by 0xCDE66A: sf_malloc (safemalloc.c:105) ==11324== by 0xCCA9C3: my_malloc (my_malloc.c:41) ==11324== by 0xCCADDD: my_strdup (my_malloc.c:137) ==11324== by 0xCAADAA: open_cached_file (mf_cache.c:65) ==11324== by 0x70A07C: Unique::Unique(int (*)(void*, void const*, void const*), void*, unsigned int, unsigned long long, unsigned int) (uniques.cc:97) ==11324== by 0x6BE7E6: Count_distinct_field::Count_distinct_field(Field*, unsigned int) (sql_statistics.cc:1254) ==11324== by 0x6BEE7C: Column_statistics_collected::init(THD*, Field*) (sql_statistics.cc:1822) ==11324== by 0x6BAECE: collect_statistics_for_table(THD*, TABLE*) (sql_statistics.cc:2038) ==11324== by 0x73FF42: mysql_admin_table(THD*, TABLE_LIST*, st_ha_check_opt*, char const*, thr_lock_type, bool, bool, unsigned int, int (*)(THD*, TABLE_LIST*, st_ha_check_opt*), int (handler::*)(THD*, st_ha_check_opt*), int (*)(THD*, TABLE_LIST*)) (sql_admin.cc:721) ==11324== by 0x741357: Analyze_table_statement::execute(THD*) (sql_admin.cc:1088) ==11324== by 0x636044: mysql_execute_command(THD*) (sql_parse.cc:4459) ==11324== by 0x63914A: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:5736) ==11324== by 0x62CFCC: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1055) ==11324== by 0x62C29F: do_command(THD*) (sql_parse.cc:794) ==11324== by 0x730D04: do_handle_one_connection(THD*) (sql_connect.cc:1253) ==11324== 158 bytes in 1 blocks are still reachable in loss record 3 of 6 ==11324== at 0x4C26C3A: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==11324== by 0xCDE66A: sf_malloc (safemalloc.c:105) ==11324== by 0xCCA9C3: my_malloc (my_malloc.c:41) ==11324== by 0xCCADDD: my_strdup (my_malloc.c:137) ==11324== by 0xCAAD7B: open_cached_file (mf_cache.c:64) ==11324== by 0x70A07C: Unique::Unique(int (*)(void*, void const*, void const*), void*, unsigned int, unsigned long long, unsigned int) (uniques.cc:97) ==11324== by 0x6BE7E6: Count_distinct_field::Count_distinct_field(Field*, unsigned int) (sql_statistics.cc:1254) ==11324== by 0x6BEE7C: Column_statistics_collected::init(THD*, Field*) (sql_statistics.cc:1822) ==11324== by 0x6BAECE: collect_statistics_for_table(THD*, TABLE*) (sql_statistics.cc:2038) ==11324== by 0x73FF42: mysql_admin_table(THD*, TABLE_LIST*, st_ha_check_opt*, char const*, thr_lock_type, bool, bool, unsigned int, int (*)(THD*, TABLE_LIST*, st_ha_check_opt*), int (handler::*)(THD*, st_ha_check_opt*), int (*)(THD*, TABLE_LIST*)) (sql_admin.cc:721) ==11324== by 0x741357: Analyze_table_statement::execute(THD*) (sql_admin.cc:1088) ==11324== by 0x636044: mysql_execute_command(THD*) (sql_parse.cc:4459) ==11324== by 0x63914A: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:5736) ==11324== by 0x62CFCC: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1055) ==11324== by 0x62C29F: do_command(THD*) (sql_parse.cc:794) ==11324== by 0x730D04: do_handle_one_connection(THD*) (sql_connect.cc:1253) ==11324== 868 bytes in 1 blocks are still reachable in loss record 5 of 6 ==11324== at 0x4C26C3A: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==11324== by 0xCDE66A: sf_malloc (safemalloc.c:105) ==11324== by 0xCCA9C3: my_malloc (my_malloc.c:41) ==11324== by 0xCA3021: init_dynamic_array2 (array.c:65) ==11324== by 0x70A011: Unique::Unique(int (*)(void*, void const*, void const*), void*, unsigned int, unsigned long long, unsigned int) (uniques.cc:90) ==11324== by 0x6BE7E6: Count_distinct_field::Count_distinct_field(Field*, unsigned int) (sql_statistics.cc:1254) ==11324== by 0x6BEE7C: Column_statistics_collected::init(THD*, Field*) (sql_statistics.cc:1822) ==11324== by 0x6BAECE: collect_statistics_for_table(THD*, TABLE*) (sql_statistics.cc:2038) ==11324== by 0x73FF42: mysql_admin_table(THD*, TABLE_LIST*, st_ha_check_opt*, char const*, thr_lock_type, bool, bool, unsigned int, int (*)(THD*, TABLE_LIST*, st_ha_check_opt*), int (handler::*)(THD*, st_ha_check_opt*), int (*)(THD*, TABLE_LIST*)) (sql_admin.cc:721) ==11324== by 0x741357: Analyze_table_statement::execute(THD*) (sql_admin.cc:1088) ==11324== by 0x636044: mysql_execute_command(THD*) (sql_parse.cc:4459) ==11324== by 0x63914A: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:5736) ==11324== by 0x62CFCC: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1055) ==11324== by 0x62C29F: do_command(THD*) (sql_parse.cc:794) ==11324== by 0x730D04: do_handle_one_connection(THD*) (sql_connect.cc:1253) ==11324== by 0x7307C7: handle_one_connection (sql_connect.cc:1168) ==11324== 65,636 bytes in 1 blocks are still reachable in loss record 6 of 6 ==11324== at 0x4C26C3A: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==11324== by 0xCDE66A: sf_malloc (safemalloc.c:105) ==11324== by 0xCCA9C3: my_malloc (my_malloc.c:41) ==11324== by 0xCAC9EB: init_io_cache (mf_iocache.c:231) ==11324== by 0xCAAE08: open_cached_file (mf_cache.c:69) ==11324== by 0x70A07C: Unique::Unique(int (*)(void*, void const*, void const*), void*, unsigned int, unsigned long long, unsigned int) (uniques.cc:97) ==11324== by 0x6BE7E6: Count_distinct_field::Count_distinct_field(Field*, unsigned int) (sql_statistics.cc:1254) ==11324== by 0x6BEE7C: Column_statistics_collected::init(THD*, Field*) (sql_statistics.cc:1822) ==11324== by 0x6BAECE: collect_statistics_for_table(THD*, TABLE*) (sql_statistics.cc:2038) ==11324== by 0x73FF42: mysql_admin_table(THD*, TABLE_LIST*, st_ha_check_opt*, char const*, thr_lock_type, bool, bool, unsigned int, int (*)(THD*, TABLE_LIST*, st_ha_check_opt*), int (handler::*)(THD*, st_ha_check_opt*), int (*)(THD*, TABLE_LIST*)) (sql_admin.cc:721) ==11324== by 0x741357: Analyze_table_statement::execute(THD*) (sql_admin.cc:1088) ==11324== by 0x636044: mysql_execute_command(THD*) (sql_parse.cc:4459) ==11324== by 0x63914A: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:5736) ==11324== by 0x62CFCC: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1055) ==11324== by 0x62C29F: do_command(THD*) (sql_parse.cc:794) ==11324== by 0x730D04: do_handle_one_connection(THD*) (sql_connect.cc:1253)

bzr version-info

1 2 3 4 revision-id: igor@askmonty.org-20120823182226-tv99ic3pbk5wela9 date: 2012-08-23 11:22:26 -0700 build-date: 2012-08-25 23:23:41 +0300 revno: 3363

As far as I can tell, it started happening since revno 3360 (not reproducible on revno 3359).

Test case:

1 2 3 4 5 6 7 8 # Run as perl mysql-test-run.pl --valgrind-mysqld <test name> SET use_stat_tables = PREFERABLY; CREATE TABLE t1 (a INT) ENGINE=MyISAM; INSERT INTO t1 VALUES (1),(2); DELETE FROM t1 WHERE a=1; ANALYZE TABLE t1;

Environment

None

Status

Assignee

Igor Babaev

Reporter

Elena Stepanova

Labels

None

External issue ID

None

External issue ID

None

Fix versions

Priority

Major