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.

3428 lines
110 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
WL#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 years ago
WL#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 years ago
WL#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 years ago
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1, 2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29, 2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and some other minor revisions. This patch implements: WL#4264 "Backup: Stabilize Service Interface" -- all the server prerequisites except si_objects.{h,cc} themselves (they can be just copied over, when needed). WL#4435: Support OUT-parameters in prepared statements. (and all issues in the initial patches for these two tasks, that were discovered in pushbuild and during testing). Bug#39519: mysql_stmt_close() should flush all data associated with the statement. After execution of a prepared statement, send OUT parameters of the invoked stored procedure, if any, to the client. When using the binary protocol, send the parameters in an additional result set over the wire. When using the text protocol, assign out parameters to the user variables from the CALL(@var1, @var2, ...) specification. The following refactoring has been made: - Protocol::send_fields() was renamed to Protocol::send_result_set_metadata(); - A new Protocol::send_result_set_row() was introduced to incapsulate common functionality for sending row data. - Signature of Protocol::prepare_for_send() was changed: this operation does not need a list of items, the number of items is fully sufficient. The following backward incompatible changes have been made: - CLIENT_MULTI_RESULTS is now enabled by default in the client; - CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
16 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
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
26 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
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
23 years ago
26 years ago
23 years ago
26 years ago
26 years ago
WL#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
WL#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 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
Bug #45640: optimizer bug produces wrong results Grouping by a subquery in a query with a distinct aggregate function lead to a wrong result (wrong and unordered grouping values). There are two related problems: 1) The query like this: SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) c FROM t1 GROUP BY aa returned wrong result, because the outer reference "t1.a" in the subquery was substituted with the Item_ref item. The Item_ref item obtains data from the result_field object that refreshes once after the end of each group. This data is not applicable to filesort since filesort() doesn't care about groups (and doesn't update result_field objects with copy_fields() and so on). Also that data is not applicable to group separation algorithm: end_send_group() checks every record with test_if_group_changed() that evaluates Item_ref items, but it refreshes those Item_ref-s only after the end of group, that is a vicious circle and the grouped column values in the output are shifted. Fix: if a) we grouping by a subquery and b) that subquery has outer references to FROM list of the grouping query, then we substitute these outer references with Item_direct_ref like references under aggregate functions: Item_direct_ref obtains data directly from the current record. 2) The query with a non-trivial grouping expression like: SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) c FROM t1 GROUP BY aa+0 also returned wrong result, since JOIN::exec() substitutes references to top-level aliases in SELECT list with Item_copy caching items. Item_copy items have same refreshing policy as Item_ref items, so the whole groping expression with Item_copy inside returns wrong result in filesort() and end_send_group(). Fix: include aliased items into GROUP BY item tree instead of Item_ref references to them.
16 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
Bug #49734: Crash on EXPLAIN EXTENDED UNION ... ORDER BY <any non-const-function> Several problems fixed : 1. Non constant expressions in UNION ... ORDER BY were not correctly cleaned up in st_select_lex_unit::cleanup() causing crashes in EXPLAIN EXTENDED because of fields quoted by these expressions pointing to the already freed temporary table used to calculate the UNION. Fixed by correctly cleaning up expressions of any depth. 2. Subqueries in the order by part of UNION ... ORDER BY ... caused a crash in EXPLAIN EXTENDED because of a transformation attempt made during EXPLAIN EXTENDED execution. Fixed by not doing the transformation when in EXPLAIN. 3. Fulltext functions caused crash when in the ORDER BY part of an un-parenthesized UNION that gets "promoted" to be valid for the whole union, e.g. SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY MATCHES (a) AGAINST ('abc' IN BOOLEAN MODE). This is a case that demonstrates a more general problem of parts of the query being moved to another level. When doing such transformation late in the optimization run when most of the flags about the contents of the query are already aggregated it's possible to "split" the flags so that they correctly reflect the new queries after the transformation. In specific the ST_SELECT_LEX::ftfunc_list is holding all the free text function for all the parts of the second SELECT in the UNION and we don't know what part of that is in the ORDER BY that we're to move to the UNION level and what part is about the other parts of the second SELECT. Fixed by throwing and error when such statements are about to be processed by adding a check for the presence of MATCH() inside the ORDER BY clause that's going to get promoted to UNION. To workaround this new limitation one must parenthesize the UNION SELECTs and provide a real global ORDER BY for the UNION outside of the parenthesis.
16 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
Fixed bug#16377: result of DATE/TIME functions were compared as strings which can lead to a wrong result. All date/time functions has the STRING result type thus their results are compared as strings. The string date representation allows a user to skip some of leading zeros. This can lead to wrong comparison result if a date/time function result is compared to such a string constant. The idea behind this bug fix is to compare results of date/time functions and data/time constants as ints, because that date/time representation is more exact. To achieve this the agg_cmp_type() is changed to take in the account that a date/time field or an date/time item should be compared as ints. This bug fix is partially back ported from 5.0. The agg_cmp_type() function now accepts THD as one of parameters. In addition, it now checks if a date/time field/function is present in the list. If so, it tries to coerce all constants to INT to make date/time comparison return correct result. The field for the constant coercion is taken from the Item_field or constructed from the Item_func. In latter case the constructed field will be freed after conversion of all constant items. Otherwise the result is same as before - aggregated with help of the item_cmp_type() function. From the Item_func_between::fix_length_and_dec() function removed the part which was converting date/time constants to int if possible. Now this is done by the agg_cmp_type() function. The new function result_as_longlong() is added to the Item class. It indicates that the item is a date/time item and result of it can be compared as int. Such items are date/time fields/functions. Correct val_int() methods are implemented for classes Item_date_typecast, Item_func_makedate, Item_time_typecast, Item_datetime_typecast. All these classes are derived from Item_str_func and Item_str_func::val_int() converts its string value to int without regard to the date/time type of these items. Arg_comparator::set_compare_func() and Arg_comparator::set_cmp_func() functions are changed to substitute result type of an item with the INT_RESULT if the item is a date/time item and another item is a constant. This is done to get a correct result of comparisons like date_time_function() = string_constant.
20 years ago
Bug#27590: Wrong DATE/DATETIME comparison. DATE and DATETIME can be compared either as strings or as int. Both methods have their disadvantages. Strings can contain valid DATETIME value but have insignificant zeros omitted thus became non-comparable with other DATETIME strings. The comparison as int usually will require conversion from the string representation and the automatic conversion in most cases is carried out in a wrong way thus producing wrong comparison result. Another problem occurs when one tries to compare DATE field with a DATETIME constant. The constant is converted to DATE losing its precision i.e. losing time part. This fix addresses the problems described above by adding a special DATE/DATETIME comparator. The comparator correctly converts DATE/DATETIME string values to int when it's necessary, adds zero time part (00:00:00) to DATE values to compare them correctly to DATETIME values. Due to correct conversion malformed DATETIME string values are correctly compared to other DATE/DATETIME values. As of this patch a DATE value equals to DATETIME value with zero time part. For example '2001-01-01' equals to '2001-01-01 00:00:00'. The compare_datetime() function is added to the Arg_comparator class. It implements the correct comparator for DATE/DATETIME values. Two supplementary functions called get_date_from_str() and get_datetime_value() are added. The first one extracts DATE/DATETIME value from a string and the second one retrieves the correct DATE/DATETIME value from an item. The new Arg_comparator::can_compare_as_dates() function is added and used to check whether two given items can be compared by the compare_datetime() comparator. Two caching variables were added to the Arg_comparator class to speedup the DATE/DATETIME comparison. One more store() method was added to the Item_cache_int class to cache int values. The new is_datetime() function was added to the Item class. It indicates whether the item returns a DATE/DATETIME value.
19 years ago
WL#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 years ago
26 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
WL#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 years ago
WL#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 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
26 years ago
26 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
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 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
Fixed bug#16377: result of DATE/TIME functions were compared as strings which can lead to a wrong result. All date/time functions has the STRING result type thus their results are compared as strings. The string date representation allows a user to skip some of leading zeros. This can lead to wrong comparison result if a date/time function result is compared to such a string constant. The idea behind this bug fix is to compare results of date/time functions and data/time constants as ints, because that date/time representation is more exact. To achieve this the agg_cmp_type() is changed to take in the account that a date/time field or an date/time item should be compared as ints. This bug fix is partially back ported from 5.0. The agg_cmp_type() function now accepts THD as one of parameters. In addition, it now checks if a date/time field/function is present in the list. If so, it tries to coerce all constants to INT to make date/time comparison return correct result. The field for the constant coercion is taken from the Item_field or constructed from the Item_func. In latter case the constructed field will be freed after conversion of all constant items. Otherwise the result is same as before - aggregated with help of the item_cmp_type() function. From the Item_func_between::fix_length_and_dec() function removed the part which was converting date/time constants to int if possible. Now this is done by the agg_cmp_type() function. The new function result_as_longlong() is added to the Item class. It indicates that the item is a date/time item and result of it can be compared as int. Such items are date/time fields/functions. Correct val_int() methods are implemented for classes Item_date_typecast, Item_func_makedate, Item_time_typecast, Item_datetime_typecast. All these classes are derived from Item_str_func and Item_str_func::val_int() converts its string value to int without regard to the date/time type of these items. Arg_comparator::set_compare_func() and Arg_comparator::set_cmp_func() functions are changed to substitute result type of an item with the INT_RESULT if the item is a date/time item and another item is a constant. This is done to get a correct result of comparisons like date_time_function() = string_constant.
20 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
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#2649 Number-to-string conversions added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
16 years ago
26 years ago
26 years ago
26 years ago
26 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
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
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1, 2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29, 2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and some other minor revisions. This patch implements: WL#4264 "Backup: Stabilize Service Interface" -- all the server prerequisites except si_objects.{h,cc} themselves (they can be just copied over, when needed). WL#4435: Support OUT-parameters in prepared statements. (and all issues in the initial patches for these two tasks, that were discovered in pushbuild and during testing). Bug#39519: mysql_stmt_close() should flush all data associated with the statement. After execution of a prepared statement, send OUT parameters of the invoked stored procedure, if any, to the client. When using the binary protocol, send the parameters in an additional result set over the wire. When using the text protocol, assign out parameters to the user variables from the CALL(@var1, @var2, ...) specification. The following refactoring has been made: - Protocol::send_fields() was renamed to Protocol::send_result_set_metadata(); - A new Protocol::send_result_set_row() was introduced to incapsulate common functionality for sending row data. - Signature of Protocol::prepare_for_send() was changed: this operation does not need a list of items, the number of items is fully sufficient. The following backward incompatible changes have been made: - CLIENT_MULTI_RESULTS is now enabled by default in the client; - CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
16 years ago
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1, 2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29, 2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and some other minor revisions. This patch implements: WL#4264 "Backup: Stabilize Service Interface" -- all the server prerequisites except si_objects.{h,cc} themselves (they can be just copied over, when needed). WL#4435: Support OUT-parameters in prepared statements. (and all issues in the initial patches for these two tasks, that were discovered in pushbuild and during testing). Bug#39519: mysql_stmt_close() should flush all data associated with the statement. After execution of a prepared statement, send OUT parameters of the invoked stored procedure, if any, to the client. When using the binary protocol, send the parameters in an additional result set over the wire. When using the text protocol, assign out parameters to the user variables from the CALL(@var1, @var2, ...) specification. The following refactoring has been made: - Protocol::send_fields() was renamed to Protocol::send_result_set_metadata(); - A new Protocol::send_result_set_row() was introduced to incapsulate common functionality for sending row data. - Signature of Protocol::prepare_for_send() was changed: this operation does not need a list of items, the number of items is fully sufficient. The following backward incompatible changes have been made: - CLIENT_MULTI_RESULTS is now enabled by default in the client; - CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
16 years ago
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1, 2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29, 2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and some other minor revisions. This patch implements: WL#4264 "Backup: Stabilize Service Interface" -- all the server prerequisites except si_objects.{h,cc} themselves (they can be just copied over, when needed). WL#4435: Support OUT-parameters in prepared statements. (and all issues in the initial patches for these two tasks, that were discovered in pushbuild and during testing). Bug#39519: mysql_stmt_close() should flush all data associated with the statement. After execution of a prepared statement, send OUT parameters of the invoked stored procedure, if any, to the client. When using the binary protocol, send the parameters in an additional result set over the wire. When using the text protocol, assign out parameters to the user variables from the CALL(@var1, @var2, ...) specification. The following refactoring has been made: - Protocol::send_fields() was renamed to Protocol::send_result_set_metadata(); - A new Protocol::send_result_set_row() was introduced to incapsulate common functionality for sending row data. - Signature of Protocol::prepare_for_send() was changed: this operation does not need a list of items, the number of items is fully sufficient. The following backward incompatible changes have been made: - CLIENT_MULTI_RESULTS is now enabled by default in the client; - CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
16 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
23 years ago
26 years ago
19 years ago
26 years ago
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
19 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
23 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
23 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
23 years ago
26 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
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
26 years ago
26 years ago
26 years ago
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1, 2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29, 2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and some other minor revisions. This patch implements: WL#4264 "Backup: Stabilize Service Interface" -- all the server prerequisites except si_objects.{h,cc} themselves (they can be just copied over, when needed). WL#4435: Support OUT-parameters in prepared statements. (and all issues in the initial patches for these two tasks, that were discovered in pushbuild and during testing). Bug#39519: mysql_stmt_close() should flush all data associated with the statement. After execution of a prepared statement, send OUT parameters of the invoked stored procedure, if any, to the client. When using the binary protocol, send the parameters in an additional result set over the wire. When using the text protocol, assign out parameters to the user variables from the CALL(@var1, @var2, ...) specification. The following refactoring has been made: - Protocol::send_fields() was renamed to Protocol::send_result_set_metadata(); - A new Protocol::send_result_set_row() was introduced to incapsulate common functionality for sending row data. - Signature of Protocol::prepare_for_send() was changed: this operation does not need a list of items, the number of items is fully sufficient. The following backward incompatible changes have been made: - CLIENT_MULTI_RESULTS is now enabled by default in the client; - CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
16 years ago
26 years ago
26 years ago
26 years ago
21 years ago
26 years ago
26 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
26 years ago
21 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 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
Bug #45640: optimizer bug produces wrong results Grouping by a subquery in a query with a distinct aggregate function lead to a wrong result (wrong and unordered grouping values). There are two related problems: 1) The query like this: SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) c FROM t1 GROUP BY aa returned wrong result, because the outer reference "t1.a" in the subquery was substituted with the Item_ref item. The Item_ref item obtains data from the result_field object that refreshes once after the end of each group. This data is not applicable to filesort since filesort() doesn't care about groups (and doesn't update result_field objects with copy_fields() and so on). Also that data is not applicable to group separation algorithm: end_send_group() checks every record with test_if_group_changed() that evaluates Item_ref items, but it refreshes those Item_ref-s only after the end of group, that is a vicious circle and the grouped column values in the output are shifted. Fix: if a) we grouping by a subquery and b) that subquery has outer references to FROM list of the grouping query, then we substitute these outer references with Item_direct_ref like references under aggregate functions: Item_direct_ref obtains data directly from the current record. 2) The query with a non-trivial grouping expression like: SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) c FROM t1 GROUP BY aa+0 also returned wrong result, since JOIN::exec() substitutes references to top-level aliases in SELECT list with Item_copy caching items. Item_copy items have same refreshing policy as Item_ref items, so the whole groping expression with Item_copy inside returns wrong result in filesort() and end_send_group(). Fix: include aliased items into GROUP BY item tree instead of Item_ref references to them.
16 years ago
Fixed bug#16377: result of DATE/TIME functions were compared as strings which can lead to a wrong result. All date/time functions has the STRING result type thus their results are compared as strings. The string date representation allows a user to skip some of leading zeros. This can lead to wrong comparison result if a date/time function result is compared to such a string constant. The idea behind this bug fix is to compare results of date/time functions and data/time constants as ints, because that date/time representation is more exact. To achieve this the agg_cmp_type() is changed to take in the account that a date/time field or an date/time item should be compared as ints. This bug fix is partially back ported from 5.0. The agg_cmp_type() function now accepts THD as one of parameters. In addition, it now checks if a date/time field/function is present in the list. If so, it tries to coerce all constants to INT to make date/time comparison return correct result. The field for the constant coercion is taken from the Item_field or constructed from the Item_func. In latter case the constructed field will be freed after conversion of all constant items. Otherwise the result is same as before - aggregated with help of the item_cmp_type() function. From the Item_func_between::fix_length_and_dec() function removed the part which was converting date/time constants to int if possible. Now this is done by the agg_cmp_type() function. The new function result_as_longlong() is added to the Item class. It indicates that the item is a date/time item and result of it can be compared as int. Such items are date/time fields/functions. Correct val_int() methods are implemented for classes Item_date_typecast, Item_func_makedate, Item_time_typecast, Item_datetime_typecast. All these classes are derived from Item_str_func and Item_str_func::val_int() converts its string value to int without regard to the date/time type of these items. Arg_comparator::set_compare_func() and Arg_comparator::set_cmp_func() functions are changed to substitute result type of an item with the INT_RESULT if the item is a date/time item and another item is a constant. This is done to get a correct result of comparisons like date_time_function() = string_constant.
20 years ago
26 years ago
23 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
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
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
26 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
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
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes Changes that requires code changes in other code of other storage engines. (Note that all changes are very straightforward and one should find all issues by compiling a --debug build and fixing all compiler errors and all asserts in field.cc while running the test suite), - New optional handler function introduced: reset() This is called after every DML statement to make it easy for a handler to statement specific cleanups. (The only case it's not called is if force the file to be closed) - handler::extra(HA_EXTRA_RESET) is removed. Code that was there before should be moved to handler::reset() - table->read_set contains a bitmap over all columns that are needed in the query. read_row() and similar functions only needs to read these columns - table->write_set contains a bitmap over all columns that will be updated in the query. write_row() and update_row() only needs to update these columns. The above bitmaps should now be up to date in all context (including ALTER TABLE, filesort()). The handler is informed of any changes to the bitmap after fix_fields() by calling the virtual function handler::column_bitmaps_signal(). If the handler does caching of these bitmaps (instead of using table->read_set, table->write_set), it should redo the caching in this code. as the signal() may be sent several times, it's probably best to set a variable in the signal and redo the caching on read_row() / write_row() if the variable was set. - Removed the read_set and write_set bitmap objects from the handler class - Removed all column bit handling functions from the handler class. (Now one instead uses the normal bitmap functions in my_bitmap.c instead of handler dedicated bitmap functions) - field->query_id is removed. One should instead instead check table->read_set and table->write_set if a field is used in the query. - handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now instead use table->read_set to check for which columns to retrieve. - If a handler needs to call Field->val() or Field->store() on columns that are not used in the query, one should install a temporary all-columns-used map while doing so. For this, we provide the following functions: my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set); field->val(); dbug_tmp_restore_column_map(table->read_set, old_map); and similar for the write map: my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set); field->val(); dbug_tmp_restore_column_map(table->write_set, old_map); If this is not done, you will sooner or later hit a DBUG_ASSERT in the field store() / val() functions. (For not DBUG binaries, the dbug_tmp_restore_column_map() and dbug_tmp_restore_column_map() are inline dummy functions and should be optimized away be the compiler). - If one needs to temporary set the column map for all binaries (and not just to avoid the DBUG_ASSERT() in the Field::store() / Field::val() methods) one should use the functions tmp_use_all_columns() and tmp_restore_column_map() instead of the above dbug_ variants. - All 'status' fields in the handler base class (like records, data_file_length etc) are now stored in a 'stats' struct. This makes it easier to know what status variables are provided by the base handler. This requires some trivial variable names in the extra() function. - New virtual function handler::records(). This is called to optimize COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true. (stats.records is not supposed to be an exact value. It's only has to be 'reasonable enough' for the optimizer to be able to choose a good optimization path). - Non virtual handler::init() function added for caching of virtual constants from engine. - Removed has_transactions() virtual method. Now one should instead return HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support transactions. - The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument that is to be used with 'new handler_name()' to allocate the handler in the right area. The xxxx_create_handler() function is also responsible for any initialization of the object before returning. For example, one should change: static handler *myisam_create_handler(TABLE_SHARE *table) { return new ha_myisam(table); } -> static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) { return new (mem_root) ha_myisam(table); } - New optional virtual function: use_hidden_primary_key(). This is called in case of an update/delete when (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined but we don't have a primary key. This allows the handler to take precisions in remembering any hidden primary key to able to update/delete any found row. The default handler marks all columns to be read. - handler::table_flags() now returns a ulonglong (to allow for more flags). - New/changed table_flags() - HA_HAS_RECORDS Set if ::records() is supported - HA_NO_TRANSACTIONS Set if engine doesn't support transactions - HA_PRIMARY_KEY_REQUIRED_FOR_DELETE Set if we should mark all primary key columns for read when reading rows as part of a DELETE statement. If there is no primary key, all columns are marked for read. - HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some cases (based on table->read_set) - HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION. - HA_DUPP_POS Renamed to HA_DUPLICATE_POS - HA_REQUIRES_KEY_COLUMNS_FOR_DELETE Set this if we should mark ALL key columns for read when when reading rows as part of a DELETE statement. In case of an update we will mark all keys for read for which key part changed value. - HA_STATS_RECORDS_IS_EXACT Set this if stats.records is exact. (This saves us some extra records() calls when optimizing COUNT(*)) - Removed table_flags() - HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if handler::records() gives an exact count() and HA_STATS_RECORDS_IS_EXACT if stats.records is exact. - HA_READ_RND_SAME Removed (no one supported this one) - Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk() - Renamed handler::dupp_pos to handler::dup_pos - Removed not used variable handler::sortkey Upper level handler changes: - ha_reset() now does some overall checks and calls ::reset() - ha_table_flags() added. This is a cached version of table_flags(). The cache is updated on engine creation time and updated on open. MySQL level changes (not obvious from the above): - DBUG_ASSERT() added to check that column usage matches what is set in the column usage bit maps. (This found a LOT of bugs in current column marking code). - In 5.1 before, all used columns was marked in read_set and only updated columns was marked in write_set. Now we only mark columns for which we need a value in read_set. - Column bitmaps are created in open_binary_frm() and open_table_from_share(). (Before this was in table.cc) - handler::table_flags() calls are replaced with handler::ha_table_flags() - For calling field->val() you must have the corresponding bit set in table->read_set. For calling field->store() you must have the corresponding bit set in table->write_set. (There are asserts in all store()/val() functions to catch wrong usage) - thd->set_query_id is renamed to thd->mark_used_columns and instead of setting this to an integer value, this has now the values: MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE Changed also all variables named 'set_query_id' to mark_used_columns. - In filesort() we now inform the handler of exactly which columns are needed doing the sort and choosing the rows. - The TABLE_SHARE object has a 'all_set' column bitmap one can use when one needs a column bitmap with all columns set. (This is used for table->use_all_columns() and other places) - The TABLE object has 3 column bitmaps: - def_read_set Default bitmap for columns to be read - def_write_set Default bitmap for columns to be written - tmp_set Can be used as a temporary bitmap when needed. The table object has also two pointer to bitmaps read_set and write_set that the handler should use to find out which columns are used in which way. - count() optimization now calls handler::records() instead of using handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true). - Added extra argument to Item::walk() to indicate if we should also traverse sub queries. - Added TABLE parameter to cp_buffer_from_ref() - Don't close tables created with CREATE ... SELECT but keep them in the table cache. (Faster usage of newly created tables). New interfaces: - table->clear_column_bitmaps() to initialize the bitmaps for tables at start of new statements. - table->column_bitmaps_set() to set up new column bitmaps and signal the handler about this. - table->column_bitmaps_set_no_signal() for some few cases where we need to setup new column bitmaps but don't signal the handler (as the handler has already been signaled about these before). Used for the momement only in opt_range.cc when doing ROR scans. - table->use_all_columns() to install a bitmap where all columns are marked as use in the read and the write set. - table->default_column_bitmaps() to install the normal read and write column bitmaps, but not signaling the handler about this. This is mainly used when creating TABLE instances. - table->mark_columns_needed_for_delete(), table->mark_columns_needed_for_delete() and table->mark_columns_needed_for_insert() to allow us to put additional columns in column usage maps if handler so requires. (The handler indicates what it neads in handler->table_flags()) - table->prepare_for_position() to allow us to tell handler that it needs to read primary key parts to be able to store them in future table->position() calls. (This replaces the table->file->ha_retrieve_all_pk function) - table->mark_auto_increment_column() to tell handler are going to update columns part of any auto_increment key. - table->mark_columns_used_by_index() to mark all columns that is part of an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow it to quickly know that it only needs to read colums that are part of the key. (The handler can also use the column map for detecting this, but simpler/faster handler can just monitor the extra() call). - table->mark_columns_used_by_index_no_reset() to in addition to other columns, also mark all columns that is used by the given key. - table->restore_column_maps_after_mark_index() to restore to default column maps after a call to table->mark_columns_used_by_index(). - New item function register_field_in_read_map(), for marking used columns in table->read_map. Used by filesort() to mark all used columns - Maintain in TABLE->merge_keys set of all keys that are used in query. (Simplices some optimization loops) - Maintain Field->part_of_key_not_clustered which is like Field->part_of_key but the field in the clustered key is not assumed to be part of all index. (used in opt_range.cc for faster loops) - dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map() tmp_use_all_columns() and tmp_restore_column_map() functions to temporally mark all columns as usable. The 'dbug_' version is primarily intended inside a handler when it wants to just call Field:store() & Field::val() functions, but don't need the column maps set for any other usage. (ie:: bitmap_is_set() is never called) - We can't use compare_records() to skip updates for handlers that returns a partial column set and the read_set doesn't cover all columns in the write set. The reason for this is that if we have a column marked only for write we can't in the MySQL level know if the value changed or not. The reason this worked before was that MySQL marked all to be written columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden bug'. - open_table_from_share() does not anymore setup temporary MEM_ROOT object as a thread specific variable for the handler. Instead we send the to-be-used MEMROOT to get_new_handler(). (Simpler, faster code) Bugs fixed: - Column marking was not done correctly in a lot of cases. (ALTER TABLE, when using triggers, auto_increment fields etc) (Could potentially result in wrong values inserted in table handlers relying on that the old column maps or field->set_query_id was correct) Especially when it comes to triggers, there may be cases where the old code would cause lost/wrong values for NDB and/or InnoDB tables. - Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags: OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG. This allowed me to remove some wrong warnings about: "Some non-transactional changed tables couldn't be rolled back" - Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset (thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose some warnings about "Some non-transactional changed tables couldn't be rolled back") - Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table() which could cause delete_table to report random failures. - Fixed core dumps for some tests when running with --debug - Added missing FN_LIBCHAR in mysql_rm_tmp_tables() (This has probably caused us to not properly remove temporary files after crash) - slow_logs was not properly initialized, which could maybe cause extra/lost entries in slow log. - If we get an duplicate row on insert, change column map to read and write all columns while retrying the operation. This is required by the definition of REPLACE and also ensures that fields that are only part of UPDATE are properly handled. This fixed a bug in NDB and REPLACE where REPLACE wrongly copied some column values from the replaced row. - For table handler that doesn't support NULL in keys, we would give an error when creating a primary key with NULL fields, even after the fields has been automaticly converted to NOT NULL. - Creating a primary key on a SPATIAL key, would fail if field was not declared as NOT NULL. Cleanups: - Removed not used condition argument to setup_tables - Removed not needed item function reset_query_id_processor(). - Field->add_index is removed. Now this is instead maintained in (field->flags & FIELD_IN_ADD_INDEX) - Field->fieldnr is removed (use field->field_index instead) - New argument to filesort() to indicate that it should return a set of row pointers (not used columns). This allowed me to remove some references to sql_command in filesort and should also enable us to return column results in some cases where we couldn't before. - Changed column bitmap handling in opt_range.cc to be aligned with TABLE bitmap, which allowed me to use bitmap functions instead of looping over all fields to create some needed bitmaps. (Faster and smaller code) - Broke up found too long lines - Moved some variable declaration at start of function for better code readability. - Removed some not used arguments from functions. (setup_fields(), mysql_prepare_insert_check_table()) - setup_fields() now takes an enum instead of an int for marking columns usage. - For internal temporary tables, use handler::write_row(), handler::delete_row() and handler::update_row() instead of handler::ha_xxxx() for faster execution. - Changed some constants to enum's and define's. - Using separate column read and write sets allows for easier checking of timestamp field was set by statement. - Remove calls to free_io_cache() as this is now done automaticly in ha_reset() - Don't build table->normalized_path as this is now identical to table->path (after bar's fixes to convert filenames) - Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to do comparision with the 'convert-dbug-for-diff' tool. Things left to do in 5.1: - We wrongly log failed CREATE TABLE ... SELECT in some cases when using row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result) Mats has promised to look into this. - Test that my fix for CREATE TABLE ... SELECT is indeed correct. (I added several test cases for this, but in this case it's better that someone else also tests this throughly). Lars has promosed to do this.
20 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
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
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes Changes that requires code changes in other code of other storage engines. (Note that all changes are very straightforward and one should find all issues by compiling a --debug build and fixing all compiler errors and all asserts in field.cc while running the test suite), - New optional handler function introduced: reset() This is called after every DML statement to make it easy for a handler to statement specific cleanups. (The only case it's not called is if force the file to be closed) - handler::extra(HA_EXTRA_RESET) is removed. Code that was there before should be moved to handler::reset() - table->read_set contains a bitmap over all columns that are needed in the query. read_row() and similar functions only needs to read these columns - table->write_set contains a bitmap over all columns that will be updated in the query. write_row() and update_row() only needs to update these columns. The above bitmaps should now be up to date in all context (including ALTER TABLE, filesort()). The handler is informed of any changes to the bitmap after fix_fields() by calling the virtual function handler::column_bitmaps_signal(). If the handler does caching of these bitmaps (instead of using table->read_set, table->write_set), it should redo the caching in this code. as the signal() may be sent several times, it's probably best to set a variable in the signal and redo the caching on read_row() / write_row() if the variable was set. - Removed the read_set and write_set bitmap objects from the handler class - Removed all column bit handling functions from the handler class. (Now one instead uses the normal bitmap functions in my_bitmap.c instead of handler dedicated bitmap functions) - field->query_id is removed. One should instead instead check table->read_set and table->write_set if a field is used in the query. - handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now instead use table->read_set to check for which columns to retrieve. - If a handler needs to call Field->val() or Field->store() on columns that are not used in the query, one should install a temporary all-columns-used map while doing so. For this, we provide the following functions: my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set); field->val(); dbug_tmp_restore_column_map(table->read_set, old_map); and similar for the write map: my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set); field->val(); dbug_tmp_restore_column_map(table->write_set, old_map); If this is not done, you will sooner or later hit a DBUG_ASSERT in the field store() / val() functions. (For not DBUG binaries, the dbug_tmp_restore_column_map() and dbug_tmp_restore_column_map() are inline dummy functions and should be optimized away be the compiler). - If one needs to temporary set the column map for all binaries (and not just to avoid the DBUG_ASSERT() in the Field::store() / Field::val() methods) one should use the functions tmp_use_all_columns() and tmp_restore_column_map() instead of the above dbug_ variants. - All 'status' fields in the handler base class (like records, data_file_length etc) are now stored in a 'stats' struct. This makes it easier to know what status variables are provided by the base handler. This requires some trivial variable names in the extra() function. - New virtual function handler::records(). This is called to optimize COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true. (stats.records is not supposed to be an exact value. It's only has to be 'reasonable enough' for the optimizer to be able to choose a good optimization path). - Non virtual handler::init() function added for caching of virtual constants from engine. - Removed has_transactions() virtual method. Now one should instead return HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support transactions. - The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument that is to be used with 'new handler_name()' to allocate the handler in the right area. The xxxx_create_handler() function is also responsible for any initialization of the object before returning. For example, one should change: static handler *myisam_create_handler(TABLE_SHARE *table) { return new ha_myisam(table); } -> static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root) { return new (mem_root) ha_myisam(table); } - New optional virtual function: use_hidden_primary_key(). This is called in case of an update/delete when (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined but we don't have a primary key. This allows the handler to take precisions in remembering any hidden primary key to able to update/delete any found row. The default handler marks all columns to be read. - handler::table_flags() now returns a ulonglong (to allow for more flags). - New/changed table_flags() - HA_HAS_RECORDS Set if ::records() is supported - HA_NO_TRANSACTIONS Set if engine doesn't support transactions - HA_PRIMARY_KEY_REQUIRED_FOR_DELETE Set if we should mark all primary key columns for read when reading rows as part of a DELETE statement. If there is no primary key, all columns are marked for read. - HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some cases (based on table->read_set) - HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION. - HA_DUPP_POS Renamed to HA_DUPLICATE_POS - HA_REQUIRES_KEY_COLUMNS_FOR_DELETE Set this if we should mark ALL key columns for read when when reading rows as part of a DELETE statement. In case of an update we will mark all keys for read for which key part changed value. - HA_STATS_RECORDS_IS_EXACT Set this if stats.records is exact. (This saves us some extra records() calls when optimizing COUNT(*)) - Removed table_flags() - HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if handler::records() gives an exact count() and HA_STATS_RECORDS_IS_EXACT if stats.records is exact. - HA_READ_RND_SAME Removed (no one supported this one) - Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk() - Renamed handler::dupp_pos to handler::dup_pos - Removed not used variable handler::sortkey Upper level handler changes: - ha_reset() now does some overall checks and calls ::reset() - ha_table_flags() added. This is a cached version of table_flags(). The cache is updated on engine creation time and updated on open. MySQL level changes (not obvious from the above): - DBUG_ASSERT() added to check that column usage matches what is set in the column usage bit maps. (This found a LOT of bugs in current column marking code). - In 5.1 before, all used columns was marked in read_set and only updated columns was marked in write_set. Now we only mark columns for which we need a value in read_set. - Column bitmaps are created in open_binary_frm() and open_table_from_share(). (Before this was in table.cc) - handler::table_flags() calls are replaced with handler::ha_table_flags() - For calling field->val() you must have the corresponding bit set in table->read_set. For calling field->store() you must have the corresponding bit set in table->write_set. (There are asserts in all store()/val() functions to catch wrong usage) - thd->set_query_id is renamed to thd->mark_used_columns and instead of setting this to an integer value, this has now the values: MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE Changed also all variables named 'set_query_id' to mark_used_columns. - In filesort() we now inform the handler of exactly which columns are needed doing the sort and choosing the rows. - The TABLE_SHARE object has a 'all_set' column bitmap one can use when one needs a column bitmap with all columns set. (This is used for table->use_all_columns() and other places) - The TABLE object has 3 column bitmaps: - def_read_set Default bitmap for columns to be read - def_write_set Default bitmap for columns to be written - tmp_set Can be used as a temporary bitmap when needed. The table object has also two pointer to bitmaps read_set and write_set that the handler should use to find out which columns are used in which way. - count() optimization now calls handler::records() instead of using handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true). - Added extra argument to Item::walk() to indicate if we should also traverse sub queries. - Added TABLE parameter to cp_buffer_from_ref() - Don't close tables created with CREATE ... SELECT but keep them in the table cache. (Faster usage of newly created tables). New interfaces: - table->clear_column_bitmaps() to initialize the bitmaps for tables at start of new statements. - table->column_bitmaps_set() to set up new column bitmaps and signal the handler about this. - table->column_bitmaps_set_no_signal() for some few cases where we need to setup new column bitmaps but don't signal the handler (as the handler has already been signaled about these before). Used for the momement only in opt_range.cc when doing ROR scans. - table->use_all_columns() to install a bitmap where all columns are marked as use in the read and the write set. - table->default_column_bitmaps() to install the normal read and write column bitmaps, but not signaling the handler about this. This is mainly used when creating TABLE instances. - table->mark_columns_needed_for_delete(), table->mark_columns_needed_for_delete() and table->mark_columns_needed_for_insert() to allow us to put additional columns in column usage maps if handler so requires. (The handler indicates what it neads in handler->table_flags()) - table->prepare_for_position() to allow us to tell handler that it needs to read primary key parts to be able to store them in future table->position() calls. (This replaces the table->file->ha_retrieve_all_pk function) - table->mark_auto_increment_column() to tell handler are going to update columns part of any auto_increment key. - table->mark_columns_used_by_index() to mark all columns that is part of an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow it to quickly know that it only needs to read colums that are part of the key. (The handler can also use the column map for detecting this, but simpler/faster handler can just monitor the extra() call). - table->mark_columns_used_by_index_no_reset() to in addition to other columns, also mark all columns that is used by the given key. - table->restore_column_maps_after_mark_index() to restore to default column maps after a call to table->mark_columns_used_by_index(). - New item function register_field_in_read_map(), for marking used columns in table->read_map. Used by filesort() to mark all used columns - Maintain in TABLE->merge_keys set of all keys that are used in query. (Simplices some optimization loops) - Maintain Field->part_of_key_not_clustered which is like Field->part_of_key but the field in the clustered key is not assumed to be part of all index. (used in opt_range.cc for faster loops) - dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map() tmp_use_all_columns() and tmp_restore_column_map() functions to temporally mark all columns as usable. The 'dbug_' version is primarily intended inside a handler when it wants to just call Field:store() & Field::val() functions, but don't need the column maps set for any other usage. (ie:: bitmap_is_set() is never called) - We can't use compare_records() to skip updates for handlers that returns a partial column set and the read_set doesn't cover all columns in the write set. The reason for this is that if we have a column marked only for write we can't in the MySQL level know if the value changed or not. The reason this worked before was that MySQL marked all to be written columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden bug'. - open_table_from_share() does not anymore setup temporary MEM_ROOT object as a thread specific variable for the handler. Instead we send the to-be-used MEMROOT to get_new_handler(). (Simpler, faster code) Bugs fixed: - Column marking was not done correctly in a lot of cases. (ALTER TABLE, when using triggers, auto_increment fields etc) (Could potentially result in wrong values inserted in table handlers relying on that the old column maps or field->set_query_id was correct) Especially when it comes to triggers, there may be cases where the old code would cause lost/wrong values for NDB and/or InnoDB tables. - Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags: OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG. This allowed me to remove some wrong warnings about: "Some non-transactional changed tables couldn't be rolled back" - Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset (thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose some warnings about "Some non-transactional changed tables couldn't be rolled back") - Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table() which could cause delete_table to report random failures. - Fixed core dumps for some tests when running with --debug - Added missing FN_LIBCHAR in mysql_rm_tmp_tables() (This has probably caused us to not properly remove temporary files after crash) - slow_logs was not properly initialized, which could maybe cause extra/lost entries in slow log. - If we get an duplicate row on insert, change column map to read and write all columns while retrying the operation. This is required by the definition of REPLACE and also ensures that fields that are only part of UPDATE are properly handled. This fixed a bug in NDB and REPLACE where REPLACE wrongly copied some column values from the replaced row. - For table handler that doesn't support NULL in keys, we would give an error when creating a primary key with NULL fields, even after the fields has been automaticly converted to NOT NULL. - Creating a primary key on a SPATIAL key, would fail if field was not declared as NOT NULL. Cleanups: - Removed not used condition argument to setup_tables - Removed not needed item function reset_query_id_processor(). - Field->add_index is removed. Now this is instead maintained in (field->flags & FIELD_IN_ADD_INDEX) - Field->fieldnr is removed (use field->field_index instead) - New argument to filesort() to indicate that it should return a set of row pointers (not used columns). This allowed me to remove some references to sql_command in filesort and should also enable us to return column results in some cases where we couldn't before. - Changed column bitmap handling in opt_range.cc to be aligned with TABLE bitmap, which allowed me to use bitmap functions instead of looping over all fields to create some needed bitmaps. (Faster and smaller code) - Broke up found too long lines - Moved some variable declaration at start of function for better code readability. - Removed some not used arguments from functions. (setup_fields(), mysql_prepare_insert_check_table()) - setup_fields() now takes an enum instead of an int for marking columns usage. - For internal temporary tables, use handler::write_row(), handler::delete_row() and handler::update_row() instead of handler::ha_xxxx() for faster execution. - Changed some constants to enum's and define's. - Using separate column read and write sets allows for easier checking of timestamp field was set by statement. - Remove calls to free_io_cache() as this is now done automaticly in ha_reset() - Don't build table->normalized_path as this is now identical to table->path (after bar's fixes to convert filenames) - Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to do comparision with the 'convert-dbug-for-diff' tool. Things left to do in 5.1: - We wrongly log failed CREATE TABLE ... SELECT in some cases when using row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result) Mats has promised to look into this. - Test that my fix for CREATE TABLE ... SELECT is indeed correct. (I added several test cases for this, but in this case it's better that someone else also tests this throughly). Lars has promosed to do this.
20 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#27590: Wrong DATE/DATETIME comparison. DATE and DATETIME can be compared either as strings or as int. Both methods have their disadvantages. Strings can contain valid DATETIME value but have insignificant zeros omitted thus became non-comparable with other DATETIME strings. The comparison as int usually will require conversion from the string representation and the automatic conversion in most cases is carried out in a wrong way thus producing wrong comparison result. Another problem occurs when one tries to compare DATE field with a DATETIME constant. The constant is converted to DATE losing its precision i.e. losing time part. This fix addresses the problems described above by adding a special DATE/DATETIME comparator. The comparator correctly converts DATE/DATETIME string values to int when it's necessary, adds zero time part (00:00:00) to DATE values to compare them correctly to DATETIME values. Due to correct conversion malformed DATETIME string values are correctly compared to other DATE/DATETIME values. As of this patch a DATE value equals to DATETIME value with zero time part. For example '2001-01-01' equals to '2001-01-01 00:00:00'. The compare_datetime() function is added to the Arg_comparator class. It implements the correct comparator for DATE/DATETIME values. Two supplementary functions called get_date_from_str() and get_datetime_value() are added. The first one extracts DATE/DATETIME value from a string and the second one retrieves the correct DATE/DATETIME value from an item. The new Arg_comparator::can_compare_as_dates() function is added and used to check whether two given items can be compared by the compare_datetime() comparator. Two caching variables were added to the Arg_comparator class to speedup the DATE/DATETIME comparison. One more store() method was added to the Item_cache_int class to cache int values. The new is_datetime() function was added to the Item class. It indicates whether the item returns a DATE/DATETIME value.
19 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#27590: Wrong DATE/DATETIME comparison. DATE and DATETIME can be compared either as strings or as int. Both methods have their disadvantages. Strings can contain valid DATETIME value but have insignificant zeros omitted thus became non-comparable with other DATETIME strings. The comparison as int usually will require conversion from the string representation and the automatic conversion in most cases is carried out in a wrong way thus producing wrong comparison result. Another problem occurs when one tries to compare DATE field with a DATETIME constant. The constant is converted to DATE losing its precision i.e. losing time part. This fix addresses the problems described above by adding a special DATE/DATETIME comparator. The comparator correctly converts DATE/DATETIME string values to int when it's necessary, adds zero time part (00:00:00) to DATE values to compare them correctly to DATETIME values. Due to correct conversion malformed DATETIME string values are correctly compared to other DATE/DATETIME values. As of this patch a DATE value equals to DATETIME value with zero time part. For example '2001-01-01' equals to '2001-01-01 00:00:00'. The compare_datetime() function is added to the Arg_comparator class. It implements the correct comparator for DATE/DATETIME values. Two supplementary functions called get_date_from_str() and get_datetime_value() are added. The first one extracts DATE/DATETIME value from a string and the second one retrieves the correct DATE/DATETIME value from an item. The new Arg_comparator::can_compare_as_dates() function is added and used to check whether two given items can be compared by the compare_datetime() comparator. Two caching variables were added to the Arg_comparator class to speedup the DATE/DATETIME comparison. One more store() method was added to the Item_cache_int class to cache int values. The new is_datetime() function was added to the Item class. It indicates whether the item returns a DATE/DATETIME value.
19 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
Bug#34384: Slow down on constant conversion. When values of different types are compared they're converted to a type that allows correct comparison. This conversion is done for each comparison and takes some time. When a constant is being compared it's possible to cache the value after conversion to speedup comparison. In some cases (large dataset, complex WHERE condition with many type conversions) query might be executed 7% faster. A test case isn't provided because all changes are internal and isn't visible outside. The behavior of the Item_cache is changed to cache values on the first request of cached value rather than at the moment of storing item to be cached. A flag named value_cached is added to the Item_cache class. It's set to TRUE when cache holds the value of the last stored item. Function named cache_value() is added to the Item_cache class and derived classes. This function actually caches the value of the saved item. Item_cache_xxx::store functions now only store item to be cached and set value_cached flag to FALSE. Item_cache_xxx::val_xxx functions are changed to call cache_value function prior to returning cached value if value_cached is FALSE. The Arg_comparator::set_cmp_func function now calls cache_converted_constant to cache constants if they need a type conversion. The Item_cache::get_cache function is overloaded to allow setting of the cache type. The cache_converted_constant function is added to the Arg_comparator class. It checks whether a value can and should be cached and if so caches it.
16 years ago
16 years ago
26 years ago
A fix and test case for Bug#5987 "subselect in bool function crashes server (prepared statements)": the bug was that all boolean items always recovered its original arguments at statement cleanup stage. This collided with Item_subselect::select_transformer, which tries to permanently change the item tree to use a transformed subselect instead of original one. So we had this call sequence for prepare: mysql_stmt_prepare -> JOIN::prepare -> Item_subselect::fix_fields -> the item tree gets transformed -> Item_bool_rowready_func2::cleanup, item tree is recovered to original state, while it shouldn't have been; mysql_stmt_execute -> attempts to execute a broken tree -> crash. Now instead of bluntly recovering all arguments of bool functions in Item_bool_rowready_func2::cleanup, we recover only those which were changed, and do it in one place. There still would exist a possibility for a collision with subselect tranformation, if permanent and temporary changes were performed at the same stage. But fortunately subselect transformation is always done first, so it doesn't conflict with the optimization done by propogate_cond_constants. Now we have: mysql_stmt_prepare -> JOIN::prepare -> subselect transformation permanently changes the tree -> cleanup doesn't recover anything, because nothing was registered for recovery. mysql_stmt_execute -> JOIN::prepare (the tree is already transformed, so it doesn't change), JOIN::optimize -> propogate_cond_constants -> temporary changes the item tree with constants -> JOIN::execute -> cleanup -> the changes done by propogate_cond_constants are recovered, as they were registered for recovery.
21 years ago
  1. #ifndef ITEM_INCLUDED
  2. #define ITEM_INCLUDED
  3. /* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  14. #ifdef USE_PRAGMA_INTERFACE
  15. #pragma interface /* gcc class implementation */
  16. #endif
  17. #include "sql_priv.h" /* STRING_BUFFER_USUAL_SIZE */
  18. #include "unireg.h"
  19. #include "sql_const.h" /* RAND_TABLE_BIT, MAX_FIELD_NAME */
  20. #include "unireg.h" // REQUIRED: for other includes
  21. #include "thr_malloc.h" /* sql_calloc */
  22. #include "field.h" /* Derivation */
  23. class Protocol;
  24. struct TABLE_LIST;
  25. void item_init(void); /* Init item functions */
  26. class Item_field;
  27. class user_var_entry;
  28. /*
  29. "Declared Type Collation"
  30. A combination of collation and its derivation.
  31. Flags for collation aggregation modes:
  32. MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
  33. MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
  34. (i.e. constant).
  35. MY_COLL_ALLOW_CONV - allow any kind of conversion
  36. (combination of the above two)
  37. MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
  38. (e.g. when aggregating for comparison)
  39. MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
  40. and MY_COLL_DISALLOW_NONE
  41. */
  42. #define MY_COLL_ALLOW_SUPERSET_CONV 1
  43. #define MY_COLL_ALLOW_COERCIBLE_CONV 2
  44. #define MY_COLL_DISALLOW_NONE 4
  45. #define MY_COLL_ALLOW_CONV (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV)
  46. #define MY_COLL_CMP_CONV (MY_COLL_ALLOW_CONV | MY_COLL_DISALLOW_NONE)
  47. class DTCollation {
  48. public:
  49. CHARSET_INFO *collation;
  50. enum Derivation derivation;
  51. uint repertoire;
  52. void set_repertoire_from_charset(CHARSET_INFO *cs)
  53. {
  54. repertoire= cs->state & MY_CS_PUREASCII ?
  55. MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
  56. }
  57. DTCollation()
  58. {
  59. collation= &my_charset_bin;
  60. derivation= DERIVATION_NONE;
  61. repertoire= MY_REPERTOIRE_UNICODE30;
  62. }
  63. DTCollation(CHARSET_INFO *collation_arg, Derivation derivation_arg)
  64. {
  65. collation= collation_arg;
  66. derivation= derivation_arg;
  67. set_repertoire_from_charset(collation_arg);
  68. }
  69. void set(DTCollation &dt)
  70. {
  71. collation= dt.collation;
  72. derivation= dt.derivation;
  73. repertoire= dt.repertoire;
  74. }
  75. void set(CHARSET_INFO *collation_arg, Derivation derivation_arg)
  76. {
  77. collation= collation_arg;
  78. derivation= derivation_arg;
  79. set_repertoire_from_charset(collation_arg);
  80. }
  81. void set(CHARSET_INFO *collation_arg,
  82. Derivation derivation_arg,
  83. uint repertoire_arg)
  84. {
  85. collation= collation_arg;
  86. derivation= derivation_arg;
  87. repertoire= repertoire_arg;
  88. }
  89. void set_numeric()
  90. {
  91. collation= &my_charset_numeric;
  92. derivation= DERIVATION_NUMERIC;
  93. repertoire= MY_REPERTOIRE_NUMERIC;
  94. }
  95. void set(CHARSET_INFO *collation_arg)
  96. {
  97. collation= collation_arg;
  98. set_repertoire_from_charset(collation_arg);
  99. }
  100. void set(Derivation derivation_arg)
  101. { derivation= derivation_arg; }
  102. bool aggregate(DTCollation &dt, uint flags= 0);
  103. bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
  104. { set(dt1); return aggregate(dt2, flags); }
  105. const char *derivation_name() const
  106. {
  107. switch(derivation)
  108. {
  109. case DERIVATION_NUMERIC: return "NUMERIC";
  110. case DERIVATION_IGNORABLE: return "IGNORABLE";
  111. case DERIVATION_COERCIBLE: return "COERCIBLE";
  112. case DERIVATION_IMPLICIT: return "IMPLICIT";
  113. case DERIVATION_SYSCONST: return "SYSCONST";
  114. case DERIVATION_EXPLICIT: return "EXPLICIT";
  115. case DERIVATION_NONE: return "NONE";
  116. default: return "UNKNOWN";
  117. }
  118. }
  119. };
  120. /*************************************************************************/
  121. /*
  122. A framework to easily handle different return types for hybrid items
  123. (hybrid item is an item whose operand can be of any type, e.g. integer,
  124. real, decimal).
  125. */
  126. struct Hybrid_type_traits;
  127. struct Hybrid_type
  128. {
  129. longlong integer;
  130. double real;
  131. /*
  132. Use two decimal buffers interchangeably to speed up += operation
  133. which has no native support in decimal library.
  134. Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
  135. The third decimal is used as a handy temporary storage.
  136. */
  137. my_decimal dec_buf[3];
  138. int used_dec_buf_no;
  139. /*
  140. Traits moved to a separate class to
  141. a) be able to easily change object traits in runtime
  142. b) they work as a differentiator for the union above
  143. */
  144. const Hybrid_type_traits *traits;
  145. Hybrid_type() {}
  146. /* XXX: add traits->copy() when needed */
  147. Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
  148. };
  149. /* Hybryd_type_traits interface + default implementation for REAL_RESULT */
  150. struct Hybrid_type_traits
  151. {
  152. virtual Item_result type() const { return REAL_RESULT; }
  153. virtual void
  154. fix_length_and_dec(Item *item, Item *arg) const;
  155. /* Hybrid_type operations. */
  156. virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
  157. virtual void add(Hybrid_type *val, Field *f) const
  158. { val->real+= f->val_real(); }
  159. virtual void div(Hybrid_type *val, ulonglong u) const
  160. { val->real/= ulonglong2double(u); }
  161. virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
  162. { return (longlong) rint(val->real); }
  163. virtual double val_real(Hybrid_type *val) const { return val->real; }
  164. virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
  165. virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
  166. static const Hybrid_type_traits *instance();
  167. Hybrid_type_traits() {}
  168. virtual ~Hybrid_type_traits() {}
  169. };
  170. struct Hybrid_type_traits_decimal: public Hybrid_type_traits
  171. {
  172. virtual Item_result type() const { return DECIMAL_RESULT; }
  173. virtual void
  174. fix_length_and_dec(Item *arg, Item *item) const;
  175. /* Hybrid_type operations. */
  176. virtual void set_zero(Hybrid_type *val) const;
  177. virtual void add(Hybrid_type *val, Field *f) const;
  178. virtual void div(Hybrid_type *val, ulonglong u) const;
  179. virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const;
  180. virtual double val_real(Hybrid_type *val) const;
  181. virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
  182. { return &val->dec_buf[val->used_dec_buf_no]; }
  183. virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
  184. static const Hybrid_type_traits_decimal *instance();
  185. Hybrid_type_traits_decimal() {};
  186. };
  187. struct Hybrid_type_traits_integer: public Hybrid_type_traits
  188. {
  189. virtual Item_result type() const { return INT_RESULT; }
  190. virtual void
  191. fix_length_and_dec(Item *arg, Item *item) const;
  192. /* Hybrid_type operations. */
  193. virtual void set_zero(Hybrid_type *val) const
  194. { val->integer= 0; }
  195. virtual void add(Hybrid_type *val, Field *f) const
  196. { val->integer+= f->val_int(); }
  197. virtual void div(Hybrid_type *val, ulonglong u) const
  198. { val->integer/= (longlong) u; }
  199. virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
  200. { return val->integer; }
  201. virtual double val_real(Hybrid_type *val) const
  202. { return (double) val->integer; }
  203. virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
  204. {
  205. int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
  206. return &val->dec_buf[2];
  207. }
  208. virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const
  209. { buf->set(val->integer, &my_charset_bin); return buf;}
  210. static const Hybrid_type_traits_integer *instance();
  211. Hybrid_type_traits_integer() {};
  212. };
  213. void dummy_error_processor(THD *thd, void *data);
  214. void view_error_processor(THD *thd, void *data);
  215. /*
  216. Instances of Name_resolution_context store the information necesary for
  217. name resolution of Items and other context analysis of a query made in
  218. fix_fields().
  219. This structure is a part of SELECT_LEX, a pointer to this structure is
  220. assigned when an item is created (which happens mostly during parsing
  221. (sql_yacc.yy)), but the structure itself will be initialized after parsing
  222. is complete
  223. TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
  224. separate SELECT_LEX which allow to remove tricks of changing this
  225. structure before and after INSERT/CREATE and its SELECT to make correct
  226. field name resolution.
  227. */
  228. struct Name_resolution_context: Sql_alloc
  229. {
  230. /*
  231. The name resolution context to search in when an Item cannot be
  232. resolved in this context (the context of an outer select)
  233. */
  234. Name_resolution_context *outer_context;
  235. /*
  236. List of tables used to resolve the items of this context. Usually these
  237. are tables from the FROM clause of SELECT statement. The exceptions are
  238. INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
  239. subquery is not moved to a separate SELECT_LEX. For these types of
  240. statements we have to change this member dynamically to ensure correct
  241. name resolution of different parts of the statement.
  242. */
  243. TABLE_LIST *table_list;
  244. /*
  245. In most cases the two table references below replace 'table_list' above
  246. for the purpose of name resolution. The first and last name resolution
  247. table references allow us to search only in a sub-tree of the nested
  248. join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
  249. and JOIN ... ON.
  250. */
  251. TABLE_LIST *first_name_resolution_table;
  252. /*
  253. Last table to search in the list of leaf table references that begins
  254. with first_name_resolution_table.
  255. */
  256. TABLE_LIST *last_name_resolution_table;
  257. /*
  258. SELECT_LEX item belong to, in case of merged VIEW it can differ from
  259. SELECT_LEX where item was created, so we can't use table_list/field_list
  260. from there
  261. */
  262. st_select_lex *select_lex;
  263. /*
  264. Processor of errors caused during Item name resolving, now used only to
  265. hide underlying tables in errors about views (i.e. it substitute some
  266. errors for views)
  267. */
  268. void (*error_processor)(THD *, void *);
  269. void *error_processor_data;
  270. /*
  271. When TRUE items are resolved in this context both against the
  272. SELECT list and this->table_list. If FALSE, items are resolved
  273. only against this->table_list.
  274. */
  275. bool resolve_in_select_list;
  276. /*
  277. Security context of this name resolution context. It's used for views
  278. and is non-zero only if the view is defined with SQL SECURITY DEFINER.
  279. */
  280. Security_context *security_ctx;
  281. Name_resolution_context()
  282. :outer_context(0), table_list(0), select_lex(0),
  283. error_processor_data(0),
  284. security_ctx(0)
  285. {}
  286. void init()
  287. {
  288. resolve_in_select_list= FALSE;
  289. error_processor= &dummy_error_processor;
  290. first_name_resolution_table= NULL;
  291. last_name_resolution_table= NULL;
  292. }
  293. void resolve_in_table_list_only(TABLE_LIST *tables)
  294. {
  295. table_list= first_name_resolution_table= tables;
  296. resolve_in_select_list= FALSE;
  297. }
  298. void process_error(THD *thd)
  299. {
  300. (*error_processor)(thd, error_processor_data);
  301. }
  302. };
  303. /*
  304. Store and restore the current state of a name resolution context.
  305. */
  306. class Name_resolution_context_state
  307. {
  308. private:
  309. TABLE_LIST *save_table_list;
  310. TABLE_LIST *save_first_name_resolution_table;
  311. TABLE_LIST *save_next_name_resolution_table;
  312. bool save_resolve_in_select_list;
  313. TABLE_LIST *save_next_local;
  314. public:
  315. Name_resolution_context_state() {} /* Remove gcc warning */
  316. public:
  317. /* Save the state of a name resolution context. */
  318. void save_state(Name_resolution_context *context, TABLE_LIST *table_list)
  319. {
  320. save_table_list= context->table_list;
  321. save_first_name_resolution_table= context->first_name_resolution_table;
  322. save_resolve_in_select_list= context->resolve_in_select_list;
  323. save_next_local= table_list->next_local;
  324. save_next_name_resolution_table= table_list->next_name_resolution_table;
  325. }
  326. /* Restore a name resolution context from saved state. */
  327. void restore_state(Name_resolution_context *context, TABLE_LIST *table_list)
  328. {
  329. table_list->next_local= save_next_local;
  330. table_list->next_name_resolution_table= save_next_name_resolution_table;
  331. context->table_list= save_table_list;
  332. context->first_name_resolution_table= save_first_name_resolution_table;
  333. context->resolve_in_select_list= save_resolve_in_select_list;
  334. }
  335. TABLE_LIST *get_first_name_resolution_table()
  336. {
  337. return save_first_name_resolution_table;
  338. }
  339. };
  340. /*
  341. This enum is used to report information about monotonicity of function
  342. represented by Item* tree.
  343. Monotonicity is defined only for Item* trees that represent table
  344. partitioning expressions (i.e. have no subselects/user vars/PS parameters
  345. etc etc). An Item* tree is assumed to have the same monotonicity properties
  346. as its correspoinding function F:
  347. [signed] longlong F(field1, field2, ...) {
  348. put values of field_i into table record buffer;
  349. return item->val_int();
  350. }
  351. NOTE
  352. At the moment function monotonicity is not well defined (and so may be
  353. incorrect) for Item trees with parameters/return types that are different
  354. from INT_RESULT, may be NULL, or are unsigned.
  355. It will be possible to address this issue once the related partitioning bugs
  356. (BUG#16002, BUG#15447, BUG#13436) are fixed.
  357. The NOT_NULL enums are used in TO_DAYS, since TO_DAYS('2001-00-00') returns
  358. NULL which puts those rows into the NULL partition, but
  359. '2000-12-31' < '2001-00-00' < '2001-01-01'. So special handling is needed
  360. for this (see Bug#20577).
  361. */
  362. typedef enum monotonicity_info
  363. {
  364. NON_MONOTONIC, /* none of the below holds */
  365. MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
  366. MONOTONIC_INCREASING_NOT_NULL, /* But only for valid/real x and y */
  367. MONOTONIC_STRICT_INCREASING,/* F() is unary and (x < y) => (F(x) < F(y)) */
  368. MONOTONIC_STRICT_INCREASING_NOT_NULL /* But only for valid/real x and y */
  369. } enum_monotonicity_info;
  370. /*************************************************************************/
  371. class sp_rcontext;
  372. class Settable_routine_parameter
  373. {
  374. public:
  375. /*
  376. Set required privileges for accessing the parameter.
  377. SYNOPSIS
  378. set_required_privilege()
  379. rw if 'rw' is true then we are going to read and set the
  380. parameter, so SELECT and UPDATE privileges might be
  381. required, otherwise we only reading it and SELECT
  382. privilege might be required.
  383. */
  384. Settable_routine_parameter() {}
  385. virtual ~Settable_routine_parameter() {}
  386. virtual void set_required_privilege(bool rw) {};
  387. /*
  388. Set parameter value.
  389. SYNOPSIS
  390. set_value()
  391. thd thread handle
  392. ctx context to which parameter belongs (if it is local
  393. variable).
  394. it item which represents new value
  395. RETURN
  396. FALSE if parameter value has been set,
  397. TRUE if error has occured.
  398. */
  399. virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it)= 0;
  400. virtual void set_out_param_info(Send_field *info) {}
  401. virtual const Send_field *get_out_param_info() const
  402. { return NULL; }
  403. };
  404. typedef bool (Item::*Item_processor) (uchar *arg);
  405. /*
  406. Analyzer function
  407. SYNOPSIS
  408. argp in/out IN: Analysis parameter
  409. OUT: Parameter to be passed to the transformer
  410. RETURN
  411. TRUE Invoke the transformer
  412. FALSE Don't do it
  413. */
  414. typedef bool (Item::*Item_analyzer) (uchar **argp);
  415. typedef Item* (Item::*Item_transformer) (uchar *arg);
  416. typedef void (*Cond_traverser) (const Item *item, void *arg);
  417. class Item {
  418. Item(const Item &); /* Prevent use of these */
  419. void operator=(Item &);
  420. public:
  421. static void *operator new(size_t size) throw ()
  422. { return sql_alloc(size); }
  423. static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
  424. { return alloc_root(mem_root, size); }
  425. static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
  426. static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
  427. enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
  428. INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
  429. COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
  430. PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
  431. FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
  432. SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
  433. PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
  434. XPATH_NODESET, XPATH_NODESET_CMP,
  435. VIEW_FIXER_ITEM};
  436. enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
  437. enum traverse_order { POSTFIX, PREFIX };
  438. /* Reuse size, only used by SP local variable assignment, otherwize 0 */
  439. uint rsize;
  440. /*
  441. str_values's main purpose is to be used to cache the value in
  442. save_in_field
  443. */
  444. String str_value;
  445. char * name; /* Name from select */
  446. /* Original item name (if it was renamed)*/
  447. char * orig_name;
  448. /**
  449. Intrusive list pointer for free list. If not null, points to the next
  450. Item on some Query_arena's free list. For instance, stored procedures
  451. have their own Query_arena's.
  452. @see Query_arena::free_list
  453. */
  454. Item *next;
  455. uint32 max_length;
  456. uint name_length; /* Length of name */
  457. int8 marker;
  458. uint8 decimals;
  459. my_bool maybe_null; /* If item may be null */
  460. my_bool null_value; /* if item is null */
  461. my_bool unsigned_flag;
  462. my_bool with_sum_func;
  463. my_bool fixed; /* If item fixed with fix_fields */
  464. my_bool is_autogenerated_name; /* indicate was name of this Item
  465. autogenerated or set by user */
  466. DTCollation collation;
  467. my_bool with_subselect; /* If this item is a subselect or some
  468. of its arguments is or contains a
  469. subselect */
  470. Item_result cmp_context; /* Comparison context */
  471. // alloc & destruct is done as start of select using sql_alloc
  472. Item();
  473. /*
  474. Constructor used by Item_field, Item_ref & aggregate (sum) functions.
  475. Used for duplicating lists in processing queries with temporary
  476. tables
  477. Also it used for Item_cond_and/Item_cond_or for creating
  478. top AND/OR structure of WHERE clause to protect it of
  479. optimisation changes in prepared statements
  480. */
  481. Item(THD *thd, Item *item);
  482. virtual ~Item()
  483. {
  484. #ifdef EXTRA_DEBUG
  485. name=0;
  486. #endif
  487. } /*lint -e1509 */
  488. void set_name(const char *str, uint length, CHARSET_INFO *cs);
  489. void rename(char *new_name);
  490. void init_make_field(Send_field *tmp_field,enum enum_field_types type);
  491. virtual void cleanup();
  492. virtual void make_field(Send_field *field);
  493. Field *make_string_field(TABLE *table);
  494. virtual bool fix_fields(THD *, Item **);
  495. /*
  496. should be used in case where we are sure that we do not need
  497. complete fix_fields() procedure.
  498. */
  499. inline void quick_fix_field() { fixed= 1; }
  500. /* Function returns 1 on overflow and -1 on fatal errors */
  501. int save_in_field_no_warnings(Field *field, bool no_conversions);
  502. virtual int save_in_field(Field *field, bool no_conversions);
  503. virtual void save_org_in_field(Field *field)
  504. { (void) save_in_field(field, 1); }
  505. virtual int save_safe_in_field(Field *field)
  506. { return save_in_field(field, 1); }
  507. virtual bool send(Protocol *protocol, String *str);
  508. virtual bool eq(const Item *, bool binary_cmp) const;
  509. virtual Item_result result_type() const { return REAL_RESULT; }
  510. virtual Item_result cast_to_int_type() const { return result_type(); }
  511. virtual enum_field_types string_field_type() const;
  512. virtual enum_field_types field_type() const;
  513. virtual enum Type type() const =0;
  514. /*
  515. Return information about function monotonicity. See comment for
  516. enum_monotonicity_info for details. This function can only be called
  517. after fix_fields() call.
  518. */
  519. virtual enum_monotonicity_info get_monotonicity_info() const
  520. { return NON_MONOTONIC; }
  521. /*
  522. Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2"
  523. SYNOPSIS
  524. val_int_endpoint()
  525. left_endp FALSE <=> The interval is "x < const" or "x <= const"
  526. TRUE <=> The interval is "x > const" or "x >= const"
  527. incl_endp IN FALSE <=> the comparison is '<' or '>'
  528. TRUE <=> the comparison is '<=' or '>='
  529. OUT The same but for the "F(x) $CMP$ F(const)" comparison
  530. DESCRIPTION
  531. This function is defined only for unary monotonic functions. The caller
  532. supplies the source half-interval
  533. x $CMP$ const
  534. The value of const is supplied implicitly as the value this item's
  535. argument, the form of $CMP$ comparison is specified through the
  536. function's arguments. The calle returns the result interval
  537. F(x) $CMP2$ F(const)
  538. passing back F(const) as the return value, and the form of $CMP2$
  539. through the out parameter. NULL values are assumed to be comparable and
  540. be less than any non-NULL values.
  541. RETURN
  542. The output range bound, which equal to the value of val_int()
  543. - If the value of the function is NULL then the bound is the
  544. smallest possible value of LONGLONG_MIN
  545. */
  546. virtual longlong val_int_endpoint(bool left_endp, bool *incl_endp)
  547. { DBUG_ASSERT(0); return 0; }
  548. /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
  549. /*
  550. Return double precision floating point representation of item.
  551. SYNOPSIS
  552. val_real()
  553. RETURN
  554. In case of NULL value return 0.0 and set null_value flag to TRUE.
  555. If value is not null null_value flag will be reset to FALSE.
  556. */
  557. virtual double val_real()=0;
  558. /*
  559. Return integer representation of item.
  560. SYNOPSIS
  561. val_int()
  562. RETURN
  563. In case of NULL value return 0 and set null_value flag to TRUE.
  564. If value is not null null_value flag will be reset to FALSE.
  565. */
  566. virtual longlong val_int()=0;
  567. /*
  568. This is just a shortcut to avoid the cast. You should still use
  569. unsigned_flag to check the sign of the item.
  570. */
  571. inline ulonglong val_uint() { return (ulonglong) val_int(); }
  572. /*
  573. Return string representation of this item object.
  574. SYNOPSIS
  575. val_str()
  576. str an allocated buffer this or any nested Item object can use to
  577. store return value of this method.
  578. NOTE
  579. Buffer passed via argument should only be used if the item itself
  580. doesn't have an own String buffer. In case when the item maintains
  581. it's own string buffer, it's preferable to return it instead to
  582. minimize number of mallocs/memcpys.
  583. The caller of this method can modify returned string, but only in case
  584. when it was allocated on heap, (is_alloced() is true). This allows
  585. the caller to efficiently use a buffer allocated by a child without
  586. having to allocate a buffer of it's own. The buffer, given to
  587. val_str() as argument, belongs to the caller and is later used by the
  588. caller at it's own choosing.
  589. A few implications from the above:
  590. - unless you return a string object which only points to your buffer
  591. but doesn't manages it you should be ready that it will be
  592. modified.
  593. - even for not allocated strings (is_alloced() == false) the caller
  594. can change charset (see Item_func_{typecast/binary}. XXX: is this
  595. a bug?
  596. - still you should try to minimize data copying and return internal
  597. object whenever possible.
  598. RETURN
  599. In case of NULL value return 0 (NULL pointer) and set null_value flag
  600. to TRUE.
  601. If value is not null null_value flag will be reset to FALSE.
  602. */
  603. virtual String *val_str(String *str)=0;
  604. /*
  605. Returns string representation of this item in ASCII format.
  606. SYNOPSIS
  607. val_str_ascii()
  608. str - similar to val_str();
  609. NOTE
  610. This method is introduced for performance optimization purposes.
  611. 1. val_str() result of some Items in string context
  612. depends on @@character_set_results.
  613. @@character_set_results can be set to a "real multibyte" character
  614. set like UCS2, UTF16, UTF32. (We'll use only UTF32 in the examples
  615. below for convenience.)
  616. So the default string result of such functions
  617. in these circumstances is real multi-byte character set, like UTF32.
  618. For example, all numbers in string context
  619. return result in @@character_set_results:
  620. SELECT CONCAT(20010101); -> UTF32
  621. We do sprintf() first (to get ASCII representation)
  622. and then convert to UTF32;
  623. So these kind "data sources" can use ASCII representation
  624. internally, but return multi-byte data only because
  625. @@character_set_results wants so.
  626. Therefore, conversion from ASCII to UTF32 is applied internally.
  627. 2. Some other functions need in fact ASCII input.
  628. For example,
  629. inet_aton(), GeometryFromText(), Convert_TZ(), GET_FORMAT().
  630. Similar, fields of certain type, like DATE, TIME,
  631. when you insert string data into them, expect in fact ASCII input.
  632. If they get non-ASCII input, for example UTF32, they
  633. convert input from UTF32 to ASCII, and then use ASCII
  634. representation to do further processing.
  635. 3. Now imagine we pass result of a data source of the first type
  636. to a data destination of the second type.
  637. What happens:
  638. a. data source converts data from ASCII to UTF32, because
  639. @@character_set_results wants so and passes the result to
  640. data destination.
  641. b. data destination gets UTF32 string.
  642. c. data destination converts UTF32 string to ASCII,
  643. because it needs ASCII representation to be able to handle data
  644. correctly.
  645. As a result we get two steps of unnecessary conversion:
  646. From ASCII to UTF32, then from UTF32 to ASCII.
  647. A better way to handle these situations is to pass ASCII
  648. representation directly from the source to the destination.
  649. This is why val_str_ascii() introduced.
  650. RETURN
  651. Similar to val_str()
  652. */
  653. virtual String *val_str_ascii(String *str);
  654. /*
  655. Return decimal representation of item with fixed point.
  656. SYNOPSIS
  657. val_decimal()
  658. decimal_buffer buffer which can be used by Item for returning value
  659. (but can be not)
  660. NOTE
  661. Returned value should not be changed if it is not the same which was
  662. passed via argument.
  663. RETURN
  664. Return pointer on my_decimal (it can be other then passed via argument)
  665. if value is not NULL (null_value flag will be reset to FALSE).
  666. In case of NULL value it return 0 pointer and set null_value flag
  667. to TRUE.
  668. */
  669. virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
  670. /*
  671. Return boolean value of item.
  672. RETURN
  673. FALSE value is false or NULL
  674. TRUE value is true (not equal to 0)
  675. */
  676. virtual bool val_bool();
  677. virtual String *val_nodeset(String*) { return 0; }
  678. /* Helper functions, see item_sum.cc */
  679. String *val_string_from_real(String *str);
  680. String *val_string_from_int(String *str);
  681. String *val_string_from_decimal(String *str);
  682. my_decimal *val_decimal_from_real(my_decimal *decimal_value);
  683. my_decimal *val_decimal_from_int(my_decimal *decimal_value);
  684. my_decimal *val_decimal_from_string(my_decimal *decimal_value);
  685. my_decimal *val_decimal_from_date(my_decimal *decimal_value);
  686. my_decimal *val_decimal_from_time(my_decimal *decimal_value);
  687. longlong val_int_from_decimal();
  688. double val_real_from_decimal();
  689. int save_time_in_field(Field *field);
  690. int save_date_in_field(Field *field);
  691. int save_str_value_in_field(Field *field, String *result);
  692. virtual Field *get_tmp_table_field() { return 0; }
  693. /* This is also used to create fields in CREATE ... SELECT: */
  694. virtual Field *tmp_table_field(TABLE *t_arg) { return 0; }
  695. virtual const char *full_name() const { return name ? name : "???"; }
  696. /*
  697. *result* family of methods is analog of *val* family (see above) but
  698. return value of result_field of item if it is present. If Item have not
  699. result field, it return val(). This methods set null_value flag in same
  700. way as *val* methods do it.
  701. */
  702. virtual double val_result() { return val_real(); }
  703. virtual longlong val_int_result() { return val_int(); }
  704. virtual String *str_result(String* tmp) { return val_str(tmp); }
  705. virtual my_decimal *val_decimal_result(my_decimal *val)
  706. { return val_decimal(val); }
  707. virtual bool val_bool_result() { return val_bool(); }
  708. virtual bool is_null_result() { return is_null(); }
  709. /* bit map of tables used by item */
  710. virtual table_map used_tables() const { return (table_map) 0L; }
  711. /*
  712. Return table map of tables that can't be NULL tables (tables that are
  713. used in a context where if they would contain a NULL row generated
  714. by a LEFT or RIGHT join, the item would not be true).
  715. This expression is used on WHERE item to determinate if a LEFT JOIN can be
  716. converted to a normal join.
  717. Generally this function should return used_tables() if the function
  718. would return null if any of the arguments are null
  719. As this is only used in the beginning of optimization, the value don't
  720. have to be updated in update_used_tables()
  721. */
  722. virtual table_map not_null_tables() const { return used_tables(); }
  723. /*
  724. Returns true if this is a simple constant item like an integer, not
  725. a constant expression. Used in the optimizer to propagate basic constants.
  726. */
  727. virtual bool basic_const_item() const { return 0; }
  728. /* cloning of constant items (0 if it is not const) */
  729. virtual Item *clone_item() { return 0; }
  730. virtual cond_result eq_cmp_result() const { return COND_OK; }
  731. inline uint float_length(uint decimals_par) const
  732. { return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}
  733. virtual uint decimal_precision() const;
  734. inline int decimal_int_part() const
  735. { return my_decimal_int_part(decimal_precision(), decimals); }
  736. /*
  737. Returns true if this is constant (during query execution, i.e. its value
  738. will not change until next fix_fields) and its value is known.
  739. */
  740. virtual bool const_item() const { return used_tables() == 0; }
  741. /*
  742. Returns true if this is constant but its value may be not known yet.
  743. (Can be used for parameters of prep. stmts or of stored procedures.)
  744. */
  745. virtual bool const_during_execution() const
  746. { return (used_tables() & ~PARAM_TABLE_BIT) == 0; }
  747. /**
  748. This method is used for to:
  749. - to generate a view definition query (SELECT-statement);
  750. - to generate a SQL-query for EXPLAIN EXTENDED;
  751. - to generate a SQL-query to be shown in INFORMATION_SCHEMA;
  752. - debug.
  753. For more information about view definition query, INFORMATION_SCHEMA
  754. query and why they should be generated from the Item-tree, @see
  755. mysql_register_view().
  756. */
  757. virtual inline void print(String *str, enum_query_type query_type)
  758. {
  759. str->append(full_name());
  760. }
  761. void print_item_w_name(String *, enum_query_type query_type);
  762. virtual void update_used_tables() {}
  763. virtual void split_sum_func(THD *thd, Item **ref_pointer_array,
  764. List<Item> &fields) {}
  765. /* Called for items that really have to be split */
  766. void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
  767. Item **ref, bool skip_registered);
  768. virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
  769. virtual bool get_time(MYSQL_TIME *ltime);
  770. virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
  771. { return get_date(ltime,fuzzydate); }
  772. /*
  773. The method allows to determine nullness of a complex expression
  774. without fully evaluating it, instead of calling val/result*() then
  775. checking null_value. Used in Item_func_isnull/Item_func_isnotnull
  776. and Item_sum_count/Item_sum_count_distinct.
  777. Any new item which can be NULL must implement this method.
  778. */
  779. virtual bool is_null() { return 0; }
  780. /*
  781. Make sure the null_value member has a correct value.
  782. */
  783. virtual void update_null_value () { (void) val_int(); }
  784. /*
  785. Inform the item that there will be no distinction between its result
  786. being FALSE or NULL.
  787. NOTE
  788. This function will be called for eg. Items that are top-level AND-parts
  789. of the WHERE clause. Items implementing this function (currently
  790. Item_cond_and and subquery-related item) enable special optimizations
  791. when they are "top level".
  792. */
  793. virtual void top_level_item() {}
  794. /*
  795. set field of temporary table for Item which can be switched on temporary
  796. table during query processing (grouping and so on)
  797. */
  798. virtual void set_result_field(Field *field) {}
  799. virtual bool is_result_field() { return 0; }
  800. virtual bool is_bool_func() { return 0; }
  801. virtual void save_in_result_field(bool no_conversions) {}
  802. /*
  803. set value of aggregate function in case of no rows for grouping were found
  804. */
  805. virtual void no_rows_in_result() {}
  806. virtual Item *copy_or_same(THD *thd) { return this; }
  807. virtual Item *copy_andor_structure(THD *thd) { return this; }
  808. virtual Item *real_item() { return this; }
  809. virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
  810. static CHARSET_INFO *default_charset();
  811. virtual CHARSET_INFO *compare_collation() { return NULL; }
  812. /*
  813. For backward compatibility, to make numeric
  814. data types return "binary" charset in client-side metadata.
  815. */
  816. virtual CHARSET_INFO *charset_for_protocol(void) const
  817. {
  818. return result_type() == STRING_RESULT ? collation.collation :
  819. &my_charset_bin;
  820. };
  821. virtual bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
  822. {
  823. return (this->*processor)(arg);
  824. }
  825. virtual Item* transform(Item_transformer transformer, uchar *arg);
  826. /*
  827. This function performs a generic "compilation" of the Item tree.
  828. The process of compilation is assumed to go as follows:
  829. compile()
  830. {
  831. if (this->*some_analyzer(...))
  832. {
  833. compile children if any;
  834. this->*some_transformer(...);
  835. }
  836. }
  837. i.e. analysis is performed top-down while transformation is done
  838. bottom-up.
  839. */
  840. virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
  841. Item_transformer transformer, uchar *arg_t)
  842. {
  843. if ((this->*analyzer) (arg_p))
  844. return ((this->*transformer) (arg_t));
  845. return 0;
  846. }
  847. virtual void traverse_cond(Cond_traverser traverser,
  848. void *arg, traverse_order order)
  849. {
  850. (*traverser)(this, arg);
  851. }
  852. /*
  853. This is used to get the most recent version of any function in
  854. an item tree. The version is the version where a MySQL function
  855. was introduced in. So any function which is added should use
  856. this function and set the int_arg to maximum of the input data
  857. and their own version info.
  858. */
  859. virtual bool intro_version(uchar *int_arg) { return 0; }
  860. virtual bool remove_dependence_processor(uchar * arg) { return 0; }
  861. virtual bool remove_fixed(uchar * arg) { fixed= 0; return 0; }
  862. virtual bool cleanup_processor(uchar *arg);
  863. virtual bool collect_item_field_processor(uchar * arg) { return 0; }
  864. virtual bool find_item_in_field_list_processor(uchar *arg) { return 0; }
  865. virtual bool change_context_processor(uchar *context) { return 0; }
  866. virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; }
  867. virtual bool is_expensive_processor(uchar *arg) { return 0; }
  868. virtual bool find_item_processor(uchar *arg) { return this == (void *) arg; }
  869. virtual bool register_field_in_read_map(uchar *arg) { return 0; }
  870. virtual bool cache_const_expr_analyzer(uchar **arg);
  871. virtual Item* cache_const_expr_transformer(uchar *arg);
  872. /*
  873. Check if a partition function is allowed
  874. SYNOPSIS
  875. check_partition_func_processor()
  876. int_arg Ignored
  877. RETURN VALUE
  878. TRUE Partition function not accepted
  879. FALSE Partition function accepted
  880. DESCRIPTION
  881. check_partition_func_processor is used to check if a partition function
  882. uses an allowed function. An allowed function will always ensure that
  883. X=Y guarantees that also part_function(X)=part_function(Y) where X is
  884. a set of partition fields and so is Y. The problems comes mainly from
  885. character sets where two equal strings can be quite unequal. E.g. the
  886. german character for double s is equal to 2 s.
  887. The default is that an item is not allowed
  888. in a partition function. Allowed functions
  889. can never depend on server version, they cannot depend on anything
  890. related to the environment. They can also only depend on a set of
  891. fields in the table itself. They cannot depend on other tables and
  892. cannot contain any queries and cannot contain udf's or similar.
  893. If a new Item class is defined and it inherits from a class that is
  894. allowed in a partition function then it is very important to consider
  895. whether this should be inherited to the new class. If not the function
  896. below should be defined in the new Item class.
  897. The general behaviour is that most integer functions are allowed.
  898. If the partition function contains any multi-byte collations then
  899. the function check_part_func_fields will report an error on the
  900. partition function independent of what functions are used. So the
  901. only character sets allowed are single character collation and
  902. even for those only a limited set of functions are allowed. The
  903. problem with multi-byte collations is that almost every string
  904. function has the ability to change things such that two strings
  905. that are equal will not be equal after manipulated by a string
  906. function. E.g. two strings one contains a double s, there is a
  907. special german character that is equal to two s. Now assume a
  908. string function removes one character at this place, then in
  909. one the double s will be removed and in the other there will
  910. still be one s remaining and the strings are no longer equal
  911. and thus the partition function will not sort equal strings into
  912. the same partitions.
  913. So the check if a partition function is valid is two steps. First
  914. check that the field types are valid, next check that the partition
  915. function is valid. The current set of partition functions valid
  916. assumes that there are no multi-byte collations amongst the partition
  917. fields.
  918. */
  919. virtual bool check_partition_func_processor(uchar *bool_arg) { return TRUE;}
  920. virtual bool subst_argument_checker(uchar **arg)
  921. {
  922. if (*arg)
  923. *arg= NULL;
  924. return TRUE;
  925. }
  926. virtual Item *equal_fields_propagator(uchar * arg) { return this; }
  927. virtual bool set_no_const_sub(uchar *arg) { return FALSE; }
  928. virtual Item *replace_equal_field(uchar * arg) { return this; }
  929. /*
  930. Check if an expression value depends on the current timezone. Used by
  931. partitioning code to reject timezone-dependent expressions in a
  932. (sub)partitioning function.
  933. */
  934. virtual bool is_timezone_dependent_processor(uchar *bool_arg)
  935. {
  936. return FALSE;
  937. }
  938. /**
  939. Find a function of a given type
  940. @param arg the function type to search (enum Item_func::Functype)
  941. @return
  942. @retval TRUE the function type we're searching for is found
  943. @retval FALSE the function type wasn't found
  944. @description
  945. This function can be used (together with Item::walk()) to find functions
  946. in an item tree fragment.
  947. */
  948. virtual bool find_function_processor (uchar *arg)
  949. {
  950. return FALSE;
  951. }
  952. /*
  953. For SP local variable returns pointer to Item representing its
  954. current value and pointer to current Item otherwise.
  955. */
  956. virtual Item *this_item() { return this; }
  957. virtual const Item *this_item() const { return this; }
  958. /*
  959. For SP local variable returns address of pointer to Item representing its
  960. current value and pointer passed via parameter otherwise.
  961. */
  962. virtual Item **this_item_addr(THD *thd, Item **addr_arg) { return addr_arg; }
  963. // Row emulation
  964. virtual uint cols() { return 1; }
  965. virtual Item* element_index(uint i) { return this; }
  966. virtual Item** addr(uint i) { return 0; }
  967. virtual bool check_cols(uint c);
  968. // It is not row => null inside is impossible
  969. virtual bool null_inside() { return 0; }
  970. // used in row subselects to get value of elements
  971. virtual void bring_value() {}
  972. Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length);
  973. virtual Item_field *filed_for_view_update() { return 0; }
  974. virtual Item *neg_transformer(THD *thd) { return NULL; }
  975. virtual Item *update_value_transformer(uchar *select_arg) { return this; }
  976. virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
  977. void delete_self()
  978. {
  979. cleanup();
  980. delete this;
  981. }
  982. virtual bool is_splocal() { return 0; } /* Needed for error checking */
  983. /*
  984. Return Settable_routine_parameter interface of the Item. Return 0
  985. if this Item is not Settable_routine_parameter.
  986. */
  987. virtual Settable_routine_parameter *get_settable_routine_parameter()
  988. {
  989. return 0;
  990. }
  991. /*
  992. result_as_longlong() must return TRUE for Items representing DATE/TIME
  993. functions and DATE/TIME table fields.
  994. Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
  995. their values should be compared as integers (because the integer
  996. representation is more precise than the string one).
  997. */
  998. virtual bool result_as_longlong() { return FALSE; }
  999. bool is_datetime();
  1000. virtual Field::geometry_type get_geometry_type() const
  1001. { return Field::GEOM_GEOMETRY; };
  1002. String *check_well_formed_result(String *str, bool send_error= 0);
  1003. bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs);
  1004. uint32 max_char_length() const
  1005. { return max_length / collation.collation->mbmaxlen; }
  1006. void fix_length_and_charset(uint32 max_char_length_arg, CHARSET_INFO *cs)
  1007. {
  1008. max_length= max_char_length_arg * cs->mbmaxlen;
  1009. collation.collation= cs;
  1010. }
  1011. void fix_char_length(uint32 max_char_length_arg)
  1012. { max_length= max_char_length_arg * collation.collation->mbmaxlen; }
  1013. void fix_length_and_charset_datetime(uint32 max_char_length_arg)
  1014. {
  1015. collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII);
  1016. fix_char_length(max_char_length_arg);
  1017. }
  1018. };
  1019. class sp_head;
  1020. class Item_basic_constant :public Item
  1021. {
  1022. table_map used_table_map;
  1023. public:
  1024. Item_basic_constant(): Item(), used_table_map(0) {};
  1025. void set_used_tables(table_map map) { used_table_map= map; }
  1026. table_map used_tables() const { return used_table_map; }
  1027. /* to prevent drop fixed flag (no need parent cleanup call) */
  1028. void cleanup()
  1029. {
  1030. /*
  1031. Restore the original field name as it might not have been allocated
  1032. in the statement memory. If the name is auto generated, it must be
  1033. done again between subsequent executions of a prepared statement.
  1034. */
  1035. if (orig_name)
  1036. name= orig_name;
  1037. }
  1038. };
  1039. /*****************************************************************************
  1040. The class is a base class for representation of stored routine variables in
  1041. the Item-hierarchy. There are the following kinds of SP-vars:
  1042. - local variables (Item_splocal);
  1043. - CASE expression (Item_case_expr);
  1044. *****************************************************************************/
  1045. class Item_sp_variable :public Item
  1046. {
  1047. protected:
  1048. /*
  1049. THD, which is stored in fix_fields() and is used in this_item() to avoid
  1050. current_thd use.
  1051. */
  1052. THD *m_thd;
  1053. public:
  1054. LEX_STRING m_name;
  1055. public:
  1056. #ifndef DBUG_OFF
  1057. /*
  1058. Routine to which this Item_splocal belongs. Used for checking if correct
  1059. runtime context is used for variable handling.
  1060. */
  1061. sp_head *m_sp;
  1062. #endif
  1063. public:
  1064. Item_sp_variable(char *sp_var_name_str, uint sp_var_name_length);
  1065. public:
  1066. bool fix_fields(THD *thd, Item **);
  1067. double val_real();
  1068. longlong val_int();
  1069. String *val_str(String *sp);
  1070. my_decimal *val_decimal(my_decimal *decimal_value);
  1071. bool is_null();
  1072. public:
  1073. inline void make_field(Send_field *field);
  1074. inline bool const_item() const;
  1075. inline int save_in_field(Field *field, bool no_conversions);
  1076. inline bool send(Protocol *protocol, String *str);
  1077. };
  1078. /*****************************************************************************
  1079. Item_sp_variable inline implementation.
  1080. *****************************************************************************/
  1081. inline void Item_sp_variable::make_field(Send_field *field)
  1082. {
  1083. Item *it= this_item();
  1084. if (name)
  1085. it->set_name(name, (uint) strlen(name), system_charset_info);
  1086. else
  1087. it->set_name(m_name.str, (uint) m_name.length, system_charset_info);
  1088. it->make_field(field);
  1089. }
  1090. inline bool Item_sp_variable::const_item() const
  1091. {
  1092. return TRUE;
  1093. }
  1094. inline int Item_sp_variable::save_in_field(Field *field, bool no_conversions)
  1095. {
  1096. return this_item()->save_in_field(field, no_conversions);
  1097. }
  1098. inline bool Item_sp_variable::send(Protocol *protocol, String *str)
  1099. {
  1100. return this_item()->send(protocol, str);
  1101. }
  1102. /*****************************************************************************
  1103. A reference to local SP variable (incl. reference to SP parameter), used in
  1104. runtime.
  1105. *****************************************************************************/
  1106. class Item_splocal :public Item_sp_variable,
  1107. private Settable_routine_parameter
  1108. {
  1109. uint m_var_idx;
  1110. Type m_type;
  1111. Item_result m_result_type;
  1112. enum_field_types m_field_type;
  1113. public:
  1114. /*
  1115. Is this variable a parameter in LIMIT clause.
  1116. Used only during NAME_CONST substitution, to not append
  1117. NAME_CONST to the resulting query and thus not break
  1118. the slave.
  1119. */
  1120. bool limit_clause_param;
  1121. /*
  1122. Position of this reference to SP variable in the statement (the
  1123. statement itself is in sp_instr_stmt::m_query).
  1124. This is valid only for references to SP variables in statements,
  1125. excluding DECLARE CURSOR statement. It is used to replace references to SP
  1126. variables with NAME_CONST calls when putting statements into the binary
  1127. log.
  1128. Value of 0 means that this object doesn't corresponding to reference to
  1129. SP variable in query text.
  1130. */
  1131. uint pos_in_query;
  1132. /*
  1133. Byte length of SP variable name in the statement (see pos_in_query).
  1134. The value of this field may differ from the name_length value because
  1135. name_length contains byte length of UTF8-encoded item name, but
  1136. the query string (see sp_instr_stmt::m_query) is currently stored with
  1137. a charset from the SET NAMES statement.
  1138. */
  1139. uint len_in_query;
  1140. Item_splocal(const LEX_STRING &sp_var_name, uint sp_var_idx,
  1141. enum_field_types sp_var_type,
  1142. uint pos_in_q= 0, uint len_in_q= 0);
  1143. bool is_splocal() { return 1; } /* Needed for error checking */
  1144. Item *this_item();
  1145. const Item *this_item() const;
  1146. Item **this_item_addr(THD *thd, Item **);
  1147. virtual void print(String *str, enum_query_type query_type);
  1148. public:
  1149. inline const LEX_STRING *my_name() const;
  1150. inline uint get_var_idx() const;
  1151. inline enum Type type() const;
  1152. inline Item_result result_type() const;
  1153. inline enum_field_types field_type() const { return m_field_type; }
  1154. private:
  1155. bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
  1156. public:
  1157. Settable_routine_parameter *get_settable_routine_parameter()
  1158. {
  1159. return this;
  1160. }
  1161. };
  1162. /*****************************************************************************
  1163. Item_splocal inline implementation.
  1164. *****************************************************************************/
  1165. inline const LEX_STRING *Item_splocal::my_name() const
  1166. {
  1167. return &m_name;
  1168. }
  1169. inline uint Item_splocal::get_var_idx() const
  1170. {
  1171. return m_var_idx;
  1172. }
  1173. inline enum Item::Type Item_splocal::type() const
  1174. {
  1175. return m_type;
  1176. }
  1177. inline Item_result Item_splocal::result_type() const
  1178. {
  1179. return m_result_type;
  1180. }
  1181. /*****************************************************************************
  1182. A reference to case expression in SP, used in runtime.
  1183. *****************************************************************************/
  1184. class Item_case_expr :public Item_sp_variable
  1185. {
  1186. public:
  1187. Item_case_expr(uint case_expr_id);
  1188. public:
  1189. Item *this_item();
  1190. const Item *this_item() const;
  1191. Item **this_item_addr(THD *thd, Item **);
  1192. inline enum Type type() const;
  1193. inline Item_result result_type() const;
  1194. public:
  1195. /*
  1196. NOTE: print() is intended to be used from views and for debug.
  1197. Item_case_expr can not occur in views, so here it is only for debug
  1198. purposes.
  1199. */
  1200. virtual void print(String *str, enum_query_type query_type);
  1201. private:
  1202. uint m_case_expr_id;
  1203. };
  1204. /*****************************************************************************
  1205. Item_case_expr inline implementation.
  1206. *****************************************************************************/
  1207. inline enum Item::Type Item_case_expr::type() const
  1208. {
  1209. return this_item()->type();
  1210. }
  1211. inline Item_result Item_case_expr::result_type() const
  1212. {
  1213. return this_item()->result_type();
  1214. }
  1215. /*
  1216. NAME_CONST(given_name, const_value).
  1217. This 'function' has all properties of the supplied const_value (which is
  1218. assumed to be a literal constant), and the name given_name.
  1219. This is used to replace references to SP variables when we write PROCEDURE
  1220. statements into the binary log.
  1221. TODO
  1222. Together with Item_splocal and Item::this_item() we can actually extract
  1223. common a base of this class and Item_splocal. Maybe it is possible to
  1224. extract a common base with class Item_ref, too.
  1225. */
  1226. class Item_name_const : public Item
  1227. {
  1228. Item *value_item;
  1229. Item *name_item;
  1230. bool valid_args;
  1231. public:
  1232. Item_name_const(Item *name_arg, Item *val);
  1233. bool fix_fields(THD *, Item **);
  1234. enum Type type() const;
  1235. double val_real();
  1236. longlong val_int();
  1237. String *val_str(String *sp);
  1238. my_decimal *val_decimal(my_decimal *);
  1239. bool is_null();
  1240. virtual void print(String *str, enum_query_type query_type);
  1241. Item_result result_type() const
  1242. {
  1243. return value_item->result_type();
  1244. }
  1245. bool const_item() const
  1246. {
  1247. return TRUE;
  1248. }
  1249. int save_in_field(Field *field, bool no_conversions)
  1250. {
  1251. return value_item->save_in_field(field, no_conversions);
  1252. }
  1253. bool send(Protocol *protocol, String *str)
  1254. {
  1255. return value_item->send(protocol, str);
  1256. }
  1257. };
  1258. bool agg_item_collations(DTCollation &c, const char *name,
  1259. Item **items, uint nitems, uint flags, int item_sep);
  1260. bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
  1261. Item **items, uint nitems, uint flags);
  1262. bool agg_item_set_converter(DTCollation &coll, const char *fname,
  1263. Item **args, uint nargs, uint flags, int item_sep);
  1264. bool agg_item_charsets(DTCollation &c, const char *name,
  1265. Item **items, uint nitems, uint flags, int item_sep);
  1266. inline bool
  1267. agg_item_charsets_for_string_result(DTCollation &c, const char *name,
  1268. Item **items, uint nitems,
  1269. int item_sep= 1)
  1270. {
  1271. uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
  1272. MY_COLL_ALLOW_COERCIBLE_CONV;
  1273. return agg_item_charsets(c, name, items, nitems, flags, item_sep);
  1274. }
  1275. inline bool
  1276. agg_item_charsets_for_comparison(DTCollation &c, const char *name,
  1277. Item **items, uint nitems,
  1278. int item_sep= 1)
  1279. {
  1280. uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
  1281. MY_COLL_ALLOW_COERCIBLE_CONV |
  1282. MY_COLL_DISALLOW_NONE;
  1283. return agg_item_charsets(c, name, items, nitems, flags, item_sep);
  1284. }
  1285. class Item_num: public Item_basic_constant
  1286. {
  1287. public:
  1288. Item_num() { collation.set_numeric(); } /* Remove gcc warning */
  1289. virtual Item_num *neg()= 0;
  1290. Item *safe_charset_converter(CHARSET_INFO *tocs);
  1291. bool check_partition_func_processor(uchar *int_arg) { return FALSE;}
  1292. };
  1293. #define NO_CACHED_FIELD_INDEX ((uint)(-1))
  1294. class st_select_lex;
  1295. class Item_ident :public Item
  1296. {
  1297. protected:
  1298. /*
  1299. We have to store initial values of db_name, table_name and field_name
  1300. to be able to restore them during cleanup() because they can be
  1301. updated during fix_fields() to values from Field object and life-time
  1302. of those is shorter than life-time of Item_field.
  1303. */
  1304. const char *orig_db_name;
  1305. const char *orig_table_name;
  1306. const char *orig_field_name;
  1307. public:
  1308. Name_resolution_context *context;
  1309. const char *db_name;
  1310. const char *table_name;
  1311. const char *field_name;
  1312. bool alias_name_used; /* true if item was resolved against alias */
  1313. /*
  1314. Cached value of index for this field in table->field array, used by prep.
  1315. stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
  1316. if index value is not known.
  1317. */
  1318. uint cached_field_index;
  1319. /*
  1320. Cached pointer to table which contains this field, used for the same reason
  1321. by prep. stmt. too in case then we have not-fully qualified field.
  1322. 0 - means no cached value.
  1323. */
  1324. TABLE_LIST *cached_table;
  1325. st_select_lex *depended_from;
  1326. Item_ident(Name_resolution_context *context_arg,
  1327. const char *db_name_arg, const char *table_name_arg,
  1328. const char *field_name_arg);
  1329. Item_ident(THD *thd, Item_ident *item);
  1330. Item_ident(TABLE_LIST *view_arg, const char *field_name_arg);
  1331. const char *full_name() const;
  1332. void cleanup();
  1333. bool remove_dependence_processor(uchar * arg);
  1334. virtual void print(String *str, enum_query_type query_type);
  1335. virtual bool change_context_processor(uchar *cntx)
  1336. { context= (Name_resolution_context *)cntx; return FALSE; }
  1337. friend bool insert_fields(THD *thd, Name_resolution_context *context,
  1338. const char *db_name,
  1339. const char *table_name, List_iterator<Item> *it,
  1340. bool any_privileges);
  1341. };
  1342. class Item_ident_for_show :public Item
  1343. {
  1344. public:
  1345. Field *field;
  1346. const char *db_name;
  1347. const char *table_name;
  1348. Item_ident_for_show(Field *par_field, const char *db_arg,
  1349. const char *table_name_arg)
  1350. :field(par_field), db_name(db_arg), table_name(table_name_arg)
  1351. {}
  1352. enum Type type() const { return FIELD_ITEM; }
  1353. double val_real() { return field->val_real(); }
  1354. longlong val_int() { return field->val_int(); }
  1355. String *val_str(String *str) { return field->val_str(str); }
  1356. my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
  1357. void make_field(Send_field *tmp_field);
  1358. };
  1359. class Item_equal;
  1360. class COND_EQUAL;
  1361. class Item_field :public Item_ident
  1362. {
  1363. protected:
  1364. void set_field(Field *field);
  1365. public:
  1366. Field *field,*result_field;
  1367. Item_equal *item_equal;
  1368. bool no_const_subst;
  1369. /*
  1370. if any_privileges set to TRUE then here real effective privileges will
  1371. be stored
  1372. */
  1373. uint have_privileges;
  1374. /* field need any privileges (for VIEW creation) */
  1375. bool any_privileges;
  1376. Item_field(Name_resolution_context *context_arg,
  1377. const char *db_arg,const char *table_name_arg,
  1378. const char *field_name_arg);
  1379. /*
  1380. Constructor needed to process subselect with temporary tables (see Item)
  1381. */
  1382. Item_field(THD *thd, Item_field *item);
  1383. /*
  1384. Constructor used inside setup_wild(), ensures that field, table,
  1385. and database names will live as long as Item_field (this is important
  1386. in prepared statements).
  1387. */
  1388. Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
  1389. /*
  1390. If this constructor is used, fix_fields() won't work, because
  1391. db_name, table_name and column_name are unknown. It's necessary to call
  1392. reset_field() before fix_fields() for all fields created this way.
  1393. */
  1394. Item_field(Field *field);
  1395. enum Type type() const { return FIELD_ITEM; }
  1396. bool eq(const Item *item, bool binary_cmp) const;
  1397. double val_real();
  1398. longlong val_int();
  1399. my_decimal *val_decimal(my_decimal *);
  1400. String *val_str(String*);
  1401. double val_result();
  1402. longlong val_int_result();
  1403. String *str_result(String* tmp);
  1404. my_decimal *val_decimal_result(my_decimal *);
  1405. bool val_bool_result();
  1406. bool is_null_result();
  1407. bool send(Protocol *protocol, String *str_arg);
  1408. void reset_field(Field *f);
  1409. bool fix_fields(THD *, Item **);
  1410. void make_field(Send_field *tmp_field);
  1411. int save_in_field(Field *field,bool no_conversions);
  1412. void save_org_in_field(Field *field);
  1413. table_map used_tables() const;
  1414. enum Item_result result_type () const
  1415. {
  1416. return field->result_type();
  1417. }
  1418. Item_result cast_to_int_type() const
  1419. {
  1420. return field->cast_to_int_type();
  1421. }
  1422. enum_field_types field_type() const
  1423. {
  1424. return field->type();
  1425. }
  1426. enum_monotonicity_info get_monotonicity_info() const
  1427. {
  1428. return MONOTONIC_STRICT_INCREASING;
  1429. }
  1430. longlong val_int_endpoint(bool left_endp, bool *incl_endp);
  1431. Field *get_tmp_table_field() { return result_field; }
  1432. Field *tmp_table_field(TABLE *t_arg) { return result_field; }
  1433. bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
  1434. bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
  1435. bool get_time(MYSQL_TIME *ltime);
  1436. bool is_null() { return field->is_null(); }
  1437. void update_null_value();
  1438. Item *get_tmp_table_item(THD *thd);
  1439. bool collect_item_field_processor(uchar * arg);
  1440. bool find_item_in_field_list_processor(uchar *arg);
  1441. bool register_field_in_read_map(uchar *arg);
  1442. bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
  1443. void cleanup();
  1444. bool result_as_longlong()
  1445. {
  1446. return field->can_be_compared_as_longlong();
  1447. }
  1448. Item_equal *find_item_equal(COND_EQUAL *cond_equal);
  1449. bool subst_argument_checker(uchar **arg);
  1450. Item *equal_fields_propagator(uchar *arg);
  1451. bool set_no_const_sub(uchar *arg);
  1452. Item *replace_equal_field(uchar *arg);
  1453. inline uint32 max_disp_length() { return field->max_display_length(); }
  1454. Item_field *filed_for_view_update() { return this; }
  1455. Item *safe_charset_converter(CHARSET_INFO *tocs);
  1456. int fix_outer_field(THD *thd, Field **field, Item **reference);
  1457. virtual Item *update_value_transformer(uchar *select_arg);
  1458. virtual void print(String *str, enum_query_type query_type);
  1459. Field::geometry_type get_geometry_type() const
  1460. {
  1461. DBUG_ASSERT(field_type() == MYSQL_TYPE_GEOMETRY);
  1462. return field->get_geometry_type();
  1463. }
  1464. CHARSET_INFO *charset_for_protocol(void) const
  1465. { return field->charset_for_protocol(); }
  1466. friend class Item_default_value;
  1467. friend class Item_insert_value;
  1468. friend class st_select_lex_unit;
  1469. };
  1470. class Item_null :public Item_basic_constant
  1471. {
  1472. public:
  1473. Item_null(char *name_par=0)
  1474. {
  1475. maybe_null= null_value= TRUE;
  1476. max_length= 0;
  1477. name= name_par ? name_par : (char*) "NULL";
  1478. fixed= 1;
  1479. collation.set(&my_charset_bin, DERIVATION_IGNORABLE);
  1480. }
  1481. enum Type type() const { return NULL_ITEM; }
  1482. bool eq(const Item *item, bool binary_cmp) const;
  1483. double val_real();
  1484. longlong val_int();
  1485. String *val_str(String *str);
  1486. my_decimal *val_decimal(my_decimal *);
  1487. int save_in_field(Field *field, bool no_conversions);
  1488. int save_safe_in_field(Field *field);
  1489. bool send(Protocol *protocol, String *str);
  1490. enum Item_result result_type () const { return STRING_RESULT; }
  1491. enum_field_types field_type() const { return MYSQL_TYPE_NULL; }
  1492. bool basic_const_item() const { return 1; }
  1493. Item *clone_item() { return new Item_null(name); }
  1494. bool is_null() { return 1; }
  1495. virtual inline void print(String *str, enum_query_type query_type)
  1496. {
  1497. str->append(STRING_WITH_LEN("NULL"));
  1498. }
  1499. Item *safe_charset_converter(CHARSET_INFO *tocs);
  1500. bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
  1501. };
  1502. class Item_null_result :public Item_null
  1503. {
  1504. public:
  1505. Field *result_field;
  1506. Item_null_result() : Item_null(), result_field(0) {}
  1507. bool is_result_field() { return result_field != 0; }
  1508. void save_in_result_field(bool no_conversions)
  1509. {
  1510. save_in_field(result_field, no_conversions);
  1511. }
  1512. bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
  1513. };
  1514. /* Item represents one placeholder ('?') of prepared statement */
  1515. class Item_param :public Item,
  1516. private Settable_routine_parameter
  1517. {
  1518. char cnvbuf[MAX_FIELD_WIDTH];
  1519. String cnvstr;
  1520. Item *cnvitem;
  1521. public:
  1522. enum enum_item_param_state
  1523. {
  1524. NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
  1525. STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
  1526. DECIMAL_VALUE
  1527. } state;
  1528. /*
  1529. A buffer for string and long data values. Historically all allocated
  1530. values returned from val_str() were treated as eligible to
  1531. modification. I. e. in some cases Item_func_concat can append it's
  1532. second argument to return value of the first one. Because of that we
  1533. can't return the original buffer holding string data from val_str(),
  1534. and have to have one buffer for data and another just pointing to
  1535. the data. This is the latter one and it's returned from val_str().
  1536. Can not be declared inside the union as it's not a POD type.
  1537. */
  1538. String str_value_ptr;
  1539. my_decimal decimal_value;
  1540. union
  1541. {
  1542. longlong integer;
  1543. double real;
  1544. /*
  1545. Character sets conversion info for string values.
  1546. Character sets of client and connection defined at bind time are used
  1547. for all conversions, even if one of them is later changed (i.e.
  1548. between subsequent calls to mysql_stmt_execute).
  1549. */
  1550. struct CONVERSION_INFO
  1551. {
  1552. CHARSET_INFO *character_set_client;
  1553. CHARSET_INFO *character_set_of_placeholder;
  1554. /*
  1555. This points at character set of connection if conversion
  1556. to it is required (i. e. if placeholder typecode is not BLOB).
  1557. Otherwise it's equal to character_set_client (to simplify
  1558. check in convert_str_value()).
  1559. */
  1560. CHARSET_INFO *final_character_set_of_str_value;
  1561. } cs_info;
  1562. MYSQL_TIME time;
  1563. } value;
  1564. /* Cached values for virtual methods to save us one switch. */
  1565. enum Item_result item_result_type;
  1566. enum Type item_type;
  1567. /*
  1568. Used when this item is used in a temporary table.
  1569. This is NOT placeholder metadata sent to client, as this value
  1570. is assigned after sending metadata (in setup_one_conversion_function).
  1571. For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
  1572. in result set and placeholders metadata, no matter what type you will
  1573. supply for this placeholder in mysql_stmt_execute.
  1574. */
  1575. enum enum_field_types param_type;
  1576. /*
  1577. Offset of placeholder inside statement text. Used to create
  1578. no-placeholders version of this statement for the binary log.
  1579. */
  1580. uint pos_in_query;
  1581. Item_param(uint pos_in_query_arg);
  1582. enum Item_result result_type () const { return item_result_type; }
  1583. enum Type type() const { return item_type; }
  1584. enum_field_types field_type() const { return param_type; }
  1585. double val_real();
  1586. longlong val_int();
  1587. my_decimal *val_decimal(my_decimal*);
  1588. String *val_str(String*);
  1589. bool get_time(MYSQL_TIME *tm);
  1590. bool get_date(MYSQL_TIME *tm, uint fuzzydate);
  1591. int save_in_field(Field *field, bool no_conversions);
  1592. void set_null();
  1593. void set_int(longlong i, uint32 max_length_arg);
  1594. void set_double(double i);
  1595. void set_decimal(const char *str, ulong length);
  1596. void set_decimal(const my_decimal *dv);
  1597. bool set_str(const char *str, ulong length);
  1598. bool set_longdata(const char *str, ulong length);
  1599. void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
  1600. bool set_from_user_var(THD *thd, const user_var_entry *entry);
  1601. void reset();
  1602. /*
  1603. Assign placeholder value from bind data.
  1604. Note, that 'len' has different semantics in embedded library (as we
  1605. don't need to check that packet is not broken there). See
  1606. sql_prepare.cc for details.
  1607. */
  1608. void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
  1609. const String *query_val_str(String *str) const;
  1610. bool convert_str_value(THD *thd);
  1611. /*
  1612. If value for parameter was not set we treat it as non-const
  1613. so noone will use parameters value in fix_fields still
  1614. parameter is constant during execution.
  1615. */
  1616. virtual table_map used_tables() const
  1617. { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
  1618. virtual void print(String *str, enum_query_type query_type);
  1619. bool is_null()
  1620. { DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; }
  1621. bool basic_const_item() const;
  1622. /*
  1623. This method is used to make a copy of a basic constant item when
  1624. propagating constants in the optimizer. The reason to create a new
  1625. item and not use the existing one is not precisely known (2005/04/16).
  1626. Probably we are trying to preserve tree structure of items, in other
  1627. words, avoid pointing at one item from two different nodes of the tree.
  1628. Return a new basic constant item if parameter value is a basic
  1629. constant, assert otherwise. This method is called only if
  1630. basic_const_item returned TRUE.
  1631. */
  1632. Item *safe_charset_converter(CHARSET_INFO *tocs);
  1633. Item *clone_item();
  1634. /*
  1635. Implement by-value equality evaluation if parameter value
  1636. is set and is a basic constant (integer, real or string).
  1637. Otherwise return FALSE.
  1638. */
  1639. bool eq(const Item *item, bool binary_cmp) const;
  1640. /** Item is a argument to a limit clause. */
  1641. bool limit_clause_param;
  1642. void set_param_type_and_swap_value(Item_param *from);
  1643. private:
  1644. virtual inline Settable_routine_parameter *
  1645. get_settable_routine_parameter()
  1646. {
  1647. return this;
  1648. }
  1649. virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
  1650. virtual void set_out_param_info(Send_field *info);
  1651. public:
  1652. virtual const Send_field *get_out_param_info() const;
  1653. virtual void make_field(Send_field *field);
  1654. private:
  1655. Send_field *m_out_param_info;
  1656. };
  1657. class Item_int :public Item_num
  1658. {
  1659. public:
  1660. longlong value;
  1661. Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
  1662. :value((longlong) i)
  1663. { max_length=length; fixed= 1; }
  1664. Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
  1665. :value(i)
  1666. { max_length=length; fixed= 1; }
  1667. Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
  1668. :value((longlong)i)
  1669. { max_length=length; fixed= 1; unsigned_flag= 1; }
  1670. Item_int(const char *str_arg,longlong i,uint length) :value(i)
  1671. { max_length=length; name=(char*) str_arg; fixed= 1; }
  1672. Item_int(const char *str_arg, uint length=64);
  1673. enum Type type() const { return INT_ITEM; }
  1674. enum Item_result result_type () const { return INT_RESULT; }
  1675. enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
  1676. longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
  1677. double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
  1678. my_decimal *val_decimal(my_decimal *);
  1679. String *val_str(String*);
  1680. int save_in_field(Field *field, bool no_conversions);
  1681. bool basic_const_item() const { return 1; }
  1682. Item *clone_item() { return new Item_int(name,value,max_length); }
  1683. virtual void print(String *str, enum_query_type query_type);
  1684. Item_num *neg() { value= -value; return this; }
  1685. uint decimal_precision() const
  1686. { return (uint)(max_length - test(value < 0)); }
  1687. bool eq(const Item *, bool binary_cmp) const;
  1688. bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
  1689. };
  1690. class Item_uint :public Item_int
  1691. {
  1692. public:
  1693. Item_uint(const char *str_arg, uint length);
  1694. Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {}
  1695. Item_uint(const char *str_arg, longlong i, uint length);
  1696. double val_real()
  1697. { DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); }
  1698. String *val_str(String*);
  1699. Item *clone_item() { return new Item_uint(name, value, max_length); }
  1700. int save_in_field(Field *field, bool no_conversions);
  1701. virtual void print(String *str, enum_query_type query_type);
  1702. Item_num *neg ();
  1703. uint decimal_precision() const { return max_length; }
  1704. bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
  1705. };
  1706. /* decimal (fixed point) constant */
  1707. class Item_decimal :public Item_num
  1708. {
  1709. protected:
  1710. my_decimal decimal_value;
  1711. public:
  1712. Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
  1713. Item_decimal(const char *str, const my_decimal *val_arg,
  1714. uint decimal_par, uint length);
  1715. Item_decimal(my_decimal *value_par);
  1716. Item_decimal(longlong val, bool unsig);
  1717. Item_decimal(double val, int precision, int scale);
  1718. Item_decimal(const uchar *bin, int precision, int scale);
  1719. enum Type type() const { return DECIMAL_ITEM; }
  1720. enum Item_result result_type () const { return DECIMAL_RESULT; }
  1721. enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
  1722. longlong val_int();
  1723. double val_real();
  1724. String *val_str(String*);
  1725. my_decimal *val_decimal(my_decimal *val) { return &decimal_value; }
  1726. int save_in_field(Field *field, bool no_conversions);
  1727. bool basic_const_item() const { return 1; }
  1728. Item *clone_item()
  1729. {
  1730. return new Item_decimal(name, &decimal_value, decimals, max_length);
  1731. }
  1732. virtual void print(String *str, enum_query_type query_type);
  1733. Item_num *neg()
  1734. {
  1735. my_decimal_neg(&decimal_value);
  1736. unsigned_flag= !decimal_value.sign();
  1737. return this;
  1738. }
  1739. uint decimal_precision() const { return decimal_value.precision(); }
  1740. bool eq(const Item *, bool binary_cmp) const;
  1741. void set_decimal_value(my_decimal *value_par);
  1742. bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
  1743. };
  1744. class Item_float :public Item_num
  1745. {
  1746. char *presentation;
  1747. public:
  1748. double value;
  1749. // Item_real() :value(0) {}
  1750. Item_float(const char *str_arg, uint length);
  1751. Item_float(const char *str,double val_arg,uint decimal_par,uint length)
  1752. :value(val_arg)
  1753. {
  1754. presentation= name=(char*) str;
  1755. decimals=(uint8) decimal_par;
  1756. max_length=length;
  1757. fixed= 1;
  1758. }
  1759. Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
  1760. {
  1761. decimals= (uint8) decimal_par;
  1762. fixed= 1;
  1763. }
  1764. int save_in_field(Field *field, bool no_conversions);
  1765. enum Type type() const { return REAL_ITEM; }
  1766. enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
  1767. double val_real() { DBUG_ASSERT(fixed == 1); return value; }
  1768. longlong val_int()
  1769. {
  1770. DBUG_ASSERT(fixed == 1);
  1771. if (value <= (double) LONGLONG_MIN)
  1772. {
  1773. return LONGLONG_MIN;
  1774. }
  1775. else if (value >= (double) (ulonglong) LONGLONG_MAX)
  1776. {
  1777. return LONGLONG_MAX;
  1778. }
  1779. return (longlong) rint(value);
  1780. }
  1781. String *val_str(String*);
  1782. my_decimal *val_decimal(my_decimal *);
  1783. bool basic_const_item() const { return 1; }
  1784. Item *clone_item()
  1785. { return new Item_float(name, value, decimals, max_length); }
  1786. Item_num *neg() { value= -value; return this; }
  1787. virtual void print(String *str, enum_query_type query_type);
  1788. bool eq(const Item *, bool binary_cmp) const;
  1789. };
  1790. class Item_static_float_func :public Item_float
  1791. {
  1792. const char *func_name;
  1793. public:
  1794. Item_static_float_func(const char *str, double val_arg, uint decimal_par,
  1795. uint length)
  1796. :Item_float(NullS, val_arg, decimal_par, length), func_name(str)
  1797. {}
  1798. virtual inline void print(String *str, enum_query_type query_type)
  1799. {
  1800. str->append(func_name);
  1801. }
  1802. Item *safe_charset_converter(CHARSET_INFO *tocs);
  1803. };
  1804. class Item_string :public Item_basic_constant
  1805. {
  1806. public:
  1807. Item_string(const char *str,uint length,
  1808. CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
  1809. uint repertoire= MY_REPERTOIRE_UNICODE30)
  1810. : m_cs_specified(FALSE)
  1811. {
  1812. str_value.set_or_copy_aligned(str, length, cs);
  1813. collation.set(cs, dv, repertoire);
  1814. /*
  1815. We have to have a different max_length than 'length' here to
  1816. ensure that we get the right length if we do use the item
  1817. to create a new table. In this case max_length must be the maximum
  1818. number of chars for a string of this type because we in Create_field::
  1819. divide the max_length with mbmaxlen).
  1820. */
  1821. max_length= str_value.numchars()*cs->mbmaxlen;
  1822. set_name(str, length, cs);
  1823. decimals=NOT_FIXED_DEC;
  1824. // it is constant => can be used without fix_fields (and frequently used)
  1825. fixed= 1;
  1826. }
  1827. /* Just create an item and do not fill string representation */
  1828. Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
  1829. : m_cs_specified(FALSE)
  1830. {
  1831. collation.set(cs, dv);
  1832. max_length= 0;
  1833. set_name(NULL, 0, cs);
  1834. decimals= NOT_FIXED_DEC;
  1835. fixed= 1;
  1836. }
  1837. Item_string(const char *name_par, const char *str, uint length,
  1838. CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
  1839. uint repertoire= MY_REPERTOIRE_UNICODE30)
  1840. : m_cs_specified(FALSE)
  1841. {
  1842. str_value.set_or_copy_aligned(str, length, cs);
  1843. collation.set(cs, dv, repertoire);
  1844. max_length= str_value.numchars()*cs->mbmaxlen;
  1845. set_name(name_par, 0, cs);
  1846. decimals=NOT_FIXED_DEC;
  1847. // it is constant => can be used without fix_fields (and frequently used)
  1848. fixed= 1;
  1849. }
  1850. /*
  1851. This is used in stored procedures to avoid memory leaks and
  1852. does a deep copy of its argument.
  1853. */
  1854. void set_str_with_copy(const char *str_arg, uint length_arg)
  1855. {
  1856. str_value.copy(str_arg, length_arg, collation.collation);
  1857. max_length= str_value.numchars() * collation.collation->mbmaxlen;
  1858. }
  1859. void set_repertoire_from_value()
  1860. {
  1861. collation.repertoire= my_string_repertoire(str_value.charset(),
  1862. str_value.ptr(),
  1863. str_value.length());
  1864. }
  1865. enum Type type() const { return STRING_ITEM; }
  1866. double val_real();
  1867. longlong val_int();
  1868. String *val_str(String*)
  1869. {
  1870. DBUG_ASSERT(fixed == 1);
  1871. return (String*) &str_value;
  1872. }
  1873. my_decimal *val_decimal(my_decimal *);
  1874. int save_in_field(Field *field, bool no_conversions);
  1875. enum Item_result result_type () const { return STRING_RESULT; }
  1876. enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
  1877. bool basic_const_item() const { return 1; }
  1878. bool eq(const Item *item, bool binary_cmp) const;
  1879. Item *clone_item()
  1880. {
  1881. return new Item_string(name, str_value.ptr(),
  1882. str_value.length(), collation.collation);
  1883. }
  1884. Item *safe_charset_converter(CHARSET_INFO *tocs);
  1885. inline void append(char *str, uint length)
  1886. {
  1887. str_value.append(str, length);
  1888. max_length= str_value.numchars() * collation.collation->mbmaxlen;
  1889. }
  1890. virtual void print(String *str, enum_query_type query_type);
  1891. bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
  1892. /**
  1893. Return TRUE if character-set-introducer was explicitly specified in the
  1894. original query for this item (text literal).
  1895. This operation is to be called from Item_string::print(). The idea is
  1896. that when a query is generated (re-constructed) from the Item-tree,
  1897. character-set-introducers should appear only for those literals, where
  1898. they were explicitly specified by the user. Otherwise, that may lead to
  1899. loss collation information (character set introducers implies default
  1900. collation for the literal).
  1901. Basically, that makes sense only for views and hopefully will be gone
  1902. one day when we start using original query as a view definition.
  1903. @return This operation returns the value of m_cs_specified attribute.
  1904. @retval TRUE if character set introducer was explicitly specified in
  1905. the original query.
  1906. @retval FALSE otherwise.
  1907. */
  1908. inline bool is_cs_specified() const
  1909. {
  1910. return m_cs_specified;
  1911. }
  1912. /**
  1913. Set the value of m_cs_specified attribute.
  1914. m_cs_specified attribute shows whether character-set-introducer was
  1915. explicitly specified in the original query for this text literal or
  1916. not. The attribute makes sense (is used) only for views.
  1917. This operation is to be called from the parser during parsing an input
  1918. query.
  1919. */
  1920. inline void set_cs_specified(bool cs_specified)
  1921. {
  1922. m_cs_specified= cs_specified;
  1923. }
  1924. private:
  1925. bool m_cs_specified;
  1926. };
  1927. longlong
  1928. longlong_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end);
  1929. double
  1930. double_from_string_with_check (CHARSET_INFO *cs, const char *cptr, char *end);
  1931. class Item_static_string_func :public Item_string
  1932. {
  1933. const char *func_name;
  1934. public:
  1935. Item_static_string_func(const char *name_par, const char *str, uint length,
  1936. CHARSET_INFO *cs,
  1937. Derivation dv= DERIVATION_COERCIBLE)
  1938. :Item_string(NullS, str, length, cs, dv), func_name(name_par)
  1939. {}
  1940. Item *safe_charset_converter(CHARSET_INFO *tocs);
  1941. virtual inline void print(String *str, enum_query_type query_type)
  1942. {
  1943. str->append(func_name);
  1944. }
  1945. bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
  1946. };
  1947. /* for show tables */
  1948. class Item_partition_func_safe_string: public Item_string
  1949. {
  1950. public:
  1951. Item_partition_func_safe_string(const char *name, uint length,
  1952. CHARSET_INFO *cs= NULL):
  1953. Item_string(name, length, cs)
  1954. {}
  1955. };
  1956. class Item_return_date_time :public Item_partition_func_safe_string
  1957. {
  1958. enum_field_types date_time_field_type;
  1959. public:
  1960. Item_return_date_time(const char *name_arg, enum_field_types field_type_arg)
  1961. :Item_partition_func_safe_string(name_arg, 0, &my_charset_bin),
  1962. date_time_field_type(field_type_arg)
  1963. { }
  1964. enum_field_types field_type() const { return date_time_field_type; }
  1965. };
  1966. class Item_blob :public Item_partition_func_safe_string
  1967. {
  1968. public:
  1969. Item_blob(const char *name, uint length) :
  1970. Item_partition_func_safe_string(name, length, &my_charset_bin)
  1971. { max_length= length; }
  1972. enum Type type() const { return TYPE_HOLDER; }
  1973. enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
  1974. };
  1975. /**
  1976. Item_empty_string -- is a utility class to put an item into List<Item>
  1977. which is then used in protocol.send_result_set_metadata() when sending SHOW output to
  1978. the client.
  1979. */
  1980. class Item_empty_string :public Item_partition_func_safe_string
  1981. {
  1982. public:
  1983. Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
  1984. Item_partition_func_safe_string("",0, cs ? cs : &my_charset_utf8_general_ci)
  1985. { name=(char*) header; max_length= length * collation.collation->mbmaxlen; }
  1986. void make_field(Send_field *field);
  1987. };
  1988. class Item_return_int :public Item_int
  1989. {
  1990. enum_field_types int_field_type;
  1991. public:
  1992. Item_return_int(const char *name_arg, uint length,
  1993. enum_field_types field_type_arg, longlong value= 0)
  1994. :Item_int(name_arg, value, length), int_field_type(field_type_arg)
  1995. {
  1996. unsigned_flag=1;
  1997. }
  1998. enum_field_types field_type() const { return int_field_type; }
  1999. };
  2000. class Item_hex_string: public Item_basic_constant
  2001. {
  2002. public:
  2003. Item_hex_string() {}
  2004. Item_hex_string(const char *str,uint str_length);
  2005. enum Type type() const { return VARBIN_ITEM; }
  2006. double val_real()
  2007. {
  2008. DBUG_ASSERT(fixed == 1);
  2009. return (double) (ulonglong) Item_hex_string::val_int();
  2010. }
  2011. longlong val_int();
  2012. bool basic_const_item() const { return 1; }
  2013. String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; }
  2014. my_decimal *val_decimal(my_decimal *);
  2015. int save_in_field(Field *field, bool no_conversions);
  2016. enum Item_result result_type () const { return STRING_RESULT; }
  2017. enum Item_result cast_to_int_type() const { return INT_RESULT; }
  2018. enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
  2019. virtual void print(String *str, enum_query_type query_type);
  2020. bool eq(const Item *item, bool binary_cmp) const;
  2021. virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
  2022. bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
  2023. };
  2024. class Item_bin_string: public Item_hex_string
  2025. {
  2026. public:
  2027. Item_bin_string(const char *str,uint str_length);
  2028. };
  2029. class Item_result_field :public Item /* Item with result field */
  2030. {
  2031. public:
  2032. Field *result_field; /* Save result here */
  2033. Item_result_field() :result_field(0) {}
  2034. // Constructor used for Item_sum/Item_cond_and/or (see Item comment)
  2035. Item_result_field(THD *thd, Item_result_field *item):
  2036. Item(thd, item), result_field(item->result_field)
  2037. {}
  2038. ~Item_result_field() {} /* Required with gcc 2.95 */
  2039. Field *get_tmp_table_field() { return result_field; }
  2040. Field *tmp_table_field(TABLE *t_arg) { return result_field; }
  2041. table_map used_tables() const { return 1; }
  2042. virtual void fix_length_and_dec()=0;
  2043. void set_result_field(Field *field) { result_field= field; }
  2044. bool is_result_field() { return 1; }
  2045. void save_in_result_field(bool no_conversions)
  2046. {
  2047. save_in_field(result_field, no_conversions);
  2048. }
  2049. void cleanup();
  2050. /*
  2051. This method is used for debug purposes to print the name of an
  2052. item to the debug log. The second use of this method is as
  2053. a helper function of print() and error messages, where it is
  2054. applicable. To suit both goals it should return a meaningful,
  2055. distinguishable and sintactically correct string. This method
  2056. should not be used for runtime type identification, use enum
  2057. {Sum}Functype and Item_func::functype()/Item_sum::sum_func()
  2058. instead.
  2059. Added here, to the parent class of both Item_func and Item_sum_func.
  2060. NOTE: for Items inherited from Item_sum, func_name() return part of
  2061. function name till first argument (including '(') to make difference in
  2062. names for functions with 'distinct' clause and without 'distinct' and
  2063. also to make printing of items inherited from Item_sum uniform.
  2064. */
  2065. virtual const char *func_name() const= 0;
  2066. };
  2067. class Item_ref :public Item_ident
  2068. {
  2069. protected:
  2070. void set_properties();
  2071. public:
  2072. enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF, AGGREGATE_REF };
  2073. Field *result_field; /* Save result here */
  2074. Item **ref;
  2075. Item_ref(Name_resolution_context *context_arg,
  2076. const char *db_arg, const char *table_name_arg,
  2077. const char *field_name_arg)
  2078. :Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
  2079. result_field(0), ref(0) {}
  2080. /*
  2081. This constructor is used in two scenarios:
  2082. A) *item = NULL
  2083. No initialization is performed, fix_fields() call will be necessary.
  2084. B) *item points to an Item this Item_ref will refer to. This is
  2085. used for GROUP BY. fix_fields() will not be called in this case,
  2086. so we call set_properties to make this item "fixed". set_properties
  2087. performs a subset of action Item_ref::fix_fields does, and this subset
  2088. is enough for Item_ref's used in GROUP BY.
  2089. TODO we probably fix a superset of problems like in BUG#6658. Check this
  2090. with Bar, and if we have a more broader set of problems like this.
  2091. */
  2092. Item_ref(Name_resolution_context *context_arg, Item **item,
  2093. const char *table_name_arg, const char *field_name_arg,
  2094. bool alias_name_used_arg= FALSE);
  2095. Item_ref(TABLE_LIST *view_arg, Item **item,
  2096. const char *field_name_arg, bool alias_name_used_arg= FALSE);
  2097. /* Constructor need to process subselect with temporary tables (see Item) */
  2098. Item_ref(THD *thd, Item_ref *item)
  2099. :Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {}
  2100. enum Type type() const { return REF_ITEM; }
  2101. bool eq(const Item *item, bool binary_cmp) const
  2102. {
  2103. Item *it= ((Item *) item)->real_item();
  2104. return ref && (*ref)->eq(it, binary_cmp);
  2105. }
  2106. double val_real();
  2107. longlong val_int();
  2108. my_decimal *val_decimal(my_decimal *);
  2109. bool val_bool();
  2110. String *val_str(String* tmp);
  2111. bool is_null();
  2112. bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
  2113. double val_result();
  2114. longlong val_int_result();
  2115. String *str_result(String* tmp);
  2116. my_decimal *val_decimal_result(my_decimal *);
  2117. bool val_bool_result();
  2118. bool is_null_result();
  2119. bool send(Protocol *prot, String *tmp);
  2120. void make_field(Send_field *field);
  2121. bool fix_fields(THD *, Item **);
  2122. int save_in_field(Field *field, bool no_conversions);
  2123. void save_org_in_field(Field *field);
  2124. enum Item_result result_type () const { return (*ref)->result_type(); }
  2125. enum_field_types field_type() const { return (*ref)->field_type(); }
  2126. Field *get_tmp_table_field()
  2127. { return result_field ? result_field : (*ref)->get_tmp_table_field(); }
  2128. Item *get_tmp_table_item(THD *thd);
  2129. table_map used_tables() const
  2130. {
  2131. return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
  2132. }
  2133. void update_used_tables()
  2134. {
  2135. if (!depended_from)
  2136. (*ref)->update_used_tables();
  2137. }
  2138. table_map not_null_tables() const { return (*ref)->not_null_tables(); }
  2139. void set_result_field(Field *field) { result_field= field; }
  2140. bool is_result_field() { return 1; }
  2141. void save_in_result_field(bool no_conversions)
  2142. {
  2143. (*ref)->save_in_field(result_field, no_conversions);
  2144. }
  2145. Item *real_item()
  2146. {
  2147. return ref ? (*ref)->real_item() : this;
  2148. }
  2149. bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
  2150. {
  2151. return (*ref)->walk(processor, walk_subquery, arg) ||
  2152. (this->*processor)(arg);
  2153. }
  2154. virtual void print(String *str, enum_query_type query_type);
  2155. bool result_as_longlong()
  2156. {
  2157. return (*ref)->result_as_longlong();
  2158. }
  2159. void cleanup();
  2160. Item_field *filed_for_view_update()
  2161. { return (*ref)->filed_for_view_update(); }
  2162. virtual Ref_Type ref_type() { return REF; }
  2163. // Row emulation: forwarding of ROW-related calls to ref
  2164. uint cols()
  2165. {
  2166. return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
  2167. }
  2168. Item* element_index(uint i)
  2169. {
  2170. return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
  2171. }
  2172. Item** addr(uint i)
  2173. {
  2174. return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
  2175. }
  2176. bool check_cols(uint c)
  2177. {
  2178. return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
  2179. : Item::check_cols(c);
  2180. }
  2181. bool null_inside()
  2182. {
  2183. return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
  2184. }
  2185. void bring_value()
  2186. {
  2187. if (ref && result_type() == ROW_RESULT)
  2188. (*ref)->bring_value();
  2189. }
  2190. bool get_time(MYSQL_TIME *ltime)
  2191. {
  2192. DBUG_ASSERT(fixed);
  2193. return (*ref)->get_time(ltime);
  2194. }
  2195. bool basic_const_item() { return (*ref)->basic_const_item(); }
  2196. };
  2197. /*
  2198. The same as Item_ref, but get value from val_* family of method to get
  2199. value of item on which it referred instead of result* family.
  2200. */
  2201. class Item_direct_ref :public Item_ref
  2202. {
  2203. public:
  2204. Item_direct_ref(Name_resolution_context *context_arg, Item **item,
  2205. const char *table_name_arg,
  2206. const char *field_name_arg,
  2207. bool alias_name_used_arg= FALSE)
  2208. :Item_ref(context_arg, item, table_name_arg,
  2209. field_name_arg, alias_name_used_arg)
  2210. {}
  2211. /* Constructor need to process subselect with temporary tables (see Item) */
  2212. Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
  2213. Item_direct_ref(TABLE_LIST *view_arg, Item **item,
  2214. const char *field_name_arg,
  2215. bool alias_name_used_arg= FALSE)
  2216. :Item_ref(view_arg, item, field_name_arg,
  2217. alias_name_used_arg)
  2218. {}
  2219. double val_real();
  2220. longlong val_int();
  2221. String *val_str(String* tmp);
  2222. my_decimal *val_decimal(my_decimal *);
  2223. bool val_bool();
  2224. bool is_null();
  2225. bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
  2226. virtual Ref_Type ref_type() { return DIRECT_REF; }
  2227. };
  2228. /*
  2229. Class for view fields, the same as Item_direct_ref, but call fix_fields
  2230. of reference if it is not called yet
  2231. */
  2232. class Item_direct_view_ref :public Item_direct_ref
  2233. {
  2234. public:
  2235. Item_direct_view_ref(Name_resolution_context *context_arg, Item **item,
  2236. const char *table_name_arg,
  2237. const char *field_name_arg)
  2238. :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {}
  2239. /* Constructor need to process subselect with temporary tables (see Item) */
  2240. Item_direct_view_ref(THD *thd, Item_direct_ref *item)
  2241. :Item_direct_ref(thd, item) {}
  2242. Item_direct_view_ref(TABLE_LIST *view_arg, Item **item,
  2243. const char *field_name_arg)
  2244. :Item_direct_ref(view_arg, item, field_name_arg)
  2245. {}
  2246. bool fix_fields(THD *, Item **);
  2247. bool eq(const Item *item, bool binary_cmp) const;
  2248. Item *get_tmp_table_item(THD *thd)
  2249. {
  2250. Item *item= Item_ref::get_tmp_table_item(thd);
  2251. item->name= name;
  2252. return item;
  2253. }
  2254. virtual Ref_Type ref_type() { return VIEW_REF; }
  2255. };
  2256. /*
  2257. Class for outer fields.
  2258. An object of this class is created when the select where the outer field was
  2259. resolved is a grouping one. After it has been fixed the ref field will point
  2260. to either an Item_ref or an Item_direct_ref object which will be used to
  2261. access the field.
  2262. See also comments for the fix_inner_refs() and the
  2263. Item_field::fix_outer_field() functions.
  2264. */
  2265. class Item_sum;
  2266. class Item_outer_ref :public Item_direct_ref
  2267. {
  2268. public:
  2269. Item *outer_ref;
  2270. /* The aggregate function under which this outer ref is used, if any. */
  2271. Item_sum *in_sum_func;
  2272. /*
  2273. TRUE <=> that the outer_ref is already present in the select list
  2274. of the outer select.
  2275. */
  2276. bool found_in_select_list;
  2277. Item_outer_ref(Name_resolution_context *context_arg,
  2278. Item_field *outer_field_arg)
  2279. :Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
  2280. outer_field_arg->field_name),
  2281. outer_ref(outer_field_arg), in_sum_func(0),
  2282. found_in_select_list(0)
  2283. {
  2284. ref= &outer_ref;
  2285. set_properties();
  2286. fixed= 0;
  2287. }
  2288. Item_outer_ref(Name_resolution_context *context_arg, Item **item,
  2289. const char *table_name_arg, const char *field_name_arg,
  2290. bool alias_name_used_arg)
  2291. :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
  2292. alias_name_used_arg),
  2293. outer_ref(0), in_sum_func(0), found_in_select_list(1)
  2294. {}
  2295. void save_in_result_field(bool no_conversions)
  2296. {
  2297. outer_ref->save_org_in_field(result_field);
  2298. }
  2299. bool fix_fields(THD *, Item **);
  2300. table_map used_tables() const
  2301. {
  2302. return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
  2303. }
  2304. virtual Ref_Type ref_type() { return OUTER_REF; }
  2305. };
  2306. class Item_in_subselect;
  2307. /*
  2308. An object of this class:
  2309. - Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
  2310. - Sets owner->was_null=TRUE if it has returned a NULL value from any
  2311. val_XXX() function. This allows to inject an Item_ref_null_helper
  2312. object into subquery and then check if the subquery has produced a row
  2313. with NULL value.
  2314. */
  2315. class Item_ref_null_helper: public Item_ref
  2316. {
  2317. protected:
  2318. Item_in_subselect* owner;
  2319. public:
  2320. Item_ref_null_helper(Name_resolution_context *context_arg,
  2321. Item_in_subselect* master, Item **item,
  2322. const char *table_name_arg, const char *field_name_arg)
  2323. :Item_ref(context_arg, item, table_name_arg, field_name_arg),
  2324. owner(master) {}
  2325. double val_real();
  2326. longlong val_int();
  2327. String* val_str(String* s);
  2328. my_decimal *val_decimal(my_decimal *);
  2329. bool val_bool();
  2330. bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
  2331. virtual void print(String *str, enum_query_type query_type);
  2332. /*
  2333. we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
  2334. */
  2335. table_map used_tables() const
  2336. {
  2337. return (depended_from ?
  2338. OUTER_REF_TABLE_BIT :
  2339. (*ref)->used_tables() | RAND_TABLE_BIT);
  2340. }
  2341. };
  2342. /*
  2343. The following class is used to optimize comparing of date and bigint columns
  2344. We need to save the original item ('ref') to be able to call
  2345. ref->save_in_field(). This is used to create index search keys.
  2346. An instance of Item_int_with_ref may have signed or unsigned integer value.
  2347. */
  2348. class Item_int_with_ref :public Item_int
  2349. {
  2350. Item *ref;
  2351. public:
  2352. Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) :
  2353. Item_int(i), ref(ref_arg)
  2354. {
  2355. unsigned_flag= unsigned_arg;
  2356. }
  2357. int save_in_field(Field *field, bool no_conversions)
  2358. {
  2359. return ref->save_in_field(field, no_conversions);
  2360. }
  2361. Item *clone_item();
  2362. virtual Item *real_item() { return ref; }
  2363. };
  2364. #ifdef MYSQL_SERVER
  2365. #include "gstream.h"
  2366. #include "spatial.h"
  2367. #include "item_sum.h"
  2368. #include "item_func.h"
  2369. #include "item_row.h"
  2370. #include "item_cmpfunc.h"
  2371. #include "item_strfunc.h"
  2372. #include "item_geofunc.h"
  2373. #include "item_timefunc.h"
  2374. #include "item_subselect.h"
  2375. #include "item_xmlfunc.h"
  2376. #include "item_create.h"
  2377. #endif
  2378. /**
  2379. Base class to implement typed value caching Item classes
  2380. Item_copy_ classes are very similar to the corresponding Item_
  2381. classes (e.g. Item_copy_int is similar to Item_int) but they add
  2382. the following additional functionality to Item_ :
  2383. 1. Nullability
  2384. 2. Possibility to store the value not only on instantiation time,
  2385. but also later.
  2386. Item_copy_ classes are a functionality subset of Item_cache_
  2387. classes, as e.g. they don't support comparisons with the original Item
  2388. as Item_cache_ classes do.
  2389. Item_copy_ classes are used in GROUP BY calculation.
  2390. TODO: Item_copy should be made an abstract interface and Item_copy_
  2391. classes should inherit both the respective Item_ class and the interface.
  2392. Ideally we should drop Item_copy_ classes altogether and merge
  2393. their functionality to Item_cache_ (and these should be made to inherit
  2394. from Item_).
  2395. */
  2396. class Item_copy :public Item
  2397. {
  2398. protected:
  2399. /**
  2400. Stores the type of the resulting field that would be used to store the data
  2401. in the cache. This is to avoid calls to the original item.
  2402. */
  2403. enum enum_field_types cached_field_type;
  2404. /** The original item that is copied */
  2405. Item *item;
  2406. /**
  2407. Stores the result type of the original item, so it can be returned
  2408. without calling the original item's method
  2409. */
  2410. Item_result cached_result_type;
  2411. /**
  2412. Constructor of the Item_copy class
  2413. stores metadata information about the original class as well as a
  2414. pointer to it.
  2415. */
  2416. Item_copy(Item *i)
  2417. {
  2418. item= i;
  2419. null_value=maybe_null=item->maybe_null;
  2420. decimals=item->decimals;
  2421. max_length=item->max_length;
  2422. name=item->name;
  2423. cached_field_type= item->field_type();
  2424. cached_result_type= item->result_type();
  2425. unsigned_flag= item->unsigned_flag;
  2426. }
  2427. public:
  2428. /**
  2429. Factory method to create the appropriate subclass dependent on the type of
  2430. the original item.
  2431. @param item the original item.
  2432. */
  2433. static Item_copy *create (Item *item);
  2434. /**
  2435. Update the cache with the value of the original item
  2436. This is the method that updates the cached value.
  2437. It must be explicitly called by the user of this class to store the value
  2438. of the orginal item in the cache.
  2439. */
  2440. virtual void copy() = 0;
  2441. Item *get_item() { return item; }
  2442. /** All of the subclasses should have the same type tag */
  2443. enum Type type() const { return COPY_STR_ITEM; }
  2444. enum_field_types field_type() const { return cached_field_type; }
  2445. enum Item_result result_type () const { return cached_result_type; }
  2446. void make_field(Send_field *field) { item->make_field(field); }
  2447. table_map used_tables() const { return (table_map) 1L; }
  2448. bool const_item() const { return 0; }
  2449. bool is_null() { return null_value; }
  2450. /*
  2451. Override the methods below as pure virtual to make sure all the
  2452. sub-classes implement them.
  2453. */
  2454. virtual String *val_str(String*) = 0;
  2455. virtual my_decimal *val_decimal(my_decimal *) = 0;
  2456. virtual double val_real() = 0;
  2457. virtual longlong val_int() = 0;
  2458. virtual int save_in_field(Field *field, bool no_conversions) = 0;
  2459. };
  2460. /**
  2461. Implementation of a string cache.
  2462. Uses Item::str_value for storage
  2463. */
  2464. class Item_copy_string : public Item_copy
  2465. {
  2466. public:
  2467. Item_copy_string (Item *item) : Item_copy(item) {}
  2468. String *val_str(String*);
  2469. my_decimal *val_decimal(my_decimal *);
  2470. double val_real();
  2471. longlong val_int();
  2472. void copy();
  2473. int save_in_field(Field *field, bool no_conversions);
  2474. };
  2475. class Item_copy_int : public Item_copy
  2476. {
  2477. protected:
  2478. longlong cached_value;
  2479. public:
  2480. Item_copy_int (Item *i) : Item_copy(i) {}
  2481. int save_in_field(Field *field, bool no_conversions);
  2482. virtual String *val_str(String*);
  2483. virtual my_decimal *val_decimal(my_decimal *);
  2484. virtual double val_real()
  2485. {
  2486. return null_value ? 0.0 : (double) cached_value;
  2487. }
  2488. virtual longlong val_int()
  2489. {
  2490. return null_value ? LL(0) : cached_value;
  2491. }
  2492. virtual void copy();
  2493. };
  2494. class Item_copy_uint : public Item_copy_int
  2495. {
  2496. public:
  2497. Item_copy_uint (Item *item) : Item_copy_int(item)
  2498. {
  2499. unsigned_flag= 1;
  2500. }
  2501. String *val_str(String*);
  2502. double val_real()
  2503. {
  2504. return null_value ? 0.0 : (double) (ulonglong) cached_value;
  2505. }
  2506. };
  2507. class Item_copy_float : public Item_copy
  2508. {
  2509. protected:
  2510. double cached_value;
  2511. public:
  2512. Item_copy_float (Item *i) : Item_copy(i) {}
  2513. int save_in_field(Field *field, bool no_conversions);
  2514. String *val_str(String*);
  2515. my_decimal *val_decimal(my_decimal *);
  2516. double val_real()
  2517. {
  2518. return null_value ? 0.0 : cached_value;
  2519. }
  2520. longlong val_int()
  2521. {
  2522. return (longlong) rint(val_real());
  2523. }
  2524. void copy()
  2525. {
  2526. cached_value= item->val_real();
  2527. null_value= item->null_value;
  2528. }
  2529. };
  2530. class Item_copy_decimal : public Item_copy
  2531. {
  2532. protected:
  2533. my_decimal cached_value;
  2534. public:
  2535. Item_copy_decimal (Item *i) : Item_copy(i) {}
  2536. int save_in_field(Field *field, bool no_conversions);
  2537. String *val_str(String*);
  2538. my_decimal *val_decimal(my_decimal *)
  2539. {
  2540. return null_value ? NULL: &cached_value;
  2541. }
  2542. double val_real();
  2543. longlong val_int();
  2544. void copy();
  2545. };
  2546. class Cached_item :public Sql_alloc
  2547. {
  2548. public:
  2549. my_bool null_value;
  2550. Cached_item() :null_value(0) {}
  2551. virtual bool cmp(void)=0;
  2552. virtual ~Cached_item(); /*line -e1509 */
  2553. };
  2554. class Cached_item_str :public Cached_item
  2555. {
  2556. Item *item;
  2557. String value,tmp_value;
  2558. public:
  2559. Cached_item_str(THD *thd, Item *arg);
  2560. bool cmp(void);
  2561. ~Cached_item_str(); // Deallocate String:s
  2562. };
  2563. class Cached_item_real :public Cached_item
  2564. {
  2565. Item *item;
  2566. double value;
  2567. public:
  2568. Cached_item_real(Item *item_par) :item(item_par),value(0.0) {}
  2569. bool cmp(void);
  2570. };
  2571. class Cached_item_int :public Cached_item
  2572. {
  2573. Item *item;
  2574. longlong value;
  2575. public:
  2576. Cached_item_int(Item *item_par) :item(item_par),value(0) {}
  2577. bool cmp(void);
  2578. };
  2579. class Cached_item_decimal :public Cached_item
  2580. {
  2581. Item *item;
  2582. my_decimal value;
  2583. public:
  2584. Cached_item_decimal(Item *item_par);
  2585. bool cmp(void);
  2586. };
  2587. class Cached_item_field :public Cached_item
  2588. {
  2589. uchar *buff;
  2590. Field *field;
  2591. uint length;
  2592. public:
  2593. Cached_item_field(Item_field *item)
  2594. {
  2595. field= item->field;
  2596. buff= (uchar*) sql_calloc(length=field->pack_length());
  2597. }
  2598. bool cmp(void);
  2599. };
  2600. class Item_default_value : public Item_field
  2601. {
  2602. public:
  2603. Item *arg;
  2604. Item_default_value(Name_resolution_context *context_arg)
  2605. :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
  2606. (const char *)NULL),
  2607. arg(NULL) {}
  2608. Item_default_value(Name_resolution_context *context_arg, Item *a)
  2609. :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
  2610. (const char *)NULL),
  2611. arg(a) {}
  2612. enum Type type() const { return DEFAULT_VALUE_ITEM; }
  2613. bool eq(const Item *item, bool binary_cmp) const;
  2614. bool fix_fields(THD *, Item **);
  2615. virtual void print(String *str, enum_query_type query_type);
  2616. int save_in_field(Field *field_arg, bool no_conversions);
  2617. table_map used_tables() const { return (table_map)0L; }
  2618. bool walk(Item_processor processor, bool walk_subquery, uchar *args)
  2619. {
  2620. return arg->walk(processor, walk_subquery, args) ||
  2621. (this->*processor)(args);
  2622. }
  2623. Item *transform(Item_transformer transformer, uchar *args);
  2624. };
  2625. /*
  2626. Item_insert_value -- an implementation of VALUES() function.
  2627. You can use the VALUES(col_name) function in the UPDATE clause
  2628. to refer to column values from the INSERT portion of the INSERT
  2629. ... UPDATE statement. In other words, VALUES(col_name) in the
  2630. UPDATE clause refers to the value of col_name that would be
  2631. inserted, had no duplicate-key conflict occurred.
  2632. In all other places this function returns NULL.
  2633. */
  2634. class Item_insert_value : public Item_field
  2635. {
  2636. public:
  2637. Item *arg;
  2638. Item_insert_value(Name_resolution_context *context_arg, Item *a)
  2639. :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
  2640. (const char *)NULL),
  2641. arg(a) {}
  2642. bool eq(const Item *item, bool binary_cmp) const;
  2643. bool fix_fields(THD *, Item **);
  2644. virtual void print(String *str, enum_query_type query_type);
  2645. int save_in_field(Field *field_arg, bool no_conversions)
  2646. {
  2647. return Item_field::save_in_field(field_arg, no_conversions);
  2648. }
  2649. /*
  2650. We use RAND_TABLE_BIT to prevent Item_insert_value from
  2651. being treated as a constant and precalculated before execution
  2652. */
  2653. table_map used_tables() const { return RAND_TABLE_BIT; }
  2654. bool walk(Item_processor processor, bool walk_subquery, uchar *args)
  2655. {
  2656. return arg->walk(processor, walk_subquery, args) ||
  2657. (this->*processor)(args);
  2658. }
  2659. };
  2660. class Table_triggers_list;
  2661. /*
  2662. Represents NEW/OLD version of field of row which is
  2663. changed/read in trigger.
  2664. Note: For this item main part of actual binding to Field object happens
  2665. not during fix_fields() call (like for Item_field) but right after
  2666. parsing of trigger definition, when table is opened, with special
  2667. setup_field() call. On fix_fields() stage we simply choose one of
  2668. two Field instances representing either OLD or NEW version of this
  2669. field.
  2670. */
  2671. class Item_trigger_field : public Item_field,
  2672. private Settable_routine_parameter
  2673. {
  2674. public:
  2675. /* Is this item represents row from NEW or OLD row ? */
  2676. enum row_version_type {OLD_ROW, NEW_ROW};
  2677. row_version_type row_version;
  2678. /* Next in list of all Item_trigger_field's in trigger */
  2679. Item_trigger_field *next_trg_field;
  2680. /* Index of the field in the TABLE::field array */
  2681. uint field_idx;
  2682. /* Pointer to Table_trigger_list object for table of this trigger */
  2683. Table_triggers_list *triggers;
  2684. Item_trigger_field(Name_resolution_context *context_arg,
  2685. row_version_type row_ver_arg,
  2686. const char *field_name_arg,
  2687. ulong priv, const bool ro)
  2688. :Item_field(context_arg,
  2689. (const char *)NULL, (const char *)NULL, field_name_arg),
  2690. row_version(row_ver_arg), field_idx((uint)-1), original_privilege(priv),
  2691. want_privilege(priv), table_grants(NULL), read_only (ro)
  2692. {}
  2693. void setup_field(THD *thd, TABLE *table, GRANT_INFO *table_grant_info);
  2694. enum Type type() const { return TRIGGER_FIELD_ITEM; }
  2695. bool eq(const Item *item, bool binary_cmp) const;
  2696. bool fix_fields(THD *, Item **);
  2697. virtual void print(String *str, enum_query_type query_type);
  2698. table_map used_tables() const { return (table_map)0L; }
  2699. Field *get_tmp_table_field() { return 0; }
  2700. Item *copy_or_same(THD *thd) { return this; }
  2701. Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
  2702. void cleanup();
  2703. private:
  2704. void set_required_privilege(bool rw);
  2705. bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
  2706. public:
  2707. Settable_routine_parameter *get_settable_routine_parameter()
  2708. {
  2709. return (read_only ? 0 : this);
  2710. }
  2711. bool set_value(THD *thd, Item **it)
  2712. {
  2713. return set_value(thd, NULL, it);
  2714. }
  2715. private:
  2716. /*
  2717. 'want_privilege' holds privileges required to perform operation on
  2718. this trigger field (SELECT_ACL if we are going to read it and
  2719. UPDATE_ACL if we are going to update it). It is initialized at
  2720. parse time but can be updated later if this trigger field is used
  2721. as OUT or INOUT parameter of stored routine (in this case
  2722. set_required_privilege() is called to appropriately update
  2723. want_privilege and cleanup() is responsible for restoring of
  2724. original want_privilege once parameter's value is updated).
  2725. */
  2726. ulong original_privilege;
  2727. ulong want_privilege;
  2728. GRANT_INFO *table_grants;
  2729. /*
  2730. Trigger field is read-only unless it belongs to the NEW row in a
  2731. BEFORE INSERT of BEFORE UPDATE trigger.
  2732. */
  2733. bool read_only;
  2734. };
  2735. class Item_cache: public Item_basic_constant
  2736. {
  2737. protected:
  2738. Item *example;
  2739. table_map used_table_map;
  2740. /*
  2741. Field that this object will get value from. This is set/used by
  2742. index-based subquery engines to detect and remove the equality injected
  2743. by IN->EXISTS transformation.
  2744. For all other uses of Item_cache, cached_field doesn't matter.
  2745. */
  2746. Field *cached_field;
  2747. enum enum_field_types cached_field_type;
  2748. /*
  2749. TRUE <=> cache holds value of the last stored item (i.e actual value).
  2750. store() stores item to be cached and sets this flag to FALSE.
  2751. On the first call of val_xxx function if this flag is set to FALSE the
  2752. cache_value() will be called to actually cache value of saved item.
  2753. cache_value() will set this flag to TRUE.
  2754. */
  2755. bool value_cached;
  2756. public:
  2757. Item_cache():
  2758. example(0), used_table_map(0), cached_field(0),
  2759. cached_field_type(MYSQL_TYPE_STRING),
  2760. value_cached(0)
  2761. {
  2762. fixed= 1;
  2763. null_value= 1;
  2764. }
  2765. Item_cache(enum_field_types field_type_arg):
  2766. example(0), used_table_map(0), cached_field(0),
  2767. cached_field_type(field_type_arg),
  2768. value_cached(0)
  2769. {
  2770. fixed= 1;
  2771. null_value= 1;
  2772. }
  2773. void set_used_tables(table_map map) { used_table_map= map; }
  2774. virtual bool allocate(uint i) { return 0; }
  2775. virtual bool setup(Item *item)
  2776. {
  2777. example= item;
  2778. max_length= item->max_length;
  2779. decimals= item->decimals;
  2780. collation.set(item->collation);
  2781. unsigned_flag= item->unsigned_flag;
  2782. if (item->type() == FIELD_ITEM)
  2783. cached_field= ((Item_field *)item)->field;
  2784. return 0;
  2785. };
  2786. enum Type type() const { return CACHE_ITEM; }
  2787. enum_field_types field_type() const { return cached_field_type; }
  2788. static Item_cache* get_cache(const Item *item);
  2789. static Item_cache* get_cache(const Item* item, const Item_result type);
  2790. table_map used_tables() const { return used_table_map; }
  2791. virtual void keep_array() {}
  2792. virtual void print(String *str, enum_query_type query_type);
  2793. bool eq_def(Field *field)
  2794. {
  2795. return cached_field ? cached_field->eq_def (field) : FALSE;
  2796. }
  2797. bool eq(const Item *item, bool binary_cmp) const
  2798. {
  2799. return this == item;
  2800. }
  2801. virtual void store(Item *item);
  2802. virtual bool cache_value()= 0;
  2803. bool basic_const_item() const
  2804. { return test(example && example->basic_const_item());}
  2805. };
  2806. class Item_cache_int: public Item_cache
  2807. {
  2808. protected:
  2809. longlong value;
  2810. public:
  2811. Item_cache_int(): Item_cache(),
  2812. value(0) {}
  2813. Item_cache_int(enum_field_types field_type_arg):
  2814. Item_cache(field_type_arg), value(0) {}
  2815. virtual void store(Item *item){ Item_cache::store(item); }
  2816. void store(Item *item, longlong val_arg);
  2817. double val_real();
  2818. longlong val_int();
  2819. String* val_str(String *str);
  2820. my_decimal *val_decimal(my_decimal *);
  2821. enum Item_result result_type() const { return INT_RESULT; }
  2822. bool result_as_longlong() { return TRUE; }
  2823. bool cache_value();
  2824. };
  2825. class Item_cache_real: public Item_cache
  2826. {
  2827. double value;
  2828. public:
  2829. Item_cache_real(): Item_cache(),
  2830. value(0) {}
  2831. double val_real();
  2832. longlong val_int();
  2833. String* val_str(String *str);
  2834. my_decimal *val_decimal(my_decimal *);
  2835. enum Item_result result_type() const { return REAL_RESULT; }
  2836. bool cache_value();
  2837. };
  2838. class Item_cache_decimal: public Item_cache
  2839. {
  2840. protected:
  2841. my_decimal decimal_value;
  2842. public:
  2843. Item_cache_decimal(): Item_cache() {}
  2844. double val_real();
  2845. longlong val_int();
  2846. String* val_str(String *str);
  2847. my_decimal *val_decimal(my_decimal *);
  2848. enum Item_result result_type() const { return DECIMAL_RESULT; }
  2849. bool cache_value();
  2850. };
  2851. class Item_cache_str: public Item_cache
  2852. {
  2853. char buffer[STRING_BUFFER_USUAL_SIZE];
  2854. String *value, value_buff;
  2855. bool is_varbinary;
  2856. public:
  2857. Item_cache_str(const Item *item) :
  2858. Item_cache(item->field_type()), value(0),
  2859. is_varbinary(item->type() == FIELD_ITEM &&
  2860. cached_field_type == MYSQL_TYPE_VARCHAR &&
  2861. !((const Item_field *) item)->field->has_charset())
  2862. {}
  2863. double val_real();
  2864. longlong val_int();
  2865. String* val_str(String *);
  2866. my_decimal *val_decimal(my_decimal *);
  2867. enum Item_result result_type() const { return STRING_RESULT; }
  2868. CHARSET_INFO *charset() const { return value->charset(); };
  2869. int save_in_field(Field *field, bool no_conversions);
  2870. bool cache_value();
  2871. };
  2872. class Item_cache_row: public Item_cache
  2873. {
  2874. Item_cache **values;
  2875. uint item_count;
  2876. bool save_array;
  2877. public:
  2878. Item_cache_row()
  2879. :Item_cache(), values(0), item_count(2),
  2880. save_array(0) {}
  2881. /*
  2882. 'allocate' used only in row transformer, to preallocate space for row
  2883. cache.
  2884. */
  2885. bool allocate(uint num);
  2886. /*
  2887. 'setup' is needed only by row => it not called by simple row subselect
  2888. (only by IN subselect (in subselect optimizer))
  2889. */
  2890. bool setup(Item *item);
  2891. void store(Item *item);
  2892. void illegal_method_call(const char *);
  2893. void make_field(Send_field *)
  2894. {
  2895. illegal_method_call((const char*)"make_field");
  2896. };
  2897. double val_real()
  2898. {
  2899. illegal_method_call((const char*)"val");
  2900. return 0;
  2901. };
  2902. longlong val_int()
  2903. {
  2904. illegal_method_call((const char*)"val_int");
  2905. return 0;
  2906. };
  2907. String *val_str(String *)
  2908. {
  2909. illegal_method_call((const char*)"val_str");
  2910. return 0;
  2911. };
  2912. my_decimal *val_decimal(my_decimal *val)
  2913. {
  2914. illegal_method_call((const char*)"val_decimal");
  2915. return 0;
  2916. };
  2917. enum Item_result result_type() const { return ROW_RESULT; }
  2918. uint cols() { return item_count; }
  2919. Item *element_index(uint i) { return values[i]; }
  2920. Item **addr(uint i) { return (Item **) (values + i); }
  2921. bool check_cols(uint c);
  2922. bool null_inside();
  2923. void bring_value();
  2924. void keep_array() { save_array= 1; }
  2925. void cleanup()
  2926. {
  2927. DBUG_ENTER("Item_cache_row::cleanup");
  2928. Item_cache::cleanup();
  2929. if (save_array)
  2930. bzero(values, item_count*sizeof(Item**));
  2931. else
  2932. values= 0;
  2933. DBUG_VOID_RETURN;
  2934. }
  2935. bool cache_value();
  2936. };
  2937. class Item_cache_datetime: public Item_cache
  2938. {
  2939. protected:
  2940. String str_value;
  2941. ulonglong int_value;
  2942. bool str_value_cached;
  2943. public:
  2944. Item_cache_datetime(enum_field_types field_type_arg):
  2945. Item_cache(field_type_arg), int_value(0), str_value_cached(0)
  2946. {
  2947. cmp_context= STRING_RESULT;
  2948. }
  2949. void store(Item *item, longlong val_arg);
  2950. double val_real();
  2951. longlong val_int();
  2952. String* val_str(String *str);
  2953. my_decimal *val_decimal(my_decimal *);
  2954. enum Item_result result_type() const { return STRING_RESULT; }
  2955. bool result_as_longlong() { return TRUE; }
  2956. /*
  2957. In order to avoid INT <-> STRING conversion of a DATETIME value
  2958. two cache_value functions are introduced. One (cache_value) caches STRING
  2959. value, another (cache_value_int) - INT value. Thus this cache item
  2960. completely relies on the ability of the underlying item to do the
  2961. correct conversion.
  2962. */
  2963. bool cache_value_int();
  2964. bool cache_value();
  2965. };
  2966. /*
  2967. Item_type_holder used to store type. name, length of Item for UNIONS &
  2968. derived tables.
  2969. Item_type_holder do not need cleanup() because its time of live limited by
  2970. single SP/PS execution.
  2971. */
  2972. class Item_type_holder: public Item
  2973. {
  2974. protected:
  2975. TYPELIB *enum_set_typelib;
  2976. enum_field_types fld_type;
  2977. Field::geometry_type geometry_type;
  2978. void get_full_info(Item *item);
  2979. /* It is used to count decimal precision in join_types */
  2980. int prev_decimal_int_part;
  2981. public:
  2982. Item_type_holder(THD*, Item*);
  2983. Item_result result_type() const;
  2984. enum_field_types field_type() const { return fld_type; };
  2985. enum Type type() const { return TYPE_HOLDER; }
  2986. double val_real();
  2987. longlong val_int();
  2988. my_decimal *val_decimal(my_decimal *);
  2989. String *val_str(String*);
  2990. bool join_types(THD *thd, Item *);
  2991. Field *make_field_by_type(TABLE *table);
  2992. static uint32 display_length(Item *item);
  2993. static enum_field_types get_real_type(Item *);
  2994. Field::geometry_type get_geometry_type() const { return geometry_type; };
  2995. };
  2996. class st_select_lex;
  2997. void mark_select_range_as_dependent(THD *thd,
  2998. st_select_lex *last_select,
  2999. st_select_lex *current_sel,
  3000. Field *found_field, Item *found_item,
  3001. Item_ident *resolved_item);
  3002. extern Cached_item *new_Cached_item(THD *thd, Item *item);
  3003. extern Item_result item_cmp_type(Item_result a,Item_result b);
  3004. extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
  3005. extern int stored_field_cmp_to_item(THD *thd, Field *field, Item *item);
  3006. extern const String my_null_string;
  3007. #endif /* ITEM_INCLUDED */