summaryrefslogtreecommitdiff
path: root/sql/item_timefunc.h
Commit message (Collapse)AuthorAgeFilesLines
* Merge 10.2 into 10.3Marko Mäkelä2019-05-141-1/+1
|\
| * Merge 10.1 into 10.2Marko Mäkelä2019-05-131-1/+1
| |\
| | * Merge branch '5.5' into 10.1Vicențiu Ciorbaru2019-05-111-1/+1
| | |\
| | | * Update FSF AddressVicențiu Ciorbaru2019-05-111-1/+1
| | | | | | | | | | | | | | | | * Update wrong zip-code
* | | | MDEV-16878 Functions ADDTIME and SUBTIME get wrongly removed from WHERE by ↵Alexander Barkov2018-08-021-2/+4
| | | | | | | | | | | | | | | | the equal expression optimizer
* | | | Merge commit '6b8802e8dd5467556a024d807a1df23940b00895' into bb-10.3-fix_len_decbb-10.3-fix_len_decOleksandr Byelkin2018-06-191-59/+87
|\ \ \ \ | |/ / /
| * | | MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed in ↵Oleksandr Byelkin2018-06-151-53/+72
| | | | | | | | | | | | | | | | | | | | | | | | Locked_tables_list::unlock_locked_table fix_length_and_dec now return result (error/OK)
* | | | MDEV-15702 Remove the use of STRING_ITEM from ↵Alexander Barkov2018-03-281-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Item_func_date_format::fix_length_and_dec() Implementing the task according to the description. Additionally, implementing Item_func_date_format::check_arguments().
* | | | MDEV-14645: AS OF TIMESTAMP is misused as TRX_IDSergei Golubchik2018-02-241-14/+0
| | | | | | | | | | | | | | | | | | | | Remove 1668efb722d that introduced a special magic behavior for UNIX_TIMESTAMP() in the AS OF context
* | | | Merge bb-10.2-ext into 10.3Marko Mäkelä2018-02-151-0/+8
|\ \ \ \
| * | | | MDEV-15293 CAST(AS TIME) returns bad results for ↵Alexander Barkov2018-02-131-0/+8
| | | | | | | | | | | | | | | | | | | | LAST_VALUE(),NAME_CONST(),SP variable
* | | | | MDEV-15091 : Windows, 64bit: reenable and fix warning C4267 (conversion from ↵Vladislav Vaintroub2018-02-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 'size_t' to 'type', possible loss of data) Handle string length as size_t, consistently (almost always:)) Change function prototypes to accept size_t, where in the past ulong or uint were used. change local/member variables to size_t when appropriate. This fix excludes rocksdb, spider,spider, sphinx and connect for now.
* | | | | MDEV-14645: AS OF TIMESTAMP is misused as TRX_ID [fixes #396]Aleksey Midenkov2017-12-141-0/+14
| | | | |
* | | | | Merge bb-10.2-ext into 10.3Marko Mäkelä2017-11-301-2/+9
|\ \ \ \ \ | |/ / / /
| * | | | MDEV-14376 Explicit CAST(CHAR(N)) erroneously escalates warnings to errors ↵Alexander Barkov2017-11-131-2/+9
| | | | | | | | | | | | | | | | | | | | in STRICT_ALL_TABLES
* | | | | Remove not used mem_root argument from build_clone(), get_copy() and ↵Michael Widenius2017-11-231-92/+92
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | get_item_copy() TODO: - Make get_thd_memroot() inline - To do this, we need to reduce dependence of include files, especially so that sql_class.h is not depending in item.h
* | | | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2017-10-301-2/+0
|\ \ \ \ | |/ / /
| * | | Merge branch '10.1' into 10.2Sergei Golubchik2017-10-241-1/+9
| |\ \ \ | | |/ /
| | * | Merge branch '10.0' into 10.1Sergei Golubchik2017-10-221-1/+9
| | |\ \
| | | * \ Merge branch '5.5' into 10.0Sergei Golubchik2017-10-181-1/+9
| | | |\ \ | | | | |/
| | | | * MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column valueAlexander Barkov2017-10-061-1/+9
| | | | |
| | | | * MDEV-10524 Assertion `arg1_int >= 0' failed in ↵Alexander Barkov2016-12-191-12/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Item_func_additive_op::result_precision() This change is a backport from 10.0 to 5.5 for: 1. The full patch for: MDEV-4841 Wrong character set of ADDTIME() and DATE_ADD() 9adb6e991ec87b65d04929f115d9d0c899e4ab19 2. A small fragment of: MDEV-5298 Illegal mix of collations on timestamp 03f6778d61a74bdd7d09103a16473a2a5624cf66 which overrides Item_temporal_hybrid_func::cmp_type(), and adds a new line into cache_temporal_4265.result.
* | | | | Fixing Item_func_hybrid_field_type::date_op(,uint) to date_op(,ulonglong)Alexander Barkov2017-10-031-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixing the data type for the "fuzzydate" parameter to Item_func_hybrid_field_type::date_op() from uint to ulonglong, for consistency with Item::get_date().
* | | | | MDEV-13967 Parameter data type control for Item_long_funcAlexander Barkov2017-10-011-20/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Implementing stricter data type control for Item_long_func descendants - Cleanup: renaming Type_handler::can_return_str_ascii() to can_return_text() (a better name).
* | | | | MDEV-13966 Parameter data type control for Item_temporal_funcAlexander Barkov2017-09-301-0/+22
| | | | |
* | | | | MDEV-13965 Parameter data type control for Item_longlong_funcAlexander Barkov2017-09-291-0/+4
| | | | |
* | | | | MDEV-11553 Can't restore a PERSISTENT column that uses DATE_FORMAT()Sergei Golubchik2017-09-231-7/+20
| | | | | | | | | | | | | | | | | | | | 3-argument form of DATE_FORMAT
* | | | | Merge branch '10.2' into bb-10.2-extSergei Golubchik2017-09-231-0/+1
|\ \ \ \ \ | |/ / / /
| * | | | MDEV-13868 cannot insert 1288481126 in a timestamp column in Europe/MoscowSergei Golubchik2017-09-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | make insert NULL into a timestamp mark the field as having an explicit value. So that the field won't be assigned the value again in TABLE::update_default_field() make Item_func_now_local::save_in_field(timestamp_field) not to go through MYSQL_TIME - this conversion is lossy around DST change times. This fixes inserting a default value into a timestamp field.
* | | | | Merge 10.2 into bb-10.2-extMarko Mäkelä2017-09-201-3/+3
|\ \ \ \ \ | |/ / / /
| * | | | cleanupSergei Golubchik2017-09-181-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Item_func_format::print() was redundant and other changes
| * | | | bugfix: TIME_FORMAT() should be ok in stored generated columnsSergei Golubchik2017-09-181-0/+2
| | | | |
* | | | | Fixing a few data type related problems: MDEV-12875, MDEV-12886, MDEV-12916Alexander Barkov2017-05-251-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a joint patch fixing the following problems: MDEV-12875 Wrong VIEW column data type for COALESCE(int_column) MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable All above problem happened because the global function ::create_tmp_field() called the top-level Item::create_tmp_field(), which made some tranformation for INT-result data types. For example, INT(11) became BIGINT(11), because 11 is a corner case and it's not known if it fits or does not fit into INT range, so Item::create_tmp_field() converted it to BIGINT(11) for safety. The main idea of this patch is to avoid such tranformations. 1. Fixing Item::create_tmp_field() not to have a special case for INT_RESULT. Item::create_tmp_field() is changed not to have a special case for INT_RESULT (which earlier made a decision based on Item's max_length). It now calls tmp_table_field_from_field_type() for INT_RESULT, therefore preserves the original data type (e.g. INT, YEAR) without conversion to BIGINT. This change is valid, because a number of recent fixes (e.g. in Item_func_int, Item_hybrid_func, Item_int, Item_splocal) guarantee that item->type_handler() now properly returns type_handler_long vs type_handler_longlong. So no adjustment by length is needed any more for Items returning INT_RESULT. After this change, Item::create_tmp_field() calls tmp_table_field_from_field_type() for all XXX_RESULT, except REAL_RESULT. 2. Fixing Item::create_tmp_field() not to have a special case for REAL_RESULT. Note, the reason for a special case for REAL_RESULT is to have a special constructor for Field_double(), forcing Field_real::not_fixed to be set to true. Taking into account that only Item_sum descendants actually need a special constructor call Field_double(not_fixed=true), not too loose precision when mixing individual rows to the aggregate result: - renaming Item::create_tmp_field() to Item_sum::create_tmp_field(). - changing Item::create_tmp_field() just to call tmp_table_field_from_field_type() for all XXX_RESULT types. A special case for REAL_RESULT in Item::create_tmp_field() is now gone. Item::create_tmp_field() is now symmetric for all XXX_RESULT types, and now just calls tmp_table_field_from_field_type(). 3. Fixing Item_func::create_field_for_create_select() not to have a special case for STRING_RESULT. After changes #1 and #2, the code in Item_func::create_field_for_create_select(), testing result_type(), becomes useless, because: now Item::create_tmp_field() and tmp_table_field_from_field_type() do exactly the same thing for all XXX_RESULT types for Item_func descendants: a. It calls tmp_table_field_from_field_type for STRING_RESULT directly. b. For other XXX_RESULT, it goes through Item::create_tmp_field(), which calls the global function ::create_tmp_field(), which calls item->create_tmp_field() for FUNC_ITEM, which calls tmp_table_field_from_field_type() again. So removing the virtual implementation of Item_func::create_field_for_create_select(). The inherited Item::create_field_for_create_select() now perfectly does the job, as it also calls tmp_table_field_from_field_type() for FUNC_ITEM, independently from XXX_RESULT type. 4. Taking into account #1 and #2, as well as some recent changes, removing virtual implementations: - Item_hybrid_func::create_tmp_field() - Item_hybrid_func::create_field_for_create_select() - Item_int_func::create_tmp_field() - Item_int_func::create_field_for_create_select() - Item_temporal_func::create_field_for_create_select() The derived versions from Item now perfectly work. 5. Moving a piece of code from create_tmp_field_from_item() to a new function create_tmp_field_from_item_finalize(), to reuse it in two places (see #6). 6. Changing the code responsible for BIT->INT/BIGIN tranformation (which is called for the cases when the created table, e.g. HEAP, does not fully support BIT) not to call create_tmp_field_from_item(), because the latter now calls tmp_table_field_from_field_type() instead of create_tmp_field() and thefore cannot do BIT transformation. So rewriting this code using a sequence of these calls: - item->type_handler_long_or_longlong() - handler->make_and_init_table_field() - create_tmp_field_from_item_finalize() 7. Miscelaneous changes: - Moving type_handler_long_or_longlong() from "protected" to "public", as it's now needed in the global function create_tmp_field(). 8. The above changes fixed MDEV-12875, MDEV-12886, MDEV-12916. So adding tests for these bugs.
* | | | | Fixing a few problems with data type and metadata for INT result functions ↵Alexander Barkov2017-05-231-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (MDEV-12852, MDEV-12853, MDEV-12869) This is a joint patch for: MDEV-12852 Out-of-range errors when CAST(1-2 AS UNSIGNED MDEV-12853 Out-of-range errors when CAST('-1' AS UNSIGNED MDEV-12869 Wrong metadata for integer additive and multiplicative operators 1. Fixing all Item_func_numhybrid descendants to set the precise data type handler (type_handler_long or type_handler_longlong) at fix_fields() time. This fixes MDEV-12869. 2. Fixing Item_func_unsigned_typecast to set the precise data type handler at fix_fields() time. This fixes MDEV-12852 and MDEV-12853. This is done by: - fixing Type_handler::Item_func_unsigned_fix_length_and_dec() and Type_handler_string_result::Item_func_unsigned_fix_length_and_dec() to properly detect situations when a negative epxression is converted to UNSIGNED. In this case, length of the result is now always set to MAX_BIGINT_WIDTH without trying to use args[0]->max_length, as very short arguments can produce very long result in such conversion: CAST(-1 AS UNSIGNED) -> 18446744073709551614 - adding a new virtual method "longlong Item::val_int_max() const", to preserve the old behavior for expressions like this: CAST(1 AS UNSIGNED) to stay under the INT data type (instead of BIGINT) for small positive integer literals. Using Item::unsigned_flag would not help, because Item_int does not set unsigned_flag to "true" for positive numbers. 3. Adding helper methods: * Item::type_handler_long_or_longlong() * Type_handler::type_handler_long_or_longlong() and reusing them in a few places, to reduce code duplication. 4. Making reorganation in create_tmp_field() and create_field_for_create_select() for Item_hybrid_func and descendants, to reduce duplicate code. They all now have a similar behavior in respect of creating fields. Only Item_func_user_var descendants have a different behavior. So moving the default behvior to Item_hybrid_func, and overriding behavior on Item_func_user_var level.
* | | | | MDEV-12866 Out-of-range error with CREATE..SELECT..TO_SECONDS(NOW())Alexander Barkov2017-05-221-3/+3
| | | | |
* | | | | MDEV-12856 Wrong .. metadata for DIV + MDEV-12857..errors on ↵Alexander Barkov2017-05-211-5/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CREATE..SELECT..DIV This is a joint patch for: MDEV-12856 Wrong result set metadata for DIV MDEV-12857 Out-of-range errors on CREATE..SELECT 2222222222 DIV 1
* | | | | MDEV-12854 Synchronize CREATE..SELECT data type and result set metadata data ↵Alexander Barkov2017-05-201-32/+35
| | | | | | | | | | | | | | | | | | | | type for INT functions
* | | | | MDEV-12719 Determine Item::result_type() from Item::type_handler()Alexander Barkov2017-05-071-4/+0
| | | | |
* | | | | MDEV-12718 Determine Item::cmp_type() from Item::type_handler()Alexander Barkov2017-05-071-1/+0
| | | | |
* | | | | MDEV-12714 Determine Item::field_type() from Item::type_handler()Alexander Barkov2017-05-061-13/+0
| | | | |
* | | | | MDEV-12713 Define virtual type_handler() for all Item classesAlexander Barkov2017-05-061-3/+16
| | | | |
* | | | | MDEV-9217 Split Item::tmp_table_field_from_field_type() into virtual methods ↵Alexander Barkov2017-04-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in Type_handler - Adding Type_handler::make_table_field() and moving pieces of the code from Item::tmp_table_field_from_field_type() to virtual implementations for various type handlers. - Adding a new Type_all_attributes, to access to Item's extended attributes, such as decimal_precision() and geometry_type(). - Adding a new class Record_addr, to pass record related information to Type_handler methods (ptr, null_ptr and null_bit) as a single structure. Note, later it will possibly be extended for BIT-alike field purposes, by adding new members (bit_ptr_arg, bit_ofs_arg). - Moving the code from Field_new_decimal::create_from_item() to Type_handler_newdecimal::make_table_field(). - Removing Field_new_decimal() and Field_geom() helper constructor variants that were used for temporary field creation. - Adding Item_field::type_handler(), Field::type_handler() and Field_blob::type_handler() to return correct type handlers for blob variants, according to Field_blob::packlength. - Adding Type_handler_blob_common, as a common parent for Type_handler_tiny_blob, Type_handler_blob, Type_handler_medium_blob and Type_handler_long_blob. - Implementing Type_handler_blob_common::Item_hybrid_func_fix_attributes(). It's needed for cases when TEXT variants of different character sets are mixed in LEAST, GREATEST, CASE and its abreviations (IF, IFNULL, COALESCE), e.g.: CREATE TABLE t1 ( a TINYTEXT CHARACTER SET latin1, b TINYTEXT CHARACTER SET utf8 ); CREATE TABLE t2 AS SELECT COALESCE(a,b) FROM t1; Type handler aggregation returns TINYTEXT as a common data type for the two columns. But as conversion from latin1 to utf8 happens for "a", the maximum possible length of "a" grows from 255 to 255*3. Type_handler_blob_common::Item_hybrid_func_fix_attributes() makes sure to update the blob type handler according to max_length. - Adding Type_handler::blob_type_handler(uint max_octet_length). - Adding a few m_type_aggregator_for_result.add() pairs, because now Item_xxx::type_handler() can return pointers to type_handler_tiny_blob, type_handler_blob, type_handler_medium_blob, type_handler_long_blob. Before the patch only type_handler_blob was possible result of type_handler(). - Making type_handler_tiny_blob, type_handler_blob, type_handler_medium_blob, type_handler_long_blob public. - Removing the condition in Item_sum_avg::create_tmp_field() checking Item_sum_avg::result_type() against DECIMAL_RESULT. Now both REAL_RESULT and DECIMAL_RESULT are symmetrically handled by tmp_table_field_from_field_type(). - Removing Item_geometry_func::create_field_for_create_select(), as the inherited version perfectly works. - Fixing Item_func_as_wkb::field_type() to return MYSQL_TYPE_LONG_BLOB rather than MYSQL_TYPE_BLOB. It's needed to make sure that tmp_table_field_from_field_type() creates a LONGBLOB field for AsWKB(). - Fixing Item_func_as_wkt::fix_length_and_dec() to set max_length to UINT32_MAX rather than MAX_BLOB_WIDTH, to make sure that tmp_table_field_from_field_type() creates a LONGTEXT field for AsWKT(). - Removing Item_func_set_user_var::create_field_for_create_select(), as the inherited version works fine. - Adding Item_func_get_user_var::create_field_for_create_select() to make sure that "CREATE TABLE t1 AS SELECT @string_user variable" always creates a field of LONGTEXT/LONGBLOB type. - Item_func_ifnull::create_field_for_create_select() behavior has changed. Before the patch it passed set_blob_packflag=false, which meant to create LONGBLOB for all blob variants. Now it takes into account max_length, which gives better column data types for: CREATE TABLE t2 AS SELECT IFNULL(blob_column1, blob_column2) FROM t1; - Fixing Item_func_nullif::fix_length_and_dec() to use set_handler(args[2]->type_handler()) instead of set_handler_by_field_type(args[2]->field_type()). This is needed to distinguish between BLOB variants. - Implementing Item_blob::type_handler(), to make sure to create proper BLOB field variant, according to max_length, for queries like: CREATE TABLE t1 AS SELECT some_blob_field FROM INFORMATION_SCHEMA.SOME_TABLE; - Fixing Item_field::real_type_handler() to make sure that the code aggregating fields for UNION gets a proper BLOB variant type handler from fields. - Adding a special code into Item_type_holder::make_field_by_type(), to make sure that after aggregating field types it also properly takes into account max_length when mixing TEXT variants of different character sets and chooses a proper TEXT variant: CREATE TABLE t1 ( a TINYTEXT CHARACTER SET latin1, b TINYTEXT CHARACTER SET utf8 ); CREATE TABLE t2 AS SELECT a FROM t1 UNION SELECT b FROM t1; - Adding tests, for better coverage of IFNULL, NULLIF, UNION. - The fact that tmp_table_field_from_field_type() now takes into account BLOB variants (instead of always creating LONGBLOB), tests results for WEIGHT_STRING() and NULLIF() and UNION have become more precise.
* | | | | MDEV-12559 Split Item::temporal_precision() into virtual methods in Type_handlerAlexander Barkov2017-04-221-20/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Adding a new virtual method Type_handler::Item_time_precision() - Adding a new virtual method Type_handler::Item_datetime_precision() - Removing Item::temporal_precision() and adding Item::time_precision() and Item::datetime_precision() instead. - Moving Item_func_convert_tz::fix_length_and_dec() from item_timefunc.cc to item_timefunc.h. It's only two lines, and we're changing it anyway. - Removing Item_temporal_typecast::fix_length_and_dec_generic(), moving this code to Type_handler::Item_{date|time|datetime}_typecast_fix_length_and_dec(). This allows to get rid of one more field_type() call. Also, in the old reduction, Item_date_typecast::fix_length_and_dec() unnecessarily called args[0]->temporal_precision(). The new reduction does not call args[0]->datetime_precision(), as DATE does not have fractional digits.
* | | | | MDEV-12514 Split Item_temporal_func::fix_length_and_dec() + MDEV-12515Alexander Barkov2017-04-191-31/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements MDEV-12514 according to the task descriptions. It automatically fixes: MDEV-12515 Wrong value when storing DATE_ADD() and ADDTIME() to a numeric field Additionally: a. Moves Item_func::set_attributes_temporal() to Type_str_attributes::fix_attributes_temporal(), which is a more proper place and name for it. b. Continues replacing calls for: set_handler_by_field_type(MYSQL_TYPE_XXX) to corresponding: set_handler(&type_handler_xxx) which is faster. Note, we should eventually get rid of almost all set_handler_by_field_type(). c. Makes type_handler_string, type_handler_time2, type_handler_newdate, type_handler_datetime2 public. (all built-in handlers will become public eventually) d. Removing Item_temporal_func::sql_mode, as it was not used.
* | | | | Derive Item_func_makedate from Item_datefunc rather than Item_temporal_funcAlexander Barkov2017-04-151-3/+3
| | | | |
* | | | | MDEV-12303 Add Type_handler::Item_xxx_fix_length_and_dec() for CAST classesAlexander Barkov2017-04-041-2/+21
| | | | |
* | | | | MDEV-11672 mysql_list_field() returns wrong default values for VIEWAlexander Barkov2016-12-291-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem happened because Item_ident_for_show::field_type() always returned MYSQL_TYPE_DOUBLE and ignored the actual data type of the referenced Field. As a result, the execution always used Item_ident_for_show::val_real() to send the default value of the field, so most default values for non-numeric types were displayed as '0'. This patch: 1. Cleanup: a. Removes Send_field::charsetnr, as it's been unused since introduction of Item::charset_for_protocol() in MySQL-5.5. b. Adds the "const" qualifier to Field::char_length(). This is needed for (5.a), see below. 2. Introduces a new virtual method Type_handler::charset_for_protocol(), returning item->collation.collation for string data types, or &my_charset_bin for non-string data types. 3. Changes Item::charset_for_protocol() from virtual to non-virtual. It now calls type_handler()->charset_for_protocol(). As a good side effect, duplicate code in Item::charset_for_protocol() and Item_temporal_hybrid_func::charset_for_protocol() is now gone. 4. Fixes Item_ident_for_show::field_type() to correctly return its data type according to the data type of the referenced field. This actually fixes the problem reported in MDEV-11672. Now the default value is sent using a correct method, e.g. val_str() for VARCHAR/TEXT, or val_int() for INT/BIGINT. This required additional changes: a. in DBUG_ASSERT in Protocol::store(const char *,size_t,CHARSET_INFO), This method is now used by mysqld_list_fields(), which (unlike normal SELECT queries) does not set field_types/field_pos/field_count. b. Item_ident_for_show::Item_ident_for_show() now set standard attributes (collation, decimals, max_length, unsigned_flag) according to the referenced field, to make charset_for_protocol() return the correct value and to make mysqld_list_fields() correctly send default values. 5. In order to share the code between Item_field::set_field() and Item_ident_for_show::Item_ident_for_show(): a. Introduces a new method Type_std_attributes::set(const Field*) b. To make (a) possible, moves Item::fix_char_length() from Item to Type_std_attributes, also moves char_to_byte_length_safe() from item.h to sql_type.h c. Additionally, moves Item::fix_length_and_charset() and Item::max_char_length() from Item to Type_std_attributes. This is not directly needed for the fix and is done just for symmetry with fix_char_length(), as these three methods are directly related to each other.
* | | | | MDEV-11337 Split Item::save_in_field() into virtual methods in Type_handlerAlexander Barkov2016-12-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also fixes: MDEV-11331 Wrong result for INSERT INTO t1 (datetime_field) VALUES (hybrid_function_of_TIME_data_type) MDEV-11333 Expect "Impossible where condition" for WHERE timestamp_field>=DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR) This patch does the following: 1. Splits the function Item::save_in_field() into pieces: - Item::save_str_in_field() - Item::save_real_in_field() - Item::save_decimal_in_field() - Item::save_int_in_field() 2. Adds the missing "no_conversion" parameters to Item::save_time_in_field() and Item::save_date_in_field(), so this parameter is now correctly passed to set_field_to_null_with_conversions(). This fixes the problem reported in 11333. 3. Introduces a new virtual method Type_handler::Item_save_in_field() and uses the methods Item::save_xxx_in_field() from the implementations of Type_handler_xxx::Item_save_in_field(). These changes additionally fix the problem reported in MDEV-11331, as the old code erroneously handled expressions like COALESE(datetime-expression) through the STRING_RESULT branch of Item::save_in_field() and therefore they looked like string type expressions for the target fields. Now such expressions are correctly handled by Item::save_date_in_field().
* | | | | MDEV-10811 Change design from "Item is Type_handler" to "Item has Type_handler"Alexander Barkov2016-12-161-0/+2
|/ / / /
* | | | Item::print(): remove redundant parenthesesSergei Golubchik2016-12-121-0/+1
| | | | | | | | | | | | | | | | | | | | by introducing new Item::precedence() method and using it to decide whether parentheses are required