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.

4634 lines
141 KiB

26 years ago
26 years ago
26 years ago
24 years ago
24 years ago
26 years ago
26 years ago
24 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
Prevent bugs by making DBUG_* expressions syntactically equivalent to a single statement. --- Bug#24795: SHOW PROFILE Profiling is only partially functional on some architectures. Where there is no getrusage() system call, presently Null values are returned where it would be required. Notably, Windows needs some love applied to make it as useful. Syntax this adds: SHOW PROFILES SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] where "n" is an integer and "types" is zero or many (comma-separated) of "CPU" "MEMORY" (not presently supported) "BLOCK IO" "CONTEXT SWITCHES" "PAGE FAULTS" "IPC" "SWAPS" "SOURCE" "ALL" It also adds a session variable (boolean) "profiling", set to "no" by default, and (integer) profiling_history_size, set to 15 by default. This patch abstracts setting THDs' "proc_info" behind a macro that can be used as a hook into the profiling code when profiling support is compiled in. All future code in this line should use that mechanism for setting thd->proc_info. --- Tests are now set to omit the statistics. --- Adds an Information_schema table, "profiling" for access to "show profile" data. --- Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795 into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community --- Fix merge problems. --- Fixed one bug in the query_source being NULL. Updated test results. --- Include more thorough profiling tests. Improve support for prepared statements. Use session-specific query IDs, starting at zero. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length.
19 years ago
Prevent bugs by making DBUG_* expressions syntactically equivalent to a single statement. --- Bug#24795: SHOW PROFILE Profiling is only partially functional on some architectures. Where there is no getrusage() system call, presently Null values are returned where it would be required. Notably, Windows needs some love applied to make it as useful. Syntax this adds: SHOW PROFILES SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] where "n" is an integer and "types" is zero or many (comma-separated) of "CPU" "MEMORY" (not presently supported) "BLOCK IO" "CONTEXT SWITCHES" "PAGE FAULTS" "IPC" "SWAPS" "SOURCE" "ALL" It also adds a session variable (boolean) "profiling", set to "no" by default, and (integer) profiling_history_size, set to 15 by default. This patch abstracts setting THDs' "proc_info" behind a macro that can be used as a hook into the profiling code when profiling support is compiled in. All future code in this line should use that mechanism for setting thd->proc_info. --- Tests are now set to omit the statistics. --- Adds an Information_schema table, "profiling" for access to "show profile" data. --- Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795 into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community --- Fix merge problems. --- Fixed one bug in the query_source being NULL. Updated test results. --- Include more thorough profiling tests. Improve support for prepared statements. Use session-specific query IDs, starting at zero. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length.
19 years ago
23 years ago
23 years ago
23 years ago
23 years ago
26 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
26 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
Prevent bugs by making DBUG_* expressions syntactically equivalent to a single statement. --- Bug#24795: SHOW PROFILE Profiling is only partially functional on some architectures. Where there is no getrusage() system call, presently Null values are returned where it would be required. Notably, Windows needs some love applied to make it as useful. Syntax this adds: SHOW PROFILES SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] where "n" is an integer and "types" is zero or many (comma-separated) of "CPU" "MEMORY" (not presently supported) "BLOCK IO" "CONTEXT SWITCHES" "PAGE FAULTS" "IPC" "SWAPS" "SOURCE" "ALL" It also adds a session variable (boolean) "profiling", set to "no" by default, and (integer) profiling_history_size, set to 15 by default. This patch abstracts setting THDs' "proc_info" behind a macro that can be used as a hook into the profiling code when profiling support is compiled in. All future code in this line should use that mechanism for setting thd->proc_info. --- Tests are now set to omit the statistics. --- Adds an Information_schema table, "profiling" for access to "show profile" data. --- Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795 into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community --- Fix merge problems. --- Fixed one bug in the query_source being NULL. Updated test results. --- Include more thorough profiling tests. Improve support for prepared statements. Use session-specific query IDs, starting at zero. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length.
19 years ago
23 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
Prevent bugs by making DBUG_* expressions syntactically equivalent to a single statement. --- Bug#24795: SHOW PROFILE Profiling is only partially functional on some architectures. Where there is no getrusage() system call, presently Null values are returned where it would be required. Notably, Windows needs some love applied to make it as useful. Syntax this adds: SHOW PROFILES SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] where "n" is an integer and "types" is zero or many (comma-separated) of "CPU" "MEMORY" (not presently supported) "BLOCK IO" "CONTEXT SWITCHES" "PAGE FAULTS" "IPC" "SWAPS" "SOURCE" "ALL" It also adds a session variable (boolean) "profiling", set to "no" by default, and (integer) profiling_history_size, set to 15 by default. This patch abstracts setting THDs' "proc_info" behind a macro that can be used as a hook into the profiling code when profiling support is compiled in. All future code in this line should use that mechanism for setting thd->proc_info. --- Tests are now set to omit the statistics. --- Adds an Information_schema table, "profiling" for access to "show profile" data. --- Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795 into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community --- Fix merge problems. --- Fixed one bug in the query_source being NULL. Updated test results. --- Include more thorough profiling tests. Improve support for prepared statements. Use session-specific query IDs, starting at zero. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length.
19 years ago
22 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
Prevent bugs by making DBUG_* expressions syntactically equivalent to a single statement. --- Bug#24795: SHOW PROFILE Profiling is only partially functional on some architectures. Where there is no getrusage() system call, presently Null values are returned where it would be required. Notably, Windows needs some love applied to make it as useful. Syntax this adds: SHOW PROFILES SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] where "n" is an integer and "types" is zero or many (comma-separated) of "CPU" "MEMORY" (not presently supported) "BLOCK IO" "CONTEXT SWITCHES" "PAGE FAULTS" "IPC" "SWAPS" "SOURCE" "ALL" It also adds a session variable (boolean) "profiling", set to "no" by default, and (integer) profiling_history_size, set to 15 by default. This patch abstracts setting THDs' "proc_info" behind a macro that can be used as a hook into the profiling code when profiling support is compiled in. All future code in this line should use that mechanism for setting thd->proc_info. --- Tests are now set to omit the statistics. --- Adds an Information_schema table, "profiling" for access to "show profile" data. --- Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795 into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community --- Fix merge problems. --- Fixed one bug in the query_source being NULL. Updated test results. --- Include more thorough profiling tests. Improve support for prepared statements. Use session-specific query IDs, starting at zero. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length.
19 years ago
Prevent bugs by making DBUG_* expressions syntactically equivalent to a single statement. --- Bug#24795: SHOW PROFILE Profiling is only partially functional on some architectures. Where there is no getrusage() system call, presently Null values are returned where it would be required. Notably, Windows needs some love applied to make it as useful. Syntax this adds: SHOW PROFILES SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] where "n" is an integer and "types" is zero or many (comma-separated) of "CPU" "MEMORY" (not presently supported) "BLOCK IO" "CONTEXT SWITCHES" "PAGE FAULTS" "IPC" "SWAPS" "SOURCE" "ALL" It also adds a session variable (boolean) "profiling", set to "no" by default, and (integer) profiling_history_size, set to 15 by default. This patch abstracts setting THDs' "proc_info" behind a macro that can be used as a hook into the profiling code when profiling support is compiled in. All future code in this line should use that mechanism for setting thd->proc_info. --- Tests are now set to omit the statistics. --- Adds an Information_schema table, "profiling" for access to "show profile" data. --- Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795 into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community --- Fix merge problems. --- Fixed one bug in the query_source being NULL. Updated test results. --- Include more thorough profiling tests. Improve support for prepared statements. Use session-specific query IDs, starting at zero. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length.
19 years ago
26 years ago
Prevent bugs by making DBUG_* expressions syntactically equivalent to a single statement. --- Bug#24795: SHOW PROFILE Profiling is only partially functional on some architectures. Where there is no getrusage() system call, presently Null values are returned where it would be required. Notably, Windows needs some love applied to make it as useful. Syntax this adds: SHOW PROFILES SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] where "n" is an integer and "types" is zero or many (comma-separated) of "CPU" "MEMORY" (not presently supported) "BLOCK IO" "CONTEXT SWITCHES" "PAGE FAULTS" "IPC" "SWAPS" "SOURCE" "ALL" It also adds a session variable (boolean) "profiling", set to "no" by default, and (integer) profiling_history_size, set to 15 by default. This patch abstracts setting THDs' "proc_info" behind a macro that can be used as a hook into the profiling code when profiling support is compiled in. All future code in this line should use that mechanism for setting thd->proc_info. --- Tests are now set to omit the statistics. --- Adds an Information_schema table, "profiling" for access to "show profile" data. --- Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795 into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community --- Fix merge problems. --- Fixed one bug in the query_source being NULL. Updated test results. --- Include more thorough profiling tests. Improve support for prepared statements. Use session-specific query IDs, starting at zero. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length.
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
24 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
24 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
22 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
21 years ago
21 years ago
21 years ago
21 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
21 years ago
21 years ago
21 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
sql/ha_innodb.cc enabled query cache for ndb modified engine interface somewhat sql/ha_innodb.h enabled query cache for ndb modified engine interface somewhat sql/ha_ndbcluster.cc enabled query cache for ndb modified engine interface somewhat ndb will only allow caching and retrieval if running autocommit - return false, but do not invalidate commit count is used as engine data, i.e. - store commit count before store of cache - allow retrieval if commit count has not changed on a table - invalidate if commit count has changed sql/ha_ndbcluster.h enabled query cache for ndb modified engine interface somewhat sql/handler.cc enabled query cache for ndb modified engine interface somewhat sql/handler.h enabled query cache for ndb modified engine interface somewhat new virtual handler method cached_table_registration called on each table before alowing store in query cache - return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed - sets ulonglong (engine_data) that is stored in query cache for each table - sets callback to be called for each table before usage of cached query, callback = 0 -> no check later sql/mysql_priv.h enabled query cache for ndb modified engine interface somewhat callcack prototype for callback to engine before query cache retrieval sql/sql_cache.cc enabled query cache for ndb modified engine interface somewhat if callback is set on table in cache, do callback to check if allowed to use cache if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table + changes to store and pass callback and engine_data around sql/sql_cache.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data sql/table.h enabled query cache for ndb modified engine interface somewhat changes to store callback and engine_data
21 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
21 years ago
21 years ago
21 years ago
21 years ago
23 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
26 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
WL#3817: Simplify string / memory area types and make things more consistent (first part) The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
19 years ago
  1. /* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /*
  13. Description of the query cache:
  14. 1. Query_cache object consists of
  15. - query cache memory pool (cache)
  16. - queries hash (queries)
  17. - tables hash (tables)
  18. - list of blocks ordered as they allocated in memory
  19. (first_block)
  20. - list of queries block (queries_blocks)
  21. - list of used tables (tables_blocks)
  22. 2. Query cache memory pool (cache) consists of
  23. - table of steps of memory bins allocation
  24. - table of free memory bins
  25. - blocks of memory
  26. 3. Memory blocks
  27. Every memory block has the following structure:
  28. +----------------------------------------------------------+
  29. | Block header (Query_cache_block structure) |
  30. +----------------------------------------------------------+
  31. |Table of database table lists (used for queries & tables) |
  32. +----------------------------------------------------------+
  33. | Type depended header |
  34. |(Query_cache_query, Query_cache_table, Query_cache_result)|
  35. +----------------------------------------------------------+
  36. | Data ... |
  37. +----------------------------------------------------------+
  38. Block header consists of:
  39. - type:
  40. FREE Free memory block
  41. QUERY Query block
  42. RESULT Ready to send result
  43. RES_CONT Result's continuation
  44. RES_BEG First block of results, that is not yet complete,
  45. written to cache
  46. RES_INCOMPLETE Allocated for results data block
  47. TABLE Block with database table description
  48. INCOMPLETE The destroyed block
  49. - length of block (length)
  50. - length of data & headers (used)
  51. - physical list links (pnext/pprev) - used for the list of
  52. blocks ordered as they are allocated in physical memory
  53. - logical list links (next/prev) - used for queries block list, tables block
  54. list, free memory block lists and list of results block in query
  55. - number of elements in table of database table list (n_tables)
  56. 4. Query & results blocks
  57. Query stored in cache consists of following blocks:
  58. more more
  59. recent+-------------+ old
  60. <-----|Query block 1|------> double linked list of queries block
  61. prev | | next
  62. +-------------+
  63. <-| table 0 |-> (see "Table of database table lists" description)
  64. <-| table 1 |->
  65. | ... | +--------------------------+
  66. +-------------+ +-------------------------+ |
  67. NET | | | V V |
  68. struct| | +-+------------+ +------------+ |
  69. <-----|query header |----->|Result block|-->|Result block|-+ doublelinked
  70. writer| |result| |<--| | list of results
  71. +-------------+ +------------+ +------------+
  72. |charset | +------------+ +------------+ no table of dbtables
  73. |encoding + | | result | | result |
  74. |query text |<-----| header | | header |------+
  75. +-------------+parent| | | |parent|
  76. ^ +------------+ +------------+ |
  77. | |result data | |result data | |
  78. | +------------+ +------------+ |
  79. +---------------------------------------------------+
  80. First query is registered. During the registration query block is
  81. allocated. This query block is included in query hash and is linked
  82. with appropriate database tables lists (if there is no appropriate
  83. list exists it will be created).
  84. Later when query has performed results is written into the result blocks.
  85. A result block cannot be smaller then QUERY_CACHE_MIN_RESULT_DATA_SIZE.
  86. When new result is written to cache it is appended to the last result
  87. block, if no more free space left in the last block, new block is
  88. allocated.
  89. 5. Table of database table lists.
  90. For quick invalidation of queries all query are linked in lists on used
  91. database tables basis (when table will be changed (insert/delete/...)
  92. this queries will be removed from cache).
  93. Root of such list is table block:
  94. +------------+ list of used tables (used while invalidation of
  95. <----| Table |-----> whole database)
  96. prev| block |next +-----------+
  97. | | +-----------+ |Query block|
  98. | | |Query block| +-----------+
  99. +------------+ +-----------+ | ... |
  100. +->| table 0 |------>|table 0 |----->| table N |---+
  101. |+-| |<------| |<-----| |<-+|
  102. || +------------+ | ... | | ... | ||
  103. || |table header| +-----------+ +-----------+ ||
  104. || +------------+ | ... | | ... | ||
  105. || |db name + | +-----------+ +-----------+ ||
  106. || |table name | ||
  107. || +------------+ ||
  108. |+--------------------------------------------------------+|
  109. +----------------------------------------------------------+
  110. Table block is included into the tables hash (tables).
  111. 6. Free blocks, free blocks bins & steps of freeblock bins.
  112. When we just started only one free memory block existed. All query
  113. cache memory (that will be used for block allocation) were
  114. containing in this block.
  115. When a new block is allocated we find most suitable memory block
  116. (minimal of >= required size). If such a block can not be found, we try
  117. to find max block < required size (if we allocate block for results).
  118. If there is no free memory, oldest query is removed from cache, and then
  119. we try to allocate memory. Last step should be repeated until we find
  120. suitable block or until there is no unlocked query found.
  121. If the block is found and its length more then we need, it should be
  122. split into 2 blocks.
  123. New blocks cannot be smaller then min_allocation_unit_bytes.
  124. When a block becomes free, its neighbor-blocks should be tested and if
  125. there are free blocks among them, they should be joined into one block.
  126. Free memory blocks are stored in bins according to their sizes.
  127. The bins are stored in size-descending order.
  128. These bins are distributed (by size) approximately logarithmically.
  129. First bin (number 0) stores free blocks with
  130. size <= query_cache_size>>QUERY_CACHE_MEM_BIN_FIRST_STEP_PWR2.
  131. It is first (number 0) step.
  132. On the next step distributed (1 + QUERY_CACHE_MEM_BIN_PARTS_INC) *
  133. QUERY_CACHE_MEM_BIN_PARTS_MUL bins. This bins allocated in interval from
  134. query_cache_size>>QUERY_CACHE_MEM_BIN_FIRST_STEP_PWR2 to
  135. query_cache_size>>QUERY_CACHE_MEM_BIN_FIRST_STEP_PWR2 >>
  136. QUERY_CACHE_MEM_BIN_STEP_PWR2
  137. ...
  138. On each step interval decreases in 2 power of
  139. QUERY_CACHE_MEM_BIN_STEP_PWR2
  140. times, number of bins (that distributed on this step) increases. If on
  141. the previous step there were N bins distributed , on the current there
  142. would be distributed
  143. (N + QUERY_CACHE_MEM_BIN_PARTS_INC) * QUERY_CACHE_MEM_BIN_PARTS_MUL
  144. bins.
  145. Last distributed bin stores blocks with size near min_allocation_unit
  146. bytes.
  147. For example:
  148. query_cache_size>>QUERY_CACHE_MEM_BIN_FIRST_STEP_PWR2 = 100,
  149. min_allocation_unit = 17,
  150. QUERY_CACHE_MEM_BIN_STEP_PWR2 = 1,
  151. QUERY_CACHE_MEM_BIN_PARTS_INC = 1,
  152. QUERY_CACHE_MEM_BIN_PARTS_MUL = 1
  153. (in followed picture showed right (low) bound of bin):
  154. | 100>>1 50>>1 |25>>1|
  155. | | | | | |
  156. | 100 75 50 41 33 25 21 18 15| 12 | - bins right (low) bounds
  157. |\---/\-----/\--------/\--------|---/ |
  158. | 0 1 2 3 | | - steps
  159. \-----------------------------/ \---/
  160. bins that we store in cache this bin showed for example only
  161. Calculation of steps/bins distribution is performed only when query cache
  162. is resized.
  163. When we need to find appropriate bin, first we should find appropriate
  164. step, then we should calculate number of bins that are using data
  165. stored in Query_cache_memory_bin_step structure.
  166. Free memory blocks are sorted in bins in lists with size-ascending order
  167. (more small blocks needed frequently then bigger one).
  168. 7. Packing cache.
  169. Query cache packing is divided into two operation:
  170. - pack_cache
  171. - join_results
  172. pack_cache moved all blocks to "top" of cache and create one block of free
  173. space at the "bottom":
  174. before pack_cache after pack_cache
  175. +-------------+ +-------------+
  176. | query 1 | | query 1 |
  177. +-------------+ +-------------+
  178. | table 1 | | table 1 |
  179. +-------------+ +-------------+
  180. | results 1.1 | | results 1.1 |
  181. +-------------+ +-------------+
  182. | free | | query 2 |
  183. +-------------+ +-------------+
  184. | query 2 | | table 2 |
  185. +-------------+ ---> +-------------+
  186. | table 2 | | results 1.2 |
  187. +-------------+ +-------------+
  188. | results 1.2 | | results 2 |
  189. +-------------+ +-------------+
  190. | free | | free |
  191. +-------------+ | |
  192. | results 2 | | |
  193. +-------------+ | |
  194. | free | | |
  195. +-------------+ +-------------+
  196. pack_cache scan blocks in physical address order and move every non-free
  197. block "higher".
  198. pack_cach remove every free block it finds. The length of the deleted block
  199. is accumulated to the "gap". All non free blocks should be shifted with the
  200. "gap" step.
  201. join_results scans all complete queries. If the results of query are not
  202. stored in the same block, join_results tries to move results so, that they
  203. are stored in one block.
  204. before join_results after join_results
  205. +-------------+ +-------------+
  206. | query 1 | | query 1 |
  207. +-------------+ +-------------+
  208. | table 1 | | table 1 |
  209. +-------------+ +-------------+
  210. | results 1.1 | | free |
  211. +-------------+ +-------------+
  212. | query 2 | | query 2 |
  213. +-------------+ +-------------+
  214. | table 2 | | table 2 |
  215. +-------------+ ---> +-------------+
  216. | results 1.2 | | free |
  217. +-------------+ +-------------+
  218. | results 2 | | results 2 |
  219. +-------------+ +-------------+
  220. | free | | results 1 |
  221. | | | |
  222. | | +-------------+
  223. | | | free |
  224. | | | |
  225. +-------------+ +-------------+
  226. If join_results allocated new block(s) then we need call pack_cache again.
  227. 7. Interface
  228. The query cache interfaces with the rest of the server code through 7
  229. functions:
  230. 1. Query_cache::send_result_to_client
  231. - Called before parsing and used to match a statement with the stored
  232. queries hash.
  233. If a match is found the cached result set is sent through repeated
  234. calls to net_real_write. (note: calling thread doesn't have a regis-
  235. tered result set writer: thd->net.query_cache_query=0)
  236. 2. Query_cache::store_query
  237. - Called just before handle_select() and is used to register a result
  238. set writer to the statement currently being processed
  239. (thd->net.query_cache_query).
  240. 3. query_cache_insert
  241. - Called from net_real_write to append a result set to a cached query
  242. if (and only if) this query has a registered result set writer
  243. (thd->net.query_cache_query).
  244. 4. Query_cache::invalidate
  245. - Called from various places to invalidate query cache based on data-
  246. base, table and myisam file name. During an on going invalidation
  247. the query cache is temporarily disabled.
  248. 5. Query_cache::flush
  249. - Used when a RESET QUERY CACHE is issued. This clears the entire
  250. cache block by block.
  251. 6. Query_cache::resize
  252. - Used to change the available memory used by the query cache. This
  253. will also invalidate the entrie query cache in one free operation.
  254. 7. Query_cache::pack
  255. - Used when a FLUSH QUERY CACHE is issued. This changes the order of
  256. the used memory blocks in physical memory order and move all avail-
  257. able memory to the 'bottom' of the memory.
  258. TODO list:
  259. - Delayed till after-parsing qache answer (for column rights processing)
  260. - Optimize cache resizing
  261. - if new_size < old_size then pack & shrink
  262. - if new_size > old_size copy cached query to new cache
  263. - Move MRG_MYISAM table type processing to handlers, something like:
  264. tables_used->table->file->register_used_filenames(callback,
  265. first_argument);
  266. - QC improvement suggested by Monty:
  267. - Add a counter in open_table() for how many MERGE (ISAM or MyISAM)
  268. tables are cached in the table cache.
  269. (This will be trivial when we have the new table cache in place I
  270. have been working on)
  271. - After this we can add the following test around the for loop in
  272. is_cacheable::
  273. if (thd->temp_tables || global_merge_table_count)
  274. - Another option would be to set thd->lex->safe_to_cache_query to 0
  275. in 'get_lock_data' if any of the tables was a tmp table or a
  276. MRG_ISAM table.
  277. (This could be done with almost no speed penalty)
  278. */
  279. #include "mysql_priv.h"
  280. #ifdef HAVE_QUERY_CACHE
  281. #include <m_ctype.h>
  282. #include <my_dir.h>
  283. #include <hash.h>
  284. #include "../storage/myisammrg/ha_myisammrg.h"
  285. #include "../storage/myisammrg/myrg_def.h"
  286. #ifdef EMBEDDED_LIBRARY
  287. #include "emb_qcache.h"
  288. #endif
  289. #if !defined(EXTRA_DBUG) && !defined(DBUG_OFF)
  290. #define MUTEX_LOCK(M) { DBUG_PRINT("lock", ("mutex lock 0x%lx", (ulong)(M))); \
  291. pthread_mutex_lock(M);}
  292. #define MUTEX_UNLOCK(M) {DBUG_PRINT("lock", ("mutex unlock 0x%lx",\
  293. (ulong)(M))); pthread_mutex_unlock(M);}
  294. #define RW_WLOCK(M) {DBUG_PRINT("lock", ("rwlock wlock 0x%lx",(ulong)(M))); \
  295. if (!rw_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")); \
  296. else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); }
  297. #define RW_RLOCK(M) {DBUG_PRINT("lock", ("rwlock rlock 0x%lx", (ulong)(M))); \
  298. if (!rw_rdlock(M)) DBUG_PRINT("lock", ("rwlock rlock ok")); \
  299. else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); }
  300. #define RW_UNLOCK(M) {DBUG_PRINT("lock", ("rwlock unlock 0x%lx",(ulong)(M))); \
  301. if (!rw_unlock(M)) DBUG_PRINT("lock", ("rwlock unlock ok")); \
  302. else DBUG_PRINT("lock", ("rwlock unlock FAILED %d", errno)); }
  303. #define BLOCK_LOCK_WR(B) {DBUG_PRINT("lock", ("%d LOCK_WR 0x%lx",\
  304. __LINE__,(ulong)(B))); \
  305. B->query()->lock_writing();}
  306. #define BLOCK_LOCK_RD(B) {DBUG_PRINT("lock", ("%d LOCK_RD 0x%lx",\
  307. __LINE__,(ulong)(B))); \
  308. B->query()->lock_reading();}
  309. #define BLOCK_UNLOCK_WR(B) { \
  310. DBUG_PRINT("lock", ("%d UNLOCK_WR 0x%lx",\
  311. __LINE__,(ulong)(B)));B->query()->unlock_writing();}
  312. #define BLOCK_UNLOCK_RD(B) { \
  313. DBUG_PRINT("lock", ("%d UNLOCK_RD 0x%lx",\
  314. __LINE__,(ulong)(B)));B->query()->unlock_reading();}
  315. #define DUMP(C) DBUG_EXECUTE("qcache", {\
  316. (C)->cache_dump(); (C)->queries_dump();(C)->tables_dump();})
  317. /**
  318. Causes the thread to wait in a spin lock for a query kill signal.
  319. This function is used by the test frame work to identify race conditions.
  320. The signal is caught and ignored and the thread is not killed.
  321. */
  322. static void debug_wait_for_kill(const char *info)
  323. {
  324. DBUG_ENTER("debug_wait_for_kill");
  325. const char *prev_info;
  326. THD *thd;
  327. thd= current_thd;
  328. prev_info= thd->proc_info;
  329. thd->proc_info= info;
  330. sql_print_information("%s", info);
  331. while(!thd->killed)
  332. my_sleep(1000);
  333. thd->killed= THD::NOT_KILLED;
  334. sql_print_information("Exit debug_wait_for_kill");
  335. thd->proc_info= prev_info;
  336. DBUG_VOID_RETURN;
  337. }
  338. #else
  339. #define MUTEX_LOCK(M) pthread_mutex_lock(M)
  340. #define MUTEX_UNLOCK(M) pthread_mutex_unlock(M)
  341. #define RW_WLOCK(M) rw_wrlock(M)
  342. #define RW_RLOCK(M) rw_rdlock(M)
  343. #define RW_UNLOCK(M) rw_unlock(M)
  344. #define BLOCK_LOCK_WR(B) B->query()->lock_writing()
  345. #define BLOCK_LOCK_RD(B) B->query()->lock_reading()
  346. #define BLOCK_UNLOCK_WR(B) B->query()->unlock_writing()
  347. #define BLOCK_UNLOCK_RD(B) B->query()->unlock_reading()
  348. #define DUMP(C)
  349. #endif
  350. const char *query_cache_type_names[]= { "OFF", "ON", "DEMAND",NullS };
  351. TYPELIB query_cache_type_typelib=
  352. {
  353. array_elements(query_cache_type_names)-1,"", query_cache_type_names, NULL
  354. };
  355. /**
  356. Serialize access to the query cache.
  357. If the lock cannot be granted the thread hangs in a conditional wait which
  358. is signalled on each unlock.
  359. The lock attempt will also fail without wait if lock_and_suspend() is in
  360. effect by another thread. This enables a quick path in execution to skip waits
  361. when the outcome is known.
  362. @return
  363. @retval FALSE An exclusive lock was taken
  364. @retval TRUE The locking attempt failed
  365. */
  366. bool Query_cache::try_lock(void)
  367. {
  368. bool interrupt= FALSE;
  369. DBUG_ENTER("Query_cache::try_lock");
  370. pthread_mutex_lock(&structure_guard_mutex);
  371. while (1)
  372. {
  373. if (m_cache_lock_status == Query_cache::UNLOCKED)
  374. {
  375. m_cache_lock_status= Query_cache::LOCKED;
  376. #ifndef DBUG_OFF
  377. THD *thd= current_thd;
  378. if (thd)
  379. m_cache_lock_thread_id= thd->thread_id;
  380. #endif
  381. break;
  382. }
  383. else if (m_cache_lock_status == Query_cache::LOCKED_NO_WAIT)
  384. {
  385. /*
  386. If query cache is protected by a LOCKED_NO_WAIT lock this thread
  387. should avoid using the query cache as it is being evicted.
  388. */
  389. interrupt= TRUE;
  390. break;
  391. }
  392. else
  393. {
  394. DBUG_ASSERT(m_cache_lock_status == Query_cache::LOCKED);
  395. pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
  396. }
  397. }
  398. pthread_mutex_unlock(&structure_guard_mutex);
  399. DBUG_RETURN(interrupt);
  400. }
  401. /**
  402. Serialize access to the query cache.
  403. If the lock cannot be granted the thread hangs in a conditional wait which
  404. is signalled on each unlock.
  405. This method also suspends the query cache so that other threads attempting to
  406. lock the cache with try_lock() will fail directly without waiting.
  407. It is used by all methods which flushes or destroys the whole cache.
  408. */
  409. void Query_cache::lock_and_suspend(void)
  410. {
  411. DBUG_ENTER("Query_cache::lock_and_suspend");
  412. pthread_mutex_lock(&structure_guard_mutex);
  413. while (m_cache_lock_status != Query_cache::UNLOCKED)
  414. pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
  415. m_cache_lock_status= Query_cache::LOCKED_NO_WAIT;
  416. #ifndef DBUG_OFF
  417. THD *thd= current_thd;
  418. if (thd)
  419. m_cache_lock_thread_id= thd->thread_id;
  420. #endif
  421. /* Wake up everybody, a whole cache flush is starting! */
  422. pthread_cond_broadcast(&COND_cache_status_changed);
  423. pthread_mutex_unlock(&structure_guard_mutex);
  424. DBUG_VOID_RETURN;
  425. }
  426. /**
  427. Serialize access to the query cache.
  428. If the lock cannot be granted the thread hangs in a conditional wait which
  429. is signalled on each unlock.
  430. It is used by all methods which invalidates one or more tables.
  431. */
  432. void Query_cache::lock(void)
  433. {
  434. DBUG_ENTER("Query_cache::lock");
  435. pthread_mutex_lock(&structure_guard_mutex);
  436. while (m_cache_lock_status != Query_cache::UNLOCKED)
  437. pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
  438. m_cache_lock_status= Query_cache::LOCKED;
  439. #ifndef DBUG_OFF
  440. THD *thd= current_thd;
  441. if (thd)
  442. m_cache_lock_thread_id= thd->thread_id;
  443. #endif
  444. pthread_mutex_unlock(&structure_guard_mutex);
  445. DBUG_VOID_RETURN;
  446. }
  447. /**
  448. Set the query cache to UNLOCKED and signal waiting threads.
  449. */
  450. void Query_cache::unlock(void)
  451. {
  452. DBUG_ENTER("Query_cache::unlock");
  453. pthread_mutex_lock(&structure_guard_mutex);
  454. #ifndef DBUG_OFF
  455. THD *thd= current_thd;
  456. if (thd)
  457. DBUG_ASSERT(m_cache_lock_thread_id == thd->thread_id);
  458. #endif
  459. DBUG_ASSERT(m_cache_lock_status == Query_cache::LOCKED ||
  460. m_cache_lock_status == Query_cache::LOCKED_NO_WAIT);
  461. m_cache_lock_status= Query_cache::UNLOCKED;
  462. DBUG_PRINT("Query_cache",("Sending signal"));
  463. pthread_cond_signal(&COND_cache_status_changed);
  464. pthread_mutex_unlock(&structure_guard_mutex);
  465. DBUG_VOID_RETURN;
  466. }
  467. /**
  468. Helper function for determine if a SELECT statement has a SQL_NO_CACHE
  469. directive.
  470. @param sql A pointer to the first white space character after SELECT
  471. @return
  472. @retval TRUE The character string contains SQL_NO_CACHE
  473. @retval FALSE No directive found.
  474. */
  475. static bool has_no_cache_directive(char *sql)
  476. {
  477. int i=0;
  478. while (sql[i] == ' ')
  479. ++i;
  480. if (my_toupper(system_charset_info, sql[i]) == 'S' &&
  481. my_toupper(system_charset_info, sql[i+1]) == 'Q' &&
  482. my_toupper(system_charset_info, sql[i+2]) == 'L' &&
  483. my_toupper(system_charset_info, sql[i+3]) == '_' &&
  484. my_toupper(system_charset_info, sql[i+4]) == 'N' &&
  485. my_toupper(system_charset_info, sql[i+5]) == 'O' &&
  486. my_toupper(system_charset_info, sql[i+6]) == '_' &&
  487. my_toupper(system_charset_info, sql[i+7]) == 'C' &&
  488. my_toupper(system_charset_info, sql[i+8]) == 'A' &&
  489. my_toupper(system_charset_info, sql[i+9]) == 'C' &&
  490. my_toupper(system_charset_info, sql[i+10]) == 'H' &&
  491. my_toupper(system_charset_info, sql[i+11]) == 'E' &&
  492. my_toupper(system_charset_info, sql[i+12]) == ' ')
  493. return TRUE;
  494. return FALSE;
  495. }
  496. /*****************************************************************************
  497. Query_cache_block_table method(s)
  498. *****************************************************************************/
  499. inline Query_cache_block * Query_cache_block_table::block()
  500. {
  501. return (Query_cache_block *)(((uchar*)this) -
  502. ALIGN_SIZE(sizeof(Query_cache_block_table)*n) -
  503. ALIGN_SIZE(sizeof(Query_cache_block)));
  504. }
  505. /*****************************************************************************
  506. Query_cache_block method(s)
  507. *****************************************************************************/
  508. void Query_cache_block::init(ulong block_length)
  509. {
  510. DBUG_ENTER("Query_cache_block::init");
  511. DBUG_PRINT("qcache", ("init block: 0x%lx length: %lu", (ulong) this,
  512. block_length));
  513. length = block_length;
  514. used = 0;
  515. type = Query_cache_block::FREE;
  516. n_tables = 0;
  517. DBUG_VOID_RETURN;
  518. }
  519. void Query_cache_block::destroy()
  520. {
  521. DBUG_ENTER("Query_cache_block::destroy");
  522. DBUG_PRINT("qcache", ("destroy block 0x%lx, type %d",
  523. (ulong) this, type));
  524. type = INCOMPLETE;
  525. DBUG_VOID_RETURN;
  526. }
  527. inline uint Query_cache_block::headers_len()
  528. {
  529. return (ALIGN_SIZE(sizeof(Query_cache_block_table)*n_tables) +
  530. ALIGN_SIZE(sizeof(Query_cache_block)));
  531. }
  532. inline uchar* Query_cache_block::data(void)
  533. {
  534. return (uchar*)( ((uchar*)this) + headers_len() );
  535. }
  536. inline Query_cache_query * Query_cache_block::query()
  537. {
  538. #ifndef DBUG_OFF
  539. if (type != QUERY)
  540. query_cache.wreck(__LINE__, "incorrect block type");
  541. #endif
  542. return (Query_cache_query *) data();
  543. }
  544. inline Query_cache_table * Query_cache_block::table()
  545. {
  546. #ifndef DBUG_OFF
  547. if (type != TABLE)
  548. query_cache.wreck(__LINE__, "incorrect block type");
  549. #endif
  550. return (Query_cache_table *) data();
  551. }
  552. inline Query_cache_result * Query_cache_block::result()
  553. {
  554. #ifndef DBUG_OFF
  555. if (type != RESULT && type != RES_CONT && type != RES_BEG &&
  556. type != RES_INCOMPLETE)
  557. query_cache.wreck(__LINE__, "incorrect block type");
  558. #endif
  559. return (Query_cache_result *) data();
  560. }
  561. inline Query_cache_block_table * Query_cache_block::table(TABLE_COUNTER_TYPE n)
  562. {
  563. return ((Query_cache_block_table *)
  564. (((uchar*)this)+ALIGN_SIZE(sizeof(Query_cache_block)) +
  565. n*sizeof(Query_cache_block_table)));
  566. }
  567. /*****************************************************************************
  568. * Query_cache_table method(s)
  569. *****************************************************************************/
  570. extern "C"
  571. {
  572. uchar *query_cache_table_get_key(const uchar *record, size_t *length,
  573. my_bool not_used __attribute__((unused)))
  574. {
  575. Query_cache_block* table_block = (Query_cache_block*) record;
  576. *length = (table_block->used - table_block->headers_len() -
  577. ALIGN_SIZE(sizeof(Query_cache_table)));
  578. return (((uchar *) table_block->data()) +
  579. ALIGN_SIZE(sizeof(Query_cache_table)));
  580. }
  581. }
  582. /*****************************************************************************
  583. Query_cache_query methods
  584. *****************************************************************************/
  585. /*
  586. Following methods work for block read/write locking only in this
  587. particular case and in interaction with structure_guard_mutex.
  588. Lock for write prevents any other locking. (exclusive use)
  589. Lock for read prevents only locking for write.
  590. */
  591. inline void Query_cache_query::lock_writing()
  592. {
  593. RW_WLOCK(&lock);
  594. }
  595. /*
  596. Needed for finding queries, that we may delete from cache.
  597. We don't want to wait while block become unlocked. In addition,
  598. block locking means that query is now used and we don't need to
  599. remove it.
  600. */
  601. my_bool Query_cache_query::try_lock_writing()
  602. {
  603. DBUG_ENTER("Query_cache_block::try_lock_writing");
  604. if (rw_trywrlock(&lock)!=0)
  605. {
  606. DBUG_PRINT("info", ("can't lock rwlock"));
  607. DBUG_RETURN(0);
  608. }
  609. DBUG_PRINT("info", ("rwlock 0x%lx locked", (ulong) &lock));
  610. DBUG_RETURN(1);
  611. }
  612. inline void Query_cache_query::lock_reading()
  613. {
  614. RW_RLOCK(&lock);
  615. }
  616. inline void Query_cache_query::unlock_writing()
  617. {
  618. RW_UNLOCK(&lock);
  619. }
  620. inline void Query_cache_query::unlock_reading()
  621. {
  622. RW_UNLOCK(&lock);
  623. }
  624. void Query_cache_query::init_n_lock()
  625. {
  626. DBUG_ENTER("Query_cache_query::init_n_lock");
  627. res=0; wri = 0; len = 0;
  628. my_rwlock_init(&lock, NULL);
  629. lock_writing();
  630. DBUG_PRINT("qcache", ("inited & locked query for block 0x%lx",
  631. (long) (((uchar*) this) -
  632. ALIGN_SIZE(sizeof(Query_cache_block)))));
  633. DBUG_VOID_RETURN;
  634. }
  635. void Query_cache_query::unlock_n_destroy()
  636. {
  637. DBUG_ENTER("Query_cache_query::unlock_n_destroy");
  638. DBUG_PRINT("qcache", ("destroyed & unlocked query for block 0x%lx",
  639. (long) (((uchar*) this) -
  640. ALIGN_SIZE(sizeof(Query_cache_block)))));
  641. /*
  642. The following call is not needed on system where one can destroy an
  643. active semaphore
  644. */
  645. this->unlock_writing();
  646. rwlock_destroy(&lock);
  647. DBUG_VOID_RETURN;
  648. }
  649. extern "C"
  650. {
  651. uchar *query_cache_query_get_key(const uchar *record, size_t *length,
  652. my_bool not_used)
  653. {
  654. Query_cache_block *query_block = (Query_cache_block*) record;
  655. *length = (query_block->used - query_block->headers_len() -
  656. ALIGN_SIZE(sizeof(Query_cache_query)));
  657. return (((uchar *) query_block->data()) +
  658. ALIGN_SIZE(sizeof(Query_cache_query)));
  659. }
  660. }
  661. /*****************************************************************************
  662. Functions to store things into the query cache
  663. *****************************************************************************/
  664. /*
  665. Note on double-check locking (DCL) usage.
  666. Below, in query_cache_insert(), query_cache_abort() and
  667. query_cache_end_of_result() we use what is called double-check
  668. locking (DCL) for NET::query_cache_query. I.e. we test it first
  669. without a lock, and, if positive, test again under the lock.
  670. This means that if we see 'NET::query_cache_query == 0' without a
  671. lock we will skip the operation. But this is safe here: when we
  672. started to cache a query, we called Query_cache::store_query(), and
  673. NET::query_cache_query was set to non-zero in this thread (and the
  674. thread always sees results of its memory operations, mutex or not).
  675. If later we see 'NET::query_cache_query == 0' without locking a
  676. mutex, that may only mean that some other thread have reset it by
  677. invalidating the query. Skipping the operation in this case is the
  678. right thing to do, as NET::query_cache_query won't get non-zero for
  679. this query again.
  680. See also comments in Query_cache::store_query() and
  681. Query_cache::send_result_to_client().
  682. NOTE, however, that double-check locking is not applicable in
  683. 'invalidate' functions, as we may erroneously skip invalidation,
  684. because the thread doing invalidation may never see non-zero
  685. NET::query_cache_query.
  686. */
  687. void query_cache_init_query(NET *net)
  688. {
  689. /*
  690. It is safe to initialize 'NET::query_cache_query' without a lock
  691. here, because before it will be accessed from different threads it
  692. will be set in this thread under a lock, and access from the same
  693. thread is always safe.
  694. */
  695. net->query_cache_query= 0;
  696. }
  697. /*
  698. Insert the packet into the query cache.
  699. */
  700. void query_cache_insert(NET *net, const char *packet, ulong length)
  701. {
  702. DBUG_ENTER("query_cache_insert");
  703. /* See the comment on double-check locking usage above. */
  704. if (net->query_cache_query == 0)
  705. DBUG_VOID_RETURN;
  706. DBUG_EXECUTE_IF("wait_in_query_cache_insert",
  707. debug_wait_for_kill("wait_in_query_cache_insert"); );
  708. if (query_cache.try_lock())
  709. DBUG_VOID_RETURN;
  710. Query_cache_block *query_block= (Query_cache_block*)net->query_cache_query;
  711. if (!query_block)
  712. {
  713. /*
  714. We lost the writer and the currently processed query has been
  715. invalidated; there is nothing left to do.
  716. */
  717. query_cache.unlock();
  718. DBUG_VOID_RETURN;
  719. }
  720. BLOCK_LOCK_WR(query_block);
  721. Query_cache_query *header= query_block->query();
  722. Query_cache_block *result= header->result();
  723. DUMP(&query_cache);
  724. DBUG_PRINT("qcache", ("insert packet %lu bytes long",length));
  725. /*
  726. On success, STRUCT_UNLOCK is done by append_result_data. Otherwise, we
  727. still need structure_guard_mutex to free the query, and therefore unlock
  728. it later in this function.
  729. */
  730. if (!query_cache.append_result_data(&result, length, (uchar*) packet,
  731. query_block))
  732. {
  733. DBUG_PRINT("warning", ("Can't append data"));
  734. header->result(result);
  735. DBUG_PRINT("qcache", ("free query 0x%lx", (ulong) query_block));
  736. // The following call will remove the lock on query_block
  737. query_cache.free_query(query_block);
  738. query_cache.refused++;
  739. // append_result_data no success => we need unlock
  740. query_cache.unlock();
  741. DBUG_VOID_RETURN;
  742. }
  743. header->result(result);
  744. header->last_pkt_nr= net->pkt_nr;
  745. BLOCK_UNLOCK_WR(query_block);
  746. DBUG_EXECUTE("check_querycache",query_cache.check_integrity(0););
  747. DBUG_VOID_RETURN;
  748. }
  749. void query_cache_abort(NET *net)
  750. {
  751. DBUG_ENTER("query_cache_abort");
  752. THD *thd= current_thd;
  753. /* See the comment on double-check locking usage above. */
  754. if (net->query_cache_query == 0)
  755. DBUG_VOID_RETURN;
  756. if (query_cache.try_lock())
  757. DBUG_VOID_RETURN;
  758. /*
  759. While we were waiting another thread might have changed the status
  760. of the writer. Make sure the writer still exists before continue.
  761. */
  762. Query_cache_block *query_block= ((Query_cache_block*)
  763. net->query_cache_query);
  764. if (query_block)
  765. {
  766. thd_proc_info(thd, "storing result in query cache");
  767. DUMP(&query_cache);
  768. BLOCK_LOCK_WR(query_block);
  769. // The following call will remove the lock on query_block
  770. query_cache.free_query(query_block);
  771. net->query_cache_query= 0;
  772. DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1););
  773. }
  774. query_cache.unlock();
  775. DBUG_VOID_RETURN;
  776. }
  777. void query_cache_end_of_result(THD *thd)
  778. {
  779. Query_cache_block *query_block;
  780. DBUG_ENTER("query_cache_end_of_result");
  781. /* See the comment on double-check locking usage above. */
  782. if (thd->net.query_cache_query == 0)
  783. DBUG_VOID_RETURN;
  784. /* Ensure that only complete results are cached. */
  785. DBUG_ASSERT(thd->main_da.is_eof());
  786. if (thd->killed)
  787. {
  788. query_cache_abort(&thd->net);
  789. DBUG_VOID_RETURN;
  790. }
  791. #ifdef EMBEDDED_LIBRARY
  792. query_cache_insert(&thd->net, (char*)thd,
  793. emb_count_querycache_size(thd));
  794. #endif
  795. if (query_cache.try_lock())
  796. DBUG_VOID_RETURN;
  797. query_block= ((Query_cache_block*) thd->net.query_cache_query);
  798. if (query_block)
  799. {
  800. /*
  801. The writer is still present; finish last result block by chopping it to
  802. suitable size if needed and setting block type. Since this is the last
  803. block, the writer should be dropped.
  804. */
  805. thd_proc_info(thd, "storing result in query cache");
  806. DUMP(&query_cache);
  807. BLOCK_LOCK_WR(query_block);
  808. Query_cache_query *header= query_block->query();
  809. Query_cache_block *last_result_block;
  810. ulong allign_size;
  811. ulong len;
  812. if (header->result() == 0)
  813. {
  814. DBUG_PRINT("error", ("End of data with no result blocks; "
  815. "Query '%s' removed from cache.", header->query()));
  816. /*
  817. Extra safety: empty result should not happen in the normal call
  818. to this function. In the release version that query should be ignored
  819. and removed from QC.
  820. */
  821. DBUG_ASSERT(0);
  822. query_cache.free_query(query_block);
  823. query_cache.unlock();
  824. DBUG_VOID_RETURN;
  825. }
  826. last_result_block= header->result()->prev;
  827. allign_size= ALIGN_SIZE(last_result_block->used);
  828. len= max(query_cache.min_allocation_unit, allign_size);
  829. if (last_result_block->length >= query_cache.min_allocation_unit + len)
  830. query_cache.split_block(last_result_block,len);
  831. header->found_rows(current_thd->limit_found_rows);
  832. header->result()->type= Query_cache_block::RESULT;
  833. /* Drop the writer. */
  834. header->writer(0);
  835. thd->net.query_cache_query= 0;
  836. BLOCK_UNLOCK_WR(query_block);
  837. DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1););
  838. }
  839. query_cache.unlock();
  840. DBUG_VOID_RETURN;
  841. }
  842. void query_cache_invalidate_by_MyISAM_filename(const char *filename)
  843. {
  844. query_cache.invalidate_by_MyISAM_filename(filename);
  845. DBUG_EXECUTE("check_querycache",query_cache.check_integrity(0););
  846. }
  847. /*
  848. The following function forms part of the C plugin API
  849. */
  850. extern "C"
  851. void mysql_query_cache_invalidate4(THD *thd,
  852. const char *key, unsigned key_length,
  853. int using_trx)
  854. {
  855. query_cache.invalidate(thd, key, (uint32) key_length, (my_bool) using_trx);
  856. }
  857. /*****************************************************************************
  858. Query_cache methods
  859. *****************************************************************************/
  860. Query_cache::Query_cache(ulong query_cache_limit_arg,
  861. ulong min_allocation_unit_arg,
  862. ulong min_result_data_size_arg,
  863. uint def_query_hash_size_arg,
  864. uint def_table_hash_size_arg)
  865. :query_cache_size(0),
  866. query_cache_limit(query_cache_limit_arg),
  867. queries_in_cache(0), hits(0), inserts(0), refused(0),
  868. total_blocks(0), lowmem_prunes(0),
  869. min_allocation_unit(ALIGN_SIZE(min_allocation_unit_arg)),
  870. min_result_data_size(ALIGN_SIZE(min_result_data_size_arg)),
  871. def_query_hash_size(ALIGN_SIZE(def_query_hash_size_arg)),
  872. def_table_hash_size(ALIGN_SIZE(def_table_hash_size_arg)),
  873. initialized(0)
  874. {
  875. ulong min_needed= (ALIGN_SIZE(sizeof(Query_cache_block)) +
  876. ALIGN_SIZE(sizeof(Query_cache_block_table)) +
  877. ALIGN_SIZE(sizeof(Query_cache_query)) + 3);
  878. set_if_bigger(min_allocation_unit,min_needed);
  879. this->min_allocation_unit= ALIGN_SIZE(min_allocation_unit);
  880. set_if_bigger(this->min_result_data_size,min_allocation_unit);
  881. }
  882. ulong Query_cache::resize(ulong query_cache_size_arg)
  883. {
  884. ulong new_query_cache_size;
  885. DBUG_ENTER("Query_cache::resize");
  886. DBUG_PRINT("qcache", ("from %lu to %lu",query_cache_size,
  887. query_cache_size_arg));
  888. DBUG_ASSERT(initialized);
  889. lock_and_suspend();
  890. /*
  891. Wait for all readers and writers to exit. When the list of all queries
  892. is iterated over with a block level lock, we are done.
  893. */
  894. Query_cache_block *block= queries_blocks;
  895. if (block)
  896. {
  897. do
  898. {
  899. BLOCK_LOCK_WR(block);
  900. Query_cache_query *query= block->query();
  901. if (query && query->writer())
  902. {
  903. /*
  904. Drop the writer; this will cancel any attempts to store
  905. the processed statement associated with this writer.
  906. */
  907. query->writer()->query_cache_query= 0;
  908. query->writer(0);
  909. refused++;
  910. }
  911. BLOCK_UNLOCK_WR(block);
  912. block= block->next;
  913. } while (block != queries_blocks);
  914. }
  915. free_cache();
  916. query_cache_size= query_cache_size_arg;
  917. new_query_cache_size= init_cache();
  918. if (new_query_cache_size)
  919. DBUG_EXECUTE("check_querycache",check_integrity(1););
  920. unlock();
  921. DBUG_RETURN(new_query_cache_size);
  922. }
  923. ulong Query_cache::set_min_res_unit(ulong size)
  924. {
  925. if (size < min_allocation_unit)
  926. size= min_allocation_unit;
  927. return (min_result_data_size= ALIGN_SIZE(size));
  928. }
  929. void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
  930. {
  931. TABLE_COUNTER_TYPE local_tables;
  932. ulong tot_length;
  933. DBUG_ENTER("Query_cache::store_query");
  934. /*
  935. Testing 'query_cache_size' without a lock here is safe: the thing
  936. we may loose is that the query won't be cached, but we save on
  937. mutex locking in the case when query cache is disabled or the
  938. query is uncachable.
  939. See also a note on double-check locking usage above.
  940. */
  941. if (thd->locked_tables || query_cache_size == 0)
  942. DBUG_VOID_RETURN;
  943. uint8 tables_type= 0;
  944. if ((local_tables= is_cacheable(thd, thd->query_length(),
  945. thd->query(), thd->lex, tables_used,
  946. &tables_type)))
  947. {
  948. NET *net= &thd->net;
  949. Query_cache_query_flags flags;
  950. // fill all gaps between fields with 0 to get repeatable key
  951. bzero(&flags, QUERY_CACHE_FLAGS_SIZE);
  952. flags.client_long_flag= test(thd->client_capabilities & CLIENT_LONG_FLAG);
  953. flags.client_protocol_41= test(thd->client_capabilities &
  954. CLIENT_PROTOCOL_41);
  955. /*
  956. Protocol influences result format, so statement results in the binary
  957. protocol (COM_EXECUTE) cannot be served to statements asking for results
  958. in the text protocol (COM_QUERY) and vice-versa.
  959. */
  960. flags.result_in_binary_protocol= (unsigned int) thd->protocol->type();
  961. flags.more_results_exists= test(thd->server_status &
  962. SERVER_MORE_RESULTS_EXISTS);
  963. flags.in_trans= test(thd->server_status & SERVER_STATUS_IN_TRANS);
  964. flags.autocommit= test(thd->server_status & SERVER_STATUS_AUTOCOMMIT);
  965. flags.pkt_nr= net->pkt_nr;
  966. flags.character_set_client_num=
  967. thd->variables.character_set_client->number;
  968. flags.character_set_results_num=
  969. (thd->variables.character_set_results ?
  970. thd->variables.character_set_results->number :
  971. UINT_MAX);
  972. flags.collation_connection_num=
  973. thd->variables.collation_connection->number;
  974. flags.limit= thd->variables.select_limit;
  975. flags.time_zone= thd->variables.time_zone;
  976. flags.sql_mode= thd->variables.sql_mode;
  977. flags.max_sort_length= thd->variables.max_sort_length;
  978. flags.lc_time_names= thd->variables.lc_time_names;
  979. flags.group_concat_max_len= thd->variables.group_concat_max_len;
  980. flags.div_precision_increment= thd->variables.div_precincrement;
  981. flags.default_week_format= thd->variables.default_week_format;
  982. DBUG_PRINT("qcache", ("\
  983. long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
  984. CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
  985. sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
  986. def_week_frmt: %lu, in_trans: %d, autocommit: %d",
  987. (int)flags.client_long_flag,
  988. (int)flags.client_protocol_41,
  989. (int)flags.result_in_binary_protocol,
  990. (int)flags.more_results_exists,
  991. flags.pkt_nr,
  992. flags.character_set_client_num,
  993. flags.character_set_results_num,
  994. flags.collation_connection_num,
  995. (ulong) flags.limit,
  996. (ulong) flags.time_zone,
  997. flags.sql_mode,
  998. flags.max_sort_length,
  999. flags.group_concat_max_len,
  1000. flags.div_precision_increment,
  1001. flags.default_week_format,
  1002. (int)flags.in_trans,
  1003. (int)flags.autocommit));
  1004. /*
  1005. Make InnoDB to release the adaptive hash index latch before
  1006. acquiring the query cache mutex.
  1007. */
  1008. ha_release_temporary_latches(thd);
  1009. /*
  1010. A table- or a full flush operation can potentially take a long time to
  1011. finish. We choose not to wait for them and skip caching statements
  1012. instead.
  1013. */
  1014. if (try_lock())
  1015. DBUG_VOID_RETURN;
  1016. if (query_cache_size == 0)
  1017. {
  1018. unlock();
  1019. DBUG_VOID_RETURN;
  1020. }
  1021. DUMP(this);
  1022. if (ask_handler_allowance(thd, tables_used))
  1023. {
  1024. refused++;
  1025. unlock();
  1026. DBUG_VOID_RETURN;
  1027. }
  1028. /* Key is query + database + flag */
  1029. if (thd->db_length)
  1030. {
  1031. memcpy(thd->query() + thd->query_length() + 1, thd->db,
  1032. thd->db_length);
  1033. DBUG_PRINT("qcache", ("database: %s length: %u",
  1034. thd->db, (unsigned) thd->db_length));
  1035. }
  1036. else
  1037. {
  1038. DBUG_PRINT("qcache", ("No active database"));
  1039. }
  1040. tot_length= thd->query_length() + thd->db_length + 1 +
  1041. QUERY_CACHE_FLAGS_SIZE;
  1042. /*
  1043. We should only copy structure (don't use it location directly)
  1044. because of alignment issue
  1045. */
  1046. memcpy((void*) (thd->query() + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
  1047. &flags, QUERY_CACHE_FLAGS_SIZE);
  1048. /* Check if another thread is processing the same query? */
  1049. Query_cache_block *competitor = (Query_cache_block *)
  1050. hash_search(&queries, (uchar*) thd->query(), tot_length);
  1051. DBUG_PRINT("qcache", ("competitor 0x%lx", (ulong) competitor));
  1052. if (competitor == 0)
  1053. {
  1054. /* Query is not in cache and no one is working with it; Store it */
  1055. Query_cache_block *query_block;
  1056. query_block= write_block_data(tot_length, (uchar*) thd->query(),
  1057. ALIGN_SIZE(sizeof(Query_cache_query)),
  1058. Query_cache_block::QUERY, local_tables);
  1059. if (query_block != 0)
  1060. {
  1061. DBUG_PRINT("qcache", ("query block 0x%lx allocated, %lu",
  1062. (ulong) query_block, query_block->used));
  1063. Query_cache_query *header = query_block->query();
  1064. header->init_n_lock();
  1065. if (my_hash_insert(&queries, (uchar*) query_block))
  1066. {
  1067. refused++;
  1068. DBUG_PRINT("qcache", ("insertion in query hash"));
  1069. header->unlock_n_destroy();
  1070. free_memory_block(query_block);
  1071. unlock();
  1072. goto end;
  1073. }
  1074. if (!register_all_tables(query_block, tables_used, local_tables))
  1075. {
  1076. refused++;
  1077. DBUG_PRINT("warning", ("tables list including failed"));
  1078. hash_delete(&queries, (uchar *) query_block);
  1079. header->unlock_n_destroy();
  1080. free_memory_block(query_block);
  1081. unlock();
  1082. goto end;
  1083. }
  1084. double_linked_list_simple_include(query_block, &queries_blocks);
  1085. inserts++;
  1086. queries_in_cache++;
  1087. net->query_cache_query= (uchar*) query_block;
  1088. header->writer(net);
  1089. header->tables_type(tables_type);
  1090. unlock();
  1091. // init_n_lock make query block locked
  1092. BLOCK_UNLOCK_WR(query_block);
  1093. }
  1094. else
  1095. {
  1096. // We have not enough memory to store query => do nothing
  1097. refused++;
  1098. unlock();
  1099. DBUG_PRINT("warning", ("Can't allocate query"));
  1100. }
  1101. }
  1102. else
  1103. {
  1104. // Another thread is processing the same query => do nothing
  1105. refused++;
  1106. unlock();
  1107. DBUG_PRINT("qcache", ("Another thread process same query"));
  1108. }
  1109. }
  1110. else if (thd->lex->sql_command == SQLCOM_SELECT)
  1111. statistic_increment(refused, &structure_guard_mutex);
  1112. end:
  1113. DBUG_VOID_RETURN;
  1114. }
  1115. /*
  1116. Check if the query is in the cache. If it was cached, send it
  1117. to the user.
  1118. RESULTS
  1119. 1 Query was not cached.
  1120. 0 The query was cached and user was sent the result.
  1121. -1 The query was cached but we didn't have rights to use it.
  1122. No error is sent to the client yet.
  1123. NOTE
  1124. This method requires that sql points to allocated memory of size:
  1125. tot_length= query_length + thd->db_length + 1 + QUERY_CACHE_FLAGS_SIZE;
  1126. */
  1127. int
  1128. Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
  1129. {
  1130. ulonglong engine_data;
  1131. Query_cache_query *query;
  1132. Query_cache_block *first_result_block, *result_block;
  1133. Query_cache_block_table *block_table, *block_table_end;
  1134. ulong tot_length;
  1135. Query_cache_query_flags flags;
  1136. DBUG_ENTER("Query_cache::send_result_to_client");
  1137. /*
  1138. Testing 'query_cache_size' without a lock here is safe: the thing
  1139. we may loose is that the query won't be served from cache, but we
  1140. save on mutex locking in the case when query cache is disabled.
  1141. See also a note on double-check locking usage above.
  1142. */
  1143. if (thd->locked_tables || thd->variables.query_cache_type == 0 ||
  1144. query_cache_size == 0)
  1145. goto err;
  1146. if (!thd->lex->safe_to_cache_query)
  1147. {
  1148. DBUG_PRINT("qcache", ("SELECT is non-cacheable"));
  1149. goto err;
  1150. }
  1151. {
  1152. uint i= 0;
  1153. /*
  1154. Skip '(' characters in queries like following:
  1155. (select a from t1) union (select a from t1);
  1156. */
  1157. while (sql[i]=='(')
  1158. i++;
  1159. /*
  1160. Test if the query is a SELECT
  1161. (pre-space is removed in dispatch_command).
  1162. First '/' looks like comment before command it is not
  1163. frequently appeared in real life, consequently we can
  1164. check all such queries, too.
  1165. */
  1166. if ((my_toupper(system_charset_info, sql[i]) != 'S' ||
  1167. my_toupper(system_charset_info, sql[i + 1]) != 'E' ||
  1168. my_toupper(system_charset_info, sql[i + 2]) != 'L') &&
  1169. sql[i] != '/')
  1170. {
  1171. DBUG_PRINT("qcache", ("The statement is not a SELECT; Not cached"));
  1172. goto err;
  1173. }
  1174. if (query_length > 20 && has_no_cache_directive(&sql[i+6]))
  1175. {
  1176. /*
  1177. We do not increase 'refused' statistics here since it will be done
  1178. later when the query is parsed.
  1179. */
  1180. DBUG_PRINT("qcache", ("The statement has a SQL_NO_CACHE directive"));
  1181. goto err;
  1182. }
  1183. }
  1184. /*
  1185. Try to obtain an exclusive lock on the query cache. If the cache is
  1186. disabled or if a full cache flush is in progress, the attempt to
  1187. get the lock is aborted.
  1188. */
  1189. if (try_lock())
  1190. goto err;
  1191. if (query_cache_size == 0)
  1192. goto err_unlock;
  1193. /*
  1194. Check that we haven't forgot to reset the query cache variables;
  1195. make sure there are no attached query cache writer to this thread.
  1196. */
  1197. DBUG_ASSERT(thd->net.query_cache_query == 0);
  1198. Query_cache_block *query_block;
  1199. tot_length= query_length + thd->db_length + 1 + QUERY_CACHE_FLAGS_SIZE;
  1200. if (thd->db_length)
  1201. {
  1202. memcpy(sql+query_length+1, thd->db, thd->db_length);
  1203. DBUG_PRINT("qcache", ("database: '%s' length: %u",
  1204. thd->db, (unsigned)thd->db_length));
  1205. }
  1206. else
  1207. {
  1208. DBUG_PRINT("qcache", ("No active database"));
  1209. }
  1210. thd_proc_info(thd, "checking query cache for query");
  1211. // fill all gaps between fields with 0 to get repeatable key
  1212. bzero(&flags, QUERY_CACHE_FLAGS_SIZE);
  1213. flags.client_long_flag= test(thd->client_capabilities & CLIENT_LONG_FLAG);
  1214. flags.client_protocol_41= test(thd->client_capabilities &
  1215. CLIENT_PROTOCOL_41);
  1216. flags.result_in_binary_protocol= (unsigned int)thd->protocol->type();
  1217. flags.more_results_exists= test(thd->server_status &
  1218. SERVER_MORE_RESULTS_EXISTS);
  1219. flags.in_trans= test(thd->server_status & SERVER_STATUS_IN_TRANS);
  1220. flags.autocommit= test(thd->server_status & SERVER_STATUS_AUTOCOMMIT);
  1221. flags.pkt_nr= thd->net.pkt_nr;
  1222. flags.character_set_client_num= thd->variables.character_set_client->number;
  1223. flags.character_set_results_num=
  1224. (thd->variables.character_set_results ?
  1225. thd->variables.character_set_results->number :
  1226. UINT_MAX);
  1227. flags.collation_connection_num= thd->variables.collation_connection->number;
  1228. flags.limit= thd->variables.select_limit;
  1229. flags.time_zone= thd->variables.time_zone;
  1230. flags.sql_mode= thd->variables.sql_mode;
  1231. flags.max_sort_length= thd->variables.max_sort_length;
  1232. flags.group_concat_max_len= thd->variables.group_concat_max_len;
  1233. flags.div_precision_increment= thd->variables.div_precincrement;
  1234. flags.default_week_format= thd->variables.default_week_format;
  1235. flags.lc_time_names= thd->variables.lc_time_names;
  1236. DBUG_PRINT("qcache", ("\
  1237. long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
  1238. CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
  1239. sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
  1240. def_week_frmt: %lu, in_trans: %d, autocommit: %d",
  1241. (int)flags.client_long_flag,
  1242. (int)flags.client_protocol_41,
  1243. (int)flags.result_in_binary_protocol,
  1244. (int)flags.more_results_exists,
  1245. flags.pkt_nr,
  1246. flags.character_set_client_num,
  1247. flags.character_set_results_num,
  1248. flags.collation_connection_num,
  1249. (ulong) flags.limit,
  1250. (ulong) flags.time_zone,
  1251. flags.sql_mode,
  1252. flags.max_sort_length,
  1253. flags.group_concat_max_len,
  1254. flags.div_precision_increment,
  1255. flags.default_week_format,
  1256. (int)flags.in_trans,
  1257. (int)flags.autocommit));
  1258. memcpy((uchar *)(sql + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
  1259. (uchar*) &flags, QUERY_CACHE_FLAGS_SIZE);
  1260. query_block = (Query_cache_block *) hash_search(&queries, (uchar*) sql,
  1261. tot_length);
  1262. /* Quick abort on unlocked data */
  1263. if (query_block == 0 ||
  1264. query_block->query()->result() == 0 ||
  1265. query_block->query()->result()->type != Query_cache_block::RESULT)
  1266. {
  1267. DBUG_PRINT("qcache", ("No query in query hash or no results"));
  1268. goto err_unlock;
  1269. }
  1270. DBUG_PRINT("qcache", ("Query in query hash 0x%lx", (ulong)query_block));
  1271. /* Now lock and test that nothing changed while blocks was unlocked */
  1272. BLOCK_LOCK_RD(query_block);
  1273. query = query_block->query();
  1274. result_block= first_result_block= query->result();
  1275. if (result_block == 0 || result_block->type != Query_cache_block::RESULT)
  1276. {
  1277. /* The query is probably yet processed */
  1278. DBUG_PRINT("qcache", ("query found, but no data or data incomplete"));
  1279. BLOCK_UNLOCK_RD(query_block);
  1280. goto err_unlock;
  1281. }
  1282. DBUG_PRINT("qcache", ("Query have result 0x%lx", (ulong) query));
  1283. if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
  1284. (query->tables_type() & HA_CACHE_TBL_TRANSACT))
  1285. {
  1286. DBUG_PRINT("qcache",
  1287. ("we are in transaction and have transaction tables in query"));
  1288. BLOCK_UNLOCK_RD(query_block);
  1289. goto err_unlock;
  1290. }
  1291. // Check access;
  1292. thd_proc_info(thd, "checking privileges on cached query");
  1293. block_table= query_block->table(0);
  1294. block_table_end= block_table+query_block->n_tables;
  1295. for (; block_table != block_table_end; block_table++)
  1296. {
  1297. TABLE_LIST table_list;
  1298. TABLE *tmptable;
  1299. Query_cache_table *table = block_table->parent;
  1300. /*
  1301. Check that we have not temporary tables with same names of tables
  1302. of this query. If we have such tables, we will not send data from
  1303. query cache, because temporary tables hide real tables by which
  1304. query in query cache was made.
  1305. */
  1306. for (tmptable= thd->temporary_tables; tmptable ; tmptable= tmptable->next)
  1307. {
  1308. if (tmptable->s->table_cache_key.length - TMP_TABLE_KEY_EXTRA ==
  1309. table->key_length() &&
  1310. !memcmp(tmptable->s->table_cache_key.str, table->data(),
  1311. table->key_length()))
  1312. {
  1313. DBUG_PRINT("qcache",
  1314. ("Temporary table detected: '%s.%s'",
  1315. table_list.db, table_list.alias));
  1316. unlock();
  1317. /*
  1318. We should not store result of this query because it contain
  1319. temporary tables => assign following variable to make check
  1320. faster.
  1321. */
  1322. thd->lex->safe_to_cache_query=0;
  1323. BLOCK_UNLOCK_RD(query_block);
  1324. DBUG_RETURN(-1);
  1325. }
  1326. }
  1327. bzero((char*) &table_list,sizeof(table_list));
  1328. table_list.db = table->db();
  1329. table_list.alias= table_list.table_name= table->table();
  1330. #ifndef NO_EMBEDDED_ACCESS_CHECKS
  1331. if (check_table_access(thd,SELECT_ACL,&table_list, 1, TRUE))
  1332. {
  1333. DBUG_PRINT("qcache",
  1334. ("probably no SELECT access to %s.%s => return to normal processing",
  1335. table_list.db, table_list.alias));
  1336. unlock();
  1337. thd->lex->safe_to_cache_query=0; // Don't try to cache this
  1338. BLOCK_UNLOCK_RD(query_block);
  1339. DBUG_RETURN(-1); // Privilege error
  1340. }
  1341. if (table_list.grant.want_privilege)
  1342. {
  1343. DBUG_PRINT("qcache", ("Need to check column privileges for %s.%s",
  1344. table_list.db, table_list.alias));
  1345. BLOCK_UNLOCK_RD(query_block);
  1346. thd->lex->safe_to_cache_query= 0; // Don't try to cache this
  1347. goto err_unlock; // Parse query
  1348. }
  1349. #endif /*!NO_EMBEDDED_ACCESS_CHECKS*/
  1350. engine_data= table->engine_data();
  1351. if (table->callback() &&
  1352. !(*table->callback())(thd, table->db(),
  1353. table->key_length(),
  1354. &engine_data))
  1355. {
  1356. DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s",
  1357. table_list.db, table_list.alias));
  1358. BLOCK_UNLOCK_RD(query_block);
  1359. if (engine_data != table->engine_data())
  1360. {
  1361. DBUG_PRINT("qcache",
  1362. ("Handler require invalidation queries of %s.%s %lu-%lu",
  1363. table_list.db, table_list.alias,
  1364. (ulong) engine_data, (ulong) table->engine_data()));
  1365. invalidate_table_internal(thd,
  1366. (uchar *) table->db(),
  1367. table->key_length());
  1368. }
  1369. else
  1370. thd->lex->safe_to_cache_query= 0; // Don't try to cache this
  1371. goto err_unlock; // Parse query
  1372. }
  1373. else
  1374. DBUG_PRINT("qcache", ("handler allow caching %s,%s",
  1375. table_list.db, table_list.alias));
  1376. }
  1377. move_to_query_list_end(query_block);
  1378. hits++;
  1379. unlock();
  1380. /*
  1381. Send cached result to client
  1382. */
  1383. #ifndef EMBEDDED_LIBRARY
  1384. thd_proc_info(thd, "sending cached result to client");
  1385. do
  1386. {
  1387. DBUG_PRINT("qcache", ("Results (len: %lu used: %lu headers: %lu)",
  1388. result_block->length, result_block->used,
  1389. (ulong) (result_block->headers_len()+
  1390. ALIGN_SIZE(sizeof(Query_cache_result)))));
  1391. Query_cache_result *result = result_block->result();
  1392. if (net_real_write(&thd->net, result->data(),
  1393. result_block->used -
  1394. result_block->headers_len() -
  1395. ALIGN_SIZE(sizeof(Query_cache_result))))
  1396. break; // Client aborted
  1397. result_block = result_block->next;
  1398. thd->net.pkt_nr= query->last_pkt_nr; // Keep packet number updated
  1399. } while (result_block != first_result_block);
  1400. #else
  1401. {
  1402. Querycache_stream qs(result_block, result_block->headers_len() +
  1403. ALIGN_SIZE(sizeof(Query_cache_result)));
  1404. emb_load_querycache_result(thd, &qs);
  1405. }
  1406. #endif /*!EMBEDDED_LIBRARY*/
  1407. thd->limit_found_rows = query->found_rows();
  1408. thd->status_var.last_query_cost= 0.0;
  1409. thd->main_da.disable_status();
  1410. BLOCK_UNLOCK_RD(query_block);
  1411. DBUG_RETURN(1); // Result sent to client
  1412. err_unlock:
  1413. unlock();
  1414. err:
  1415. DBUG_RETURN(0); // Query was not cached
  1416. }
  1417. /*
  1418. Remove all cached queries that uses any of the tables in the list
  1419. */
  1420. void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used,
  1421. my_bool using_transactions)
  1422. {
  1423. DBUG_ENTER("Query_cache::invalidate (table list)");
  1424. using_transactions= using_transactions &&
  1425. (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
  1426. for (; tables_used; tables_used= tables_used->next_local)
  1427. {
  1428. DBUG_ASSERT(!using_transactions || tables_used->table!=0);
  1429. if (tables_used->derived)
  1430. continue;
  1431. if (using_transactions &&
  1432. (tables_used->table->file->table_cache_type() ==
  1433. HA_CACHE_TBL_TRANSACT))
  1434. /*
  1435. tables_used->table can't be 0 in transaction.
  1436. Only 'drop' invalidate not opened table, but 'drop'
  1437. force transaction finish.
  1438. */
  1439. thd->add_changed_table(tables_used->table);
  1440. else
  1441. invalidate_table(thd, tables_used);
  1442. }
  1443. DBUG_EXECUTE_IF("wait_after_query_cache_invalidate",
  1444. debug_wait_for_kill("wait_after_query_cache_invalidate"););
  1445. DBUG_VOID_RETURN;
  1446. }
  1447. void Query_cache::invalidate(CHANGED_TABLE_LIST *tables_used)
  1448. {
  1449. DBUG_ENTER("Query_cache::invalidate (changed table list)");
  1450. THD *thd= current_thd;
  1451. for (; tables_used; tables_used= tables_used->next)
  1452. {
  1453. thd_proc_info(thd, "invalidating query cache entries (table list)");
  1454. invalidate_table(thd, (uchar*) tables_used->key, tables_used->key_length);
  1455. DBUG_PRINT("qcache", ("db: %s table: %s", tables_used->key,
  1456. tables_used->key+
  1457. strlen(tables_used->key)+1));
  1458. }
  1459. DBUG_VOID_RETURN;
  1460. }
  1461. /*
  1462. Invalidate locked for write
  1463. SYNOPSIS
  1464. Query_cache::invalidate_locked_for_write()
  1465. tables_used - table list
  1466. NOTE
  1467. can be used only for opened tables
  1468. */
  1469. void Query_cache::invalidate_locked_for_write(TABLE_LIST *tables_used)
  1470. {
  1471. THD *thd= current_thd;
  1472. DBUG_ENTER("Query_cache::invalidate_locked_for_write");
  1473. for (; tables_used; tables_used= tables_used->next_local)
  1474. {
  1475. thd_proc_info(thd, "invalidating query cache entries (table)");
  1476. if (tables_used->lock_type >= TL_WRITE_ALLOW_WRITE &&
  1477. tables_used->table)
  1478. {
  1479. invalidate_table(thd, tables_used->table);
  1480. }
  1481. }
  1482. DBUG_VOID_RETURN;
  1483. }
  1484. /*
  1485. Remove all cached queries that uses the given table
  1486. */
  1487. void Query_cache::invalidate(THD *thd, TABLE *table,
  1488. my_bool using_transactions)
  1489. {
  1490. DBUG_ENTER("Query_cache::invalidate (table)");
  1491. using_transactions= using_transactions &&
  1492. (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
  1493. if (using_transactions &&
  1494. (table->file->table_cache_type() == HA_CACHE_TBL_TRANSACT))
  1495. thd->add_changed_table(table);
  1496. else
  1497. invalidate_table(thd, table);
  1498. DBUG_VOID_RETURN;
  1499. }
  1500. void Query_cache::invalidate(THD *thd, const char *key, uint32 key_length,
  1501. my_bool using_transactions)
  1502. {
  1503. DBUG_ENTER("Query_cache::invalidate (key)");
  1504. using_transactions= using_transactions &&
  1505. (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
  1506. if (using_transactions) // used for innodb => has_transactions() is TRUE
  1507. thd->add_changed_table(key, key_length);
  1508. else
  1509. invalidate_table(thd, (uchar*)key, key_length);
  1510. DBUG_VOID_RETURN;
  1511. }
  1512. /**
  1513. Remove all cached queries that uses the given database.
  1514. */
  1515. void Query_cache::invalidate(char *db)
  1516. {
  1517. bool restart= FALSE;
  1518. DBUG_ENTER("Query_cache::invalidate (db)");
  1519. /*
  1520. Lock the query cache and queue all invalidation attempts to avoid
  1521. the risk of a race between invalidation, cache inserts and flushes.
  1522. */
  1523. lock();
  1524. THD *thd= current_thd;
  1525. if (query_cache_size > 0)
  1526. {
  1527. if (tables_blocks)
  1528. {
  1529. Query_cache_block *table_block = tables_blocks;
  1530. do {
  1531. restart= FALSE;
  1532. do
  1533. {
  1534. Query_cache_block *next= table_block->next;
  1535. Query_cache_table *table = table_block->table();
  1536. if (strcmp(table->db(),db) == 0)
  1537. {
  1538. Query_cache_block_table *list_root= table_block->table(0);
  1539. invalidate_query_block_list(thd,list_root);
  1540. }
  1541. table_block= next;
  1542. /*
  1543. If our root node to used tables became null then the last element
  1544. in the table list was removed when a query was invalidated;
  1545. Terminate the search.
  1546. */
  1547. if (tables_blocks == 0)
  1548. {
  1549. table_block= tables_blocks;
  1550. }
  1551. /*
  1552. If the iterated list has changed underlying structure;
  1553. we need to restart the search.
  1554. */
  1555. else if (table_block->type == Query_cache_block::FREE)
  1556. {
  1557. restart= TRUE;
  1558. table_block= tables_blocks;
  1559. }
  1560. /*
  1561. The used tables are linked in a circular list;
  1562. loop until we return to the begining.
  1563. */
  1564. } while (table_block != tables_blocks);
  1565. /*
  1566. Invalidating a table will also mean that all cached queries using
  1567. this table also will be invalidated. This will in turn change the
  1568. list of tables associated with these queries and the linked list of
  1569. used table will be changed. Because of this we might need to restart
  1570. the search when a table has been invalidated.
  1571. */
  1572. } while (restart);
  1573. } // end if( tables_blocks )
  1574. }
  1575. unlock();
  1576. DBUG_VOID_RETURN;
  1577. }
  1578. void Query_cache::invalidate_by_MyISAM_filename(const char *filename)
  1579. {
  1580. DBUG_ENTER("Query_cache::invalidate_by_MyISAM_filename");
  1581. /* Calculate the key outside the lock to make the lock shorter */
  1582. char key[MAX_DBKEY_LENGTH];
  1583. uint32 db_length;
  1584. uint key_length= filename_2_table_key(key, filename, &db_length);
  1585. THD *thd= current_thd;
  1586. invalidate_table(thd,(uchar *)key, key_length);
  1587. DBUG_VOID_RETURN;
  1588. }
  1589. /* Remove all queries from cache */
  1590. void Query_cache::flush()
  1591. {
  1592. DBUG_ENTER("Query_cache::flush");
  1593. DBUG_EXECUTE_IF("wait_in_query_cache_flush1",
  1594. debug_wait_for_kill("wait_in_query_cache_flush1"););
  1595. lock_and_suspend();
  1596. if (query_cache_size > 0)
  1597. {
  1598. DUMP(this);
  1599. flush_cache();
  1600. DUMP(this);
  1601. }
  1602. DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1););
  1603. unlock();
  1604. DBUG_VOID_RETURN;
  1605. }
  1606. /**
  1607. Rearrange the memory blocks and join result in cache in 1 block (if
  1608. result length > join_limit)
  1609. @param[in] join_limit If the minimum length of a result block to be joined.
  1610. @param[in] iteration_limit The maximum number of packing and joining
  1611. sequences.
  1612. */
  1613. void Query_cache::pack(ulong join_limit, uint iteration_limit)
  1614. {
  1615. DBUG_ENTER("Query_cache::pack");
  1616. /*
  1617. If the entire qc is being invalidated we can bail out early
  1618. instead of waiting for the lock.
  1619. */
  1620. if (try_lock())
  1621. DBUG_VOID_RETURN;
  1622. if (query_cache_size == 0)
  1623. {
  1624. unlock();
  1625. DBUG_VOID_RETURN;
  1626. }
  1627. uint i = 0;
  1628. do
  1629. {
  1630. pack_cache();
  1631. } while ((++i < iteration_limit) && join_results(join_limit));
  1632. unlock();
  1633. DBUG_VOID_RETURN;
  1634. }
  1635. void Query_cache::destroy()
  1636. {
  1637. DBUG_ENTER("Query_cache::destroy");
  1638. if (!initialized)
  1639. {
  1640. DBUG_PRINT("qcache", ("Query Cache not initialized"));
  1641. }
  1642. else
  1643. {
  1644. /* Underlying code expects the lock. */
  1645. lock_and_suspend();
  1646. free_cache();
  1647. unlock();
  1648. pthread_cond_destroy(&COND_cache_status_changed);
  1649. pthread_mutex_destroy(&structure_guard_mutex);
  1650. initialized = 0;
  1651. }
  1652. DBUG_VOID_RETURN;
  1653. }
  1654. /*****************************************************************************
  1655. init/destroy
  1656. *****************************************************************************/
  1657. void Query_cache::init()
  1658. {
  1659. DBUG_ENTER("Query_cache::init");
  1660. pthread_mutex_init(&structure_guard_mutex,MY_MUTEX_INIT_FAST);
  1661. pthread_cond_init(&COND_cache_status_changed, NULL);
  1662. m_cache_lock_status= Query_cache::UNLOCKED;
  1663. initialized = 1;
  1664. DBUG_VOID_RETURN;
  1665. }
  1666. ulong Query_cache::init_cache()
  1667. {
  1668. uint mem_bin_count, num, step;
  1669. ulong mem_bin_size, prev_size, inc;
  1670. ulong additional_data_size, max_mem_bin_size, approx_additional_data_size;
  1671. int align;
  1672. DBUG_ENTER("Query_cache::init_cache");
  1673. approx_additional_data_size = (sizeof(Query_cache) +
  1674. sizeof(uchar*)*(def_query_hash_size+
  1675. def_table_hash_size));
  1676. if (query_cache_size < approx_additional_data_size)
  1677. goto err;
  1678. query_cache_size-= approx_additional_data_size;
  1679. align= query_cache_size % ALIGN_SIZE(1);
  1680. if (align)
  1681. {
  1682. query_cache_size-= align;
  1683. approx_additional_data_size+= align;
  1684. }
  1685. /*
  1686. Count memory bins number.
  1687. Check section 6. in start comment for the used algorithm.
  1688. */
  1689. max_mem_bin_size = query_cache_size >> QUERY_CACHE_MEM_BIN_FIRST_STEP_PWR2;
  1690. mem_bin_count = (uint) ((1 + QUERY_CACHE_MEM_BIN_PARTS_INC) *
  1691. QUERY_CACHE_MEM_BIN_PARTS_MUL);
  1692. mem_bin_num = 1;
  1693. mem_bin_steps = 1;
  1694. mem_bin_size = max_mem_bin_size >> QUERY_CACHE_MEM_BIN_STEP_PWR2;
  1695. prev_size = 0;
  1696. if (mem_bin_size <= min_allocation_unit)
  1697. {
  1698. DBUG_PRINT("qcache", ("too small query cache => query cache disabled"));
  1699. // TODO here (and above) should be warning in 4.1
  1700. goto err;
  1701. }
  1702. while (mem_bin_size > min_allocation_unit)
  1703. {
  1704. mem_bin_num += mem_bin_count;
  1705. prev_size = mem_bin_size;
  1706. mem_bin_size >>= QUERY_CACHE_MEM_BIN_STEP_PWR2;
  1707. mem_bin_steps++;
  1708. mem_bin_count += QUERY_CACHE_MEM_BIN_PARTS_INC;
  1709. mem_bin_count = (uint) (mem_bin_count * QUERY_CACHE_MEM_BIN_PARTS_MUL);
  1710. // Prevent too small bins spacing
  1711. if (mem_bin_count > (mem_bin_size >> QUERY_CACHE_MEM_BIN_SPC_LIM_PWR2))
  1712. mem_bin_count= (mem_bin_size >> QUERY_CACHE_MEM_BIN_SPC_LIM_PWR2);
  1713. }
  1714. inc = (prev_size - mem_bin_size) / mem_bin_count;
  1715. mem_bin_num += (mem_bin_count - (min_allocation_unit - mem_bin_size)/inc);
  1716. mem_bin_steps++;
  1717. additional_data_size = ((mem_bin_num+1) *
  1718. ALIGN_SIZE(sizeof(Query_cache_memory_bin))+
  1719. (mem_bin_steps *
  1720. ALIGN_SIZE(sizeof(Query_cache_memory_bin_step))));
  1721. if (query_cache_size < additional_data_size)
  1722. goto err;
  1723. query_cache_size -= additional_data_size;
  1724. if (!(cache= (uchar *)
  1725. my_malloc_lock(query_cache_size+additional_data_size, MYF(0))))
  1726. goto err;
  1727. DBUG_PRINT("qcache", ("cache length %lu, min unit %lu, %u bins",
  1728. query_cache_size, min_allocation_unit, mem_bin_num));
  1729. steps = (Query_cache_memory_bin_step *) cache;
  1730. bins = ((Query_cache_memory_bin *)
  1731. (cache + mem_bin_steps *
  1732. ALIGN_SIZE(sizeof(Query_cache_memory_bin_step))));
  1733. first_block = (Query_cache_block *) (cache + additional_data_size);
  1734. first_block->init(query_cache_size);
  1735. total_blocks++;
  1736. first_block->pnext=first_block->pprev=first_block;
  1737. first_block->next=first_block->prev=first_block;
  1738. /* Prepare bins */
  1739. bins[0].init(max_mem_bin_size);
  1740. steps[0].init(max_mem_bin_size,0,0);
  1741. mem_bin_count = (uint) ((1 + QUERY_CACHE_MEM_BIN_PARTS_INC) *
  1742. QUERY_CACHE_MEM_BIN_PARTS_MUL);
  1743. num= step= 1;
  1744. mem_bin_size = max_mem_bin_size >> QUERY_CACHE_MEM_BIN_STEP_PWR2;
  1745. while (mem_bin_size > min_allocation_unit)
  1746. {
  1747. ulong incr = (steps[step-1].size - mem_bin_size) / mem_bin_count;
  1748. unsigned long size = mem_bin_size;
  1749. for (uint i= mem_bin_count; i > 0; i--)
  1750. {
  1751. bins[num+i-1].init(size);
  1752. size += incr;
  1753. }
  1754. num += mem_bin_count;
  1755. steps[step].init(mem_bin_size, num-1, incr);
  1756. mem_bin_size >>= QUERY_CACHE_MEM_BIN_STEP_PWR2;
  1757. step++;
  1758. mem_bin_count += QUERY_CACHE_MEM_BIN_PARTS_INC;
  1759. mem_bin_count = (uint) (mem_bin_count * QUERY_CACHE_MEM_BIN_PARTS_MUL);
  1760. if (mem_bin_count > (mem_bin_size >> QUERY_CACHE_MEM_BIN_SPC_LIM_PWR2))
  1761. mem_bin_count=(mem_bin_size >> QUERY_CACHE_MEM_BIN_SPC_LIM_PWR2);
  1762. }
  1763. inc = (steps[step-1].size - mem_bin_size) / mem_bin_count;
  1764. /*
  1765. num + mem_bin_count > mem_bin_num, but index never be > mem_bin_num
  1766. because block with size < min_allocated_unit never will be requested
  1767. */
  1768. steps[step].init(mem_bin_size, num + mem_bin_count - 1, inc);
  1769. {
  1770. uint skiped = (min_allocation_unit - mem_bin_size)/inc;
  1771. ulong size = mem_bin_size + inc*skiped;
  1772. uint i = mem_bin_count - skiped;
  1773. while (i-- > 0)
  1774. {
  1775. bins[num+i].init(size);
  1776. size += inc;
  1777. }
  1778. }
  1779. bins[mem_bin_num].number = 1; // For easy end test in get_free_block
  1780. free_memory = free_memory_blocks = 0;
  1781. insert_into_free_memory_list(first_block);
  1782. DUMP(this);
  1783. VOID(hash_init(&queries, &my_charset_bin, def_query_hash_size, 0, 0,
  1784. query_cache_query_get_key, 0, 0));
  1785. #ifndef FN_NO_CASE_SENCE
  1786. /*
  1787. If lower_case_table_names!=0 then db and table names are already
  1788. converted to lower case and we can use binary collation for their
  1789. comparison (no matter if file system case sensitive or not).
  1790. If we have case-sensitive file system (like on most Unixes) and
  1791. lower_case_table_names == 0 then we should distinguish my_table
  1792. and MY_TABLE cases and so again can use binary collation.
  1793. */
  1794. VOID(hash_init(&tables, &my_charset_bin, def_table_hash_size, 0, 0,
  1795. query_cache_table_get_key, 0, 0));
  1796. #else
  1797. /*
  1798. On windows, OS/2, MacOS X with HFS+ or any other case insensitive
  1799. file system if lower_case_table_names!=0 we have same situation as
  1800. in previous case, but if lower_case_table_names==0 then we should
  1801. not distinguish cases (to be compatible in behavior with underlying
  1802. file system) and so should use case insensitive collation for
  1803. comparison.
  1804. */
  1805. VOID(hash_init(&tables,
  1806. lower_case_table_names ? &my_charset_bin :
  1807. files_charset_info,
  1808. def_table_hash_size, 0, 0,query_cache_table_get_key, 0, 0));
  1809. #endif
  1810. queries_in_cache = 0;
  1811. queries_blocks = 0;
  1812. DBUG_RETURN(query_cache_size +
  1813. additional_data_size + approx_additional_data_size);
  1814. err:
  1815. make_disabled();
  1816. DBUG_RETURN(0);
  1817. }
  1818. /* Disable the use of the query cache */
  1819. void Query_cache::make_disabled()
  1820. {
  1821. DBUG_ENTER("Query_cache::make_disabled");
  1822. query_cache_size= 0;
  1823. queries_blocks= 0;
  1824. free_memory= 0;
  1825. free_memory_blocks= 0;
  1826. bins= 0;
  1827. steps= 0;
  1828. cache= 0;
  1829. mem_bin_num= mem_bin_steps= 0;
  1830. queries_in_cache= 0;
  1831. first_block= 0;
  1832. total_blocks= 0;
  1833. tables_blocks= 0;
  1834. DBUG_VOID_RETURN;
  1835. }
  1836. /**
  1837. @class Query_cache
  1838. Free all resources allocated by the cache.
  1839. This function frees all resources allocated by the cache. You
  1840. have to call init_cache() before using the cache again. This function
  1841. requires the structure_guard_mutex to be locked.
  1842. */
  1843. void Query_cache::free_cache()
  1844. {
  1845. DBUG_ENTER("Query_cache::free_cache");
  1846. my_free((uchar*) cache, MYF(MY_ALLOW_ZERO_PTR));
  1847. make_disabled();
  1848. hash_free(&queries);
  1849. hash_free(&tables);
  1850. DBUG_VOID_RETURN;
  1851. }
  1852. /*****************************************************************************
  1853. Free block data
  1854. *****************************************************************************/
  1855. /**
  1856. Flush the cache.
  1857. This function will flush cache contents. It assumes we have
  1858. 'structure_guard_mutex' locked. The function sets the m_cache_status flag and
  1859. releases the lock, so other threads may proceed skipping the cache as if it
  1860. is disabled. Concurrent flushes are performed in turn.
  1861. After flush_cache() call, the cache is flushed, all the freed memory is
  1862. accumulated in bin[0], and the 'structure_guard_mutex' is locked. However,
  1863. since we could release the mutex during execution, the rest of the cache
  1864. state could have been changed, and should not be relied on.
  1865. */
  1866. void Query_cache::flush_cache()
  1867. {
  1868. DBUG_EXECUTE_IF("wait_in_query_cache_flush2",
  1869. debug_wait_for_kill("wait_in_query_cache_flush2"););
  1870. my_hash_reset(&queries);
  1871. while (queries_blocks != 0)
  1872. {
  1873. BLOCK_LOCK_WR(queries_blocks);
  1874. free_query_internal(queries_blocks);
  1875. }
  1876. }
  1877. /*
  1878. Free oldest query that is not in use by another thread.
  1879. Returns 1 if we couldn't remove anything
  1880. */
  1881. my_bool Query_cache::free_old_query()
  1882. {
  1883. DBUG_ENTER("Query_cache::free_old_query");
  1884. if (queries_blocks)
  1885. {
  1886. /*
  1887. try_lock_writing used to prevent client because here lock
  1888. sequence is breached.
  1889. Also we don't need remove locked queries at this point.
  1890. */
  1891. Query_cache_block *query_block= 0;
  1892. if (queries_blocks != 0)
  1893. {
  1894. Query_cache_block *block = queries_blocks;
  1895. /* Search until we find first query that we can remove */
  1896. do
  1897. {
  1898. Query_cache_query *header = block->query();
  1899. if (header->result() != 0 &&
  1900. header->result()->type == Query_cache_block::RESULT &&
  1901. block->query()->try_lock_writing())
  1902. {
  1903. query_block = block;
  1904. break;
  1905. }
  1906. } while ((block=block->next) != queries_blocks );
  1907. }
  1908. if (query_block != 0)
  1909. {
  1910. free_query(query_block);
  1911. lowmem_prunes++;
  1912. DBUG_RETURN(0);
  1913. }
  1914. }
  1915. DBUG_RETURN(1); // Nothing to remove
  1916. }
  1917. /*
  1918. free_query_internal() - free query from query cache.
  1919. SYNOPSIS
  1920. free_query_internal()
  1921. query_block Query_cache_block representing the query
  1922. DESCRIPTION
  1923. This function will remove the query from a cache, and place its
  1924. memory blocks to the list of free blocks. 'query_block' must be
  1925. locked for writing, this function will release (and destroy) this
  1926. lock.
  1927. NOTE
  1928. 'query_block' should be removed from 'queries' hash _before_
  1929. calling this method, as the lock will be destroyed here.
  1930. */
  1931. void Query_cache::free_query_internal(Query_cache_block *query_block)
  1932. {
  1933. DBUG_ENTER("Query_cache::free_query_internal");
  1934. DBUG_PRINT("qcache", ("free query 0x%lx %lu bytes result",
  1935. (ulong) query_block,
  1936. query_block->query()->length() ));
  1937. queries_in_cache--;
  1938. Query_cache_query *query= query_block->query();
  1939. if (query->writer() != 0)
  1940. {
  1941. /* Tell MySQL that this query should not be cached anymore */
  1942. query->writer()->query_cache_query= 0;
  1943. query->writer(0);
  1944. }
  1945. double_linked_list_exclude(query_block, &queries_blocks);
  1946. Query_cache_block_table *table= query_block->table(0);
  1947. for (TABLE_COUNTER_TYPE i= 0; i < query_block->n_tables; i++)
  1948. unlink_table(table++);
  1949. Query_cache_block *result_block= query->result();
  1950. /*
  1951. The following is true when query destruction was called and no results
  1952. in query . (query just registered and then abort/pack/flush called)
  1953. */
  1954. if (result_block != 0)
  1955. {
  1956. if (result_block->type != Query_cache_block::RESULT)
  1957. {
  1958. // removing unfinished query
  1959. refused++;
  1960. inserts--;
  1961. }
  1962. Query_cache_block *block= result_block;
  1963. do
  1964. {
  1965. Query_cache_block *current= block;
  1966. block= block->next;
  1967. free_memory_block(current);
  1968. } while (block != result_block);
  1969. }
  1970. else
  1971. {
  1972. // removing unfinished query
  1973. refused++;
  1974. inserts--;
  1975. }
  1976. query->unlock_n_destroy();
  1977. free_memory_block(query_block);
  1978. DBUG_VOID_RETURN;
  1979. }
  1980. /*
  1981. free_query() - free query from query cache.
  1982. SYNOPSIS
  1983. free_query()
  1984. query_block Query_cache_block representing the query
  1985. DESCRIPTION
  1986. This function will remove 'query_block' from 'queries' hash, and
  1987. then call free_query_internal(), which see.
  1988. */
  1989. void Query_cache::free_query(Query_cache_block *query_block)
  1990. {
  1991. DBUG_ENTER("Query_cache::free_query");
  1992. DBUG_PRINT("qcache", ("free query 0x%lx %lu bytes result",
  1993. (ulong) query_block,
  1994. query_block->query()->length() ));
  1995. hash_delete(&queries,(uchar *) query_block);
  1996. free_query_internal(query_block);
  1997. DBUG_VOID_RETURN;
  1998. }
  1999. /*****************************************************************************
  2000. Query data creation
  2001. *****************************************************************************/
  2002. Query_cache_block *
  2003. Query_cache::write_block_data(ulong data_len, uchar* data,
  2004. ulong header_len,
  2005. Query_cache_block::block_type type,
  2006. TABLE_COUNTER_TYPE ntab)
  2007. {
  2008. ulong all_headers_len = (ALIGN_SIZE(sizeof(Query_cache_block)) +
  2009. ALIGN_SIZE(ntab*sizeof(Query_cache_block_table)) +
  2010. header_len);
  2011. ulong len = data_len + all_headers_len;
  2012. ulong align_len= ALIGN_SIZE(len);
  2013. DBUG_ENTER("Query_cache::write_block_data");
  2014. DBUG_PRINT("qcache", ("data: %ld, header: %ld, all header: %ld",
  2015. data_len, header_len, all_headers_len));
  2016. Query_cache_block *block= allocate_block(max(align_len,
  2017. min_allocation_unit),1, 0);
  2018. if (block != 0)
  2019. {
  2020. block->type = type;
  2021. block->n_tables = ntab;
  2022. block->used = len;
  2023. memcpy((uchar *) block+ all_headers_len, data, data_len);
  2024. }
  2025. DBUG_RETURN(block);
  2026. }
  2027. my_bool
  2028. Query_cache::append_result_data(Query_cache_block **current_block,
  2029. ulong data_len, uchar* data,
  2030. Query_cache_block *query_block)
  2031. {
  2032. DBUG_ENTER("Query_cache::append_result_data");
  2033. DBUG_PRINT("qcache", ("append %lu bytes to 0x%lx query",
  2034. data_len, (long) query_block));
  2035. if (query_block->query()->add(data_len) > query_cache_limit)
  2036. {
  2037. DBUG_PRINT("qcache", ("size limit reached %lu > %lu",
  2038. query_block->query()->length(),
  2039. query_cache_limit));
  2040. DBUG_RETURN(0);
  2041. }
  2042. if (*current_block == 0)
  2043. {
  2044. DBUG_PRINT("qcache", ("allocated first result data block %lu", data_len));
  2045. DBUG_RETURN(write_result_data(current_block, data_len, data, query_block,
  2046. Query_cache_block::RES_BEG));
  2047. }
  2048. Query_cache_block *last_block = (*current_block)->prev;
  2049. DBUG_PRINT("qcache", ("lastblock 0x%lx len %lu used %lu",
  2050. (ulong) last_block, last_block->length,
  2051. last_block->used));
  2052. my_bool success = 1;
  2053. ulong last_block_free_space= last_block->length - last_block->used;
  2054. /*
  2055. We will first allocate and write the 'tail' of data, that doesn't fit
  2056. in the 'last_block'. Only if this succeeds, we will fill the last_block.
  2057. This saves us a memcpy if the query doesn't fit in the query cache.
  2058. */
  2059. // Try join blocks if physically next block is free...
  2060. ulong tail = data_len - last_block_free_space;
  2061. ulong append_min = get_min_append_result_data_size();
  2062. if (last_block_free_space < data_len &&
  2063. append_next_free_block(last_block,
  2064. max(tail, append_min)))
  2065. last_block_free_space = last_block->length - last_block->used;
  2066. // If no space in last block (even after join) allocate new block
  2067. if (last_block_free_space < data_len)
  2068. {
  2069. DBUG_PRINT("qcache", ("allocate new block for %lu bytes",
  2070. data_len-last_block_free_space));
  2071. Query_cache_block *new_block = 0;
  2072. success = write_result_data(&new_block, data_len-last_block_free_space,
  2073. (uchar*)(((uchar*)data)+last_block_free_space),
  2074. query_block,
  2075. Query_cache_block::RES_CONT);
  2076. /*
  2077. new_block may be != 0 even !success (if write_result_data
  2078. allocate a small block but failed to allocate continue)
  2079. */
  2080. if (new_block != 0)
  2081. double_linked_list_join(last_block, new_block);
  2082. }
  2083. else
  2084. {
  2085. // It is success (nobody can prevent us write data)
  2086. unlock();
  2087. }
  2088. // Now finally write data to the last block
  2089. if (success && last_block_free_space > 0)
  2090. {
  2091. ulong to_copy = min(data_len,last_block_free_space);
  2092. DBUG_PRINT("qcache", ("use free space %lub at block 0x%lx to copy %lub",
  2093. last_block_free_space, (ulong)last_block, to_copy));
  2094. memcpy((uchar*) last_block + last_block->used, data, to_copy);
  2095. last_block->used+=to_copy;
  2096. }
  2097. DBUG_RETURN(success);
  2098. }
  2099. my_bool Query_cache::write_result_data(Query_cache_block **result_block,
  2100. ulong data_len, uchar* data,
  2101. Query_cache_block *query_block,
  2102. Query_cache_block::block_type type)
  2103. {
  2104. DBUG_ENTER("Query_cache::write_result_data");
  2105. DBUG_PRINT("qcache", ("data_len %lu",data_len));
  2106. /*
  2107. Reserve block(s) for filling
  2108. During data allocation we must have structure_guard_mutex locked.
  2109. As data copy is not a fast operation, it's better if we don't have
  2110. structure_guard_mutex locked during data coping.
  2111. Thus we first allocate space and lock query, then unlock
  2112. structure_guard_mutex and copy data.
  2113. */
  2114. my_bool success = allocate_data_chain(result_block, data_len, query_block,
  2115. type == Query_cache_block::RES_BEG);
  2116. if (success)
  2117. {
  2118. // It is success (nobody can prevent us write data)
  2119. unlock();
  2120. uint headers_len = (ALIGN_SIZE(sizeof(Query_cache_block)) +
  2121. ALIGN_SIZE(sizeof(Query_cache_result)));
  2122. #ifndef EMBEDDED_LIBRARY
  2123. Query_cache_block *block= *result_block;
  2124. uchar *rest= data;
  2125. // Now fill list of blocks that created by allocate_data_chain
  2126. do
  2127. {
  2128. block->type = type;
  2129. ulong length = block->used - headers_len;
  2130. DBUG_PRINT("qcache", ("write %lu byte in block 0x%lx",length,
  2131. (ulong)block));
  2132. memcpy((uchar*) block+headers_len, rest, length);
  2133. rest += length;
  2134. block = block->next;
  2135. type = Query_cache_block::RES_CONT;
  2136. } while (block != *result_block);
  2137. #else
  2138. /*
  2139. Set type of first block, emb_store_querycache_result() will handle
  2140. the others.
  2141. */
  2142. (*result_block)->type= type;
  2143. Querycache_stream qs(*result_block, headers_len);
  2144. emb_store_querycache_result(&qs, (THD*)data);
  2145. #endif /*!EMBEDDED_LIBRARY*/
  2146. }
  2147. else
  2148. {
  2149. if (*result_block != 0)
  2150. {
  2151. // Destroy list of blocks that was created & locked by lock_result_data
  2152. Query_cache_block *block = *result_block;
  2153. do
  2154. {
  2155. Query_cache_block *current = block;
  2156. block = block->next;
  2157. free_memory_block(current);
  2158. } while (block != *result_block);
  2159. *result_block = 0;
  2160. /*
  2161. It is not success => not unlock structure_guard_mutex (we need it to
  2162. free query)
  2163. */
  2164. }
  2165. }
  2166. DBUG_PRINT("qcache", ("success %d", (int) success));
  2167. DBUG_RETURN(success);
  2168. }
  2169. inline ulong Query_cache::get_min_first_result_data_size()
  2170. {
  2171. if (queries_in_cache < QUERY_CACHE_MIN_ESTIMATED_QUERIES_NUMBER)
  2172. return min_result_data_size;
  2173. ulong avg_result = (query_cache_size - free_memory) / queries_in_cache;
  2174. avg_result = min(avg_result, query_cache_limit);
  2175. return max(min_result_data_size, avg_result);
  2176. }
  2177. inline ulong Query_cache::get_min_append_result_data_size()
  2178. {
  2179. return min_result_data_size;
  2180. }
  2181. /*
  2182. Allocate one or more blocks to hold data
  2183. */
  2184. my_bool Query_cache::allocate_data_chain(Query_cache_block **result_block,
  2185. ulong data_len,
  2186. Query_cache_block *query_block,
  2187. my_bool first_block_arg)
  2188. {
  2189. ulong all_headers_len = (ALIGN_SIZE(sizeof(Query_cache_block)) +
  2190. ALIGN_SIZE(sizeof(Query_cache_result)));
  2191. ulong min_size = (first_block_arg ?
  2192. get_min_first_result_data_size():
  2193. get_min_append_result_data_size());
  2194. Query_cache_block *prev_block= NULL;
  2195. Query_cache_block *new_block;
  2196. DBUG_ENTER("Query_cache::allocate_data_chain");
  2197. DBUG_PRINT("qcache", ("data_len %lu, all_headers_len %lu",
  2198. data_len, all_headers_len));
  2199. do
  2200. {
  2201. ulong len= data_len + all_headers_len;
  2202. ulong align_len= ALIGN_SIZE(len);
  2203. if (!(new_block= allocate_block(max(min_size, align_len),
  2204. min_result_data_size == 0,
  2205. all_headers_len + min_result_data_size)))
  2206. {
  2207. DBUG_PRINT("warning", ("Can't allocate block for results"));
  2208. DBUG_RETURN(FALSE);
  2209. }
  2210. new_block->n_tables = 0;
  2211. new_block->used = min(len, new_block->length);
  2212. new_block->type = Query_cache_block::RES_INCOMPLETE;
  2213. new_block->next = new_block->prev = new_block;
  2214. Query_cache_result *header = new_block->result();
  2215. header->parent(query_block);
  2216. DBUG_PRINT("qcache", ("Block len %lu used %lu",
  2217. new_block->length, new_block->used));
  2218. if (prev_block)
  2219. double_linked_list_join(prev_block, new_block);
  2220. else
  2221. *result_block= new_block;
  2222. if (new_block->length >= len)
  2223. break;
  2224. /*
  2225. We got less memory then we need (no big memory blocks) =>
  2226. Continue to allocated more blocks until we got everything we need.
  2227. */
  2228. data_len= len - new_block->length;
  2229. prev_block= new_block;
  2230. } while (1);
  2231. DBUG_RETURN(TRUE);
  2232. }
  2233. /*****************************************************************************
  2234. Tables management
  2235. *****************************************************************************/
  2236. /*
  2237. Invalidate the first table in the table_list
  2238. */
  2239. void Query_cache::invalidate_table(THD *thd, TABLE_LIST *table_list)
  2240. {
  2241. if (table_list->table != 0)
  2242. invalidate_table(thd, table_list->table); // Table is open
  2243. else
  2244. {
  2245. char key[MAX_DBKEY_LENGTH];
  2246. uint key_length;
  2247. key_length=(uint) (strmov(strmov(key,table_list->db)+1,
  2248. table_list->table_name) -key)+ 1;
  2249. // We don't store temporary tables => no key_length+=4 ...
  2250. invalidate_table(thd, (uchar *)key, key_length);
  2251. }
  2252. }
  2253. void Query_cache::invalidate_table(THD *thd, TABLE *table)
  2254. {
  2255. invalidate_table(thd, (uchar*) table->s->table_cache_key.str,
  2256. table->s->table_cache_key.length);
  2257. }
  2258. void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length)
  2259. {
  2260. DBUG_EXECUTE_IF("wait_in_query_cache_invalidate1",
  2261. debug_wait_for_kill("wait_in_query_cache_invalidate1"); );
  2262. /*
  2263. Lock the query cache and queue all invalidation attempts to avoid
  2264. the risk of a race between invalidation, cache inserts and flushes.
  2265. */
  2266. lock();
  2267. DBUG_EXECUTE_IF("wait_in_query_cache_invalidate2",
  2268. debug_wait_for_kill("wait_in_query_cache_invalidate2"); );
  2269. if (query_cache_size > 0)
  2270. invalidate_table_internal(thd, key, key_length);
  2271. unlock();
  2272. }
  2273. /**
  2274. Try to locate and invalidate a table by name.
  2275. The caller must ensure that no other thread is trying to work with
  2276. the query cache when this function is executed.
  2277. @pre structure_guard_mutex is acquired or LOCKED is set.
  2278. */
  2279. void
  2280. Query_cache::invalidate_table_internal(THD *thd, uchar *key, uint32 key_length)
  2281. {
  2282. Query_cache_block *table_block=
  2283. (Query_cache_block*)hash_search(&tables, key, key_length);
  2284. if (table_block)
  2285. {
  2286. Query_cache_block_table *list_root= table_block->table(0);
  2287. invalidate_query_block_list(thd, list_root);
  2288. }
  2289. }
  2290. /**
  2291. Invalidate a linked list of query cache blocks.
  2292. Each block tries to acquire a block level lock before
  2293. free_query is a called. This function will in turn affect
  2294. related table- and result-blocks.
  2295. @param[in,out] thd Thread context.
  2296. @param[in,out] list_root A pointer to a circular list of query blocks.
  2297. */
  2298. void
  2299. Query_cache::invalidate_query_block_list(THD *thd,
  2300. Query_cache_block_table *list_root)
  2301. {
  2302. while (list_root->next != list_root)
  2303. {
  2304. Query_cache_block *query_block= list_root->next->block();
  2305. BLOCK_LOCK_WR(query_block);
  2306. free_query(query_block);
  2307. DBUG_EXECUTE_IF("debug_cache_locks", sleep(10););
  2308. }
  2309. }
  2310. /*
  2311. Register given table list begining with given position in tables table of
  2312. block
  2313. SYNOPSIS
  2314. Query_cache::register_tables_from_list
  2315. tables_used given table list
  2316. counter number current position in table of tables of block
  2317. block_table pointer to current position in tables table of block
  2318. RETURN
  2319. 0 error
  2320. number of next position of table entry in table of tables of block
  2321. */
  2322. TABLE_COUNTER_TYPE
  2323. Query_cache::register_tables_from_list(TABLE_LIST *tables_used,
  2324. TABLE_COUNTER_TYPE counter,
  2325. Query_cache_block_table *block_table)
  2326. {
  2327. TABLE_COUNTER_TYPE n;
  2328. DBUG_ENTER("Query_cache::register_tables_from_list");
  2329. for (n= counter;
  2330. tables_used;
  2331. tables_used= tables_used->next_global, n++, block_table++)
  2332. {
  2333. if (tables_used->is_anonymous_derived_table())
  2334. {
  2335. DBUG_PRINT("qcache", ("derived table skipped"));
  2336. n--;
  2337. block_table--;
  2338. continue;
  2339. }
  2340. block_table->n= n;
  2341. if (tables_used->view)
  2342. {
  2343. char key[MAX_DBKEY_LENGTH];
  2344. uint key_length;
  2345. DBUG_PRINT("qcache", ("view: %s db: %s",
  2346. tables_used->view_name.str,
  2347. tables_used->view_db.str));
  2348. key_length= (uint) (strmov(strmov(key, tables_used->view_db.str) + 1,
  2349. tables_used->view_name.str) - key) + 1;
  2350. /*
  2351. There are not callback function for for VIEWs
  2352. */
  2353. if (!insert_table(key_length, key, block_table,
  2354. tables_used->view_db.length + 1,
  2355. HA_CACHE_TBL_NONTRANSACT, 0, 0))
  2356. DBUG_RETURN(0);
  2357. /*
  2358. We do not need to register view tables here because they are already
  2359. present in the global list.
  2360. */
  2361. }
  2362. else
  2363. {
  2364. DBUG_PRINT("qcache",
  2365. ("table: %s db: %s openinfo: 0x%lx keylen: %lu key: 0x%lx",
  2366. tables_used->table->s->table_name.str,
  2367. tables_used->table->s->table_cache_key.str,
  2368. (ulong) tables_used->table,
  2369. (ulong) tables_used->table->s->table_cache_key.length,
  2370. (ulong) tables_used->table->s->table_cache_key.str));
  2371. if (!insert_table(tables_used->table->s->table_cache_key.length,
  2372. tables_used->table->s->table_cache_key.str,
  2373. block_table,
  2374. tables_used->db_length,
  2375. tables_used->table->file->table_cache_type(),
  2376. tables_used->callback_func,
  2377. tables_used->engine_data))
  2378. DBUG_RETURN(0);
  2379. #ifdef WITH_MYISAMMRG_STORAGE_ENGINE
  2380. /*
  2381. XXX FIXME: Some generic mechanism is required here instead of this
  2382. MYISAMMRG-specific implementation.
  2383. */
  2384. if (tables_used->table->s->db_type()->db_type == DB_TYPE_MRG_MYISAM)
  2385. {
  2386. ha_myisammrg *handler = (ha_myisammrg *) tables_used->table->file;
  2387. MYRG_INFO *file = handler->myrg_info();
  2388. for (MYRG_TABLE *table = file->open_tables;
  2389. table != file->end_table ;
  2390. table++)
  2391. {
  2392. char key[MAX_DBKEY_LENGTH];
  2393. uint32 db_length;
  2394. uint key_length= filename_2_table_key(key, table->table->filename,
  2395. &db_length);
  2396. (++block_table)->n= ++n;
  2397. /*
  2398. There are not callback function for for MyISAM, and engine data
  2399. */
  2400. if (!insert_table(key_length, key, block_table,
  2401. db_length,
  2402. tables_used->table->file->table_cache_type(),
  2403. 0, 0))
  2404. DBUG_RETURN(0);
  2405. }
  2406. }
  2407. #endif
  2408. }
  2409. }
  2410. DBUG_RETURN(n - counter);
  2411. }
  2412. /*
  2413. Store all used tables
  2414. SYNOPSIS
  2415. register_all_tables()
  2416. block Store tables in this block
  2417. tables_used List if used tables
  2418. tables_arg Not used ?
  2419. */
  2420. my_bool Query_cache::register_all_tables(Query_cache_block *block,
  2421. TABLE_LIST *tables_used,
  2422. TABLE_COUNTER_TYPE tables_arg)
  2423. {
  2424. TABLE_COUNTER_TYPE n;
  2425. DBUG_PRINT("qcache", ("register tables block 0x%lx, n %d, header %x",
  2426. (ulong) block, (int) tables_arg,
  2427. (int) ALIGN_SIZE(sizeof(Query_cache_block))));
  2428. Query_cache_block_table *block_table = block->table(0);
  2429. n= register_tables_from_list(tables_used, 0, block_table);
  2430. if (n==0)
  2431. {
  2432. /* Unlink the tables we allocated above */
  2433. for (Query_cache_block_table *tmp = block->table(0) ;
  2434. tmp != block_table;
  2435. tmp++)
  2436. unlink_table(tmp);
  2437. }
  2438. return test(n);
  2439. }
  2440. /**
  2441. Insert used table name into the cache.
  2442. @return Error status
  2443. @retval FALSE On error
  2444. @retval TRUE On success
  2445. */
  2446. my_bool
  2447. Query_cache::insert_table(uint key_len, char *key,
  2448. Query_cache_block_table *node,
  2449. uint32 db_length, uint8 cache_type,
  2450. qc_engine_callback callback,
  2451. ulonglong engine_data)
  2452. {
  2453. DBUG_ENTER("Query_cache::insert_table");
  2454. DBUG_PRINT("qcache", ("insert table node 0x%lx, len %d",
  2455. (ulong)node, key_len));
  2456. THD *thd= current_thd;
  2457. Query_cache_block *table_block=
  2458. (Query_cache_block *)hash_search(&tables, (uchar*) key, key_len);
  2459. if (table_block &&
  2460. table_block->table()->engine_data() != engine_data)
  2461. {
  2462. DBUG_PRINT("qcache",
  2463. ("Handler require invalidation queries of %s.%s %lu-%lu",
  2464. table_block->table()->db(),
  2465. table_block->table()->table(),
  2466. (ulong) engine_data,
  2467. (ulong) table_block->table()->engine_data()));
  2468. /*
  2469. as far as we delete all queries with this table, table block will be
  2470. deleted, too
  2471. */
  2472. {
  2473. Query_cache_block_table *list_root= table_block->table(0);
  2474. invalidate_query_block_list(thd, list_root);
  2475. }
  2476. table_block= 0;
  2477. }
  2478. if (table_block == 0)
  2479. {
  2480. DBUG_PRINT("qcache", ("new table block from 0x%lx (%u)",
  2481. (ulong) key, (int) key_len));
  2482. table_block= write_block_data(key_len, (uchar*) key,
  2483. ALIGN_SIZE(sizeof(Query_cache_table)),
  2484. Query_cache_block::TABLE, 1);
  2485. if (table_block == 0)
  2486. {
  2487. DBUG_PRINT("qcache", ("Can't write table name to cache"));
  2488. DBUG_RETURN(0);
  2489. }
  2490. Query_cache_table *header= table_block->table();
  2491. double_linked_list_simple_include(table_block,
  2492. &tables_blocks);
  2493. /*
  2494. First node in the Query_cache_block_table-chain is the table-type
  2495. block. This block will only have one Query_cache_block_table (n=0).
  2496. */
  2497. Query_cache_block_table *list_root= table_block->table(0);
  2498. list_root->n= 0;
  2499. /*
  2500. The node list is circular in nature.
  2501. */
  2502. list_root->next= list_root->prev= list_root;
  2503. if (my_hash_insert(&tables, (const uchar *) table_block))
  2504. {
  2505. DBUG_PRINT("qcache", ("Can't insert table to hash"));
  2506. // write_block_data return locked block
  2507. free_memory_block(table_block);
  2508. DBUG_RETURN(0);
  2509. }
  2510. char *db= header->db();
  2511. header->table(db + db_length + 1);
  2512. header->key_length(key_len);
  2513. header->type(cache_type);
  2514. header->callback(callback);
  2515. header->engine_data(engine_data);
  2516. /*
  2517. We insert this table without the assumption that it isn't refrenenced by
  2518. any queries.
  2519. */
  2520. header->m_cached_query_count= 0;
  2521. }
  2522. /*
  2523. Table is now in the cache; link the table_block-node associated
  2524. with the currently processed query into the chain of queries depending
  2525. on the cached table.
  2526. */
  2527. Query_cache_block_table *list_root= table_block->table(0);
  2528. node->next= list_root->next;
  2529. list_root->next= node;
  2530. node->next->prev= node;
  2531. node->prev= list_root;
  2532. node->parent= table_block->table();
  2533. /*
  2534. Increase the counter to keep track on how long this chain
  2535. of queries is.
  2536. */
  2537. Query_cache_table *table_block_data= table_block->table();
  2538. table_block_data->m_cached_query_count++;
  2539. DBUG_RETURN(1);
  2540. }
  2541. void Query_cache::unlink_table(Query_cache_block_table *node)
  2542. {
  2543. DBUG_ENTER("Query_cache::unlink_table");
  2544. node->prev->next= node->next;
  2545. node->next->prev= node->prev;
  2546. Query_cache_block_table *neighbour= node->next;
  2547. Query_cache_table *table_block_data= node->parent;
  2548. table_block_data->m_cached_query_count--;
  2549. DBUG_ASSERT(table_block_data->m_cached_query_count >= 0);
  2550. if (neighbour->next == neighbour)
  2551. {
  2552. DBUG_ASSERT(table_block_data->m_cached_query_count == 0);
  2553. /*
  2554. If neighbor is root of list, the list is empty.
  2555. The root of the list is always a table-type block
  2556. which contain exactly one Query_cache_block_table
  2557. node object, thus we can use the block() method
  2558. to calculate the Query_cache_block address.
  2559. */
  2560. Query_cache_block *table_block= neighbour->block();
  2561. double_linked_list_exclude(table_block,
  2562. &tables_blocks);
  2563. hash_delete(&tables,(uchar *) table_block);
  2564. free_memory_block(table_block);
  2565. }
  2566. DBUG_VOID_RETURN;
  2567. }
  2568. /*****************************************************************************
  2569. Free memory management
  2570. *****************************************************************************/
  2571. Query_cache_block *
  2572. Query_cache::allocate_block(ulong len, my_bool not_less, ulong min)
  2573. {
  2574. DBUG_ENTER("Query_cache::allocate_block");
  2575. DBUG_PRINT("qcache", ("len %lu, not less %d, min %lu",
  2576. len, not_less,min));
  2577. if (len >= min(query_cache_size, query_cache_limit))
  2578. {
  2579. DBUG_PRINT("qcache", ("Query cache hase only %lu memory and limit %lu",
  2580. query_cache_size, query_cache_limit));
  2581. DBUG_RETURN(0); // in any case we don't have such piece of memory
  2582. }
  2583. /* Free old queries until we have enough memory to store this block */
  2584. Query_cache_block *block;
  2585. do
  2586. {
  2587. block= get_free_block(len, not_less, min);
  2588. }
  2589. while (block == 0 && !free_old_query());
  2590. if (block != 0) // If we found a suitable block
  2591. {
  2592. if (block->length >= ALIGN_SIZE(len) + min_allocation_unit)
  2593. split_block(block,ALIGN_SIZE(len));
  2594. }
  2595. DBUG_RETURN(block);
  2596. }
  2597. Query_cache_block *
  2598. Query_cache::get_free_block(ulong len, my_bool not_less, ulong min)
  2599. {
  2600. Query_cache_block *block = 0, *first = 0;
  2601. DBUG_ENTER("Query_cache::get_free_block");
  2602. DBUG_PRINT("qcache",("length %lu, not_less %d, min %lu", len,
  2603. (int)not_less, min));
  2604. /* Find block with minimal size > len */
  2605. uint start = find_bin(len);
  2606. // try matching bin
  2607. if (bins[start].number != 0)
  2608. {
  2609. Query_cache_block *list = bins[start].free_blocks;
  2610. if (list->prev->length >= len) // check block with max size
  2611. {
  2612. first = list;
  2613. uint n = 0;
  2614. while ( n < QUERY_CACHE_MEM_BIN_TRY &&
  2615. first->length < len) //we don't need irst->next != list
  2616. {
  2617. first=first->next;
  2618. n++;
  2619. }
  2620. if (first->length >= len)
  2621. block=first;
  2622. else // we don't need if (first->next != list)
  2623. {
  2624. n = 0;
  2625. block = list->prev;
  2626. while (n < QUERY_CACHE_MEM_BIN_TRY &&
  2627. block->length > len)
  2628. {
  2629. block=block->prev;
  2630. n++;
  2631. }
  2632. if (block->length < len)
  2633. block=block->next;
  2634. }
  2635. }
  2636. else
  2637. first = list->prev;
  2638. }
  2639. if (block == 0 && start > 0)
  2640. {
  2641. DBUG_PRINT("qcache",("Try bins with bigger block size"));
  2642. // Try more big bins
  2643. int i = start - 1;
  2644. while (i > 0 && bins[i].number == 0)
  2645. i--;
  2646. if (bins[i].number > 0)
  2647. block = bins[i].free_blocks;
  2648. }
  2649. // If no big blocks => try less size (if it is possible)
  2650. if (block == 0 && ! not_less)
  2651. {
  2652. DBUG_PRINT("qcache",("Try to allocate a smaller block"));
  2653. if (first != 0 && first->length > min)
  2654. block = first;
  2655. else
  2656. {
  2657. uint i = start + 1;
  2658. /* bins[mem_bin_num].number contains 1 for easy end test */
  2659. for (i= start+1 ; bins[i].number == 0 ; i++) ;
  2660. if (i < mem_bin_num && bins[i].free_blocks->prev->length >= min)
  2661. block = bins[i].free_blocks->prev;
  2662. }
  2663. }
  2664. if (block != 0)
  2665. exclude_from_free_memory_list(block);
  2666. DBUG_PRINT("qcache",("getting block 0x%lx", (ulong) block));
  2667. DBUG_RETURN(block);
  2668. }
  2669. void Query_cache::free_memory_block(Query_cache_block *block)
  2670. {
  2671. DBUG_ENTER("Query_cache::free_memory_block");
  2672. block->used=0;
  2673. block->type= Query_cache_block::FREE; // mark block as free in any case
  2674. DBUG_PRINT("qcache",
  2675. ("first_block 0x%lx, block 0x%lx, pnext 0x%lx pprev 0x%lx",
  2676. (ulong) first_block, (ulong) block, (ulong) block->pnext,
  2677. (ulong) block->pprev));
  2678. if (block->pnext != first_block && block->pnext->is_free())
  2679. block = join_free_blocks(block, block->pnext);
  2680. if (block != first_block && block->pprev->is_free())
  2681. block = join_free_blocks(block->pprev, block->pprev);
  2682. insert_into_free_memory_list(block);
  2683. DBUG_VOID_RETURN;
  2684. }
  2685. void Query_cache::split_block(Query_cache_block *block, ulong len)
  2686. {
  2687. DBUG_ENTER("Query_cache::split_block");
  2688. Query_cache_block *new_block = (Query_cache_block*)(((uchar*) block)+len);
  2689. new_block->init(block->length - len);
  2690. total_blocks++;
  2691. block->length=len;
  2692. new_block->pnext = block->pnext;
  2693. block->pnext = new_block;
  2694. new_block->pprev = block;
  2695. new_block->pnext->pprev = new_block;
  2696. if (block->type == Query_cache_block::FREE)
  2697. {
  2698. // if block was free then it already joined with all free neighbours
  2699. insert_into_free_memory_list(new_block);
  2700. }
  2701. else
  2702. free_memory_block(new_block);
  2703. DBUG_PRINT("qcache", ("split 0x%lx (%lu) new 0x%lx",
  2704. (ulong) block, len, (ulong) new_block));
  2705. DBUG_VOID_RETURN;
  2706. }
  2707. Query_cache_block *
  2708. Query_cache::join_free_blocks(Query_cache_block *first_block_arg,
  2709. Query_cache_block *block_in_list)
  2710. {
  2711. Query_cache_block *second_block;
  2712. DBUG_ENTER("Query_cache::join_free_blocks");
  2713. DBUG_PRINT("qcache",
  2714. ("join first 0x%lx, pnext 0x%lx, in list 0x%lx",
  2715. (ulong) first_block_arg, (ulong) first_block_arg->pnext,
  2716. (ulong) block_in_list));
  2717. exclude_from_free_memory_list(block_in_list);
  2718. second_block = first_block_arg->pnext;
  2719. // May be was not free block
  2720. second_block->used=0;
  2721. second_block->destroy();
  2722. total_blocks--;
  2723. first_block_arg->length += second_block->length;
  2724. first_block_arg->pnext = second_block->pnext;
  2725. second_block->pnext->pprev = first_block_arg;
  2726. DBUG_RETURN(first_block_arg);
  2727. }
  2728. my_bool Query_cache::append_next_free_block(Query_cache_block *block,
  2729. ulong add_size)
  2730. {
  2731. Query_cache_block *next_block = block->pnext;
  2732. DBUG_ENTER("Query_cache::append_next_free_block");
  2733. DBUG_PRINT("enter", ("block 0x%lx, add_size %lu", (ulong) block,
  2734. add_size));
  2735. if (next_block != first_block && next_block->is_free())
  2736. {
  2737. ulong old_len = block->length;
  2738. exclude_from_free_memory_list(next_block);
  2739. next_block->destroy();
  2740. total_blocks--;
  2741. block->length += next_block->length;
  2742. block->pnext = next_block->pnext;
  2743. next_block->pnext->pprev = block;
  2744. if (block->length > ALIGN_SIZE(old_len + add_size) + min_allocation_unit)
  2745. split_block(block,ALIGN_SIZE(old_len + add_size));
  2746. DBUG_PRINT("exit", ("block was appended"));
  2747. DBUG_RETURN(1);
  2748. }
  2749. DBUG_RETURN(0);
  2750. }
  2751. void Query_cache::exclude_from_free_memory_list(Query_cache_block *free_block)
  2752. {
  2753. DBUG_ENTER("Query_cache::exclude_from_free_memory_list");
  2754. Query_cache_memory_bin *bin = *((Query_cache_memory_bin **)
  2755. free_block->data());
  2756. double_linked_list_exclude(free_block, &bin->free_blocks);
  2757. bin->number--;
  2758. free_memory-=free_block->length;
  2759. free_memory_blocks--;
  2760. DBUG_PRINT("qcache",("exclude block 0x%lx, bin 0x%lx", (ulong) free_block,
  2761. (ulong) bin));
  2762. DBUG_VOID_RETURN;
  2763. }
  2764. void Query_cache::insert_into_free_memory_list(Query_cache_block *free_block)
  2765. {
  2766. DBUG_ENTER("Query_cache::insert_into_free_memory_list");
  2767. uint idx = find_bin(free_block->length);
  2768. insert_into_free_memory_sorted_list(free_block, &bins[idx].free_blocks);
  2769. /*
  2770. We have enough memory in block for storing bin reference due to
  2771. min_allocation_unit choice
  2772. */
  2773. Query_cache_memory_bin **bin_ptr = ((Query_cache_memory_bin**)
  2774. free_block->data());
  2775. *bin_ptr = bins+idx;
  2776. (*bin_ptr)->number++;
  2777. DBUG_PRINT("qcache",("insert block 0x%lx, bin[%d] 0x%lx",
  2778. (ulong) free_block, idx, (ulong) *bin_ptr));
  2779. DBUG_VOID_RETURN;
  2780. }
  2781. uint Query_cache::find_bin(ulong size)
  2782. {
  2783. DBUG_ENTER("Query_cache::find_bin");
  2784. // Binary search
  2785. int left = 0, right = mem_bin_steps;
  2786. do
  2787. {
  2788. int middle = (left + right) / 2;
  2789. if (steps[middle].size > size)
  2790. left = middle+1;
  2791. else
  2792. right = middle;
  2793. } while (left < right);
  2794. if (left == 0)
  2795. {
  2796. // first bin not subordinate of common rules
  2797. DBUG_PRINT("qcache", ("first bin (# 0), size %lu",size));
  2798. DBUG_RETURN(0);
  2799. }
  2800. uint bin = steps[left].idx -
  2801. (uint)((size - steps[left].size)/steps[left].increment);
  2802. DBUG_PRINT("qcache", ("bin %u step %u, size %lu step size %lu",
  2803. bin, left, size, steps[left].size));
  2804. DBUG_RETURN(bin);
  2805. }
  2806. /*****************************************************************************
  2807. Lists management
  2808. *****************************************************************************/
  2809. void Query_cache::move_to_query_list_end(Query_cache_block *query_block)
  2810. {
  2811. DBUG_ENTER("Query_cache::move_to_query_list_end");
  2812. double_linked_list_exclude(query_block, &queries_blocks);
  2813. double_linked_list_simple_include(query_block, &queries_blocks);
  2814. DBUG_VOID_RETURN;
  2815. }
  2816. void Query_cache::insert_into_free_memory_sorted_list(Query_cache_block *
  2817. new_block,
  2818. Query_cache_block **
  2819. list)
  2820. {
  2821. DBUG_ENTER("Query_cache::insert_into_free_memory_sorted_list");
  2822. /*
  2823. list sorted by size in ascendant order, because we need small blocks
  2824. more frequently than bigger ones
  2825. */
  2826. new_block->used = 0;
  2827. new_block->n_tables = 0;
  2828. new_block->type = Query_cache_block::FREE;
  2829. if (*list == 0)
  2830. {
  2831. *list = new_block->next=new_block->prev=new_block;
  2832. DBUG_PRINT("qcache", ("inserted into empty list"));
  2833. }
  2834. else
  2835. {
  2836. Query_cache_block *point = *list;
  2837. if (point->length >= new_block->length)
  2838. {
  2839. point = point->prev;
  2840. *list = new_block;
  2841. }
  2842. else
  2843. {
  2844. /* Find right position in sorted list to put block */
  2845. while (point->next != *list &&
  2846. point->next->length < new_block->length)
  2847. point=point->next;
  2848. }
  2849. new_block->prev = point;
  2850. new_block->next = point->next;
  2851. new_block->next->prev = new_block;
  2852. point->next = new_block;
  2853. }
  2854. free_memory+=new_block->length;
  2855. free_memory_blocks++;
  2856. DBUG_VOID_RETURN;
  2857. }
  2858. void
  2859. Query_cache::double_linked_list_simple_include(Query_cache_block *point,
  2860. Query_cache_block **
  2861. list_pointer)
  2862. {
  2863. DBUG_ENTER("Query_cache::double_linked_list_simple_include");
  2864. DBUG_PRINT("qcache", ("including block 0x%lx", (ulong) point));
  2865. if (*list_pointer == 0)
  2866. *list_pointer=point->next=point->prev=point;
  2867. else
  2868. {
  2869. // insert to the end of list
  2870. point->next = (*list_pointer);
  2871. point->prev = (*list_pointer)->prev;
  2872. point->prev->next = point;
  2873. (*list_pointer)->prev = point;
  2874. }
  2875. DBUG_VOID_RETURN;
  2876. }
  2877. void
  2878. Query_cache::double_linked_list_exclude(Query_cache_block *point,
  2879. Query_cache_block **list_pointer)
  2880. {
  2881. DBUG_ENTER("Query_cache::double_linked_list_exclude");
  2882. DBUG_PRINT("qcache", ("excluding block 0x%lx, list 0x%lx",
  2883. (ulong) point, (ulong) list_pointer));
  2884. if (point->next == point)
  2885. *list_pointer = 0; // empty list
  2886. else
  2887. {
  2888. point->next->prev = point->prev;
  2889. point->prev->next = point->next;
  2890. /*
  2891. If the root is removed; select a new root
  2892. */
  2893. if (point == *list_pointer)
  2894. *list_pointer= point->next;
  2895. }
  2896. DBUG_VOID_RETURN;
  2897. }
  2898. void Query_cache::double_linked_list_join(Query_cache_block *head_tail,
  2899. Query_cache_block *tail_head)
  2900. {
  2901. Query_cache_block *head_head = head_tail->next,
  2902. *tail_tail = tail_head->prev;
  2903. head_head->prev = tail_tail;
  2904. head_tail->next = tail_head;
  2905. tail_head->prev = head_tail;
  2906. tail_tail->next = head_head;
  2907. }
  2908. /*****************************************************************************
  2909. Query
  2910. *****************************************************************************/
  2911. /*
  2912. Collect information about table types, check that tables are cachable and
  2913. count them
  2914. SYNOPSIS
  2915. process_and_count_tables()
  2916. tables_used table list for processing
  2917. tables_type pointer to variable for table types collection
  2918. RETURN
  2919. 0 error
  2920. >0 number of tables
  2921. */
  2922. TABLE_COUNTER_TYPE
  2923. Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used,
  2924. uint8 *tables_type)
  2925. {
  2926. DBUG_ENTER("process_and_count_tables");
  2927. TABLE_COUNTER_TYPE table_count = 0;
  2928. for (; tables_used; tables_used= tables_used->next_global)
  2929. {
  2930. table_count++;
  2931. #ifndef NO_EMBEDDED_ACCESS_CHECKS
  2932. /*
  2933. Disable any attempt to store this statement if there are
  2934. column level grants on any referenced tables.
  2935. The grant.want_privileges flag was set to 1 in the
  2936. check_grant() function earlier if the TABLE_LIST object
  2937. had any associated column privileges.
  2938. We need to check that the TABLE_LIST object isn't part
  2939. of a VIEW definition because we want to be able to cache
  2940. views.
  2941. TODO: Although it is possible to cache views, the privilege
  2942. check on view tables always fall back on column privileges
  2943. even if there are more generic table privileges. Thus it isn't
  2944. currently possible to retrieve cached view-tables unless the
  2945. client has the super user privileges.
  2946. */
  2947. if (tables_used->grant.want_privilege &&
  2948. tables_used->belong_to_view == NULL)
  2949. {
  2950. DBUG_PRINT("qcache", ("Don't cache statement as it refers to "
  2951. "tables with column privileges."));
  2952. thd->lex->safe_to_cache_query= 0;
  2953. DBUG_RETURN(0);
  2954. }
  2955. #endif
  2956. if (tables_used->view)
  2957. {
  2958. DBUG_PRINT("qcache", ("view: %s db: %s",
  2959. tables_used->view_name.str,
  2960. tables_used->view_db.str));
  2961. *tables_type|= HA_CACHE_TBL_NONTRANSACT;
  2962. }
  2963. else
  2964. {
  2965. DBUG_PRINT("qcache", ("table: %s db: %s type: %u",
  2966. tables_used->table->s->table_name.str,
  2967. tables_used->table->s->db.str,
  2968. tables_used->table->s->db_type()->db_type));
  2969. if (tables_used->derived)
  2970. {
  2971. table_count--;
  2972. DBUG_PRINT("qcache", ("derived table skipped"));
  2973. continue;
  2974. }
  2975. *tables_type|= tables_used->table->file->table_cache_type();
  2976. /*
  2977. table_alias_charset used here because it depends of
  2978. lower_case_table_names variable
  2979. */
  2980. if (tables_used->table->s->tmp_table != NO_TMP_TABLE ||
  2981. (*tables_type & HA_CACHE_TBL_NOCACHE) ||
  2982. (tables_used->db_length == 5 &&
  2983. my_strnncoll(table_alias_charset,
  2984. (uchar*)tables_used->table->s->table_cache_key.str, 6,
  2985. (uchar*)"mysql",6) == 0))
  2986. {
  2987. DBUG_PRINT("qcache",
  2988. ("select not cacheable: temporary, system or "
  2989. "other non-cacheable table(s)"));
  2990. DBUG_RETURN(0);
  2991. }
  2992. #ifdef WITH_MYISAMMRG_STORAGE_ENGINE
  2993. /*
  2994. XXX FIXME: Some generic mechanism is required here instead of this
  2995. MYISAMMRG-specific implementation.
  2996. */
  2997. if (tables_used->table->s->db_type()->db_type == DB_TYPE_MRG_MYISAM)
  2998. {
  2999. ha_myisammrg *handler = (ha_myisammrg *)tables_used->table->file;
  3000. MYRG_INFO *file = handler->myrg_info();
  3001. table_count+= (file->end_table - file->open_tables);
  3002. }
  3003. #endif
  3004. }
  3005. }
  3006. DBUG_RETURN(table_count);
  3007. }
  3008. /*
  3009. If query is cacheable return number tables in query
  3010. (query without tables are not cached)
  3011. */
  3012. TABLE_COUNTER_TYPE
  3013. Query_cache::is_cacheable(THD *thd, uint32 query_len, char *query, LEX *lex,
  3014. TABLE_LIST *tables_used, uint8 *tables_type)
  3015. {
  3016. TABLE_COUNTER_TYPE table_count;
  3017. DBUG_ENTER("Query_cache::is_cacheable");
  3018. if (query_cache_is_cacheable_query(lex) &&
  3019. (thd->variables.query_cache_type == 1 ||
  3020. (thd->variables.query_cache_type == 2 && (lex->select_lex.options &
  3021. OPTION_TO_QUERY_CACHE))))
  3022. {
  3023. DBUG_PRINT("qcache", ("options: %lx %lx type: %u",
  3024. (long) OPTION_TO_QUERY_CACHE,
  3025. (long) lex->select_lex.options,
  3026. (int) thd->variables.query_cache_type));
  3027. if (!(table_count= process_and_count_tables(thd, tables_used,
  3028. tables_type)))
  3029. DBUG_RETURN(0);
  3030. if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
  3031. ((*tables_type)&HA_CACHE_TBL_TRANSACT))
  3032. {
  3033. DBUG_PRINT("qcache", ("not in autocommin mode"));
  3034. DBUG_RETURN(0);
  3035. }
  3036. DBUG_PRINT("qcache", ("select is using %d tables", table_count));
  3037. DBUG_RETURN(table_count);
  3038. }
  3039. DBUG_PRINT("qcache",
  3040. ("not interesting query: %d or not cacheable, options %lx %lx type: %u",
  3041. (int) lex->sql_command,
  3042. (long) OPTION_TO_QUERY_CACHE,
  3043. (long) lex->select_lex.options,
  3044. (int) thd->variables.query_cache_type));
  3045. DBUG_RETURN(0);
  3046. }
  3047. /*
  3048. Check handler allowance to cache query with these tables
  3049. SYNOPSYS
  3050. Query_cache::ask_handler_allowance()
  3051. thd - thread handlers
  3052. tables_used - tables list used in query
  3053. RETURN
  3054. 0 - caching allowed
  3055. 1 - caching disallowed
  3056. */
  3057. my_bool Query_cache::ask_handler_allowance(THD *thd,
  3058. TABLE_LIST *tables_used)
  3059. {
  3060. DBUG_ENTER("Query_cache::ask_handler_allowance");
  3061. for (; tables_used; tables_used= tables_used->next_global)
  3062. {
  3063. TABLE *table;
  3064. handler *handler;
  3065. if (!(table= tables_used->table))
  3066. continue;
  3067. handler= table->file;
  3068. if (!handler->register_query_cache_table(thd,
  3069. table->s->table_cache_key.str,
  3070. table->s->table_cache_key.length,
  3071. &tables_used->callback_func,
  3072. &tables_used->engine_data))
  3073. {
  3074. DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s",
  3075. tables_used->db, tables_used->alias));
  3076. thd->lex->safe_to_cache_query= 0; // Don't try to cache this
  3077. DBUG_RETURN(1);
  3078. }
  3079. }
  3080. DBUG_RETURN(0);
  3081. }
  3082. /*****************************************************************************
  3083. Packing
  3084. *****************************************************************************/
  3085. /**
  3086. Rearrange all memory blocks so that free memory joins at the
  3087. 'bottom' of the allocated memory block containing all cache data.
  3088. @see Query_cache::pack(ulong join_limit, uint iteration_limit)
  3089. */
  3090. void Query_cache::pack_cache()
  3091. {
  3092. DBUG_ENTER("Query_cache::pack_cache");
  3093. DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1););
  3094. uchar *border = 0;
  3095. Query_cache_block *before = 0;
  3096. ulong gap = 0;
  3097. my_bool ok = 1;
  3098. Query_cache_block *block = first_block;
  3099. DUMP(this);
  3100. if (first_block)
  3101. {
  3102. do
  3103. {
  3104. Query_cache_block *next=block->pnext;
  3105. ok = move_by_type(&border, &before, &gap, block);
  3106. block = next;
  3107. } while (ok && block != first_block);
  3108. if (border != 0)
  3109. {
  3110. Query_cache_block *new_block = (Query_cache_block *) border;
  3111. new_block->init(gap);
  3112. total_blocks++;
  3113. new_block->pnext = before->pnext;
  3114. before->pnext = new_block;
  3115. new_block->pprev = before;
  3116. new_block->pnext->pprev = new_block;
  3117. insert_into_free_memory_list(new_block);
  3118. }
  3119. DUMP(this);
  3120. }
  3121. DBUG_EXECUTE("check_querycache",query_cache.check_integrity(1););
  3122. DBUG_VOID_RETURN;
  3123. }
  3124. my_bool Query_cache::move_by_type(uchar **border,
  3125. Query_cache_block **before, ulong *gap,
  3126. Query_cache_block *block)
  3127. {
  3128. DBUG_ENTER("Query_cache::move_by_type");
  3129. my_bool ok = 1;
  3130. switch (block->type) {
  3131. case Query_cache_block::FREE:
  3132. {
  3133. DBUG_PRINT("qcache", ("block 0x%lx FREE", (ulong) block));
  3134. if (*border == 0)
  3135. {
  3136. *border = (uchar *) block;
  3137. *before = block->pprev;
  3138. DBUG_PRINT("qcache", ("gap beginning here"));
  3139. }
  3140. exclude_from_free_memory_list(block);
  3141. *gap +=block->length;
  3142. block->pprev->pnext=block->pnext;
  3143. block->pnext->pprev=block->pprev;
  3144. block->destroy();
  3145. total_blocks--;
  3146. DBUG_PRINT("qcache", ("added to gap (%lu)", *gap));
  3147. break;
  3148. }
  3149. case Query_cache_block::TABLE:
  3150. {
  3151. HASH_SEARCH_STATE record_idx;
  3152. DBUG_PRINT("qcache", ("block 0x%lx TABLE", (ulong) block));
  3153. if (*border == 0)
  3154. break;
  3155. ulong len = block->length, used = block->used;
  3156. Query_cache_block_table *list_root = block->table(0);
  3157. Query_cache_block_table *tprev = list_root->prev,
  3158. *tnext = list_root->next;
  3159. Query_cache_block *prev = block->prev,
  3160. *next = block->next,
  3161. *pprev = block->pprev,
  3162. *pnext = block->pnext,
  3163. *new_block =(Query_cache_block *) *border;
  3164. uint tablename_offset = block->table()->table() - block->table()->db();
  3165. char *data = (char*) block->data();
  3166. uchar *key;
  3167. size_t key_length;
  3168. key=query_cache_table_get_key((uchar*) block, &key_length, 0);
  3169. hash_first(&tables, (uchar*) key, key_length, &record_idx);
  3170. block->destroy();
  3171. new_block->init(len);
  3172. new_block->type=Query_cache_block::TABLE;
  3173. new_block->used=used;
  3174. new_block->n_tables=1;
  3175. memmove((char*) new_block->data(), data, len-new_block->headers_len());
  3176. relink(block, new_block, next, prev, pnext, pprev);
  3177. if (tables_blocks == block)
  3178. tables_blocks = new_block;
  3179. Query_cache_block_table *nlist_root = new_block->table(0);
  3180. nlist_root->n = 0;
  3181. nlist_root->next = tnext;
  3182. tnext->prev = nlist_root;
  3183. nlist_root->prev = tprev;
  3184. tprev->next = nlist_root;
  3185. DBUG_PRINT("qcache",
  3186. ("list_root: 0x%lx tnext 0x%lx tprev 0x%lx tprev->next 0x%lx tnext->prev 0x%lx",
  3187. (ulong) list_root, (ulong) tnext, (ulong) tprev,
  3188. (ulong)tprev->next, (ulong)tnext->prev));
  3189. /*
  3190. Go through all queries that uses this table and change them to
  3191. point to the new table object
  3192. */
  3193. Query_cache_table *new_block_table=new_block->table();
  3194. for (;tnext != nlist_root; tnext=tnext->next)
  3195. tnext->parent= new_block_table;
  3196. *border += len;
  3197. *before = new_block;
  3198. /* Fix pointer to table name */
  3199. new_block->table()->table(new_block->table()->db() + tablename_offset);
  3200. /* Fix hash to point at moved block */
  3201. hash_replace(&tables, &record_idx, (uchar*) new_block);
  3202. DBUG_PRINT("qcache", ("moved %lu bytes to 0x%lx, new gap at 0x%lx",
  3203. len, (ulong) new_block, (ulong) *border));
  3204. break;
  3205. }
  3206. case Query_cache_block::QUERY:
  3207. {
  3208. HASH_SEARCH_STATE record_idx;
  3209. DBUG_PRINT("qcache", ("block 0x%lx QUERY", (ulong) block));
  3210. if (*border == 0)
  3211. break;
  3212. BLOCK_LOCK_WR(block);
  3213. ulong len = block->length, used = block->used;
  3214. TABLE_COUNTER_TYPE n_tables = block->n_tables;
  3215. Query_cache_block *prev = block->prev,
  3216. *next = block->next,
  3217. *pprev = block->pprev,
  3218. *pnext = block->pnext,
  3219. *new_block =(Query_cache_block*) *border;
  3220. char *data = (char*) block->data();
  3221. Query_cache_block *first_result_block = ((Query_cache_query *)
  3222. block->data())->result();
  3223. uchar *key;
  3224. size_t key_length;
  3225. key=query_cache_query_get_key((uchar*) block, &key_length, 0);
  3226. hash_first(&queries, (uchar*) key, key_length, &record_idx);
  3227. // Move table of used tables
  3228. memmove((char*) new_block->table(0), (char*) block->table(0),
  3229. ALIGN_SIZE(n_tables*sizeof(Query_cache_block_table)));
  3230. block->query()->unlock_n_destroy();
  3231. block->destroy();
  3232. new_block->init(len);
  3233. new_block->type=Query_cache_block::QUERY;
  3234. new_block->used=used;
  3235. new_block->n_tables=n_tables;
  3236. memmove((char*) new_block->data(), data, len - new_block->headers_len());
  3237. relink(block, new_block, next, prev, pnext, pprev);
  3238. if (queries_blocks == block)
  3239. queries_blocks = new_block;
  3240. Query_cache_block_table *beg_of_table_table= block->table(0),
  3241. *end_of_table_table= block->table(n_tables);
  3242. uchar *beg_of_new_table_table= (uchar*) new_block->table(0);
  3243. for (TABLE_COUNTER_TYPE j=0; j < n_tables; j++)
  3244. {
  3245. Query_cache_block_table *block_table = new_block->table(j);
  3246. // use aligment from begining of table if 'next' is in same block
  3247. if ((beg_of_table_table <= block_table->next) &&
  3248. (block_table->next < end_of_table_table))
  3249. ((Query_cache_block_table *)(beg_of_new_table_table +
  3250. (((uchar*)block_table->next) -
  3251. ((uchar*)beg_of_table_table))))->prev=
  3252. block_table;
  3253. else
  3254. block_table->next->prev= block_table;
  3255. // use aligment from begining of table if 'prev' is in same block
  3256. if ((beg_of_table_table <= block_table->prev) &&
  3257. (block_table->prev < end_of_table_table))
  3258. ((Query_cache_block_table *)(beg_of_new_table_table +
  3259. (((uchar*)block_table->prev) -
  3260. ((uchar*)beg_of_table_table))))->next=
  3261. block_table;
  3262. else
  3263. block_table->prev->next = block_table;
  3264. }
  3265. DBUG_PRINT("qcache", ("after circle tt"));
  3266. *border += len;
  3267. *before = new_block;
  3268. new_block->query()->result(first_result_block);
  3269. if (first_result_block != 0)
  3270. {
  3271. Query_cache_block *result_block = first_result_block;
  3272. do
  3273. {
  3274. result_block->result()->parent(new_block);
  3275. result_block = result_block->next;
  3276. } while ( result_block != first_result_block );
  3277. }
  3278. Query_cache_query *new_query= ((Query_cache_query *) new_block->data());
  3279. my_rwlock_init(&new_query->lock, NULL);
  3280. /*
  3281. If someone is writing to this block, inform the writer that the block
  3282. has been moved.
  3283. */
  3284. NET *net = new_block->query()->writer();
  3285. if (net != 0)
  3286. {
  3287. net->query_cache_query= (uchar*) new_block;
  3288. }
  3289. /* Fix hash to point at moved block */
  3290. hash_replace(&queries, &record_idx, (uchar*) new_block);
  3291. DBUG_PRINT("qcache", ("moved %lu bytes to 0x%lx, new gap at 0x%lx",
  3292. len, (ulong) new_block, (ulong) *border));
  3293. break;
  3294. }
  3295. case Query_cache_block::RES_INCOMPLETE:
  3296. case Query_cache_block::RES_BEG:
  3297. case Query_cache_block::RES_CONT:
  3298. case Query_cache_block::RESULT:
  3299. {
  3300. DBUG_PRINT("qcache", ("block 0x%lx RES* (%d)", (ulong) block,
  3301. (int) block->type));
  3302. if (*border == 0)
  3303. break;
  3304. Query_cache_block *query_block = block->result()->parent(),
  3305. *next = block->next,
  3306. *prev = block->prev;
  3307. Query_cache_block::block_type type = block->type;
  3308. BLOCK_LOCK_WR(query_block);
  3309. ulong len = block->length, used = block->used;
  3310. Query_cache_block *pprev = block->pprev,
  3311. *pnext = block->pnext,
  3312. *new_block =(Query_cache_block*) *border;
  3313. char *data = (char*) block->data();
  3314. block->destroy();
  3315. new_block->init(len);
  3316. new_block->type=type;
  3317. new_block->used=used;
  3318. memmove((char*) new_block->data(), data, len - new_block->headers_len());
  3319. relink(block, new_block, next, prev, pnext, pprev);
  3320. new_block->result()->parent(query_block);
  3321. Query_cache_query *query = query_block->query();
  3322. if (query->result() == block)
  3323. query->result(new_block);
  3324. *border += len;
  3325. *before = new_block;
  3326. /* If result writing complete && we have free space in block */
  3327. ulong free_space= new_block->length - new_block->used;
  3328. free_space-= free_space % ALIGN_SIZE(1);
  3329. if (query->result()->type == Query_cache_block::RESULT &&
  3330. new_block->length > new_block->used &&
  3331. *gap + free_space > min_allocation_unit &&
  3332. new_block->length - free_space > min_allocation_unit)
  3333. {
  3334. *border-= free_space;
  3335. *gap+= free_space;
  3336. DBUG_PRINT("qcache",
  3337. ("rest of result free space added to gap (%lu)", *gap));
  3338. new_block->length -= free_space;
  3339. }
  3340. BLOCK_UNLOCK_WR(query_block);
  3341. DBUG_PRINT("qcache", ("moved %lu bytes to 0x%lx, new gap at 0x%lx",
  3342. len, (ulong) new_block, (ulong) *border));
  3343. break;
  3344. }
  3345. default:
  3346. DBUG_PRINT("error", ("unexpected block type %d, block 0x%lx",
  3347. (int)block->type, (ulong) block));
  3348. ok = 0;
  3349. }
  3350. DBUG_RETURN(ok);
  3351. }
  3352. void Query_cache::relink(Query_cache_block *oblock,
  3353. Query_cache_block *nblock,
  3354. Query_cache_block *next, Query_cache_block *prev,
  3355. Query_cache_block *pnext, Query_cache_block *pprev)
  3356. {
  3357. if (prev == oblock) //check pointer to himself
  3358. {
  3359. nblock->prev = nblock;
  3360. nblock->next = nblock;
  3361. }
  3362. else
  3363. {
  3364. nblock->prev = prev;
  3365. prev->next=nblock;
  3366. }
  3367. if (next != oblock)
  3368. {
  3369. nblock->next = next;
  3370. next->prev=nblock;
  3371. }
  3372. nblock->pprev = pprev; // Physical pointer to himself have only 1 free block
  3373. nblock->pnext = pnext;
  3374. pprev->pnext=nblock;
  3375. pnext->pprev=nblock;
  3376. }
  3377. my_bool Query_cache::join_results(ulong join_limit)
  3378. {
  3379. my_bool has_moving = 0;
  3380. DBUG_ENTER("Query_cache::join_results");
  3381. if (queries_blocks != 0)
  3382. {
  3383. DBUG_ASSERT(query_cache_size > 0);
  3384. Query_cache_block *block = queries_blocks;
  3385. do
  3386. {
  3387. Query_cache_query *header = block->query();
  3388. if (header->result() != 0 &&
  3389. header->result()->type == Query_cache_block::RESULT &&
  3390. header->length() > join_limit)
  3391. {
  3392. Query_cache_block *new_result_block =
  3393. get_free_block(ALIGN_SIZE(header->length()) +
  3394. ALIGN_SIZE(sizeof(Query_cache_block)) +
  3395. ALIGN_SIZE(sizeof(Query_cache_result)), 1, 0);
  3396. if (new_result_block != 0)
  3397. {
  3398. has_moving = 1;
  3399. Query_cache_block *first_result = header->result();
  3400. ulong new_len = (header->length() +
  3401. ALIGN_SIZE(sizeof(Query_cache_block)) +
  3402. ALIGN_SIZE(sizeof(Query_cache_result)));
  3403. if (new_result_block->length >
  3404. ALIGN_SIZE(new_len) + min_allocation_unit)
  3405. split_block(new_result_block, ALIGN_SIZE(new_len));
  3406. BLOCK_LOCK_WR(block);
  3407. header->result(new_result_block);
  3408. new_result_block->type = Query_cache_block::RESULT;
  3409. new_result_block->n_tables = 0;
  3410. new_result_block->used = new_len;
  3411. new_result_block->next = new_result_block->prev = new_result_block;
  3412. DBUG_PRINT("qcache", ("new block %lu/%lu (%lu)",
  3413. new_result_block->length,
  3414. new_result_block->used,
  3415. header->length()));
  3416. Query_cache_result *new_result = new_result_block->result();
  3417. new_result->parent(block);
  3418. uchar *write_to = (uchar*) new_result->data();
  3419. Query_cache_block *result_block = first_result;
  3420. do
  3421. {
  3422. ulong len = (result_block->used - result_block->headers_len() -
  3423. ALIGN_SIZE(sizeof(Query_cache_result)));
  3424. DBUG_PRINT("loop", ("add block %lu/%lu (%lu)",
  3425. result_block->length,
  3426. result_block->used,
  3427. len));
  3428. memcpy((char *) write_to,
  3429. (char*) result_block->result()->data(),
  3430. len);
  3431. write_to += len;
  3432. Query_cache_block *old_result_block = result_block;
  3433. result_block = result_block->next;
  3434. free_memory_block(old_result_block);
  3435. } while (result_block != first_result);
  3436. BLOCK_UNLOCK_WR(block);
  3437. }
  3438. }
  3439. block = block->next;
  3440. } while ( block != queries_blocks );
  3441. }
  3442. DBUG_RETURN(has_moving);
  3443. }
  3444. uint Query_cache::filename_2_table_key (char *key, const char *path,
  3445. uint32 *db_length)
  3446. {
  3447. char tablename[FN_REFLEN+2], *filename, *dbname;
  3448. DBUG_ENTER("Query_cache::filename_2_table_key");
  3449. /* Safety if filename didn't have a directory name */
  3450. tablename[0]= FN_LIBCHAR;
  3451. tablename[1]= FN_LIBCHAR;
  3452. /* Convert filename to this OS's format in tablename */
  3453. fn_format(tablename + 2, path, "", "", MY_REPLACE_EXT);
  3454. filename= tablename + dirname_length(tablename + 2) + 2;
  3455. /* Find start of databasename */
  3456. for (dbname= filename - 2 ; dbname[-1] != FN_LIBCHAR ; dbname--) ;
  3457. *db_length= (filename - dbname) - 1;
  3458. DBUG_PRINT("qcache", ("table '%-.*s.%s'", *db_length, dbname, filename));
  3459. DBUG_RETURN((uint) (strmov(strmake(key, dbname, *db_length) + 1,
  3460. filename) -key) + 1);
  3461. }
  3462. /****************************************************************************
  3463. Functions to be used when debugging
  3464. ****************************************************************************/
  3465. #if defined(DBUG_OFF) && !defined(USE_QUERY_CACHE_INTEGRITY_CHECK)
  3466. void wreck(uint line, const char *message) { query_cache_size = 0; }
  3467. void bins_dump() {}
  3468. void cache_dump() {}
  3469. void queries_dump() {}
  3470. void tables_dump() {}
  3471. my_bool check_integrity(bool not_locked) { return 0; }
  3472. my_bool in_list(Query_cache_block * root, Query_cache_block * point,
  3473. const char *name) { return 0;}
  3474. my_bool in_blocks(Query_cache_block * point) { return 0; }
  3475. #else
  3476. /*
  3477. Debug method which switch query cache off but left content for
  3478. investigation.
  3479. SYNOPSIS
  3480. Query_cache::wreck()
  3481. line line of the wreck() call
  3482. message message for logging
  3483. */
  3484. void Query_cache::wreck(uint line, const char *message)
  3485. {
  3486. THD *thd=current_thd;
  3487. DBUG_ENTER("Query_cache::wreck");
  3488. query_cache_size = 0;
  3489. if (*message)
  3490. DBUG_PRINT("error", (" %s", message));
  3491. DBUG_PRINT("warning", ("=================================="));
  3492. DBUG_PRINT("warning", ("%5d QUERY CACHE WRECK => DISABLED",line));
  3493. DBUG_PRINT("warning", ("=================================="));
  3494. if (thd)
  3495. thd->killed= THD::KILL_CONNECTION;
  3496. cache_dump();
  3497. /* check_integrity(0); */ /* Can't call it here because of locks */
  3498. bins_dump();
  3499. DBUG_VOID_RETURN;
  3500. }
  3501. void Query_cache::bins_dump()
  3502. {
  3503. uint i;
  3504. if (!initialized || query_cache_size == 0)
  3505. {
  3506. DBUG_PRINT("qcache", ("Query Cache not initialized"));
  3507. return;
  3508. }
  3509. DBUG_PRINT("qcache", ("mem_bin_num=%u, mem_bin_steps=%u",
  3510. mem_bin_num, mem_bin_steps));
  3511. DBUG_PRINT("qcache", ("-------------------------"));
  3512. DBUG_PRINT("qcache", (" size idx step"));
  3513. DBUG_PRINT("qcache", ("-------------------------"));
  3514. for (i=0; i < mem_bin_steps; i++)
  3515. {
  3516. DBUG_PRINT("qcache", ("%10lu %3d %10lu", steps[i].size, steps[i].idx,
  3517. steps[i].increment));
  3518. }
  3519. DBUG_PRINT("qcache", ("-------------------------"));
  3520. DBUG_PRINT("qcache", (" size num"));
  3521. DBUG_PRINT("qcache", ("-------------------------"));
  3522. for (i=0; i < mem_bin_num; i++)
  3523. {
  3524. DBUG_PRINT("qcache", ("%10lu %3d 0x%lx", bins[i].size, bins[i].number,
  3525. (ulong)&(bins[i])));
  3526. if (bins[i].free_blocks)
  3527. {
  3528. Query_cache_block *block = bins[i].free_blocks;
  3529. do{
  3530. DBUG_PRINT("qcache", ("\\-- %lu 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
  3531. block->length, (ulong)block,
  3532. (ulong)block->next, (ulong)block->prev,
  3533. (ulong)block->pnext, (ulong)block->pprev));
  3534. block = block->next;
  3535. } while ( block != bins[i].free_blocks );
  3536. }
  3537. }
  3538. DBUG_PRINT("qcache", ("-------------------------"));
  3539. }
  3540. void Query_cache::cache_dump()
  3541. {
  3542. if (!initialized || query_cache_size == 0)
  3543. {
  3544. DBUG_PRINT("qcache", ("Query Cache not initialized"));
  3545. return;
  3546. }
  3547. DBUG_PRINT("qcache", ("-------------------------------------"));
  3548. DBUG_PRINT("qcache", (" length used t nt"));
  3549. DBUG_PRINT("qcache", ("-------------------------------------"));
  3550. Query_cache_block *i = first_block;
  3551. do
  3552. {
  3553. DBUG_PRINT("qcache",
  3554. ("%10lu %10lu %1d %2d 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
  3555. i->length, i->used, (int)i->type,
  3556. i->n_tables, (ulong)i,
  3557. (ulong)i->next, (ulong)i->prev, (ulong)i->pnext,
  3558. (ulong)i->pprev));
  3559. i = i->pnext;
  3560. } while ( i != first_block );
  3561. DBUG_PRINT("qcache", ("-------------------------------------"));
  3562. }
  3563. void Query_cache::queries_dump()
  3564. {
  3565. if (!initialized)
  3566. {
  3567. DBUG_PRINT("qcache", ("Query Cache not initialized"));
  3568. return;
  3569. }
  3570. DBUG_PRINT("qcache", ("------------------"));
  3571. DBUG_PRINT("qcache", (" QUERIES"));
  3572. DBUG_PRINT("qcache", ("------------------"));
  3573. if (queries_blocks != 0)
  3574. {
  3575. Query_cache_block *block = queries_blocks;
  3576. do
  3577. {
  3578. size_t len;
  3579. char *str = (char*) query_cache_query_get_key((uchar*) block, &len, 0);
  3580. len-= QUERY_CACHE_FLAGS_SIZE; // Point at flags
  3581. Query_cache_query_flags flags;
  3582. memcpy(&flags, str+len, QUERY_CACHE_FLAGS_SIZE);
  3583. str[len]= 0; // make zero ending DB name
  3584. DBUG_PRINT("qcache", ("F: %u C: %u L: %lu T: '%s' (%lu) '%s' '%s'",
  3585. flags.client_long_flag,
  3586. flags.character_set_client_num,
  3587. (ulong)flags.limit,
  3588. flags.time_zone->get_name()->ptr(),
  3589. (ulong) len, str, strend(str)+1));
  3590. DBUG_PRINT("qcache", ("-b- 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx", (ulong) block,
  3591. (ulong) block->next, (ulong) block->prev,
  3592. (ulong)block->pnext, (ulong)block->pprev));
  3593. memcpy(str + len, &flags, QUERY_CACHE_FLAGS_SIZE); // restore flags
  3594. for (TABLE_COUNTER_TYPE t= 0; t < block->n_tables; t++)
  3595. {
  3596. Query_cache_table *table= block->table(t)->parent;
  3597. DBUG_PRINT("qcache", ("-t- '%s' '%s'", table->db(), table->table()));
  3598. }
  3599. Query_cache_query *header = block->query();
  3600. if (header->result())
  3601. {
  3602. Query_cache_block *result_block = header->result();
  3603. Query_cache_block *result_beg = result_block;
  3604. do
  3605. {
  3606. DBUG_PRINT("qcache", ("-r- %u %lu/%lu 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx",
  3607. (uint) result_block->type,
  3608. result_block->length, result_block->used,
  3609. (ulong) result_block,
  3610. (ulong) result_block->next,
  3611. (ulong) result_block->prev,
  3612. (ulong) result_block->pnext,
  3613. (ulong) result_block->pprev));
  3614. result_block = result_block->next;
  3615. } while ( result_block != result_beg );
  3616. }
  3617. } while ((block=block->next) != queries_blocks);
  3618. }
  3619. else
  3620. {
  3621. DBUG_PRINT("qcache", ("no queries in list"));
  3622. }
  3623. DBUG_PRINT("qcache", ("------------------"));
  3624. }
  3625. void Query_cache::tables_dump()
  3626. {
  3627. if (!initialized || query_cache_size == 0)
  3628. {
  3629. DBUG_PRINT("qcache", ("Query Cache not initialized"));
  3630. return;
  3631. }
  3632. DBUG_PRINT("qcache", ("--------------------"));
  3633. DBUG_PRINT("qcache", ("TABLES"));
  3634. DBUG_PRINT("qcache", ("--------------------"));
  3635. if (tables_blocks != 0)
  3636. {
  3637. Query_cache_block *table_block = tables_blocks;
  3638. do
  3639. {
  3640. Query_cache_table *table = table_block->table();
  3641. DBUG_PRINT("qcache", ("'%s' '%s'", table->db(), table->table()));
  3642. table_block = table_block->next;
  3643. } while (table_block != tables_blocks);
  3644. }
  3645. else
  3646. DBUG_PRINT("qcache", ("no tables in list"));
  3647. DBUG_PRINT("qcache", ("--------------------"));
  3648. }
  3649. /**
  3650. Checks integrity of the various linked lists
  3651. @return Error status code
  3652. @retval FALSE Query cache is operational.
  3653. @retval TRUE Query cache is broken.
  3654. */
  3655. my_bool Query_cache::check_integrity(bool locked)
  3656. {
  3657. my_bool result = 0;
  3658. uint i;
  3659. DBUG_ENTER("check_integrity");
  3660. if (!locked)
  3661. lock_and_suspend();
  3662. if (hash_check(&queries))
  3663. {
  3664. DBUG_PRINT("error", ("queries hash is damaged"));
  3665. result = 1;
  3666. }
  3667. if (hash_check(&tables))
  3668. {
  3669. DBUG_PRINT("error", ("tables hash is damaged"));
  3670. result = 1;
  3671. }
  3672. DBUG_PRINT("qcache", ("physical address check ..."));
  3673. ulong free=0, used=0;
  3674. Query_cache_block * block = first_block;
  3675. do
  3676. {
  3677. /* When checking at system start, there is no block. */
  3678. if (!block)
  3679. break;
  3680. DBUG_PRINT("qcache", ("block 0x%lx, type %u...",
  3681. (ulong) block, (uint) block->type));
  3682. // Check allignment
  3683. if ((((long)block) % (long) ALIGN_SIZE(1)) !=
  3684. (((long)first_block) % (long)ALIGN_SIZE(1)))
  3685. {
  3686. DBUG_PRINT("error",
  3687. ("block 0x%lx do not aligned by %d", (ulong) block,
  3688. (int) ALIGN_SIZE(1)));
  3689. result = 1;
  3690. }
  3691. // Check memory allocation
  3692. if (block->pnext == first_block) // Is it last block?
  3693. {
  3694. if (((uchar*)block) + block->length !=
  3695. ((uchar*)first_block) + query_cache_size)
  3696. {
  3697. DBUG_PRINT("error",
  3698. ("block 0x%lx, type %u, ended at 0x%lx, but cache ended at 0x%lx",
  3699. (ulong) block, (uint) block->type,
  3700. (ulong) (((uchar*)block) + block->length),
  3701. (ulong) (((uchar*)first_block) + query_cache_size)));
  3702. result = 1;
  3703. }
  3704. }
  3705. else
  3706. if (((uchar*)block) + block->length != ((uchar*)block->pnext))
  3707. {
  3708. DBUG_PRINT("error",
  3709. ("block 0x%lx, type %u, ended at 0x%lx, but next block begining at 0x%lx",
  3710. (ulong) block, (uint) block->type,
  3711. (ulong) (((uchar*)block) + block->length),
  3712. (ulong) ((uchar*)block->pnext)));
  3713. }
  3714. if (block->type == Query_cache_block::FREE)
  3715. free+= block->length;
  3716. else
  3717. used+= block->length;
  3718. switch(block->type) {
  3719. case Query_cache_block::FREE:
  3720. {
  3721. Query_cache_memory_bin *bin = *((Query_cache_memory_bin **)
  3722. block->data());
  3723. //is it correct pointer?
  3724. if (((uchar*)bin) < ((uchar*)bins) ||
  3725. ((uchar*)bin) >= ((uchar*)first_block))
  3726. {
  3727. DBUG_PRINT("error",
  3728. ("free block 0x%lx have bin pointer 0x%lx beyaond of bins array bounds [0x%lx,0x%lx]",
  3729. (ulong) block,
  3730. (ulong) bin,
  3731. (ulong) bins,
  3732. (ulong) first_block));
  3733. result = 1;
  3734. }
  3735. else
  3736. {
  3737. int idx = (((uchar*)bin) - ((uchar*)bins)) /
  3738. sizeof(Query_cache_memory_bin);
  3739. if (in_list(bins[idx].free_blocks, block, "free memory"))
  3740. result = 1;
  3741. }
  3742. break;
  3743. }
  3744. case Query_cache_block::TABLE:
  3745. if (in_list(tables_blocks, block, "tables"))
  3746. result = 1;
  3747. if (in_table_list(block->table(0), block->table(0), "table list root"))
  3748. result = 1;
  3749. break;
  3750. case Query_cache_block::QUERY:
  3751. {
  3752. if (in_list(queries_blocks, block, "query"))
  3753. result = 1;
  3754. for (TABLE_COUNTER_TYPE j=0; j < block->n_tables; j++)
  3755. {
  3756. Query_cache_block_table *block_table = block->table(j);
  3757. Query_cache_block_table *block_table_root =
  3758. (Query_cache_block_table *)
  3759. (((uchar*)block_table->parent) -
  3760. ALIGN_SIZE(sizeof(Query_cache_block_table)));
  3761. if (in_table_list(block_table, block_table_root, "table list"))
  3762. result = 1;
  3763. }
  3764. break;
  3765. }
  3766. case Query_cache_block::RES_INCOMPLETE:
  3767. // This type of block can be not lincked yet (in multithread environment)
  3768. break;
  3769. case Query_cache_block::RES_BEG:
  3770. case Query_cache_block::RES_CONT:
  3771. case Query_cache_block::RESULT:
  3772. {
  3773. Query_cache_block * query_block = block->result()->parent();
  3774. if (((uchar*)query_block) < ((uchar*)first_block) ||
  3775. ((uchar*)query_block) >= (((uchar*)first_block) + query_cache_size))
  3776. {
  3777. DBUG_PRINT("error",
  3778. ("result block 0x%lx have query block pointer 0x%lx beyaond of block pool bounds [0x%lx,0x%lx]",
  3779. (ulong) block,
  3780. (ulong) query_block,
  3781. (ulong) first_block,
  3782. (ulong) (((uchar*)first_block) + query_cache_size)));
  3783. result = 1;
  3784. }
  3785. else
  3786. {
  3787. BLOCK_LOCK_RD(query_block);
  3788. if (in_list(queries_blocks, query_block, "query from results"))
  3789. result = 1;
  3790. if (in_list(query_block->query()->result(), block,
  3791. "results"))
  3792. result = 1;
  3793. BLOCK_UNLOCK_RD(query_block);
  3794. }
  3795. break;
  3796. }
  3797. default:
  3798. DBUG_PRINT("error", ("block 0x%lx have incorrect type %u",
  3799. (long) block, block->type));
  3800. result = 1;
  3801. }
  3802. block = block->pnext;
  3803. } while (block != first_block);
  3804. if (used + free != query_cache_size)
  3805. {
  3806. DBUG_PRINT("error",
  3807. ("used memory (%lu) + free memory (%lu) != query_cache_size (%lu)",
  3808. used, free, query_cache_size));
  3809. result = 1;
  3810. }
  3811. if (free != free_memory)
  3812. {
  3813. DBUG_PRINT("error",
  3814. ("free memory (%lu) != free_memory (%lu)",
  3815. free, free_memory));
  3816. result = 1;
  3817. }
  3818. DBUG_PRINT("qcache", ("check queries ..."));
  3819. if ((block = queries_blocks))
  3820. {
  3821. do
  3822. {
  3823. DBUG_PRINT("qcache", ("block 0x%lx, type %u...",
  3824. (ulong) block, (uint) block->type));
  3825. size_t length;
  3826. uchar *key = query_cache_query_get_key((uchar*) block, &length, 0);
  3827. uchar* val = hash_search(&queries, key, length);
  3828. if (((uchar*)block) != val)
  3829. {
  3830. DBUG_PRINT("error", ("block 0x%lx found in queries hash like 0x%lx",
  3831. (ulong) block, (ulong) val));
  3832. }
  3833. if (in_blocks(block))
  3834. result = 1;
  3835. Query_cache_block * results = block->query()->result();
  3836. if (results)
  3837. {
  3838. Query_cache_block * result_block = results;
  3839. do
  3840. {
  3841. DBUG_PRINT("qcache", ("block 0x%lx, type %u...",
  3842. (ulong) block, (uint) block->type));
  3843. if (in_blocks(result_block))
  3844. result = 1;
  3845. result_block = result_block->next;
  3846. } while (result_block != results);
  3847. }
  3848. block = block->next;
  3849. } while (block != queries_blocks);
  3850. }
  3851. DBUG_PRINT("qcache", ("check tables ..."));
  3852. if ((block = tables_blocks))
  3853. {
  3854. do
  3855. {
  3856. DBUG_PRINT("qcache", ("block 0x%lx, type %u...",
  3857. (ulong) block, (uint) block->type));
  3858. size_t length;
  3859. uchar *key = query_cache_table_get_key((uchar*) block, &length, 0);
  3860. uchar* val = hash_search(&tables, key, length);
  3861. if (((uchar*)block) != val)
  3862. {
  3863. DBUG_PRINT("error", ("block 0x%lx found in tables hash like 0x%lx",
  3864. (ulong) block, (ulong) val));
  3865. }
  3866. if (in_blocks(block))
  3867. result = 1;
  3868. block=block->next;
  3869. } while (block != tables_blocks);
  3870. }
  3871. DBUG_PRINT("qcache", ("check free blocks"));
  3872. for (i = 0; i < mem_bin_num; i++)
  3873. {
  3874. if ((block = bins[i].free_blocks))
  3875. {
  3876. uint count = 0;
  3877. do
  3878. {
  3879. DBUG_PRINT("qcache", ("block 0x%lx, type %u...",
  3880. (ulong) block, (uint) block->type));
  3881. if (in_blocks(block))
  3882. result = 1;
  3883. count++;
  3884. block=block->next;
  3885. } while (block != bins[i].free_blocks);
  3886. if (count != bins[i].number)
  3887. {
  3888. DBUG_PRINT("error", ("bins[%d].number= %d, but bin have %d blocks",
  3889. i, bins[i].number, count));
  3890. result = 1;
  3891. }
  3892. }
  3893. }
  3894. DBUG_ASSERT(result == 0);
  3895. if (!locked)
  3896. unlock();
  3897. DBUG_RETURN(result);
  3898. }
  3899. my_bool Query_cache::in_blocks(Query_cache_block * point)
  3900. {
  3901. my_bool result = 0;
  3902. Query_cache_block *block = point;
  3903. //back
  3904. do
  3905. {
  3906. if (block->pprev->pnext != block)
  3907. {
  3908. DBUG_PRINT("error",
  3909. ("block 0x%lx in physical list is incorrect linked, prev block 0x%lx refered as next to 0x%lx (check from 0x%lx)",
  3910. (ulong) block, (ulong) block->pprev,
  3911. (ulong) block->pprev->pnext,
  3912. (ulong) point));
  3913. //back trace
  3914. for (; block != point; block = block->pnext)
  3915. DBUG_PRINT("error", ("back trace 0x%lx", (ulong) block));
  3916. result = 1;
  3917. goto err1;
  3918. }
  3919. block = block->pprev;
  3920. } while (block != first_block && block != point);
  3921. if (block != first_block)
  3922. {
  3923. DBUG_PRINT("error",
  3924. ("block 0x%lx (0x%lx<-->0x%lx) not owned by pysical list",
  3925. (ulong) block, (ulong) block->pprev, (ulong )block->pnext));
  3926. return 1;
  3927. }
  3928. err1:
  3929. //forward
  3930. block = point;
  3931. do
  3932. {
  3933. if (block->pnext->pprev != block)
  3934. {
  3935. DBUG_PRINT("error",
  3936. ("block 0x%lx in physicel list is incorrect linked, next block 0x%lx refered as prev to 0x%lx (check from 0x%lx)",
  3937. (ulong) block, (ulong) block->pnext,
  3938. (ulong) block->pnext->pprev,
  3939. (ulong) point));
  3940. //back trace
  3941. for (; block != point; block = block->pprev)
  3942. DBUG_PRINT("error", ("back trace 0x%lx", (ulong) block));
  3943. result = 1;
  3944. goto err2;
  3945. }
  3946. block = block->pnext;
  3947. } while (block != first_block);
  3948. err2:
  3949. return result;
  3950. }
  3951. my_bool Query_cache::in_list(Query_cache_block * root,
  3952. Query_cache_block * point,
  3953. const char *name)
  3954. {
  3955. my_bool result = 0;
  3956. Query_cache_block *block = point;
  3957. //back
  3958. do
  3959. {
  3960. if (block->prev->next != block)
  3961. {
  3962. DBUG_PRINT("error",
  3963. ("block 0x%lx in list '%s' 0x%lx is incorrect linked, prev block 0x%lx refered as next to 0x%lx (check from 0x%lx)",
  3964. (ulong) block, name, (ulong) root, (ulong) block->prev,
  3965. (ulong) block->prev->next,
  3966. (ulong) point));
  3967. //back trace
  3968. for (; block != point; block = block->next)
  3969. DBUG_PRINT("error", ("back trace 0x%lx", (ulong) block));
  3970. result = 1;
  3971. goto err1;
  3972. }
  3973. block = block->prev;
  3974. } while (block != root && block != point);
  3975. if (block != root)
  3976. {
  3977. DBUG_PRINT("error",
  3978. ("block 0x%lx (0x%lx<-->0x%lx) not owned by list '%s' 0x%lx",
  3979. (ulong) block,
  3980. (ulong) block->prev, (ulong) block->next,
  3981. name, (ulong) root));
  3982. return 1;
  3983. }
  3984. err1:
  3985. // forward
  3986. block = point;
  3987. do
  3988. {
  3989. if (block->next->prev != block)
  3990. {
  3991. DBUG_PRINT("error",
  3992. ("block 0x%lx in list '%s' 0x%lx is incorrect linked, next block 0x%lx refered as prev to 0x%lx (check from 0x%lx)",
  3993. (ulong) block, name, (ulong) root, (ulong) block->next,
  3994. (ulong) block->next->prev,
  3995. (ulong) point));
  3996. //back trace
  3997. for (; block != point; block = block->prev)
  3998. DBUG_PRINT("error", ("back trace 0x%lx", (ulong) block));
  3999. result = 1;
  4000. goto err2;
  4001. }
  4002. block = block->next;
  4003. } while (block != root);
  4004. err2:
  4005. return result;
  4006. }
  4007. void dump_node(Query_cache_block_table * node,
  4008. const char * call, const char * descr)
  4009. {
  4010. DBUG_PRINT("qcache", ("%s: %s: node: 0x%lx", call, descr, (ulong) node));
  4011. DBUG_PRINT("qcache", ("%s: %s: node block: 0x%lx",
  4012. call, descr, (ulong) node->block()));
  4013. DBUG_PRINT("qcache", ("%s: %s: next: 0x%lx", call, descr,
  4014. (ulong) node->next));
  4015. DBUG_PRINT("qcache", ("%s: %s: prev: 0x%lx", call, descr,
  4016. (ulong) node->prev));
  4017. }
  4018. my_bool Query_cache::in_table_list(Query_cache_block_table * root,
  4019. Query_cache_block_table * point,
  4020. const char *name)
  4021. {
  4022. my_bool result = 0;
  4023. Query_cache_block_table *table = point;
  4024. dump_node(root, name, "parameter root");
  4025. //back
  4026. do
  4027. {
  4028. dump_node(table, name, "list element << ");
  4029. if (table->prev->next != table)
  4030. {
  4031. DBUG_PRINT("error",
  4032. ("table 0x%lx(0x%lx) in list '%s' 0x%lx(0x%lx) is incorrect linked, prev table 0x%lx(0x%lx) refered as next to 0x%lx(0x%lx) (check from 0x%lx(0x%lx))",
  4033. (ulong) table, (ulong) table->block(), name,
  4034. (ulong) root, (ulong) root->block(),
  4035. (ulong) table->prev, (ulong) table->prev->block(),
  4036. (ulong) table->prev->next,
  4037. (ulong) table->prev->next->block(),
  4038. (ulong) point, (ulong) point->block()));
  4039. //back trace
  4040. for (; table != point; table = table->next)
  4041. DBUG_PRINT("error", ("back trace 0x%lx(0x%lx)",
  4042. (ulong) table, (ulong) table->block()));
  4043. result = 1;
  4044. goto err1;
  4045. }
  4046. table = table->prev;
  4047. } while (table != root && table != point);
  4048. if (table != root)
  4049. {
  4050. DBUG_PRINT("error",
  4051. ("table 0x%lx(0x%lx) (0x%lx(0x%lx)<-->0x%lx(0x%lx)) not owned by list '%s' 0x%lx(0x%lx)",
  4052. (ulong) table, (ulong) table->block(),
  4053. (ulong) table->prev, (ulong) table->prev->block(),
  4054. (ulong) table->next, (ulong) table->next->block(),
  4055. name, (ulong) root, (ulong) root->block()));
  4056. return 1;
  4057. }
  4058. err1:
  4059. // forward
  4060. table = point;
  4061. do
  4062. {
  4063. dump_node(table, name, "list element >> ");
  4064. if (table->next->prev != table)
  4065. {
  4066. DBUG_PRINT("error",
  4067. ("table 0x%lx(0x%lx) in list '%s' 0x%lx(0x%lx) is incorrect linked, next table 0x%lx(0x%lx) refered as prev to 0x%lx(0x%lx) (check from 0x%lx(0x%lx))",
  4068. (ulong) table, (ulong) table->block(),
  4069. name, (ulong) root, (ulong) root->block(),
  4070. (ulong) table->next, (ulong) table->next->block(),
  4071. (ulong) table->next->prev,
  4072. (ulong) table->next->prev->block(),
  4073. (ulong) point, (ulong) point->block()));
  4074. //back trace
  4075. for (; table != point; table = table->prev)
  4076. DBUG_PRINT("error", ("back trace 0x%lx(0x%lx)",
  4077. (ulong) table, (ulong) table->block()));
  4078. result = 1;
  4079. goto err2;
  4080. }
  4081. table = table->next;
  4082. } while (table != root);
  4083. err2:
  4084. return result;
  4085. }
  4086. #endif /* DBUG_OFF */
  4087. #endif /*HAVE_QUERY_CACHE*/