Commit graph

2665 commits

Author SHA1 Message Date
Alexander Barkov
ee6ac4d313 MDEV-12574 MAX(old_decimal) produces a column of the old DECIMAL type 2018-06-25 09:08:07 +04:00
Alexander Barkov
fe3f9fa918 MDEV-12809 Bad column type created for TEXT(1431655798) CHARACTER SET utf8 2018-06-21 15:17:15 +04:00
Marko Mäkelä
0121d5a790 Merge 10.2 into 10.3 2018-06-18 15:43:59 +03:00
Alexander Barkov
2cdb483bc4 MDEV-15352 AUTO_INCREMENT breaks after updating a column value to a negative number 2018-06-14 13:13:23 +04:00
Sergey Vojtovich
7ffd7fe962 Cleanup isnan() portability checks 2018-05-26 13:26:32 +04:00
Sergey Vojtovich
bc469a0bdf Cleanup isinf() portability checks
Original problem reported by Wlad: re-compilation of 10.3 on top of 10.2
build would cache undefined HAVE_ISINF from 10.2, whereas it is expected
to be 1 in 10.3.

std::isinf() seem to be available on all supported platforms.
2018-05-26 13:17:22 +04:00
Sergey Vojtovich
54999f4e75 Use std::isfinite in C++ code
This is addition to parent revision fixing build failures.
2018-05-24 00:12:25 +04:00
Sergey Vojtovich
c982924242 MDEV-15592 - Column COMPRESSED should select a 'high order' datatype
Compressed blob columns didn't accept data at their capacity. E.g. storing
255 bytes to TINYBLOB results in "Data too long" error.

Now it is allowed assuming compression method was able to produce shorter
string (so that both metadata and compressed data fits blob) and
column_compression_threshold is lower than blob.

If no compression was performed, we still have to reserve additional byte
for metadata and thus we perform normal data truncation and return it's
status.
2018-05-11 19:57:07 +04:00
Monty
30ebc3ee9e Add likely/unlikely to speed up execution
Added to:
- if (error)
- Lex
- sql_yacc.yy and sql_yacc_ora.yy
- In header files to alloc() calls
- Added thd argument to thd_net_is_killed()
2018-05-07 00:07:32 +03:00
Sergey Vojtovich
68cbabbfb0 MDEV-15938 - TINYTEXT CHARACTER SET utf8 COMPRESSED truncates data
Unexpected data truncation may occur when storing data to compressed blob
column having multi byte variable length character sets.

The reason was incorrect number of characters limit was enforced for
blobs.
2018-04-30 19:34:08 +04:00
Eugene Kosov
7b2bdd8984 register keyword c++17 warning 2018-04-24 12:48:32 +03:00
Alexander Barkov
c555dc768f MDEV-15971 Split the code for CHARACTER_OCTET_LENGTH and CHARACTER_MAXIMUM_LENGTH into methods in Field 2018-04-22 13:30:31 +04:00
Alexander Barkov
9aaf62d058 MDEV-15926 MEDIUMINT returns wrong I_S attributes
Problem:

The logic in store_column_type() with a switch on field type was
hard to follow. The part for MEDIUMINT (MYSQL_TYPE_INT24) was not correct.
It erroneously calculated the precision of MEDIUMINT UNSIGNED
as 7 instead of 8.

A similar hard-to-follow switch doing some type specific calculations
resided in adjust_max_effective_column_length(). It was also wrong for
MEDIUMINT (reported as a separate issue in MDEV-15946).

Solution:

1. Introducing a new class Information_schema_numeric_attributes
2. Adding a new virtual method Field::information_schema_numeric_attributes()
3. Splitting the logic in store_column_type() into virtual
   implementations of information_schema_numeric_attributes().
4. In order to avoid adding duplicate code for the integer data types,
   adding a new virtual method Field_int::numeric_precision(),
   which returns the number of digits.

Additional changes:

1. Adding the "const" qualifier to Field::max_display_length()

2. Moving the code from adjust_max_effective_column_length()
  directly to Field::max_display_length().
  There was no any sense to have two implementations:
  - a set of wrong virtual implementations for Field_xxx::max_display_length()
  - additional code in adjust_max_effective_column_length() fixing
    bad results of Field_xxx::max_display_length()
  This change is safe:
  - The code using Field::max_display_length()
    in field.cc, sql_show.cc, sql_type.cc is not affected.
  - The code in rpl_utility.cc is also not affected.
    See a new DBUG_ASSSERT and new comments explaining why.

  In the new reduction, Field_xxx::max_display_length() returns
  correct results for all integer types (except MEDIUMINT, see below).

  Putting implementations of numeric_precision() and max_display_length()
  near each other in field.h made the logic much clearer and thus
  helped to reveal bad results for Field_medium::max_display_length(),
  which returns 9 instead of 8 for signed MEDIUMINT fields.
  This problem will be addressed separately (MDEV-15946).

Note, this change is also useful for pluggable data types (see MDEV-4912),
as now a user defined Field_xxx has a way to control what's returned
in INFORMATION_SCHEMA.COLUMNS.NUMERIC_PRECISION and
INFORMATION_SCHEMA.COLUMNS.NUMERIC_SCALE by implementing
a desired behavior in Field_xxx::information_schema_numeric_attributes().
2018-04-20 18:11:27 +04:00
Sergey Vojtovich
3dec6c48bc MDEV-15762 - VARCHAR(0) COMPRESSED crashes the server
Character set safe truncation is done when storing non-empty string in
VARCHAR(0) COMPRESSED column, so that string becomes empty. The code
didn't expect empty string after truncation.

Fixed by moving empty string check after truncation.
2018-04-20 17:05:28 +04:00
Alexander Barkov
a1a966fc0e Cleanup: renaming methods make_field(Send_field*) to make_send_field(..)
Renaming methods:
- Field::make_field(Send_field*) to make_send_field(..)
- Item::make_field(THD *,Send_field *) to make_send_field(..)
- Item::init_make_field(Send_field *, enum_field_type) to init_make_send_field(..)

These names looked similar to other functions that are used
for a very different purpose (creating Field instances):
- Public function "Field * make_field(..)"
- Method "Field *Column_defitinion::make_field(..)"

The rename makes it's easier to search the code using "grep".
2018-04-05 21:27:33 +04:00
Alexander Barkov
342d3df6b1 Cleanup: removing duplicate code, adding "const", etc
- Adding class Field_int as a common
  parent for Field_{longlong|long|short|medium|tiny}
- Moving store_decimal(), val_decimal(), get_date(), store_time_dec(),
  get_date(), val_bool() from Field_num to Field_int
- Adding Field_int::val_str_from_long() and reusing it in
  Field_tiny::val_str(), Field_short::val_str(), Field_medium::val_str()
  and Field_long::val_str(). This removes a good amount of duplicate code
- Adding "const" qualifier to "virtual bool Field::optimize_range()".
2018-04-02 22:36:38 +04:00
Sergey Vojtovich
443b9a418c MDEV-14929 - AddressSanitizer: memcpy-param-overlap in Field_longstr::compress
Handle overlaping "from" and Field_blob_compressed::value for compressed
blobs similarily to regular blobs.
2018-04-02 15:45:22 +04:00
Alexander Barkov
556a9202ce Cleanup: moving timestamp_to_TIME() as a method to THD 2018-03-30 14:29:23 +04:00
Alexander Barkov
e263530bea MDEV-15597 Add class Load_data_outvar and avoid using Item::STRING_ITEM for Item_user_var_as_out_param detection 2018-03-20 13:02:44 +04:00
Alexander Barkov
6ec3de5d2d MDEV-15497 Wrong empty value in a GEOMETRY column on LOAD DATA
- Adding a new virtual method Field::load_data_set_no_data().
- Overriding Field_timestamp::load_data_set_no_data() and moving
  the TIMESTAMP specific code there.
- Overriding Field_geom::load_data_set_no_data() and implementing
  GEOMETRY specific behavior, to prevent writing empty strings
  when the loaded file ends unexpectedly. This fixes the bug.
