You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

508 lines
15 KiB

Remove compiler warnings (Including some warnings from -Wstrict-aliasing) Don't use static link by default (in compile-pentium) as some new systems doesn't have all static libraries available Change type for functions in plugin.h:str_mysql_ftparser_param() to const unsigned char and string lengths to size_t. One effect of the above change is that one needs to include mysql_global.h or define size_t before including plugin.h This fixes a case where mysql_client_test failed with newer gcc that enables strict-aliasing by default BUILD/compile-pentium: Don't use static link by default as some new systems doesn't have all static libraries available client/mysql_upgrade.c: Remove not used variable cmd-line-utils/readline/config_readline.h: Define some constants to get rid of compiler warnings on Linux cmd-line-utils/readline/display.c: Get rid of compiler warnings cmd-line-utils/readline/history.c: Got rid of compiler warnings: - Defining some strings as const - Added cast cmd-line-utils/readline/rlmbutil.h: Added cast to get rid of compiler warnings cmd-line-utils/readline/text.c: Remove not needed initialization to get rid of compiler warnings cmd-line-utils/readline/xmalloc.c: Changed types to 'const char* to get rid of compiler warnings configure.in: Ensure that we use MariaDB as suffix include/mysql/plugin.h: Changed types to 'const unsigned char* to get rid of compiler warnings (in other parts of the code) Change length for not \0 terminated string to size_t include/mysql/plugin.h.pp: Update related to plugin.h libmysql/libmysql.c: Fixed bug that caused core dump with newer gcc when strict aliasing is not turned off mysql-test/t/information_schema.test: Test is depending on innodb mysql-test/t/not_partition.test: Fixed wrong directory name (Not noticed before as we don't ususally run this test) mysys/lf_hash.c: Got rid of compiler warnings from -Wstrict-aliasing mysys/my_redel.c: Removed not used variable regex/engine.c: Changed types to 'const char* to get rid of compiler warnings regex/engine.ih: Changed types to 'const char* to get rid of compiler warnings sql/sp_head.cc: Got rid of compiler warning from -Wstrict-aliasing sql/sql_base.cc: Got rid of compiler warnings from -Wstrict-aliasing (The original code was probably wrong as nj_col->table_field was sql/sql_builtin.cc.in: plugin.h needs to have size_t defined sql/sql_parse.cc: Remove used variable sql/sql_select.cc: Got rid of compiler warnings from -Wstrict-aliasing sql/sql_show.cc: Added #ifdef to get rid of compiler warning when not using partition engine sql/table.cc: Got rid of compiler warning from -Wstrict-aliasing storage/maria/ha_maria.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/maria/lockman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/ma_check.c: Got rid of compiler warnings from -Wstrict-aliasing Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_check_standalone.h: Update to compatible _ma_killed_ptr() from ha_maria.cc storage/maria/ma_ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing Ensure that 'subkeys' is 32 bit storage/maria/ma_ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_sort.c: Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_state.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/maria_def.h: Redefine ma_killed_ptr() storage/maria/maria_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/trnman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_stopwords.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ha_myisam.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/myisam/mi_check.c: Use new killed_ptr() function storage/myisam/myisam_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/myisamchk.c: Update to compatible killed_ptr() from ha_myisam.cc storage/myisam/myisamdef.h: Redefine killed_ptr() storage/myisam/myisamlog.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/sort.c: Change to use new version of killed_ptr; Don't call it as often as before storage/xtradb/fil/fil0fil.c: Fixedc ompiler warning storage/xtradb/trx/trx0i_s.c: Include mysql_plugin.h later to ensure that size_t is defined
16 years ago
Remove compiler warnings (Including some warnings from -Wstrict-aliasing) Don't use static link by default (in compile-pentium) as some new systems doesn't have all static libraries available Change type for functions in plugin.h:str_mysql_ftparser_param() to const unsigned char and string lengths to size_t. One effect of the above change is that one needs to include mysql_global.h or define size_t before including plugin.h This fixes a case where mysql_client_test failed with newer gcc that enables strict-aliasing by default BUILD/compile-pentium: Don't use static link by default as some new systems doesn't have all static libraries available client/mysql_upgrade.c: Remove not used variable cmd-line-utils/readline/config_readline.h: Define some constants to get rid of compiler warnings on Linux cmd-line-utils/readline/display.c: Get rid of compiler warnings cmd-line-utils/readline/history.c: Got rid of compiler warnings: - Defining some strings as const - Added cast cmd-line-utils/readline/rlmbutil.h: Added cast to get rid of compiler warnings cmd-line-utils/readline/text.c: Remove not needed initialization to get rid of compiler warnings cmd-line-utils/readline/xmalloc.c: Changed types to 'const char* to get rid of compiler warnings configure.in: Ensure that we use MariaDB as suffix include/mysql/plugin.h: Changed types to 'const unsigned char* to get rid of compiler warnings (in other parts of the code) Change length for not \0 terminated string to size_t include/mysql/plugin.h.pp: Update related to plugin.h libmysql/libmysql.c: Fixed bug that caused core dump with newer gcc when strict aliasing is not turned off mysql-test/t/information_schema.test: Test is depending on innodb mysql-test/t/not_partition.test: Fixed wrong directory name (Not noticed before as we don't ususally run this test) mysys/lf_hash.c: Got rid of compiler warnings from -Wstrict-aliasing mysys/my_redel.c: Removed not used variable regex/engine.c: Changed types to 'const char* to get rid of compiler warnings regex/engine.ih: Changed types to 'const char* to get rid of compiler warnings sql/sp_head.cc: Got rid of compiler warning from -Wstrict-aliasing sql/sql_base.cc: Got rid of compiler warnings from -Wstrict-aliasing (The original code was probably wrong as nj_col->table_field was sql/sql_builtin.cc.in: plugin.h needs to have size_t defined sql/sql_parse.cc: Remove used variable sql/sql_select.cc: Got rid of compiler warnings from -Wstrict-aliasing sql/sql_show.cc: Added #ifdef to get rid of compiler warning when not using partition engine sql/table.cc: Got rid of compiler warning from -Wstrict-aliasing storage/maria/ha_maria.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/maria/lockman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/ma_check.c: Got rid of compiler warnings from -Wstrict-aliasing Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_check_standalone.h: Update to compatible _ma_killed_ptr() from ha_maria.cc storage/maria/ma_ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing Ensure that 'subkeys' is 32 bit storage/maria/ma_ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_sort.c: Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_state.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/maria_def.h: Redefine ma_killed_ptr() storage/maria/maria_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/trnman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_stopwords.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ha_myisam.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/myisam/mi_check.c: Use new killed_ptr() function storage/myisam/myisam_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/myisamchk.c: Update to compatible killed_ptr() from ha_myisam.cc storage/myisam/myisamdef.h: Redefine killed_ptr() storage/myisam/myisamlog.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/sort.c: Change to use new version of killed_ptr; Don't call it as often as before storage/xtradb/fil/fil0fil.c: Fixedc ompiler warning storage/xtradb/trx/trx0i_s.c: Include mysql_plugin.h later to ensure that size_t is defined
16 years ago
Remove compiler warnings (Including some warnings from -Wstrict-aliasing) Don't use static link by default (in compile-pentium) as some new systems doesn't have all static libraries available Change type for functions in plugin.h:str_mysql_ftparser_param() to const unsigned char and string lengths to size_t. One effect of the above change is that one needs to include mysql_global.h or define size_t before including plugin.h This fixes a case where mysql_client_test failed with newer gcc that enables strict-aliasing by default BUILD/compile-pentium: Don't use static link by default as some new systems doesn't have all static libraries available client/mysql_upgrade.c: Remove not used variable cmd-line-utils/readline/config_readline.h: Define some constants to get rid of compiler warnings on Linux cmd-line-utils/readline/display.c: Get rid of compiler warnings cmd-line-utils/readline/history.c: Got rid of compiler warnings: - Defining some strings as const - Added cast cmd-line-utils/readline/rlmbutil.h: Added cast to get rid of compiler warnings cmd-line-utils/readline/text.c: Remove not needed initialization to get rid of compiler warnings cmd-line-utils/readline/xmalloc.c: Changed types to 'const char* to get rid of compiler warnings configure.in: Ensure that we use MariaDB as suffix include/mysql/plugin.h: Changed types to 'const unsigned char* to get rid of compiler warnings (in other parts of the code) Change length for not \0 terminated string to size_t include/mysql/plugin.h.pp: Update related to plugin.h libmysql/libmysql.c: Fixed bug that caused core dump with newer gcc when strict aliasing is not turned off mysql-test/t/information_schema.test: Test is depending on innodb mysql-test/t/not_partition.test: Fixed wrong directory name (Not noticed before as we don't ususally run this test) mysys/lf_hash.c: Got rid of compiler warnings from -Wstrict-aliasing mysys/my_redel.c: Removed not used variable regex/engine.c: Changed types to 'const char* to get rid of compiler warnings regex/engine.ih: Changed types to 'const char* to get rid of compiler warnings sql/sp_head.cc: Got rid of compiler warning from -Wstrict-aliasing sql/sql_base.cc: Got rid of compiler warnings from -Wstrict-aliasing (The original code was probably wrong as nj_col->table_field was sql/sql_builtin.cc.in: plugin.h needs to have size_t defined sql/sql_parse.cc: Remove used variable sql/sql_select.cc: Got rid of compiler warnings from -Wstrict-aliasing sql/sql_show.cc: Added #ifdef to get rid of compiler warning when not using partition engine sql/table.cc: Got rid of compiler warning from -Wstrict-aliasing storage/maria/ha_maria.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/maria/lockman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/ma_check.c: Got rid of compiler warnings from -Wstrict-aliasing Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_check_standalone.h: Update to compatible _ma_killed_ptr() from ha_maria.cc storage/maria/ma_ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing Ensure that 'subkeys' is 32 bit storage/maria/ma_ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_sort.c: Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_state.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/maria_def.h: Redefine ma_killed_ptr() storage/maria/maria_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/trnman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_stopwords.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ha_myisam.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/myisam/mi_check.c: Use new killed_ptr() function storage/myisam/myisam_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/myisamchk.c: Update to compatible killed_ptr() from ha_myisam.cc storage/myisam/myisamdef.h: Redefine killed_ptr() storage/myisam/myisamlog.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/sort.c: Change to use new version of killed_ptr; Don't call it as often as before storage/xtradb/fil/fil0fil.c: Fixedc ompiler warning storage/xtradb/trx/trx0i_s.c: Include mysql_plugin.h later to ensure that size_t is defined
16 years ago
Remove compiler warnings (Including some warnings from -Wstrict-aliasing) Don't use static link by default (in compile-pentium) as some new systems doesn't have all static libraries available Change type for functions in plugin.h:str_mysql_ftparser_param() to const unsigned char and string lengths to size_t. One effect of the above change is that one needs to include mysql_global.h or define size_t before including plugin.h This fixes a case where mysql_client_test failed with newer gcc that enables strict-aliasing by default BUILD/compile-pentium: Don't use static link by default as some new systems doesn't have all static libraries available client/mysql_upgrade.c: Remove not used variable cmd-line-utils/readline/config_readline.h: Define some constants to get rid of compiler warnings on Linux cmd-line-utils/readline/display.c: Get rid of compiler warnings cmd-line-utils/readline/history.c: Got rid of compiler warnings: - Defining some strings as const - Added cast cmd-line-utils/readline/rlmbutil.h: Added cast to get rid of compiler warnings cmd-line-utils/readline/text.c: Remove not needed initialization to get rid of compiler warnings cmd-line-utils/readline/xmalloc.c: Changed types to 'const char* to get rid of compiler warnings configure.in: Ensure that we use MariaDB as suffix include/mysql/plugin.h: Changed types to 'const unsigned char* to get rid of compiler warnings (in other parts of the code) Change length for not \0 terminated string to size_t include/mysql/plugin.h.pp: Update related to plugin.h libmysql/libmysql.c: Fixed bug that caused core dump with newer gcc when strict aliasing is not turned off mysql-test/t/information_schema.test: Test is depending on innodb mysql-test/t/not_partition.test: Fixed wrong directory name (Not noticed before as we don't ususally run this test) mysys/lf_hash.c: Got rid of compiler warnings from -Wstrict-aliasing mysys/my_redel.c: Removed not used variable regex/engine.c: Changed types to 'const char* to get rid of compiler warnings regex/engine.ih: Changed types to 'const char* to get rid of compiler warnings sql/sp_head.cc: Got rid of compiler warning from -Wstrict-aliasing sql/sql_base.cc: Got rid of compiler warnings from -Wstrict-aliasing (The original code was probably wrong as nj_col->table_field was sql/sql_builtin.cc.in: plugin.h needs to have size_t defined sql/sql_parse.cc: Remove used variable sql/sql_select.cc: Got rid of compiler warnings from -Wstrict-aliasing sql/sql_show.cc: Added #ifdef to get rid of compiler warning when not using partition engine sql/table.cc: Got rid of compiler warning from -Wstrict-aliasing storage/maria/ha_maria.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/maria/lockman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/ma_check.c: Got rid of compiler warnings from -Wstrict-aliasing Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_check_standalone.h: Update to compatible _ma_killed_ptr() from ha_maria.cc storage/maria/ma_ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing Ensure that 'subkeys' is 32 bit storage/maria/ma_ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_sort.c: Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_state.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/maria_def.h: Redefine ma_killed_ptr() storage/maria/maria_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/trnman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_stopwords.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ha_myisam.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/myisam/mi_check.c: Use new killed_ptr() function storage/myisam/myisam_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/myisamchk.c: Update to compatible killed_ptr() from ha_myisam.cc storage/myisam/myisamdef.h: Redefine killed_ptr() storage/myisam/myisamlog.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/sort.c: Change to use new version of killed_ptr; Don't call it as often as before storage/xtradb/fil/fil0fil.c: Fixedc ompiler warning storage/xtradb/trx/trx0i_s.c: Include mysql_plugin.h later to ensure that size_t is defined
16 years ago
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled Essentially, the problem is that safemalloc is excruciatingly slow as it checks all allocated blocks for overrun at each memory management primitive, yielding a almost exponential slowdown for the memory management functions (malloc, realloc, free). The overrun check basically consists of verifying some bytes of a block for certain magic keys, which catches some simple forms of overrun. Another minor problem is violation of aliasing rules and that its own internal list of blocks is prone to corruption. Another issue with safemalloc is rather the maintenance cost as the tool has a significant impact on the server code. Given the magnitude of memory debuggers available nowadays, especially those that are provided with the platform malloc implementation, maintenance of a in-house and largely obsolete memory debugger becomes a burden that is not worth the effort due to its slowness and lack of support for detecting more common forms of heap corruption. Since there are third-party tools that can provide the same functionality at a lower or comparable performance cost, the solution is to simply remove safemalloc. Third-party tools can provide the same functionality at a lower or comparable performance cost. The removal of safemalloc also allows a simplification of the malloc wrappers, removing quite a bit of kludge: redefinition of my_malloc, my_free and the removal of the unused second argument of my_free. Since free() always check whether the supplied pointer is null, redudant checks are also removed. Also, this patch adds unit testing for my_malloc and moves my_realloc implementation into the same file as the other memory allocation primitives. client/mysqldump.c: Pass my_free directly as its signature is compatible with the callback type -- which wasn't the case for free_table_ent.
16 years ago
Remove compiler warnings (Including some warnings from -Wstrict-aliasing) Don't use static link by default (in compile-pentium) as some new systems doesn't have all static libraries available Change type for functions in plugin.h:str_mysql_ftparser_param() to const unsigned char and string lengths to size_t. One effect of the above change is that one needs to include mysql_global.h or define size_t before including plugin.h This fixes a case where mysql_client_test failed with newer gcc that enables strict-aliasing by default BUILD/compile-pentium: Don't use static link by default as some new systems doesn't have all static libraries available client/mysql_upgrade.c: Remove not used variable cmd-line-utils/readline/config_readline.h: Define some constants to get rid of compiler warnings on Linux cmd-line-utils/readline/display.c: Get rid of compiler warnings cmd-line-utils/readline/history.c: Got rid of compiler warnings: - Defining some strings as const - Added cast cmd-line-utils/readline/rlmbutil.h: Added cast to get rid of compiler warnings cmd-line-utils/readline/text.c: Remove not needed initialization to get rid of compiler warnings cmd-line-utils/readline/xmalloc.c: Changed types to 'const char* to get rid of compiler warnings configure.in: Ensure that we use MariaDB as suffix include/mysql/plugin.h: Changed types to 'const unsigned char* to get rid of compiler warnings (in other parts of the code) Change length for not \0 terminated string to size_t include/mysql/plugin.h.pp: Update related to plugin.h libmysql/libmysql.c: Fixed bug that caused core dump with newer gcc when strict aliasing is not turned off mysql-test/t/information_schema.test: Test is depending on innodb mysql-test/t/not_partition.test: Fixed wrong directory name (Not noticed before as we don't ususally run this test) mysys/lf_hash.c: Got rid of compiler warnings from -Wstrict-aliasing mysys/my_redel.c: Removed not used variable regex/engine.c: Changed types to 'const char* to get rid of compiler warnings regex/engine.ih: Changed types to 'const char* to get rid of compiler warnings sql/sp_head.cc: Got rid of compiler warning from -Wstrict-aliasing sql/sql_base.cc: Got rid of compiler warnings from -Wstrict-aliasing (The original code was probably wrong as nj_col->table_field was sql/sql_builtin.cc.in: plugin.h needs to have size_t defined sql/sql_parse.cc: Remove used variable sql/sql_select.cc: Got rid of compiler warnings from -Wstrict-aliasing sql/sql_show.cc: Added #ifdef to get rid of compiler warning when not using partition engine sql/table.cc: Got rid of compiler warning from -Wstrict-aliasing storage/maria/ha_maria.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/maria/lockman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/ma_check.c: Got rid of compiler warnings from -Wstrict-aliasing Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_check_standalone.h: Update to compatible _ma_killed_ptr() from ha_maria.cc storage/maria/ma_ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing Ensure that 'subkeys' is 32 bit storage/maria/ma_ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/maria/ma_sort.c: Change to use new version of _ma_killed_ptr; Don't call it as often as before storage/maria/ma_state.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/maria_def.h: Redefine ma_killed_ptr() storage/maria/maria_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/maria/trnman.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_boolean_search.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_nlq_search.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/ft_parser.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ft_stopwords.c: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ftdefs.h: Changed pointers from char -> const char* and length to size_t (to get rid of compiler warnings and casts) storage/myisam/ha_myisam.cc: Got rid of compiler warnings from -Wstrict-aliasing: - Use the thd_killed() API function storage/myisam/mi_check.c: Use new killed_ptr() function storage/myisam/myisam_ftdump.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/myisamchk.c: Update to compatible killed_ptr() from ha_myisam.cc storage/myisam/myisamdef.h: Redefine killed_ptr() storage/myisam/myisamlog.c: Got rid of compiler warnings from -Wstrict-aliasing storage/myisam/sort.c: Change to use new version of killed_ptr; Don't call it as often as before storage/xtradb/fil/fil0fil.c: Fixedc ompiler warning storage/xtradb/trx/trx0i_s.c: Include mysql_plugin.h later to ensure that size_t is defined
16 years ago
  1. /* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. /*
  13. extensible hash
  14. TODO
  15. try to get rid of dummy nodes ?
  16. for non-unique hash, count only _distinct_ values
  17. (but how to do it in lf_hash_delete ?)
  18. */
  19. #include <my_global.h>
  20. #include <m_string.h>
  21. #include <my_sys.h>
  22. #include <my_bit.h>
  23. #include <lf.h>
  24. LF_REQUIRE_PINS(3)
  25. /* An element of the list */
  26. typedef struct {
  27. intptr volatile link; /* a pointer to the next element in a listand a flag */
  28. uint32 hashnr; /* reversed hash number, for sorting */
  29. const uchar *key;
  30. size_t keylen;
  31. /*
  32. data is stored here, directly after the keylen.
  33. thus the pointer to data is (void*)(slist_element_ptr+1)
  34. */
  35. } LF_SLIST;
  36. const int LF_HASH_OVERHEAD= sizeof(LF_SLIST);
  37. /*
  38. a structure to pass the context (pointers two the three successive elements
  39. in a list) from lfind to linsert/ldelete
  40. */
  41. typedef struct {
  42. intptr volatile *prev;
  43. LF_SLIST *curr, *next;
  44. } CURSOR;
  45. /*
  46. the last bit in LF_SLIST::link is a "deleted" flag.
  47. the helper macros below convert it to a pure pointer or a pure flag
  48. */
  49. #define PTR(V) (LF_SLIST *)((V) & (~(intptr)1))
  50. #define DELETED(V) ((V) & 1)
  51. /*
  52. DESCRIPTION
  53. Search for hashnr/key/keylen in the list starting from 'head' and
  54. position the cursor. The list is ORDER BY hashnr, key
  55. RETURN
  56. 0 - not found
  57. 1 - found
  58. NOTE
  59. cursor is positioned in either case
  60. pins[0..2] are used, they are NOT removed on return
  61. */
  62. static int lfind(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
  63. const uchar *key, uint keylen, CURSOR *cursor, LF_PINS *pins)
  64. {
  65. uint32 cur_hashnr;
  66. const uchar *cur_key;
  67. uint cur_keylen;
  68. intptr link;
  69. retry:
  70. cursor->prev= (intptr *)head;
  71. do { /* PTR() isn't necessary below, head is a dummy node */
  72. cursor->curr= (LF_SLIST *)(*cursor->prev);
  73. _lf_pin(pins, 1, cursor->curr);
  74. } while (*cursor->prev != (intptr)cursor->curr && LF_BACKOFF);
  75. for (;;)
  76. {
  77. if (unlikely(!cursor->curr))
  78. return 0; /* end of the list */
  79. do {
  80. /* QQ: XXX or goto retry ? */
  81. link= cursor->curr->link;
  82. cursor->next= PTR(link);
  83. _lf_pin(pins, 0, cursor->next);
  84. } while (link != cursor->curr->link && LF_BACKOFF);
  85. cur_hashnr= cursor->curr->hashnr;
  86. cur_key= cursor->curr->key;
  87. cur_keylen= cursor->curr->keylen;
  88. if (*cursor->prev != (intptr)cursor->curr)
  89. {
  90. (void)LF_BACKOFF;
  91. goto retry;
  92. }
  93. if (!DELETED(link))
  94. {
  95. if (cur_hashnr >= hashnr)
  96. {
  97. int r= 1;
  98. if (cur_hashnr > hashnr ||
  99. (r= my_strnncoll(cs, (uchar*) cur_key, cur_keylen, (uchar*) key,
  100. keylen)) >= 0)
  101. return !r;
  102. }
  103. cursor->prev= &(cursor->curr->link);
  104. _lf_pin(pins, 2, cursor->curr);
  105. }
  106. else
  107. {
  108. /*
  109. we found a deleted node - be nice, help the other thread
  110. and remove this deleted node
  111. */
  112. if (my_atomic_casptr((void **) cursor->prev,
  113. (void **)(char*) &cursor->curr, cursor->next))
  114. _lf_alloc_free(pins, cursor->curr);
  115. else
  116. {
  117. (void)LF_BACKOFF;
  118. goto retry;
  119. }
  120. }
  121. cursor->curr= cursor->next;
  122. _lf_pin(pins, 1, cursor->curr);
  123. }
  124. }
  125. /*
  126. DESCRIPTION
  127. insert a 'node' in the list that starts from 'head' in the correct
  128. position (as found by lfind)
  129. RETURN
  130. 0 - inserted
  131. not 0 - a pointer to a duplicate (not pinned and thus unusable)
  132. NOTE
  133. it uses pins[0..2], on return all pins are removed.
  134. if there're nodes with the same key value, a new node is added before them.
  135. */
  136. static LF_SLIST *linsert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
  137. LF_SLIST *node, LF_PINS *pins, uint flags)
  138. {
  139. CURSOR cursor;
  140. int res;
  141. for (;;)
  142. {
  143. if (lfind(head, cs, node->hashnr, node->key, node->keylen,
  144. &cursor, pins) &&
  145. (flags & LF_HASH_UNIQUE))
  146. {
  147. res= 0; /* duplicate found */
  148. break;
  149. }
  150. else
  151. {
  152. node->link= (intptr)cursor.curr;
  153. DBUG_ASSERT(node->link != (intptr)node); /* no circular references */
  154. DBUG_ASSERT(cursor.prev != &node->link); /* no circular references */
  155. if (my_atomic_casptr((void **) cursor.prev,
  156. (void **)(char*) &cursor.curr, node))
  157. {
  158. res= 1; /* inserted ok */
  159. break;
  160. }
  161. }
  162. }
  163. _lf_unpin(pins, 0);
  164. _lf_unpin(pins, 1);
  165. _lf_unpin(pins, 2);
  166. /*
  167. Note that cursor.curr is not pinned here and the pointer is unreliable,
  168. the object may dissapear anytime. But if it points to a dummy node, the
  169. pointer is safe, because dummy nodes are never freed - initialize_bucket()
  170. uses this fact.
  171. */
  172. return res ? 0 : cursor.curr;
  173. }
  174. /*
  175. DESCRIPTION
  176. deletes a node as identified by hashnr/keey/keylen from the list
  177. that starts from 'head'
  178. RETURN
  179. 0 - ok
  180. 1 - not found
  181. NOTE
  182. it uses pins[0..2], on return all pins are removed.
  183. */
  184. static int ldelete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
  185. const uchar *key, uint keylen, LF_PINS *pins)
  186. {
  187. CURSOR cursor;
  188. int res;
  189. for (;;)
  190. {
  191. if (!lfind(head, cs, hashnr, key, keylen, &cursor, pins))
  192. {
  193. res= 1; /* not found */
  194. break;
  195. }
  196. else
  197. {
  198. /* mark the node deleted */
  199. if (my_atomic_casptr((void **) (char*) &(cursor.curr->link),
  200. (void **) (char*) &cursor.next,
  201. (void *)(((intptr)cursor.next) | 1)))
  202. {
  203. /* and remove it from the list */
  204. if (my_atomic_casptr((void **)cursor.prev,
  205. (void **)(char*)&cursor.curr, cursor.next))
  206. _lf_alloc_free(pins, cursor.curr);
  207. else
  208. {
  209. /*
  210. somebody already "helped" us and removed the node ?
  211. Let's check if we need to help that someone too!
  212. (to ensure the number of "set DELETED flag" actions
  213. is equal to the number of "remove from the list" actions)
  214. */
  215. lfind(head, cs, hashnr, key, keylen, &cursor, pins);
  216. }
  217. res= 0;
  218. break;
  219. }
  220. }
  221. }
  222. _lf_unpin(pins, 0);
  223. _lf_unpin(pins, 1);
  224. _lf_unpin(pins, 2);
  225. return res;
  226. }
  227. /*
  228. DESCRIPTION
  229. searches for a node as identified by hashnr/keey/keylen in the list
  230. that starts from 'head'
  231. RETURN
  232. 0 - not found
  233. node - found
  234. NOTE
  235. it uses pins[0..2], on return the pin[2] keeps the node found
  236. all other pins are removed.
  237. */
  238. static LF_SLIST *lsearch(LF_SLIST * volatile *head, CHARSET_INFO *cs,
  239. uint32 hashnr, const uchar *key, uint keylen,
  240. LF_PINS *pins)
  241. {
  242. CURSOR cursor;
  243. int res= lfind(head, cs, hashnr, key, keylen, &cursor, pins);
  244. if (res)
  245. _lf_pin(pins, 2, cursor.curr);
  246. else
  247. _lf_unpin(pins, 2);
  248. _lf_unpin(pins, 1);
  249. _lf_unpin(pins, 0);
  250. return res ? cursor.curr : 0;
  251. }
  252. static inline const uchar* hash_key(const LF_HASH *hash,
  253. const uchar *record, size_t *length)
  254. {
  255. if (hash->get_key)
  256. return (*hash->get_key)(record, length, 0);
  257. *length= hash->key_length;
  258. return record + hash->key_offset;
  259. }
  260. /*
  261. Compute the hash key value from the raw key.
  262. @note, that the hash value is limited to 2^31, because we need one
  263. bit to distinguish between normal and dummy nodes.
  264. */
  265. static inline uint calc_hash(LF_HASH *hash, const uchar *key, uint keylen)
  266. {
  267. ulong nr1= 1, nr2= 4;
  268. hash->charset->coll->hash_sort(hash->charset, (uchar*) key, keylen,
  269. &nr1, &nr2);
  270. return nr1 & INT_MAX32;
  271. }
  272. #define MAX_LOAD 1.0 /* average number of elements in a bucket */
  273. static int initialize_bucket(LF_HASH *, LF_SLIST * volatile*, uint, LF_PINS *);
  274. /*
  275. Initializes lf_hash, the arguments are compatible with hash_init
  276. @note element_size sets both the size of allocated memory block for
  277. lf_alloc and a size of memcpy'ed block size in lf_hash_insert. Typically
  278. they are the same, indeed. But LF_HASH::element_size can be decreased
  279. after lf_hash_init, and then lf_alloc will allocate larger block that
  280. lf_hash_insert will copy over. It is desireable if part of the element
  281. is expensive to initialize - for example if there is a mutex or
  282. DYNAMIC_ARRAY. In this case they should be initialize in the
  283. LF_ALLOCATOR::constructor, and lf_hash_insert should not overwrite them.
  284. See wt_init() for example.
  285. */
  286. void lf_hash_init(LF_HASH *hash, uint element_size, uint flags,
  287. uint key_offset, uint key_length, my_hash_get_key get_key,
  288. CHARSET_INFO *charset)
  289. {
  290. lf_alloc_init(&hash->alloc, sizeof(LF_SLIST)+element_size,
  291. offsetof(LF_SLIST, key));
  292. lf_dynarray_init(&hash->array, sizeof(LF_SLIST *));
  293. hash->size= 1;
  294. hash->count= 0;
  295. hash->element_size= element_size;
  296. hash->flags= flags;
  297. hash->charset= charset ? charset : &my_charset_bin;
  298. hash->key_offset= key_offset;
  299. hash->key_length= key_length;
  300. hash->get_key= get_key;
  301. DBUG_ASSERT(get_key ? !key_offset && !key_length : key_length);
  302. }
  303. void lf_hash_destroy(LF_HASH *hash)
  304. {
  305. LF_SLIST *el, **head= (LF_SLIST **)_lf_dynarray_value(&hash->array, 0);
  306. if (head)
  307. {
  308. el= *head;
  309. while (el)
  310. {
  311. intptr next= el->link;
  312. if (el->hashnr & 1)
  313. lf_alloc_direct_free(&hash->alloc, el); /* normal node */
  314. else
  315. my_free(el); /* dummy node */
  316. el= (LF_SLIST *)next;
  317. }
  318. }
  319. lf_alloc_destroy(&hash->alloc);
  320. lf_dynarray_destroy(&hash->array);
  321. }
  322. /*
  323. DESCRIPTION
  324. inserts a new element to a hash. it will have a _copy_ of
  325. data, not a pointer to it.
  326. RETURN
  327. 0 - inserted
  328. 1 - didn't (unique key conflict)
  329. -1 - out of memory
  330. NOTE
  331. see linsert() for pin usage notes
  332. */
  333. int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data)
  334. {
  335. int csize, bucket, hashnr;
  336. LF_SLIST *node, * volatile *el;
  337. lf_rwlock_by_pins(pins);
  338. node= (LF_SLIST *)_lf_alloc_new(pins);
  339. if (unlikely(!node))
  340. return -1;
  341. memcpy(node+1, data, hash->element_size);
  342. node->key= hash_key(hash, (uchar *)(node+1), &node->keylen);
  343. hashnr= calc_hash(hash, node->key, node->keylen);
  344. bucket= hashnr % hash->size;
  345. el= _lf_dynarray_lvalue(&hash->array, bucket);
  346. if (unlikely(!el))
  347. return -1;
  348. if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins)))
  349. return -1;
  350. node->hashnr= my_reverse_bits(hashnr) | 1; /* normal node */
  351. if (linsert(el, hash->charset, node, pins, hash->flags))
  352. {
  353. _lf_alloc_free(pins, node);
  354. lf_rwunlock_by_pins(pins);
  355. return 1;
  356. }
  357. csize= hash->size;
  358. if ((my_atomic_add32(&hash->count, 1)+1.0) / csize > MAX_LOAD)
  359. my_atomic_cas32(&hash->size, &csize, csize*2);
  360. lf_rwunlock_by_pins(pins);
  361. return 0;
  362. }
  363. /*
  364. DESCRIPTION
  365. deletes an element with the given key from the hash (if a hash is
  366. not unique and there're many elements with this key - the "first"
  367. matching element is deleted)
  368. RETURN
  369. 0 - deleted
  370. 1 - didn't (not found)
  371. -1 - out of memory
  372. NOTE
  373. see ldelete() for pin usage notes
  374. */
  375. int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
  376. {
  377. LF_SLIST * volatile *el;
  378. uint bucket, hashnr= calc_hash(hash, (uchar *)key, keylen);
  379. bucket= hashnr % hash->size;
  380. lf_rwlock_by_pins(pins);
  381. el= _lf_dynarray_lvalue(&hash->array, bucket);
  382. if (unlikely(!el))
  383. return -1;
  384. /*
  385. note that we still need to initialize_bucket here,
  386. we cannot return "node not found", because an old bucket of that
  387. node may've been split and the node was assigned to a new bucket
  388. that was never accessed before and thus is not initialized.
  389. */
  390. if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins)))
  391. return -1;
  392. if (ldelete(el, hash->charset, my_reverse_bits(hashnr) | 1,
  393. (uchar *)key, keylen, pins))
  394. {
  395. lf_rwunlock_by_pins(pins);
  396. return 1;
  397. }
  398. my_atomic_add32(&hash->count, -1);
  399. lf_rwunlock_by_pins(pins);
  400. return 0;
  401. }
  402. /*
  403. RETURN
  404. a pointer to an element with the given key (if a hash is not unique and
  405. there're many elements with this key - the "first" matching element)
  406. NULL if nothing is found
  407. MY_ERRPTR if OOM
  408. NOTE
  409. see lsearch() for pin usage notes
  410. */
  411. void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
  412. {
  413. LF_SLIST * volatile *el, *found;
  414. uint bucket, hashnr= calc_hash(hash, (uchar *)key, keylen);
  415. bucket= hashnr % hash->size;
  416. lf_rwlock_by_pins(pins);
  417. el= _lf_dynarray_lvalue(&hash->array, bucket);
  418. if (unlikely(!el))
  419. return MY_ERRPTR;
  420. if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins)))
  421. return MY_ERRPTR;
  422. found= lsearch(el, hash->charset, my_reverse_bits(hashnr) | 1,
  423. (uchar *)key, keylen, pins);
  424. lf_rwunlock_by_pins(pins);
  425. return found ? found+1 : 0;
  426. }
  427. static const uchar *dummy_key= (uchar*)"";
  428. /*
  429. RETURN
  430. 0 - ok
  431. -1 - out of memory
  432. */
  433. static int initialize_bucket(LF_HASH *hash, LF_SLIST * volatile *node,
  434. uint bucket, LF_PINS *pins)
  435. {
  436. uint parent= my_clear_highest_bit(bucket);
  437. LF_SLIST *dummy= (LF_SLIST *)my_malloc(sizeof(LF_SLIST), MYF(MY_WME));
  438. LF_SLIST **tmp= 0, *cur;
  439. LF_SLIST * volatile *el= _lf_dynarray_lvalue(&hash->array, parent);
  440. if (unlikely(!el || !dummy))
  441. return -1;
  442. if (*el == NULL && bucket &&
  443. unlikely(initialize_bucket(hash, el, parent, pins)))
  444. return -1;
  445. dummy->hashnr= my_reverse_bits(bucket) | 0; /* dummy node */
  446. dummy->key= dummy_key;
  447. dummy->keylen= 0;
  448. if ((cur= linsert(el, hash->charset, dummy, pins, LF_HASH_UNIQUE)))
  449. {
  450. my_free(dummy);
  451. dummy= cur;
  452. }
  453. my_atomic_casptr((void **)node, (void **)(char*) &tmp, dummy);
  454. /*
  455. note that if the CAS above failed (after linsert() succeeded),
  456. it would mean that some other thread has executed linsert() for
  457. the same dummy node, its linsert() failed, it picked up our
  458. dummy node (in "dummy= cur") and executed the same CAS as above.
  459. Which means that even if CAS above failed we don't need to retry,
  460. and we should not free(dummy) - there's no memory leak here
  461. */
  462. return 0;
  463. }