summaryrefslogtreecommitdiff
path: root/sql/field.h
Commit message (Collapse)AuthorAgeFilesLines
* A joint patch for MDEV-19284 and MDEV-19285 (INSTANT ALTER)Alexander Barkov2019-05-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes: - MDEV-19284 INSTANT ALTER with ucs2-to-utf16 conversion produces bad data - MDEV-19285 INSTANT ALTER from ascii_general_ci to latin1_general_ci produces corrupt data These regressions were introduced in 10.4.3 by: - MDEV-15564 Avoid table rebuild in ALTER TABLE on collation or charset changes Changes: 1. Cleanup: Adding a helper method Field_longstr::csinfo_change_allows_instant_alter(), to remove some duplicate code in field.cc. 2. Cleanup: removing Type_handler::Charsets_are_compatible() and static function charsets_are_compatible() and introducing new methods in the recently added class Charset instead: - encoding_allows_reinterpret_as() - encoding_and_order_allow_reinterpret_as() 3. Bug fix: Removing the code that allowed instant conversion for ascii-to->8bit and ucs2-to->utf16. This actually fixes MDEV-19284 and MDEV-19285. 4. Bug fix: Adding a helper method Charset::collation_specific_name(). The old corresponding code in Type_handler::Charsets_are_compatible() was not safe against (badly named) user-defined collations whose character set name can be longer than collation name.
* MDEV-19377 Replace Virtual_column_info::field_type to Type_handlerAlexander Barkov2019-05-011-10/+7
|
* MDEV-19317 TEXT column accepts too long literals as a default valueAlexander Barkov2019-04-251-0/+21
| | | | | | | | | Adding new virtual methods in Field: - make_empty_rec_store_default_value() - make_empty_rec_reset() This simplifies the logic for every Field type, and makes the code more friendly to pluggable data types.
* Fixed compiler warnings form gcc 7.3.1Monty2019-04-191-0/+1
|
* MDEV-19283 Move the code from Field_str::is_equal() to Field_string::is_equal()Alexander Barkov2019-04-191-2/+3
|
* MDEV-19197 Move ASSERT_COLUMN_MARKED_FOR_XXX as methods to FieldAlexander Barkov2019-04-061-0/+3
|
* Get rid of rea_create_table()Sergey Vojtovich2019-04-031-1/+1
| | | | | | | | | Moved rea_create_table() to the sole caller. Also ha_create_partitioning_metadata(CHF_CREATE_FLAG) does cleanup on error now. Part of MDEV-17805 - Remove InnoDB cache for temporary tables.
* MDEV-19125 Change Send_field::type from enum_field_types to Type_handler*Alexander Barkov2019-04-021-22/+21
|
* Merge 10.3 into 10.4Marko Mäkelä2019-03-061-0/+45
|\
| * MDEV-9519: Data corruption will happen on the Galera cluster size changeJulius Goryavsky2019-02-261-0/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we have a 2+ node cluster which is replicating from an async master and the binlog_format is set to STATEMENT and multi-row inserts are executed on a table with an auto_increment column such that values are automatically generated by MySQL, then the server node generates wrong auto_increment values, which are different from what was generated on the async master. In the title of the MDEV-9519 it was proposed to ban start slave on a Galera if master binlog_format = statement and wsrep_auto_increment_control = 1, but the problem can be solved without such a restriction. The causes and fixes: 1. We need to improve processing of changing the auto-increment values after changing the cluster size. 2. If wsrep auto_increment_control switched on during operation of the node, then we should immediately update the auto_increment_increment and auto_increment_offset global variables, without waiting of the next invocation of the wsrep_view_handler_cb() callback. In the current version these variables retain its initial values if wsrep_auto_increment_control is switched on during operation of the node, which leads to inconsistent results on the different nodes in some scenarios. 3. If wsrep auto_increment_control switched off during operation of the node, then we must return the original values of the auto_increment_increment and auto_increment_offset global variables, as the user has set. To make this possible, we need to add a "shadow copies" of these variables (which stores the latest values set by the user). https://jira.mariadb.org/browse/MDEV-9519
* | MDEV-18408 Assertion `0' failed in Item::val_native_result / ↵Alexander Barkov2019-02-251-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null upon mysqld_list_fields after crash recovery The problem happened because Item_ident_for_show did not implement val_native(). Solution: - Removing class Item_ident_for_show - Implementing a new method Protocol::send_list_fields() instead, which accepts a List<Field> instead of List<Item> as input. Now no any Item creation is done during mysqld_list_fields(). Adding helper methods, to reuse the code easier: - Moved a part of Protocol::send_result_set_metadata(), responsible for sending an individual field metadata, into a new method Protocol_text::store_field_metadata(). Reusing it in both send_list_fields() and send_result_set_metadata(). - Adding Protocol_text::store_field_metadata() - Adding Protocol_text::store_field_metadata_for_list_fields() Note, this patch also automatically fixed another bug: MDEV-18685 mysql_list_fields() returns DEFAULT 0 instead of DEFAULT NULL for view columns The reason for this bug was that Item_ident_for_show::val_xxx() and get_date() did not check field->is_null() before calling field->val_xxx()/get_date(). Now the default value is correctly sent by Protocol_text::store(Field*).
* | MDEV-371 Unique Index for long columnsSachin2019-02-221-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements engine independent unique hash index. Usage:- Unique HASH index can be created automatically for blob/varchar/test column whose key length > handler->max_key_length() or it can be explicitly specified. Automatic Creation:- Create TABLE t1 (a blob unique); Explicit Creation:- Create TABLE t1 (a int , unique(a) using HASH); Internal KEY_PART Representations:- Long unique key_info will have 2 representations. (lets understand this with an example create table t1(a blob, b blob , unique(a, b)); ) 1. User Given Representation:- key_info->key_part array will be similar to what user has defined. So in case of example it will have 2 key_parts (a, b) 2. Storage Engine Representation:- In this case there will be only one key_part and it will point to HASH_FIELD. This key_part will be always after user defined key_parts. So:- User Given Representation [a] [b] [hash_key_part] key_info->key_part ----^ Storage Engine Representation [a] [b] [hash_key_part] key_info->key_part ------------^ Table->s->key_info will have User Given Representation, While table->key_info will have Storage Engine Representation.Representation can be changed into each other by calling re/setup_keyinfo_hash function. Working:- 1. So when user specifies HASH_INDEX or key_length is > handler->max_key_length(), In mysql_prepare_create_table One extra vfield is added (for each long unique key). And key_info->algorithm is set to HA_KEY_ALG_LONG_HASH. 2. In init_from_binary_frm_image values for hash_keypart is set (like fieldnr , field and flags) 3. In parse_vcol_defs, HASH_FIELD->vcol_info is created. Item_func_hash is used with list of Item_fields, When Explicit length is given by user then Item_left is used to concatenate Item_field values. 4. In ha_write_row/ha_update_row check_duplicate_long_entry_key is called which will create the hash key from table->record[0] and then call ha_index_read_map , if we found duplicated hash , we will compare the result field by field.
* | MDEV-16975 Application-time periods: ALTER TABLENikita Malyavin2019-02-211-1/+1
| | | | | | | | | | * implicit period constraint is hidden and cannot be dropped independently * create...like and create...select support
* | MDEV-17082 Application-time periods: CREATENikita Malyavin2019-02-211-1/+3
| | | | | | | | | | * add syntax `CREATE TABLE ... PERIOD FOR <apptime>` * add table period entity
* | A cleanup for MDEV-13916 Enforce check constraint on JSON typeAlexander Barkov2019-02-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Renaming Type_handler_json to Type_handler_json_longtext There will be other JSON handlers soon, e.g. Type_handler_json_varchar. 2. Making the code more symmetric for data types: - Adding a new virtual method Type_handler::Column_definition_validate_check_constraint() - Moving JSON-specific code from sql_yacc.yy to Type_handler_json_longtext::Column_definition_validate_check_constraint() 3. Adding new files sql_type_json.cc and sql_type_json.h and moving Type_handler+JSON related code into these files.
* | MDEV-15563: Instant ROW_FORMAT=REDUNDANT column extensionMarko Mäkelä2019-02-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was developed by Aleksey Midenkov based on my design. In the original InnoDB storage format (that was retroactively named ROW_FORMAT=REDUNDANT in MySQL 5.0.3), the length of each index field is stored explicitly. Because of this, we can and now will allow instant conversion from VARCHAR to CHAR or VARBINARY to BINARY of equal or greater size, as well as instant conversion of TINYINT to SMALLINT to MEDIUMINT to INT to BIGINT (while not changing between signed and unsigned). Theoretically, we could allow changing from an unsigned integer to a bigger unsigned integer, as well as changing CHAR to VARCHAR, but that would require additional metadata and conversions whenever reading old records. Field_str::is_equal(), Field_varstring::is_equal(), Field_num::is_equal(): Return the new result IS_EQUAL_PACK_LENGTH_EXT if the table advertises HA_EXTENDED_TYPES_CONVERSION capability and we are considering the above-mentioned conversions. ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT: A new ALTER TABLE flag, similar to ALTER_COLUMN_EQUAL_PACK_LENGTH but requiring conversions when reading the data. The Field::is_equal() result IS_EQUAL_PACK_LENGTH_EXT will map to this flag. dtype_get_fixed_size_low(): For BINARY, CHAR and integer columns in ROW_FORMAT=REDUNDANT, return 0 (variable length) from now on. dtype_get_sql_null_size(): Keep returning the current size for BINARY, CHAR and integer columns, so that in ROW_FORMAT=REDUNDANT it will remain possible to update in place between NULL and NOT NULL values. btr_index_rec_validate(): Relax a CHECK TABLE length check for ROW_FORMAT=REDUNDANT tables. btr_cur_instant_init_low(): No longer trust fixed_len for ROW_FORMAT=REDUNDANT tables. We cannot rely on fixed_len anymore because the record can have shorter length from before instant extension. Note that importing such tablespace into earlier MariaDB versions produces ER_TABLE_SCHEMA_MISMATCH when using a .cfg file.
* | Merge 10.3 into 10.4Marko Mäkelä2018-12-181-1/+1
|\ \ | |/
* | MDEV-13995 MAX(timestamp) returns a wrong result near DST changeAlexander Barkov2018-12-101-0/+19
| |
* | MDEV-17928 Conversion from TIMESTAMP to VARCHAR SP variables does not work ↵Alexander Barkov2018-12-081-2/+7
| | | | | | | | well on fractional digits
* | MDEV-17319 Assertion `ts_type != MYSQL_TIMESTAMP_TIME' failed upon inserting ↵Alexander Barkov2018-12-021-11/+10
| | | | | | | | into TIME field
* | MDEV-16991 Rounding vs truncation for TIME, DATETIME, TIMESTAMPbb-10.4-mdev16991Alexander Barkov2018-11-261-6/+10
| |
* | MDEV-17792 New class Timestamp and cleanups in Date, Datetime, Field for ↵Alexander Barkov2018-11-221-3/+19
| | | | | | | | rounding
* | Merge 10.3 into 10.4Marko Mäkelä2018-11-191-0/+1
|\ \ | |/
| * Merge 10.2 into 10.3Marko Mäkelä2018-11-191-0/+1
| |\
| | * MDEV-16217: Assertion `!table || (!table->read_set || ↵bb-10.2-MDEV-16217Oleksandr Byelkin2018-11-141-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | bitmap_is_set(table->read_set, field_index))' failed in Field_num::get_date - clean up DEFAULT() to work only with default value and correctly print itself. - fix of DBUG_ASSERT about fields read/write - fix of field marking for write based really on the thd->mark_used_columns flag
* | | MDEV-17563 Different results using table or view when comparing values of ↵Alexander Barkov2018-11-081-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | time type MDEV-17625 Different warnings when comparing a garbage to DATETIME vs TIME - Splitting processes of data type conversion (to TIME/DATE,DATETIME) and warning generation. Warning are now only get collected during conversion (in an "int" variable), and are pushed in the very end of conversion (not in parallel). Warnings generated by the low level routines str_to_xxx() and number_to_xxx() can now be changed at the end, when TIME_FUZZY_DATES is applied, from "Invalid value" to "Truncated invalid value". Now "Illegal value" is issued only when the low level routine returned an error and TIME_FUZZY_DATES was not set. Otherwise, if the low level routine returned "false" (success), or if NULL was converted to a zero datetime by TIME_FUZZY_DATES, then "Truncated illegal value" is issued. This gives better warnings. - Methods Type_handler::Item_get_date() and Type_handler::Item_func_hybrid_field_type_get_date() now only convert and collect warning information, but do not push warnings. - Changing the return data type for Type_handler::Item_get_date() and Type_handler::Item_func_hybrid_field_type_get_date() from "bool" to "void". The conversion result (success vs error) can be checked by testing ltime->time_type. MYSQL_TIME_{NONE|ERROR} mean mean error, other values mean success. - Adding new wrapper methods Type_handler::Item_get_date_with_warn() and Type_handler::Item_func_hybrid_field_type_get_date_with_warn() to do conversion followed by raising warnings, and changing the code to call new Type_handler::***_with_warn() methods. - Adding a helper class Temporal::Status, a wrapper for MYSQL_TIME_STATUS with automatic initialization. - Adding a helper class Temporal::Warn, to collect warnings but without actually raising them. Moving a part of ErrConv into a separate class ErrBuff, and deriving both Temporal::Warn and ErrConv from ErrBuff. The ErrBuff part of Temporal::Warn is used to collect textual representation of the input data. - Adding a helper class Temporal::Warn_push. It's used to collect warning information during conversion, and automatically pushes warnings to the diagnostics area on its destructor time (in case of non-zero warning). - Moving more code from various functions inside class Temporal. - Adding more Temporal_hybrid constructors and protected Temporal methods make_from_xxx(), which convert and only collect warning information, but do not actually raise warnings. - Now the low level functions str_to_datetime() and str_to_time() always set status->warning if the return value is "true" (error). - Now the low level functions number_to_time() and number_to_datetime() set the "*was_cut" argument if the return value is "true" (error). - Adding a few DBUG_ASSERTs to make sure that str_to_xxx() and number_to_xxx() always set warnings on error. - Adding new warning flags MYSQL_TIME_WARN_EDOM and MYSQL_TIME_WARN_ZERO_DATE for the code symmetry. Before this change there was a special code path for (rc==true && was_cut==0) which was treated by Field_temporal::store_invalid_with_warning as "zero date violation". Now was_cut==0 always means that there are no any error/warnings/notes to be raised, not matter what rc is. - Using new Temporal_hybrid constructors in combination with Temporal::Warn_push inside str_to_datetime_with_warn(), double_to_datetime_with_warn(), int_to_datetime_with_warn(), Field::get_date(), Item::get_date_from_string(), and a few other places. - Removing methods Dec_ptr::to_datetime_with_warn(), Year::to_time_with_warn(), my_decimal::to_datetime_with_warn(), Dec_ptr::to_datetime_with_warn(). Fixing Sec6::to_time() and Sec6::to_datetime() to convert and only collect warnings, without raising warnings. Now warning raising functionality resides in Temporal::Warn_push. - Adding classes Longlong_hybrid_null and Double_null, to return both value and the "IS NULL" flag. Adding methods Item::to_double_null(), to_longlong_hybrid_null(), Item_func_hybrid_field_type::to_longlong_hybrid_null_op(), Item_func_hybrid_field_type::to_double_null_op(). Removing separate classes VInt and VInt_op, as they have been replaced by a single class Longlong_hybrid_null. - Adding a helper method Temporal::type_name_by_timestamp_type(), moving a part of make_truncated_value_warning() into it, and reusing in Temporal::Warn::push_conversion_warnings(). - Removing Item::make_zero_date() and Item_func_hybrid_field_type::make_zero_mysql_time(). They provided duplicate functionality. Now this code resides in Temporal::make_fuzzy_date(). The latter is now called for all Item types when data type conversion (to DATE/TIME/DATETIME) is involved, including Item_field and Item_direct_view_ref. This fixes MDEV-17563: Item_direct_view_ref now correctly converts NULL to a zero date when TIME_FUZZY_DATES says so.
* | | MDEV-17317 Add THD* parameter into Item::get_date() and stricter data type ↵Alexander Barkov2018-09-281-29/+29
| | | | | | | | | | | | control to "fuzzydate"
* | | MDEV-17274 Split Field_temporal_with_date::store*() for Field_date_common ↵Alexander Barkov2018-09-221-16/+32
| | | | | | | | | | | | and Field_datetime
* | | Merge 10.3 into 10.4Marko Mäkelä2018-09-111-1/+0
|\ \ \ | |/ /
| * | Merge 10.2 into 10.3Marko Mäkelä2018-09-061-47/+0
| |\ \ | | |/
| | * Merge 10.1 into 10.2Marko Mäkelä2018-08-311-46/+0
| | |\
| | | * Revert MDEV-9519 due to regressionsMarko Mäkelä2018-08-311-46/+0
| | | | | | | | | | | | | | | | This reverts commit 75dfd4acb995789ca5f86ccbd361fff9d2797e79.
| * | | Merge 10.2 into 10.3Marko Mäkelä2018-08-281-0/+46
| |\ \ \ | | |/ /
| | * | Merge 10.1 into 10.2Marko Mäkelä2018-08-211-0/+46
| | |\ \ | | | |/
| | | * This is patch for the https://jira.mariadb.org/browse/MDEV-9519 issue:Julius Goryavsky2018-08-151-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we have a 2+ node cluster which is replicating from an async master and the binlog_format is set to STATEMENT and multi-row inserts are executed on a table with an auto_increment column such that values are automatically generated by MySQL, then the server node generates wrong auto_increment values, which are different from what was generated on the async master. The causes and fixes: 1. We need to improve processing of changing the auto-increment values after changing the cluster size. 2. If wsrep auto_increment_control switched on during operation of the node, then we should immediately update the auto_increment_increment and auto_increment_offset global variables, without waiting of the next invocation of the wsrep_view_handler_cb() callback. In the current version these variables retain its initial values if wsrep_auto_increment_control is switched on during operation of the node, which leads to inconsistent results on the different nodes in some scenarios. 3. If wsrep auto_increment_control switched off during operation of the node, then we must return the original values of the auto_increment_increment and auto_increment_offset global variables, as the user has set. To make this possible, we need to add a "shadow copies" of these variables (which stores the latest values set by the user).
* | | | A cleanup for MDEV-16939: avoid timeval initialization related problems in ↵Alexander Barkov2018-08-111-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the future (compilation failures on Windows) Adding a helper class Timeval, to initialize "struct timeval" in a safe way. As a bonus, adding a method Timeval::trunc(), so the caller now can have one line instead of five lines (declaration, initializations of sec and usec, truncation, passing to store_TIMEVAL()).
* | | | Fix warning C4838 : conversion from 'type_1' to 'type_2' requires a ↵Vladislav Vaintroub2018-08-111-1/+3
| | | | | | | | | | | | | | | | narrowing conversion.
* | | | MDEV-16939 Move TIMESTAMP truncation code to ↵Alexander Barkov2018-08-111-4/+10
| | | | | | | | | | | | | | | | Field_timestamp::store_TIME_with_warn
* | | | MDEV-16935 Change the parameter of Field_xxx::store_TIME_with_dec() to const ↵Alexander Barkov2018-08-101-9/+25
| | | | | | | | | | | | | | | | Datetime* and const Time*
* | | | MDEV-16928 Move MYSQL_TIME initialization from Field_xxx::store_time_dec() ↵Alexander Barkov2018-08-091-5/+3
| | | | | | | | | | | | | | | | to new constructors Time() and Datetime()
* | | | MDEV-16926 CAST(COALESCE(year_field)) returns wrong valueAlexander Barkov2018-08-091-1/+4
| | | |
* | | | MDEV-16910 Add class VDecAlexander Barkov2018-08-071-12/+28
| | | | | | | | | | | | | | | | | | | | Adding classes VDec and VDec2_lazy, according to the task description. This patch removes around 250 duplicate code lines.
* | | | MDEV-16823 Add Type_handler::Column_definition_reuse_fix_attributes()Alexander Barkov2018-07-251-3/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adding new methods: - virtual void Type_handler::Column_definition_reuse_fix_attributes() according to the MDEV description - virtual uint32 Field::character_octet_length() To simplify handling of Column_definition::length for TEXT and VARCHAR columns (with and without compression).
* | | | MDEV-15758 Split Item_bool_func::get_mm_leaf() into virtual methods in Field ↵Alexander Barkov2018-07-201-6/+109
| | | | | | | | | | | | | | | | and Type_handler
* | | | Merge remote-tracking branch 'origin/10.3' into 10.4Alexander Barkov2018-07-031-3/+36
|\ \ \ \ | |/ / /
| * | | Merge branch '10.2' into 10.3Sergei Golubchik2018-06-301-1/+18
| |\ \ \ | | |/ /
| | * | MDEV-12574 MAX(old_decimal) produces a column of the old DECIMAL typeAlexander Barkov2018-06-251-0/+13
| | | |
| | * | MDEV-15114 ASAN heap-use-after-free in mem_heap_dup or ↵Monty2018-06-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dfield_data_is_binary_equal The bug was that innobase_get_computed_value() trashed record[0] and data in Field_blob::value Fixed by using a record on the heap for innobase_get_computed_value() Reviewer: Marko Mäkelä
| * | | MDEV-16365 Setting a column NOT NULL fails to return error forThirunarayanan Balathandayuthapani2018-06-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | NULL values when there is no DEFAULT Copy and inplace algorithm works similarly for NULL to NOT NULL conversion for the following cases: (1) strict sql mode - Should give error. (2) non-strict sql mode - Should give warnings alone (3) alter ignore table command. - Should give warnings alone.
| * | | Merge 10.2 into 10.3Marko Mäkelä2018-06-181-1/+16
| |\ \ \ | | |/ /