- Adding a new test gis-loaddaata.test.
- The test in loaddata.test for CHAR was added simply to record behavior.
  The CHAR data type did not change its behaviour (only GEOMRYRY did).
- Additionally, moving duplicate code into a new method
  Field::load_data_set_value() and reusing it in three places.
2018-03-07 19:55:12 +04:00
Sergei Golubchik
2732fcc608 Merge branch 'bb-10.2-ext' into 10.3 2018-02-23 08:43:34 +01:00
Alexander Barkov
144c7f8b6e Adding Field_timestamp::sql_mode_for_timestamp() to reuse duplicate code 2018-02-21 13:11:04 +04:00
Alexander Barkov
aef530bb69 MDEV-15340 Wrong result HOUR(case_expression_with_time_and_datetime)
The problem was that Item_func_hybrid_field_type::get_date() did not
convert the result to the correct data type, so MYSQL_TIME::time_type
of the get_date() result could be not in sync with field_type().

Changes:
1. Adding two new classes Datetime and Date to store MYSQL_TIMESTAMP_DATETIME
   and MYSQL_TIMESTAMP_DATE values respectively
   (in addition to earlier added class Time, for MYSQL_TIMESTAMP_TIME values).
2. Adding Item_func_hybrid_field_type::time_op().
   It performs the operation using TIME representation,
   and always returns a MYSQL_TIME value with time_type=MYSQL_TIMESTAMP_TIME.
   Implementing time_op() for all affected children classes.
3. Fixing all implementations of date_op() to perform the operation
   using strictly DATETIME representation. Now they always return a MYSQL_TIME
   value with time_type=MYSQL_TIMESTAMP_{DATE|DATETIME},
   according to the result data type.
4. Removing assignment of ltime.time_type to mysql_timestamp_type()
   from all val_xxx_from_date_op(), because now date_op() makes sure
   to return a proper MYSQL_TIME value with a good time_type (and other member)
5. Adding Item_func_hybrid_field_type::val_xxx_from_time_op().
6. Overriding Type_handler_time_common::Item_func_hybrid_field_type_val_xxx()
   to call val_xxx_from_time_op() instead of val_xxx_from_date_op().
7. Modified Item_func::get_arg0_date() to return strictly a TIME value
   if TIME_TIME_ONLY is passed, or return strictly a DATETIME value otherwise.
   If args[0] returned a value of a different temporal type,
   (for example a TIME value when TIME_TIME_ONLY was not passed,
    or a DATETIME value when TIME_TIME_ONLY was passed), the conversion
   is automatically applied.
   Earlier, get_arg0_date() did not guarantee a result in
   accordance to TIME_TIME_ONLY flag.
2018-02-19 23:41:01 +04:00
Marko Mäkelä
cc3b5d1fe7 Merge bb-10.2-ext into 10.3 2018-02-15 11:48:30 +02:00
Marko Mäkelä
b006d2ead4 Merge bb-10.2-ext into 10.3 2018-02-15 10:22:03 +02:00
Alexander Barkov
c17a06abf8 MDEV-15310 Range optimizer does not work well for "WHERE temporal_column NOT IN (const_list)"
There were two problems related to the bug report:
1. Item_datetime::get_date() was not implemented.
   So execution went through val_int() followed
   by int-to-datetime or int-to-time conversion.
   This was the reason why the optimizer did not
   work well on data with fractional seconds.
2. Item_datetime::set() did not have a TIME specific code
   to mix months and days to hours after unpack_time().
   This is why the optimizer did not work well with negative
   TIME values, as well as huge time values.

Changes:

1. Overriding Item_datetime::get_date(), to return ltime.
   This fixes the problem N1.
2. Cleanup: Moving pack_time() and unpack_time() from
   sql-common/my_time.c and include/my_time.h to
   sql/sql_time.cc and sql/sql_time.h, as they are not needed
   on the client side.
3. Adding a new "enum_mysql_timestamp_type ts_type" parameter
   to unpack_time() and moving the TIME specific code to mix
   months and days with hours inside unpack_time().
   Adding a new "ts_type" parameter to Item_datetime::set(),
   to pass it from the caller down to unpack_time().
   So now the TIME specific code is automatically called
   from Item_datetime::set(). This fixes the problem N2.
   This change also helped to get rid of duplicate TIME specific code
   from other three places, where mixing month/days to hours
   was done immediately after unpack_time().
   Moving the DATE specific code to zero hhmmssff
   from Item_func_min_max::get_date_native to inside unpack_time(),
   for symmetry.
4. Removing the virtual method in_vector::result_type(),
   adding in_vector::type_handler() instead.
   This helps to get result_type(), field_type(),
   mysql_timestamp_type() of an in_vector easier.
   Passing type_handler()->mysql_timestamp_type() as
   a new parameter to Item_datetime::set() inside
   in_temporal::value_to_item().
5. Cleaup: Removing separate implementations of in_datetime::get_value()
   and in_time::get_value(). Adding a single implementation
   in_temporal::get_value() instead.
   Passing type_handler()->field_type() to get_value_internal().
2018-02-14 22:58:34 +04:00
Alexander Barkov
da99e086f9 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2018-02-12 10:03:28 +04:00
Sergei Golubchik
49bcc82686 Merge branch '10.1' into 10.2 2018-02-11 13:47:16 +01:00
Alexander Barkov
e07451f71f Merge remote-tracking branch 'origin/10.0' into 10.1 2018-02-10 00:06:10 +04:00
Alexander Barkov
b0a92333c0 MDEV-15262 Wrong results for SELECT..WHERE non_indexed_datetime_column=indexed_time_column 2018-02-09 19:47:00 +04:00
Alexander Barkov
3cad31f2a7 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2018-02-08 19:06:25 +04:00
Marko Mäkelä
883496782f Merge bb-10.2-ext into 10.3 2018-02-06 17:12:17 +02:00
Sergei Golubchik
4771ae4b22 Merge branch 'github/10.1' into 10.2 2018-02-06 14:50:50 +01:00
Vladislav Vaintroub
6c279ad6a7 MDEV-15091 : Windows, 64bit: reenable and fix warning C4267 (conversion from '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.
2018-02-06 12:55:58 +00:00
Alexander Barkov
d67dcb7bb5 MDEV-15205 Remove mysql_type_to_time_type() 2018-02-04 22:55:54 +04:00
Alexander Barkov
217fc122c8 Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2018-02-04 18:40:06 +04:00
Alexander Barkov
28d4cf0c1b MDEV-15176 Storing DATETIME-alike VARCHAR data into TIME produces wrong results
When storing '0001-01-01 10:20:30x', execution went throw the last code
branch in Field_time::store_TIME_with_warning(), around the test
for (ltime->year || ltime->month). This then resulted into wrong results
because:

1. Field_time::store_TIME() does not check YYYYMM against zero.
  It assumes that ltime->days and ltime->hours are already properly set.
  So it mixed days to hours, even when YYYYMM was not zero.

2. Field_time_hires::store_TIME() does not check YYYYMM against zero.
  It assumes that ltime->year, ltime->month, ltime->days and ltime->hours
  are already properly set. So it always mixed days and even months(!) and years(!)
  to hours, using pack_time(). This gave even worse results comparing to #2.

3. Field_timef::store_TIME() did not check the entire YYYYMM for being zero.
  It only checked MM, but did not check YYYY. In case of a zero MM,
  it mixed days to hours, even if YYYY was not zero.
  The wrong code was in TIME_to_longlong_time_packed().

In the new reduction Field_time::store_TIME_with_warning() is responsible
to prepare the YYYYYMMDD part properly in all code branches
(with trailing garbage like 'x' and without trailing garbage).
It was reorganized into a more straightforward style.

Field_time:store_TIME(), Field_time_hires::store_TIME() and
TIME_to_longlong_time_packed() were fixed to do a DBUG_ASSERT
on non-zero ltime->year or ltime->month. The code testing ltime->month
was removed from TIME_to_longlong_time_packed(), as it's now
properly done on the caller level.

Truncation was moved from Field_timef::store_TIME() to
Field_time::store_TIME_with_warning().

So now all thee methods Field_time*::store_TIME() assume a properly
set input value:
- Only zero ltime->year and ltime->month are allowed.
- The value must be already properly truncated according to decimals()
  (this will help to add rounding soon, see MDEV-8894)

A "const" qualifier was added to the argument of Field_time*::store_TIME().
2018-02-04 16:43:02 +04:00
Alexander Barkov
2ecf2f9b2a Adding "const" qualifier to the MYSQL_TIME* argument of Field::store_time_dec() 2018-02-03 17:27:43 +04:00
Sachin Setiya
c8299e6278 This commit solves a couple of issues
1st. Create_field does not have function vers_sys_field() kind of handy
function, second I think Create_field and Field should not divert much , and
Field does have this function.

2nd. Versioning column does not have NOT_NULL_FLAG, since they can never be
null. So I have added NOT_NULL_FLAG.

3rd. Since I added NOT_NULL_FLAG this created one issue , versioning column
of datatype bigint unsigned were getting NO_DEFAULT_VALUE_FLAG. This makes
test like versioning.insert to fail, Reason being If a column gets this
flag if we insert 'default' value it will generate error(that is why ) test
was failing. So now versioning column wont get NO_DEFAULT_VALUE_FLAG flag.
2018-02-02 14:45:44 +05:30
Sergei Golubchik
d4df7bc9b1 Merge branch 'github/10.0' into 10.1 2018-02-02 10:09:44 +01:00
Monty
a7e352b54d Changed database, tablename and alias to be LEX_CSTRING
This was done in, among other things:
- thd->db and thd->db_length
- TABLE_LIST tablename, db, alias and schema_name
- Audit plugin database name
- lex->db
- All db and table names in Alter_table_ctx
- st_select_lex db

Other things:
- Changed a lot of functions to take const LEX_CSTRING* as argument
  for db, table_name and alias. See init_one_table() as an example.
- Changed some function arguments from LEX_CSTRING to const LEX_CSTRING
- Changed some lists from LEX_STRING to LEX_CSTRING
- threads_mysql.result changed because process list_db wasn't always
  correctly updated
- New append_identifier() function that takes LEX_CSTRING* as arguments
- Added new element tmp_buff to Alter_table_ctx to separate temp name
  handling from temporary space
- Ensure we store the length after my_casedn_str() of table/db names
- Removed not used version of rename_table_in_stat_tables()
- Changed Natural_join_column::table_name and db_name() to never return
  NULL (used for print)
- thd->get_db() now returns db as a printable string (thd->db.str or "")
2018-01-30 21:33:55 +02:00
Alexander Barkov
c7a2f23a7b Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2018-01-29 12:44:20 +04:00
Alexander Barkov
b12430adc7 MDEV-15107 Add virtual Field::sp_prepare_and_store_item(), make sp_rcontext symmetric for scalar and ROW
After MDEV-14212, the Virtual_tmp_table instance that stores a ROW
variable elements is accessible from the underlying Field_row
(rather than Item_field_row).

This patch makes some further changes by moving the code from
sp_instr_xxx, sp_rcontext, Item_xxx to Virtual_tmp_table and Field_xxx.

The data type specific code (scalar vs ROW) now resides in
a new virtual method Field_xxx::sp_prepare_and_store_item().
The the code in sp_rcontext::set_variable() and sp_eval_expr()
is now symmetric for scalar and ROW values.
The code in sp_rcontext::set_variable_row_field(), sp_rcontext::set_variable_row_field(), sp_rcontext::set_variable_row()
is now symmetric for ROW elements (i.e. scalar and ROW elements inside a ROW).

Rationale:

Prepare the code to implement these tasks soon easier:

- MDEV-12252 ROW data type for stored function return values
- MDEV-12307 ROW data type for built-in function return values
- MDEV-6121 Data type: Array
- MDEV-10593 sql_mode=ORACLE: TYPE .. AS OBJECT: basic functionality
- ROW with ROW fields (no MDEV yet)

Details:

1. Moving the code in sp_eval_expr() responsible to backup/restore
   thd->count_cuted_fields, thd->abort_on_warning,
   thd->transaction.stmt.modified_non_trans_table
   into a new helper class Sp_eval_expr_state, to reuse it easier.
   Fixing sp_eval_expr() to use this new class.

2. Moving sp_eval_expr() and sp_prepare_func_item() from public functions
   to methods in THD, so they can be reused in *.cc files easier without
   a need to include "sp_head.h".

   Splitting sp_prepare_func_item() into two parts.
   Adding a new function sp_fix_func_item(), which fixes
   the underlying items, but does not do check_cols() for them.
   Reusing sp_fix_func_item() in Field_row::sp_prepare_and_store_item().

3. Moving the code to find ROW fields by name from Item to Virtual_tmp_table

   Moving the code searching for ROW fields by their names
   from Item_field_row::element_index_by_name() to a new method
   Item_field_row to Virtual_tmp_table::sp_find_field_by_name().

   Adding wrapper methods sp_rcontext::find_row_field_by_name() and
   find_row_field_by_name_or_error(), to search for a ROW variable
   fields by the variable offset and its field name.

   Changing Item_splocal_row_field_by_name::fix_fields() to do
   use sp_rcontext::find_row_field_by_name_or_error().
   Removing virtual Item::element_index_by_name().

4. Splitting sp_rcontext::set_variable()

   Adding a new virtual method Field::sp_prepare_and_store_item().
   Spliting the two branches of the code in sp_rcontext::set_variable()
   into two virtual implementations of Field::sp_prepare_and_store_item(),
   (for Field and for Field_row).

   Moving the former part of sp_rcontext::set_variable() with the loop
   doing set_null() for all ROW fields into a new method
   Virtual_tmp_table::set_all_fields_to_null() and using it in
   Field_row::sp_prepare_and_store_item().

   Moving the former part of sp_rcontext::set_variable() with the loop
   doing set_variable_row_field() into a new method
   Virtual_tmp_table::set_all_fields_from_item() and using it in
   Field_row::sp_prepare_and_store_item().
   The loop in the new method now uses sp_prepare_and_store_item()
   instead of set_variable_row_field(), because saving/restoring
   THD flags is now done on the upper level. No needs to save/restore
   on every iteration.

5. Fixing sp_eval_expr() to simply do two things:
   - backup/restore THD flags
   - call result_field->sp_prepare_and_store_item()
   So now sp_eval_expr() can be used for both scalar and ROW variables.
   Reusing it in sp_rcontext::set_variable*().

6. Moving the loop in sp_rcontext::set_variable_row() into a
   new method Virtual_tmp_table::sp_set_all_fields_from_item_list().

   Changing the loop body to call field->sp_prepare_and_store_item()
   instead of doing set_variable_row_field(). This removes
   saving/restoring of the THD flags from every interation.
   Instead, adding the code to save/restore the flags around
   the entire loop in set_variable_row(), using Sp_eval_expr_state.
   So now saving/restoring is done only once for the entire ROW
   (a slight performance improvement).

7. Removing the code in sp_instr_set::exec_core() that sets
   a variable to NULL if the value evaluation failed.
   sp_rcontext::set_variable() now makes sure to reset
   the variable properly by effectively calling sp_eval_expr(),
   which calls virtual Field::sp_prepare_and_store_item().

   Removing the similar code from sp_instr_set_row_field::exec_core()
   and sp_instr_set_row_field_by_name::exec_core().

   Removing the method sp_rcontext::set_variable_row_field_to_null(),
   as it's not used any more.

8. Removing the call for sp_prepare_func_item() from
   sp_rcontext::set_variable_row_field(), as it was duplicate:
   it was done inside sp_eval_expr(). Now it's done inside
   virtual Field::sp_prepare_and_store_item().

9. Moving the code from sp_instr_set_row_field_by_name::exec_core()
   into sp_rcontext::set_variable_row_field_by_name(), for symmetry
   with other sp_instr_set*::exec_core()/sp_rcontext::set_variable*() pairs.
   Now sp_instr_set_row_field_by_name::exec_core() calls
   sp_rcontext::set_variable_row_field_by_name().

10. Misc:
   - Adding a helper private method sp_rcontext::virtual_tmp_table_for_row(),
     reusing it in a new sp_rcontext methods.
   - Removing Item_field_row::get_row_field(), as it's not used any more.
   - Removing the "Item *result_item" from sp_eval_expr(),
     as it's not needed any more.
2018-01-29 12:01:17 +04:00
Vicențiu Ciorbaru
d833bb65d5 Merge remote-tracking branch '5.5' into 10.0 2018-01-24 12:29:31 +02:00
Sergei Golubchik
8f102b584d Merge branch 'github/10.3' into bb-10.3-temporal 2018-01-17 00:45:02 +01:00
Sergei Golubchik
444587d8a3 BIT field woes
* get_rec_bits() was always reading two bytes, even if the
  bit field contained only of one byte
* In various places the code used field->pack_length() bytes
  starting from field->ptr, while it should be field->pack_length_in_rec()
* Field_bit::key_cmp and Field_bit::cmp_max passed field_length as
  an argument to memcmp(), but field_length is the number of bits!
2018-01-16 23:29:48 +01:00
Marko Mäkelä
70fff3688d Merge bb-10.2-ext into 10.3 2018-01-13 18:25:24 +02:00
Monty
5fce14dad0 Removed wrong DBUG_DUMP that accessed not initialized memory. 2018-01-11 23:55:13 +02:00
Aleksey Midenkov
c59c1a0736 System Versioning 1.0 pre8
Merge branch '10.3' into trunk
2018-01-10 12:36:55 +03:00
Monty
5e0b13d173 Fixed wrong arguments to printf and related functions
Other things, mainly to get
create_mysqld_error_find_printf_error tool to work:

- Added protection to not include mysqld_error.h twice
- Include "unireg.h" instead of "mysqld_error.h" in server
- Added protection if ER_XX messages are already defined
- Removed wrong calls to my_error(ER_OUTOFMEMORY) as
  my_malloc() and my_alloc will do this automatically
- Added missing %s to ER_DUP_QUERY_NAME
- Removed old and wrong calls to my_strerror() when using
  MY_ERROR_ON_RENAME (wrong merge)
- Fixed deadlock error message from Galera. Before the extra
  information given to ER_LOCK_DEADLOCK was missing because
  ER_LOCK_DEADLOCK doesn't provide any extra information.

I kept #ifdef mysqld_error_find_printf_error_used in sql_acl.h
to make it easy to do this kind of check again in the future
2018-01-04 16:24:09 +02:00
Monty
5b4c8469d5 Added CHECK_FIELD_EXPRESSION
This is needed for MDEV 13679 Enabled sequences to be used in DEFAULT

Added new option for count_cuted_fields: CHECK_FIELD_EXPRESSION
which is used to check if a DEFAULT expression is correct before
ALTER TABLE starts

Changed also all test:
  if (thd->count_cuted_fields)
  to
  if (thd->count_cuted_fields > CHECK_FIELD_EXPRESSION)
2017-12-22 14:56:58 +02:00
Aleksey Midenkov
5c0a19c873 System Versioning 1.0 pre7
Merge branch '10.3' into trunk
2017-12-21 11:16:42 +03:00
Vicențiu Ciorbaru
e3d89652e5 Merge branch '10.0' into 10.1 2017-12-20 13:30:05 +02:00
Alexander Barkov
cb121a047b An after-fix for MDEV-14008 Assertion failing: `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())
Fixing an additional failure discovered after a merge to 10.2
2017-12-20 13:49:27 +04:00
Marko Mäkelä
0436a0ff3c Merge bb-10.2-ext into 10.3 2017-12-19 17:28:22 +02:00
Marko Mäkelä
028e91f380 Merge 10.2 into bb-10.2-ext 2017-12-19 17:12:14 +02:00
Marko Mäkelä
8d70097c21 Merge 10.1 to 10.2
Follow-up fix to MDEV-14008: Let Field_double::val_uint() silently
return 0 on error
2017-12-19 16:48:28 +02:00
Aleksey Midenkov
ee68d019d1 SQL: removed VERS_HIDDEN_FLAG [closes #409] 2017-12-19 16:12:56 +03:00
Marko Mäkelä
09c5bbf471 Merge 10.0 into 10.1 2017-12-18 20:05:50 +02:00
Aleksey Midenkov
b55a149194
Timestamp-based versioning for InnoDB [closes #209]
* Removed integer_fields check
* Reworked Vers_parse_info::check_sys_fields()
* Misc renames
* versioned as vers_sys_type_t

* Removed versioned_by_sql(), versioned_by_engine()

versioned() works as before;
versioned(VERS_TIMESTAMP) is versioned_by_sql();
versioned(VERS_TRX_ID) is versioned_by_engine().

* create_tmp_table() fix
* Foreign constraints for timestamp-based
* Range auto-specifier fix
* SQL: 1-row partition rotation fix [fixes #260]
* Fix 'drop system versioning, algorithm=inplace'
2017-12-18 19:03:51 +03:00
Alexander Barkov
c1e5fef05d MDEV-14008 Assertion failing: `!is_set() || (m_status == DA_OK_BULK && is_bulk_op()) 2017-12-18 11:25:38 +04:00
Aleksey Midenkov
73606a3977 System Versioning 1.0 pre5 [closes #407]
Merge branch '10.3' into trunk

Both field_visibility and VERS_HIDDEN_FLAG exist independently.

TODO:
VERS_HIDDEN_FLAG should be replaced with SYSTEM_INVISIBLE (or COMPLETELY_INVISIBLE?).
2017-12-15 15:18:59 +03:00
Sachin Setiya
84726906c9 MDEV-10177 Invisible Columns and Invisible Index
Feature Definition:-

This feature adds invisible column functionality to server.
There is 4 level of "invisibility":

1. Not invisible (NOT_INVISIBLE) — Normal columns created by the user

2. A little bit invisible (USER_DEFINED_INVISIBLE) — columns that the
    user has marked invisible. They aren't shown in SELECT * and they
    don't require values in INSERT table VALUE (...). Otherwise
    they behave as normal columns.

3. More invisible (SYSTEM_INVISIBLE) — Can be queried explicitly,
    otherwise invisible from everything. Think ROWID sytem column.
    Because they're invisible from ALTER TABLE and from CREATE TABLE
    they cannot be created or dropped, they're created by the system.
    User cant not create a column name which is same as of
    SYSTEM_INVISIBLE.

4. Very invisible (COMPLETELY_INVISIBLE) — as above, but cannot be
    queried either. They can only show up in EXPLAIN EXTENDED (might
    be possible for a very invisible indexed virtual column) but
    otherwise they don't exist for the user.If user creates a columns
    which has same name as of COMPLETELY_INVISIBLE then
    COMPLETELY_INVISIBLE column is renamed again. So it is completely
    invisible from user.

Invisible Index(HA_INVISIBLE_KEY):-
   Creation of invisible columns require a new type of index which
   will be only visible to system. User cant see/alter/create/delete
   this index. If user creates a index which is same name as of
   invisible index then it will be renamed.

Syntax Details:-

  Only USER_DEFINED_INVISIBLE column can be created by user. This
  can be created by adding INVISIBLE suffix after column definition.

  Create table t1( a int invisible, b int);

Rules:-
  There are some rules/restrictions related to use of invisible columns
  1. All the columns in table cant be invisible.
     Create table t1(a int invisible); \\error
     Create table t1(a int invisible, b int invisble); \\error
  2. If you want invisible column to be NOT NULL then you have to supply
     Default value for the column.
     Create table t1(a int, b int not null); \\error
  3. If you create a view/create table with select * then this wont copy
     invisible fields. So newly created view/table wont have any invisible
     columns.
     Create table t2 as select * from t1;//t2 wont have t1 invisible column
     Create view v1 as select * from t1;//v1 wont have t1 invisible column
  4. Invisibility wont be forwarded to next table in any case of create
     table/view as select */(a,b,c) from table.
     Create table t2 as select a,b,c from t1; // t2 will have t1 invisible
                           // column(b), but this wont be invisible in t2
     Create view v1 as select a,b,c from t1; // v1 will have t1 invisible
                           // column(b), but this wont be invisible in v1

Implementation Details:-
  Parsing:- INVISIBLE_SYM is added into vcol_attribute(so its like unique
      suffix), It is also added into keyword_sp_not_data_type so that table
      can have column with name invisible.
  Implementation detail is given by each modified function/created function.
   (Some function are left as they were self explanatory)
   (m= Modified, n= Newly Created)

  mysql_prepare_create_table(m):- Extra checks for invisible columns are
  added. Also some DEBUG_EXECUTE_IF are also added for test cases.

  mysql_prepare_alter_table(m):- Now this will drop all the
  COMPLETELY_INVISIBLE column and HA_INVISIBLE_KEY index. Further
  Modifications are made to stop drop/change/delete of SYSTEM_INVISIBLE
  column.

  build_frm_image(m):- Now this allows incorporating field_visibility
  status into frm image. To remain compatible with old frms
  field_visibility info will be only written when any of the field is
  not NOT_INVISIBLE.

  extra2_write_additional_field_properties(n):- This will write field
  visibility info into buffer. We first write EXTRA2_FIELD_FLAGS into
  buffer/frm , then each next char will have field_visibility for each
  field.

  init_from_binary_frm_image(m):- Now if we get EXTRA2_FIELD_FLAGS,
  then we will read the next n(n= number of fields) chars and set the
  field_visibility. We also increment
  thd->status_var.feature_invisible_columns. One important thing to
  note if we find out that key contains a field whose visibility is
  > USER_DEFINED_INVISIBLE then , we declare this key as invisible
  key.

  sql_show.cc is changed accordingly to make show table, show keys
  correct.

  mysql_insert(m):- If we get to know that we are doing insert in
  this way insert into t1 values(1,1); without explicitly specifying
  columns, then we check for if we have invisible fields if yes then
  we reset the whole record, Why ? Because first we want hidden columns
  to get default/null value. Second thing auto_increment has property
  no default and no null which voilates invisible key rule 2, And
  because of this it was giving error. Reseting table->record[0]
  eliminates this issue. More info put breakpoint on handler::write_row
  and see auto_increment value.

  fill_record(m):- we continue loop if we find invisible column because
  this is already reseted/will get its value if it is default.

Test cases:- Since we can not directly add > USER_DEFINED_INVISIBLE
  column then I have debug_dbug to create it in mysql_prepare_create_table.

  Patch Credit:- Serg Golubchik
2017-12-15 02:41:52 +05:30
Marko Mäkelä
866ccc8890 Merge bb-10.2-ext into 10.3 2017-12-14 11:34:30 +02:00
Alexander Barkov
a53e087ea9 MDEV-14628 Wrong autoinc value assigned by LOAD XML in the NO_AUTO_VALUE_ON_ZERO mode
The fixes for these bugs:

Bug#27586 Wrong autoinc value assigned by LOAD DATA in the NO_AUTO_VALUE_ON_ZERO mode
Bug#22372 Disable spatial key, load data, enable spatial key, crashes table

fixed only LOAD DATA INFILE, but did not fix LOAD XML INFILE.

This patch does for LOAD XML FILE what patches for Bug#27586 and Bug#22372
earlier did for LOAD DATA INFILE.

1. Fixing the auto_increment problem:
   a. table->auto_increment_field_not_null is not set to TRUE
      anymore when a column does not have a corresponding XML tag.
   b. Adding "table->auto_increment_field_not_null= false"
      in the end of read_xml_field().
   These two changes resemble the patch for Bug#27586.

2. Fixing the GEOMETRY problem:
   The result for "reset()" was not tested for errors in read_xml_field(),
   which made it possible for empty string to sneak into a "GEOMETRY NOT NULL"
   column when this column does not have a corresponding XML tag with data.
   After this patch the result of reset() is tested and and an error is
   returned in such cases.
   This change effectively resembles the patch for Bug#22372

3. Spliting the code into a new virtual method Field::load_data_set_null().

   Rationale:
   a. To avoid duplicate code in read_sep_field() and read_xml_field():
      Changes #1 and #2 made the code handling NULL values for Field
      exactly the same in read_sep_field() and read_xml_field().

  b. To avoid tests for field_type(), which is not friendly to
     upcoming data type plugins.
     This change makes it possible for data type plugins
     to implement their own special way for handling NULL values in LOAD DATA
     by overriding Field_xxx::load_data_set_null(),
     like Field_geom and Field_timestamp do.
2017-12-13 13:22:45 +04:00
Sergei Golubchik
a46f585aa7 restore Field::get_timestamp() prototype 2017-12-05 17:57:06 +03:00
Sergei Golubchik
30841c0382 Revert "Parser: no implicit NOT NULL for system fields [fixes #163]"
This reverts commit 1cfdff5fe3c0044fa08adf5da9088dc46cc646db.

Fix it differently.
Cleanup, test results didn't change.
2017-12-05 17:48:17 +03:00
Aleksey Midenkov
2305666a05 SQL: insert delayed fix [#365 bug 3]
Affected tests (forced mode): rpl.rpl_timezone
2017-11-29 11:58:18 +03:00
Aleksey Midenkov
33085349e9 IB, SQL: removed VTQ, added TRT on SQL layer [closes #305] 2017-11-15 00:22:10 +03:00
Aleksey Midenkov
d8d7251019 System Versioning pre0.12
Merge remote-tracking branch 'origin/archive/2017-10-17' into 10.3
2017-11-07 00:37:49 +03:00
Alexander Barkov
835cbbcc7b Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3
TODO: enable MDEV-13049 optimization for 10.3
2017-10-30 20:47:39 +04:00
Alexander Barkov
003cb2f424 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-10-30 16:42:46 +04:00
Alexander Barkov
667e4b97aa MDEV-14212 Add Field_row for SP ROW variables 2017-10-30 09:24:39 +04:00
Sergei Golubchik
e0a1c745ec Merge branch '10.1' into 10.2 2017-10-24 14:53:18 +02:00
Sergei Golubchik
9d2e2d7533 Merge branch '10.0' into 10.1 2017-10-22 13:03:41 +02:00
Sergei Golubchik
da4503e956 Merge branch '5.5' into 10.0 2017-10-18 15:14:39 +02:00
Alexander Barkov
30e7d6709f Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-10-18 14:11:55 +04:00
Sergei Golubchik
df5f25fa7a Merge branch 'mysql/5.5' into 5.5 2017-10-17 10:18:17 +02:00
Sergei Golubchik
d76f5774fe MDEV-13459 Warnings, when compiling with gcc-7.x
mostly caused by -Wimplicit-fallthrough
2017-10-17 07:37:39 +02:00
Alexander Barkov
3062445a64 MDEV-14038 ALTER TABLE does not exit on error with InnoDB + bad default function
Changing Field::set_default from void to int.
It now uses the same return value notation with Field::store*()
and Item::save_in_field().
2017-10-11 18:13:44 +04:00
Alexander Barkov
a659291e85 MDEV-11586 UNION of FLOAT type results in erroneous precision
Fixing the asymmetry in the array field_types_merge_rules[][]
which caused data loss when mixing FLOAT + BIGINT in UNIONs
or hybrid functions:

1. FLOAT  + INT    = DOUBLE
2. FLOAT  + BIGINT = FLOAT
3. INT    + FLOAT  = DOUBLE
4. BIGINT + FLOAT  = DOUBLE

Now FLOAT + BIGINT (as in #2) also produces DOUBLE, like the cases #1,#3,#4 do.
2017-10-06 13:29:29 +04:00
Marko Mäkelä
2c1067166d Merge bb-10.2-ext into 10.3 2017-10-04 08:24:06 +03:00
Alexander Barkov
8ae8cd6348 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-10-02 22:35:13 +04:00
Vladislav Vaintroub
7354dc6773 MDEV-13384 - misc Windows warnings fixed 2017-09-28 17:20:46 +00:00
Vladislav Vaintroub
eba44874ca MDEV-13844 : Fix Windows warnings. Fix DBUG_PRINT.
- Fix win64 pointer truncation warnings
(usually coming from misusing 0x%lx and long cast in DBUG)

- Also fix printf-format warnings

Make the above mentioned warnings fatal.

- fix pthread_join on Windows to set return value.
2017-09-28 17:20:46 +00:00
Marko Mäkelä
4a32e2395e Merge bb-10.2-ext into 10.3 2017-09-25 22:05:56 +03:00
Sergei Golubchik
1320ad5b92 Merge branch '10.2' into bb-10.2-ext 2017-09-23 20:22:30 +02:00
Sergei Golubchik
68d1a598bc bugfix: copy timestamps correctly in INSERT...SELECT
Implement Field_timestamp::save_in_field(timestamp_field)
that stores timestamp values without converting them to MYSQL_TIME
and back, because this conversion is lossy around DST change time.
This fixes main.old-mode test.

This is 10.2 version of f8a800bec8
2017-09-22 14:01:26 +02:00
Sergei Golubchik
bc4409ab4e MDEV-13868 cannot insert 1288481126 in a timestamp column in Europe/Moscow
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.
2017-09-22 13:58:00 +02:00
Sergei Golubchik
f8a800bec8 bugfix: copy timestamps correctly in INSERT...SELECT
don't do it via MYSQL_TIME, that conversion is lossy
around DST change dates.
2017-09-21 22:03:28 +02:00
Aleksey Midenkov
88ccf759c1 SQL: pruning, derived, view fixes [fixes #244] 2017-09-01 19:05:20 +03:00
Sergey Vojtovich
fdc4779235 MDEV-11371 - column compression
Storage engine independent support for column compression.

TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT,
VARCHAR and VARBINARY columns can be compressed.

New COMPRESSED column attribute added:
COMPRESSED[=<compression_method>]

System variables added:
column_compression_threshold
column_compression_zlib_level
column_compression_zlib_strategy
column_compression_zlib_wrap

Status variables added:
Column_compressions
Column_decompressions

Limitations:
- the only supported method currently is zlib
- CSV storage engine stores data uncompressed on-disk even if COMPRESSED
  attribute is present
- it is not possible to create indexes over compressed columns.
2017-08-31 15:44:17 +04:00
Sergey Vojtovich
dd4e9cdded Get rid of Field::do_save_field_metadata()
It doesn't serve any purpose, but generates extra virtual function call.
2017-08-31 15:03:12 +04:00
Sergei Golubchik
a6e215f221 Fix compilation warnings in plugins
* update cracklib_password_check to match the new prototype
* cannot use __attribute__((format)) for my_snprintf, because
  we support format extensions that the compiler doesn't know about.
2017-08-24 01:05:48 +02:00
Michael Widenius
4aaa38d26e Enusure that my_global.h is included first
- Added sql/mariadb.h file that should be included first by files in sql
  directory, if sql_plugin.h is not used (sql_plugin.h adds SHOW variables
  that must be done before my_global.h is included)
- Removed a lot of include my_global.h from include files
- Removed include's of some files that my_global.h automatically includes
- Removed duplicated include's of my_sys.h
- Replaced include my_config.h with my_global.h
2017-08-24 01:05:44 +02:00
Tor Didriksen
ebd96c3149 Bug#19875294 ASSERTION `SRC' FAILED IN MY_STRNXFRM_UNICODE (SIG 6 -STRINGS/CTYPE-UTF8.C:5151)
Backport from 5.7 to 5.5 Field_set::val_str()
should return String("", 0, cs) rather than String(NULL, 0, cs)
2017-08-23 07:32:49 +02:00
Eugene Kosov
99baeaa951 SQL: MAX microseconds for current system rows [fixes #245] 2017-08-18 14:29:22 +03:00
Aleksey Midenkov
c2c8808a16 SQL: compare TRX_ID fields against timestamps [closes #231] 2017-08-03 16:01:16 +03:00
Alexander Barkov
4937474f86 MDEV-13414 Fix the SP code to avoid excessive use of strlen 2017-07-31 17:34:59 +04:00
Sergei Golubchik
3ef5596505 MDEV-13175 Adding a new enum value at the end of a list triggers a table rebuild
Backport of 7e29f2d64f from 10.1.

Create_field does not set BINARY_FLAG, so the check didn't work at all.
Also, character sets were already compared, so this check would've been
redundant (if it would've worked).
2017-07-20 20:13:28 +02:00
Eugene Kosov
909867d014 SQL: optimized fields fix for NOT NULL [fixes #226] 2017-07-13 18:48:30 +03:00
Marko Mäkelä
70505dd45b Merge 10.1 into 10.2 2017-05-22 09:46:51 +03:00
Alexander Barkov
5b034f1cf8 MDEV-12833 Split Column_definition::create_length_to_internal_length() to virtual methods in Type_handler 2017-05-17 18:07:20 +04:00
Alexander Barkov
fba7fbbc5c MDEV-9397 Split field.cc:calc_pack_length() into virtual methods in Type_handler
- Adding new virtual methods in Type_handler:
  * Column_definition_prepare_stage1()
  * Column_definition_prepare_stage2()
  * calc_pack_length()

- Using new methods to remove type specific code in:
  * Global function calc_pack_length()
  * Column_definition::prepare_create_field()
  * The loop body mysql_prepare_create_table()
  * Column_definition::sp_prepare_create_field()
2017-05-17 12:21:39 +04:00
Marko Mäkelä
71cd205956 Silence bogus GCC 7 warnings -Wimplicit-fallthrough
Do not silence uncertain cases, or fix any bugs.

The only functional change should be that ha_federated::extra()
is not calling DBUG_PRINT to report an unhandled case for
HA_EXTRA_PREPARE_FOR_DROP.
2017-05-17 08:27:04 +03:00
Marko Mäkelä
7972da8aa1 Silence bogus GCC 7 warnings -Wimplicit-fallthrough
Do not silence uncertain cases, or fix any bugs.

The only functional change should be that ha_federated::extra()
is not calling DBUG_PRINT to report an unhandled case for
HA_EXTRA_PREPARE_FOR_DROP.
2017-05-17 08:07:02 +03:00
Alexander Barkov
f1b729d352 MDEV-9188 Split Column_definition::check() into virtual methods in Type_handler 2017-05-16 14:29:51 +04:00
Alexander Barkov
533506b4ed MDEV-12777 Change Lex_field_type_st::m_type from enum_field_types to Type_handler pointer 2017-05-10 18:14:08 +04:00
Alexander Barkov
cc694792c9 MDEV-12717 Change Item_equal to operate Type_handler rather than Item_result 2017-05-07 01:02:37 +04:00
Aleksey Midenkov
7a525e7e93 Parser: no implicit NOT NULL for system fields [fixes #163] 2017-05-05 20:36:33 +03:00
kevg
41d9840850 SQL: remove unneded return value 2017-05-05 20:36:22 +03:00
Aleksey Midenkov
e851c140f4 SQL: (0.5) Versioned partitions [closes #77]
* one `AS OF NOW`, multiple `VERSIONING` partitions;
* rotation of `VERSIONING` partitions by record count, time period;
* rotation is multi-threaded;
* conventional subpartitions as bottom level for versioned partitions;
* `DEFAULT` keyword selects first `VERSIONING` partition;
* ALTER TABLE ADD/DROP partition;
* REBUILD PARTITION basic operation.
2017-05-05 20:36:21 +03:00
Aleksey Midenkov
a1c36f2e15 SQL: default NULL for sys fields + misc fixes
* sys fields are NULL by default (with exceptions, see comment about NOT_NULL_FLAG in #77);
* error codes renamed, messages cleared out;
* SHOW CREATE TABLE fixed;
* set_max() fix;
* redundant flag setters/getters removed;
* flags are set in sql_yacc.yy, redundant copy_info_about_generated_fields() eliminated.
2017-05-05 20:36:18 +03:00
Kosov Eugene
0581c018b7 SQL: NULL instead of optimized fields in versioned queries 2017-05-05 20:36:16 +03:00
Aleksey Midenkov
53a892fcfd IB: 0.2 part IV
* BEGIN_TS(), COMMIT_TS() SQL functions;
* VTQ instead of packed stores secs + usecs like my_timestamp_to_binary() does;
* versioned SELECT to IB is translated with COMMIT_TS();
* SQL fixes:
  - FOR_SYSTEM_TIME_UNSPECIFIED condition compares to TIMESTAMP_MAX_VALUE;
  - segfault fix #36: multiple execute of prepared stmt;
  - different tables to same stored procedure fix (#39)
* Fixes of previous parts: ON DUPLICATE KEY, other misc fixes.
2017-05-05 20:36:10 +03:00
Aleksey Midenkov
78c5d1d79c SQL: respect signed in set_max(), is_max() 2017-05-05 20:36:09 +03:00
Aleksey Midenkov
1ec7dbe176 IB: 0.2 part III
* versioned DML: INSERT, UPDATE, DELETE;
* general refactoring and fixes.

Warning: breaks 'insert' and 'update' tests since they require part IV.
2017-05-05 20:36:08 +03:00
Daniel Fiala
be6f2d302c 0.1: SQL-level System Versioning 2017-05-05 20:35:08 +03:00
Alexander Barkov
aacb4d57ca MDEV-12695 Add Column_definition::type_handler() 2017-05-05 07:00:18 +04:00
Alexander Barkov
441349aa06 MDEV-12588 Add Type_handler::type_handler_for_tmp_table() and Type_handler::type_handler_for_union()
1. Implementing the task according to the description:

a. Adding Type_handler::type_handler_for_tmp_table().
b. Adding Type_handler::type_handler_for_union_table.
c. Adding helper methods Type_handler::varstring_type_handler(const Item*),
   Type_handler::blob_type_handler(const Item*)
d. Removing Item::make_string_field() and
   Item_func_group_concat::make_string_field().
   They are not needed any more.
e. Simplifying Item::tmp_table_field_from_field_type() to just two lines.
f. Renaming Item_type_holder::make_field_by_type() and implementing
   virtual Item_type_holder::create_tmp_field() instead.
   The new implementation is also as simple as two lines.
g. Adding a new virtual method Type_all_attributes::get_typelib(),
   to access to TYPELIB definitions for ENUM and SET columns.
h. Simplifying the code branch for TIME_RESULT, DECIMAL_RESULT, STRING_RESULT
   in Item::create_tmp_field(). It's now just one line.
i. Implementing Type_handler_enum::make_table_field() and
   Type_handler_set::make_table_field().

2. Code simplification in Field_str constructor calls.

a. Changing the "CHARSET_INFO *cs" argument in constuctors for Field_str
   and its descendants to "const DTCollation &collation". This is to
   avoid two step initialization:
   - setting Field_str::derivation and Field_str::repertoire to the
     default values first
   - then resetting them using:
     set_derivation(item->derivation, item->repertoire).

b. Removing Field::set_derivation()

c. Adding a new constructor DTCollation(CHARSET_INFO *cs),
   for the old code compatibility.

3. Changes in test results

As a side effect some test results have changed, because
in the old version Item::make_string_field() converted
TINYBLOB to VARCHAR(255). Now TINYBLOB is preserved.

a. sp-row.result
   This query:
     CREATE TABLE t1 AS SELECT tinyblob_sp_variable;
   Now preserves TINYBLOB as the data type.
   Before the patch a VARCHAR(255) was created.

b. gis-debug.result
   This is a debug test, to make sure that + and - operators
   are commutative and non-commutative correspondingly.
   The exact data type is not really important.
   (But anyway, it now chooses a better data type that fits the result)
2017-04-27 14:37:27 +04:00
Alexander Barkov
b445c1ebb5 Fixing compilation failure on Windows: moving references to type_handler_xxx from field.h to field.cc 2017-04-26 10:52:18 +04:00
Alexander Barkov
2fd635409d MDEV-12426 Add Field::type_handler() + MDEV-12432
This is a joint patch for:

- MDEV-12426 Add Field::type_handler()
- MDEV-12432 Range optimizer for ENUM and SET does not return "Impossible WHERE" in some case

With the new type handler approach being added to Field, it was easier to fix
MDEV-12432 rather than to reproduce the old ENUM/SET behavior.

The patch does the following:

1. Adds Field::type_handler(), according to the task description.

2. Fixes the asymmetry between Fields and Items of ENUM and SET field types.
   Field_enum::cmp_type() returned INT_RESULT
   Item*::cmp_type() returned STRING_RESULT for ENUM and SET expressions

This asymmetry was originally done for easier coding in the optimizer sources.
However, in 10.1 we moved a lot of code to methods of the class Field:
- test_if_equality_guarantees_uniqueness()
- can_be_substituted_to_equal_item()
- get_equal_const_item()
- can_optimize_keypart_ref()
- can_optimize_hash_join()
- can_optimize_group_min_max()
- can_optimize_range()
- can_optimize_outer_join_table_elimination()

As of 10.2 only a few lines of the code in opt_range.cc, field.cc and field.h
still relayed on the fact that Field_enum::cmp_type() returns INT_RESULT:
- Some asserts in field.cc
- Field_year::get_copy_func()
- Item_func_like::get_mm_leaf()
- Item_bool_func::get_mm_leaf()
These lines have been fixed.

3. Item_bool_func::get_mm_leaf() did not work well for ENUM/SET,
see MDEV-12432. So the ENUM/SET code was rewritten, and the relevant
code in Field_enum::store() and Field_set::store() was fixed to
properly return errors to the caller.

4. The result of Field_decimal::result_type() was changed from REAL_RESULT
to DECIMAL_RESULT. Data type aggregation (e.g. in COALESCE()) is now more
precise for old DECIMAL, because Item::decimal_precision() now goes through
the DECIMAL_RESULT branch. Earlier it went through the REAL_RESULT branch.
2017-04-25 14:22:07 +04:00
Alexander Barkov
5f1544fef3 A cleanup for MDEV-9217 Split Item::tmp_table_field_from_field_type() into virtual methods in Type_handler
Fixing that the server tried to create the old decimal for:

  CREATE TABLE t2 AS SELECT old_decimal_field FROM t1
               UNION SELECT bigint_field FROM t1;

  CREATE TABLE t2 AS SELECT old_decimal_field FROM t1
               UNION SELECT mediumint_field FROM t1;

  CREATE TABLE t2 AS SELECT year FROM t1
               UNION SELECT old_decimal_field FROM t1;

  CREATE TABLE t2 AS SELCT COALESCE(old_decimal_field) FROM t1;

Solution:

1. field_types_merge_rules[][] had three MYSQL_TYPE_DECIMAL remainders.
   Fixing to MYSQL_TYPE_NEWDECIMAL, like it is done for all other type pairs.
   This fixes the above queries with UNION.

2. Convert MYSQL_TYPE_DECIMAL to MYSQL_TYPE_NEWDECIMAL in
   Item::tmp_table_field_from_field_type().
   This fixed the above query with COALESCE.

3. Adding "new Field_decimal" into Type_handler_olddecimal::make_table_field().
   In case if something goes wrong it will crash on assert only in debug builds,
   while create the old decimal in release.
   Note, this "new Field_decimal" will be needed later anyway,
   when we reuse Type_handler::make_table_field() in make_field() in field.cc.
2017-04-24 16:08:28 +04:00
Alexander Barkov
791374354c MDEV-9217 Split Item::tmp_table_field_from_field_type() into virtual methods 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.
2017-04-24 12:09:25 +04:00
Monty
5a759d31f7 Changing field::field_name and Item::name to LEX_CSTRING
Benefits of this patch:
- Removed a lot of calls to strlen(), especially for field_string
- Strings generated by parser are now const strings, less chance of
  accidently changing a string
- Removed a lot of calls with LEX_STRING as parameter (changed to pointer)
- More uniform code
- Item::name_length was not kept up to date. Now fixed
- Several bugs found and fixed (Access to null pointers,
  access of freed memory, wrong arguments to printf like functions)
- Removed a lot of casts from (const char*) to (char*)

Changes:
- This caused some ABI changes
  - lex_string_set now uses LEX_CSTRING
  - Some fucntions are now taking const char* instead of char*
- Create_field::change and after changed to LEX_CSTRING
- handler::connect_string, comment and engine_name() changed to LEX_CSTRING
- Checked printf() related calls to find bugs. Found and fixed several
  errors in old code.
- A lot of changes from LEX_STRING to LEX_CSTRING, especially related to
  parsing and events.
- Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING*
- Some changes for char* to const char*
- Added printf argument checking for my_snprintf()
- Introduced null_clex_str, star_clex_string, temp_lex_str to simplify
  code
- Added item_empty_name and item_used_name to be able to distingush between
  items that was given an empty name and items that was not given a name
  This is used in sql_yacc.yy to know when to give an item a name.
- select table_name."*' is not anymore same as table_name.*
- removed not used function Item::rename()
- Added comparision of item->name_length before some calls to
  my_strcasecmp() to speed up comparison
- Moved Item_sp_variable::make_field() from item.h to item.cc
- Some minimal code changes to avoid copying to const char *
- Fixed wrong error message in wsrep_mysql_parse()
- Fixed wrong code in find_field_in_natural_join() where real_item() was
  set when it shouldn't
- ER_ERROR_ON_RENAME was used with extra arguments.
- Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already
  give the error.

TODO:
- Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c
- Change code to not modify LEX_CSTRING for database name
  (as part of lower_case_table_names)
2017-04-23 22:35:46 +03:00
Alexander Barkov
48a7ea6da3 Uninitialized Column_definition::pack_flag for ROW-type SP variables and their fields
Fixed that the Column_definition::pack_flag member corresponding to
ROW-type SP variables and their fields was not properly initialized.
This lead to sporadic test failures. Valgrind complained about jumps
depending on uninitialized value in VALGRIND builds.

This patch makes sure that sp_head::fill_spvar_definition() is always
called for ROW variables and their fields.

Additionally, fixed that a function with a scalar parameter
erroneously acceptes ROWs with one fields. Now an error is returned.
2017-04-05 15:03:01 +04:00
Alexander Barkov
72f43df623 MDEV-10914 ROW data type for stored routine variables 2017-04-05 15:02:56 +04:00
Alexander Barkov
e34acc838b Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-04-05 14:42:14 +04:00
Sergei Petrunia
5b30c7896e Merge branch '10.2' of github.com:MariaDB/server into bb-10.2-mariarocks 2017-03-11 20:12:15 +00:00
Alexander Barkov
47b7ffb396 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-02-27 10:07:59 +04:00
Sergei Golubchik
cd4dd2b62d MDEV-10201 Bad results for CREATE TABLE t1 (a INT DEFAULT b, b INT DEFAULT 4)
Optionally do table->update_default_fields() even for INSERT
that supposedly provides values for all column. Because these
"values" might be DEFAULT, which would need table->update_default_fields()
at the end.

Also set Item_default_value::used_tables() from the default expression.
Non-zero used_field() means that mysql_insert() will initialize all
fields to their default values (with restore_record()) even if
all columns are later provided with values. Because default expressions
may refer to other columns and they must be initialized.
2017-02-13 18:12:04 +01:00
Sergei Golubchik
2195bb4e41 Merge branch '10.1' into 10.2 2017-02-10 17:01:45 +01:00
Sergei Petrunia
13c7839ba7 MariaRocks port: Fix for the previous cset (MariaRocks port: put back the assert)
- Put back the assert on SQL layer at the right location
- Adjust rdb_pack_with_make_sort_key to work around the assert (like
  it is done at other palaces):  MyRocks may need to pack a column
  value even when the column is not in the read set.
2017-01-24 21:51:57 +03:00
Sergei Petrunia
351043adda MariaRocks port: put back the assert
MyRocks seems to no longer depend on it not being present after the
merge.
2017-01-21 23:31:52 +03:00
Alexander Barkov
095ea087b4 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-01-17 18:25:18 +04:00
Vicențiu Ciorbaru
eddbae422b MDEV-11712: ArmHF EXPLAIN JSON garbage longlong values printed
Make sure printing with snprintf uses the correct typed parameters.
2017-01-16 12:49:22 +02:00
Vicențiu Ciorbaru
8e15768731 Merge branch '10.0' into 10.1 2017-01-16 03:18:14 +02:00
Monty
135e144479 MDEV-11598 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed
Found and fixed 2 problems:

- Filesort addon fields didn't mark virtual columns properly
- multi-range-read calculated vcol bitmap but was not using it.
  This caused wrong vcol field to be calculated on read, which caused the assert.
2017-01-11 09:19:45 +02:00
vicentiu
e9aed131ea Merge remote-tracking branch 'origin/5.5' into 10.0 2017-01-06 17:09:59 +02:00
Sergei Petrunia
31b2237c68 Merge branch '10.2' of github.com:MariaDB/server into 10.2-mariarocks
and a few trivial test result updates
2017-01-02 21:09:31 +00:00
Sergei Petrunia
d8288b306c Merge remote-tracking branch 'mergetrees/merge-myrocks' into 10.2-mariarocks 2017-01-01 23:33:18 +00:00
Alexander Barkov
b6aa3d2add Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2016-12-30 13:55:47 +04:00
Sergei Golubchik
4a5d25c338 Merge branch '10.1' into 10.2 2016-12-29 13:23:18 +01:00
Alexander Barkov
8aa044e674 MDEV-11478 Result data type aggregation for pluggable data types 2016-12-29 11:53:14 +04:00
Alexander Barkov
f6138883b1 MDEV-11672 mysql_list_field() returns wrong default values for VIEW
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.
2016-12-29 07:40:49 +04:00
Sergei Golubchik
9fefe97336 Merge branch 'mysql/5.5' into 5.5 2016-12-22 12:49:06 +01:00
Alexander Barkov
1c1d8fe9e4 Moving LEX::set_last_field_type() to Column_definition::set_attributes()
This is an extraction from the patch for MDEV-10577, which is not
directly related to %TYPE implementation. This patch does the following:
- Moves LEX::set_last_field_type() to Column_definition::set_attributes()
- Adds initialization of Column_definition members length, decimals,
  charset, on_update into the constructor.
- Column_definition::set_attributes() now does not set length and decimal
  to 0 any more, as they are not initialized in the constructor.
- Move Column_definition::prepare_interval_field() from field.h to field.cc,
  as it's too huge.
2016-12-16 18:33:57 +04:00
Alexander Barkov
e5dfe04da0 MDEV-11146 SP variables of the SET data type erroneously allow values with comma
There was a duplicate code to create TYPELIB from List<String>:
- In typelib() and mysql_prepare_create_table(), which was used to initialize
  table fields.
- create_typelib() and sp_prepare_create_field(), which was used to initialize
  SP variables.
create_typelib() was incomplete and didn't check for wrong SET values.

Fix:
- Moving the code from create_typelib() and mysql_prepare_create_field()
  to news methods Column_definition::create_interval_from_interval_list()
  and Column_definition::prepare_interval_field().
- Moving the code from calculate_interval_lengths() in sql_table.cc
  to a new method Column_definition::calculate_interval_lengths(), as it's now
  needed only in Column_definition::create_interval_from_interval_list()
- Reusing the new method Column_definition::prepare_interval_field() in both
  mysql_prepare_create_table() and sp_prepare_create_field(), instead of the
  old duplicate code pieces
- Removing global functions typelib() and create_typelib()

This patch also fixes:
MDEV-11155 Bad error message when creating a SET column with comma and non-ASCII characters
The problem was that ErrCongString() was called with a wrong "charset" parameter.
2016-12-16 17:31:40 +04:00
Sergei Golubchik
1db438c833 MDEV-11066 use MySQL terminology for "virtual columns" 2016-12-12 20:35:51 +01:00
Sergei Golubchik
a72f1deb2d rename Virtual_column_info::expr_item
now, when expr_str is gone, expr_item can be unambiguously
renamed to expr.
2016-12-12 20:35:48 +01:00