Commit graph

175448 commits

Author SHA1 Message Date
Sergey Vojtovich
8f9999b5fc MDEV-11212 - Clean-up MariaDB atomic operations
Removed my_atomic_initialize(): it doesn't make sense anymore.
2016-12-13 16:38:20 +04:00
Sergey Vojtovich
1369e70b56 MDEV-11212 - Clean-up MariaDB atomic operations
Removed "somewhat broken native x86 implementation". Should never be used on
supported platforms.
2016-12-13 16:38:20 +04:00
Alexander Barkov
beea3413e0 MDEV-11503 Introduce Type_handler::make_in_vector() and Item_func_in_fix_comparator_compatible_types()
This patch implements the task according to the description:

1. The old code from Item_func_in::fix_length_and_dec() was decomposed
into smaller methods:
- all_items_are_consts()
- compatible_types_scalar_bisection_possible()
- compatible_types_row_bisection_possible()
- fix_in_vector()
- fix_for_scalar_comparison_using_bisection()
- fix_for_scalar_comparison_using_cmp_items()
- fix_for_row_comparison_using_bisection()
- fix_for_row_comparison_using_cmp_items()

The data type dependend pieces where moved as methods to Type_handler.

2. Splits in_datetime into separate:
   - in_datetime, for DATETIME and DATE,
   - in_time, for TIME
   to make the code more symmetric across data types.

Additionally:
- Adds a test func_debug.test to see which calculation strategy
  (bisect or no bisect) is chosen to handle IN with various arguments.
- Adds a new helper method (to avoid duplicate code):
  cmp_item_rows::prepare_comparators()
- Changes the propotype for cmp_item_row::alloc_comparators(),
  to avoid duplicate code, and to use less current_thd.
- Changes "friend" sections in cmp_item_row and in_row from
  an exact Item_func_in method to the entire class Item_func_in,
  as their internals are now needed in multiple Item_func_in methods.
- Added more comments (e.g. on bisection, on the problem reported in MDEV-11511)
2016-12-10 22:25:17 +04:00
Alexander Barkov
e315bb7d19 Addressing Sanja's comments about for the MDEV-11485 patch 2016-12-07 10:00:46 +04:00
Alexander Barkov
fd4e986b07 MDEV-11485 Split Item_func_between::val_int() into virtual methods in Type_handler
- Removes "Item_result Item_func_opt_neg::m_compare_type" and introduces
  "Type_handler_hybrid_field_type Item_func_opt_neg::m_comparator" instead.

- Removes Item_func_between::compare_as_dates, because
  the new member m_comparator now contains the precise information
  about the data type that is used for comparison, which is important
  for TIME vs DATETIME.

- Adds a new method:
  Type_handler_hybrid_field_type::aggregate_for_comparison(const Type_handler*),
  as a better replacement for item_cmp_type(), which additionally can handle
  TIME vs DATE/DATETIME/TIMESTAMP correctly. Additionally, it correctly
  handles TIMESTAMP which fixes the problem reported in MDEV-11482.
  The old compare_as_dates/find_date_time_item() based code didn't handle
  comparison between TIME and TIMESTAMP correctly and erroneously used TIME
  comparison instead of DATETIME comparison.

- Adds a new method:
  Type_handler_hybrid_field_type::aggregate_for_comparison(Item **, uint nitems),
  as a better replacement for agg_cmp_type(), which can handle TIME.
- Splits Item_func_between::val_int() into pieces val_int_cmp_xxx(),
  one new method per XXX_RESULT.
- Adds a new virtual method Type_handler::Item_func_between_val_int()
  whose implementations use Item_func_between::val_int_cmp_xxx().
- Makes type_handler_longlong and type_handler_newdecimal public,
  as they are now needed in item_cmpfunc.cc.

Note:
This patch does not change Item_func_in to use the new aggregation methods,
so it still uses collect_cmp_type()/item_cmp_type() based aggregation.
Item_func_in will be changed in a separate patch and item_cmp_type() will be
removed.
2016-12-06 23:20:39 +04:00
Alexander Barkov
466728c452 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-06 07:52:33 +04:00
Alexander Barkov
378c3cf99d MDEV-11330 Split Item_func_hybrid_field_type::val_xxx() into methods in Type_handler 2016-12-06 07:52:33 +04:00
Alexander Barkov
98eaff34af MDEV-11298 Split Item_func_hex::val_str_ascii() into virtual methods in Type_handler 2016-12-06 07:52:33 +04:00
Alexander Barkov
587d387a03 MDEV-11365 Split the data type and attribute related code in Item_sum_hybrid::fix_fields into Type_handler::Item_sum_hybrid_fix_length_and_dec()
This patch:
- Implements the task according to the description
- Adds a new class Type_handler_numeric as a common parent
  for Type_handler_real_result, Type_handler_int_result,
  Type_handler_decimal_result, to share the common code
  between numeric data type handlers.
- Removes the dedundant call for collation.set(item->collation) in
  Item_sum_hybrid::setup_hybrid(), because setup_hybrid() is called
  either after fix_length_and_dec() or afte ther constructor
  Item_sum_hybrid(THD *thd, Item_sum_hybrid *item),
  so the collation is already properly set in all cases.
2016-12-06 07:52:33 +04:00
Alexander Barkov
81f448ce4d MDEV-11357 Split Item_cache::get_cache() into virtual methods in Type_handler
This patch:
- Adds a new virtual method Type_handler::Item_get_cache
- Splits moves Item_cache::get_cache() into the new method, every
  "case XXX_RESULT" to the corresponding Type_handler_xxx::Item_get_cache.
- Adds Item::get_cache as a convenience wrapper, to make the caller code
  shorter.
- Changes the last argument of Arg_comparator::cache_converted_constant()
  from Item_result to "const Type_handler *".
- Removes subselect_engine::cmp_type, subselect_engine::res_type,
  subselect_engine::res_field_type and derives subselect_engine
  from Type_handler_hybrid_field_type instead.
- Makes Type_handler_varchar public, as it's now needed as the
  default data type handler for subselect_engine.
2016-12-06 07:52:32 +04:00
Alexander Barkov
7ae95bd0e5 MDEV-11347 Move add_create_index_prepare(), add_key_to_list(), set_trigger_new_row(), set_local_variable(), set_system_variable(), create_item_for_sp_var() as methods to LEX
Moving another banch of functions implemented in sql_yacc.yy as methods to LEX,
to be able to reuse them between sql_yacc.yy and sql_yacc_ora.yy easier.
The list of functions:
- add_create_index_prepare()
- add_key_to_list()
- set_trigger_new_row()
- set_local_variable()
- set_system_variable()
- create_item_for_sp_var()
2016-12-06 07:52:32 +04:00
Alexander Barkov
ebd8710b78 MDEV-11344 Split Arg_comparator::set_compare_func() into virtual methods in Type_handler
This patch:
- Introduces a new virtuial method Type_handler::set_comparator_func
  and moves pieces of the code from the switch in
  Arg_comparator::set_compare_func into the corresponding
  Type_handler_xxx::set_comparator_func.
- Adds Type_handler::get_handler_by_cmp_type()
- Moves Type_handler_hybrid_field_type::get_handler_by_result_type() to
  a static method Type_handler::get_handler_by_result_type(),
  for symmetry with similar methods:
  * Type_handler::get_handler_by_field_type()
  * Type_handler::get_handler_by_real_type()
  * Type_handler::get_handler_by_cmp_type()
- Introduces Type_handler_row, to unify the code for the scalar
  data types and the ROW data type (currently for comparison purposes only).
- Adds public type_handler_row, as it's now needed in item_row.h
- Makes type_handler_null public, as it's now needed in item_cmpfunc.h
  Note, other type_handler_xxx will become public as well later.
- Removes the global variable Arg_comparator::comparator_matrix,
  as it's not needed any more.
2016-12-06 07:52:32 +04:00
Alexander Barkov
25f52725da MDEV-11337 Split Item::save_in_field() into virtual methods in Type_handler
Also fixes:
MDEV-11331 Wrong result for INSERT INTO t1 (datetime_field) VALUES (hybrid_function_of_TIME_data_type)
MDEV-11333 Expect "Impossible where condition" for WHERE timestamp_field>=DATE_ADD(TIMESTAMP'9999-01-01 00:00:00',INTERVAL 1000 YEAR)

This patch does the following:
1. Splits the function Item::save_in_field() into pieces:
- Item::save_str_in_field()
- Item::save_real_in_field()
- Item::save_decimal_in_field()
- Item::save_int_in_field()

2. Adds the missing "no_conversion" parameters to
   Item::save_time_in_field() and Item::save_date_in_field(),
   so this parameter is now correctly passed to
   set_field_to_null_with_conversions().
   This fixes the problem reported in 11333.

3. Introduces a new virtual method Type_handler::Item_save_in_field()
   and uses the methods Item::save_xxx_in_field() from the implementations
   of Type_handler_xxx::Item_save_in_field().

These changes additionally fix the problem reported in MDEV-11331,
as the old code erroneously handled expressions like
COALESE(datetime-expression) through the STRING_RESULT branch of
Item::save_in_field() and therefore they looked like string type expressions
for the target fields. Now such expressions are correctly handled by
Item::save_date_in_field().
2016-12-06 07:52:32 +04:00
Alexander Barkov
8a1c0d46eb MDEV-11346 Move functions case_stmt_xxx and add_select_to_union_list as methods to LEX
The full list of functions moved:
int case_stmt_action_expr(LEX *, Item* expr);
int case_stmt_action_when(LEX *, Item *when, bool simple);
int case_stmt_action_then(LEX *);
bool add_select_to_union_list(LEX *,bool is_union_distinct,  bool is_top_level);

This is a preparatory change for "MDEV-10142 PL/SQL parser",
to reuse the code easier between sql_yacc.yy and coming soon sql_yacc_ora.yy.
2016-12-06 07:52:32 +04:00
Alexander Barkov
fb3806fd34 MDEV-11294 Move definitions of Derivation, DTCollation, Type_std_attributes from field.h and item.h to sql_type.h 2016-12-06 07:52:32 +04:00
Alexander Barkov
b9768dd17c MDEV-11245 Move prepare_create_field and sp_prepare_create_field() as methods to Column_definition
Some upcoming tasks, e.g.:
- MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations
- MDEV-10914 ROW data type for stored routine variables

will need to reuse the code implemented in prepare_create_field(),
sp_prepare_create_field(), prepare_blob_field().

Before reusing this code, it's a good idea to move these global functions
as methods to Column_definition.

This patch:
- actually moves prepare_create_field(), sp_prepare_create_field(),
  prepare_blob_field() as methods to Column_definition
- makes sp_prepare_create_field() call prepare_create_field() at the end,
  to avoid duplicate code in MDEV-10577 and MDEV-10914.
- changes the return data type for prepare_create_field() from int to bool,
  to make it consistent with all other functions returning "ok" or "error".
- moves the implementation sp_head::fill_field_definition() from sp_head.cc
  to sp_head.h, as it now uses globally visible Column_definition methods,
  and is very simple, so inlining is now possible.
- removes the unused "LEX*" argument from sp_head::fill_field_definition()
2016-12-06 07:52:31 +04:00
Alexander Barkov
9ea06588f8 MDEV-10811 Change design from "Item is Type_handler" to "Item has Type_handler" 2016-12-06 07:52:31 +04:00
Alexander Barkov
3c4de09653 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-06 07:52:31 +04:00
Alexander Barkov
e4ec85088f Starting the 10.3 branch 2016-12-06 07:52:31 +04:00
Alexey Botchkov
3371904380 MDEV-11447 JSON_MERGE merges valid JSON objects incorrectly.
Test case added.
2016-12-06 01:39:06 +04:00
Alexey Botchkov
fba1eab92f MDEV-11446 JSON_MERGE accepts arguments in invalid format.
Test case added.
2016-12-06 01:35:40 +04:00
Alexey Botchkov
3bae5328ea MDEV-11433 JSON_MERGE returns a non-NULL result with a NULL argument.
Item_func_json_merge fixed.
2016-12-06 01:32:13 +04:00
Alexey Botchkov
486079d159 MDEV-11440 JSON has become a reserved word in MariaDB.
'JSON' made possible identifier.
2016-12-06 00:39:53 +04:00
Alexey Botchkov
3743b4c3ef MDEV-11468 JSON_UNQUOTE returns incorrect results.
Now return the argument's value when error.
2016-12-06 00:34:25 +04:00
Jan Lindström
0009f4a441 Merge pull request #268 from grooverdan/10.2-MDEV-10651-enable-test-sys_vars.innodb_buffer_pool_dump_pct_basic
MDEV-10651: enable test sys_vars.innodb_buffer_pool_dump_pct_basic
2016-12-05 17:12:29 +02:00
Marko Mäkelä
660521a43a Merge pull request #263 from grooverdan/10.2-MDEV-11451-isfinite
MDEV-11451: isinf || isnan -> !isfinite
2016-12-05 17:01:28 +02:00
Marko Mäkelä
cc85ba8f2e MDEV-11233 CREATE FULLTEXT INDEX with a token longer than 127 bytes
crashes server

This bug is the result of merging the Oracle MySQL follow-up fix
BUG#22963169 MYSQL CRASHES ON CREATE FULLTEXT INDEX
without merging the base bug fix:
Bug#79475 Insert a token of 84 4-bytes chars into fts index causes
server crash.

Unlike the above mentioned fixes in MySQL, our fix will not change
the storage format of fulltext indexes in InnoDB or XtraDB
when a character encoding with mbmaxlen=2 or mbmaxlen=3
and the length of a word is between 128 and 84*mbmaxlen bytes.
The Oracle fix would allocate 2 length bytes for these cases.

Compatibility with other MySQL and MariaDB releases is ensured by
persisting the used maximum length in the SYS_COLUMNS table in the
InnoDB data dictionary.

This fix also removes some unnecessary strcmp() calls when checking
for the legacy default collation my_charset_latin1
(my_charset_latin1.name=="latin1_swedish_ci").

fts_create_one_index_table(): Store the actual length in bytes.
This metadata will be written to the SYS_COLUMNS table.

fts_zip_initialize(): Initialize only the first byte of the buffer.
Actually the code should not even care about this first byte, because
the length is set as 0.

FTX_MAX_WORD_LEN: Define as HA_FT_MAXCHARLEN * 4 aka 336 bytes,
not as 254 bytes.

row_merge_create_fts_sort_index(): Set the actual maximum length of the
column in bytes, similar to fts_create_one_index_table().

row_merge_fts_doc_tokenize(): Remove the redundant parameter word_dtype.
Use the actual maximum length of the column. Calculate the extra_size
in the same way as row_merge_buf_encode() does.
2016-12-05 16:32:03 +02:00
Alexey Botchkov
1da0865058 MDEV-11467 JSON_EXTRACT returns incorrect results.
Item_func_json_extract::val_str fixed.
2016-12-05 09:34:28 +04:00
Alexey Botchkov
2b01461629 MDEV-11465 JSON_LENGTH returns incorrect length.
Item_func_json_length::val_int fixed.
2016-12-05 08:59:55 +04:00
Alexey Botchkov
75a51818b2 MDEV-11448 Assertion `*p_cur_step < p->last_step' failed in strings/json_lib.c handle_match.
Test case added.
2016-12-05 08:52:37 +04:00
Alexey Botchkov
fe6d0a0719 MDEV-11471 JSON_ARRAY_APPEND returns incorrect results.
Item_func_json_array_append::val_str fixed.
2016-12-05 08:43:15 +04:00
Alexey Botchkov
abb80d25f4 MDEV-11472 JSON_ARRAY_INSERT returns incorrect results.
Item_func_json_array_insert::val_str fixed.
2016-12-05 08:03:11 +04:00
Alexey Botchkov
df87dce03c MDEV-11473 JSON_REMOVE returns invalid results.
Item_func_json_remove::val_str fixed.
2016-12-05 07:42:00 +04:00
Alexey Botchkov
7e03c67ae8 MDEV-11474 JSON_DEPTH returns incorrect results.
Item_func_json_depth::val_int fixed.
2016-12-05 07:17:54 +04:00
Daniel Black
6924593ed8 MDEV-10651: enable test sys_vars.innodb_buffer_pool_dump_pct_basic
Since 10.2 (2e814d4702) this test
changed and the race condition of MDEV-10651 no longer forms part
of this test.

As such re-enable this test.

Also include save/restore of the default values of this variable.

Signed-off-by: Daniel Black <daniel.black@au.ibm.com>
2016-12-05 10:42:42 +11:00
Daniel Black
b11eb36963 MDEV-11451: isinf || isnan -> !isfinite
There are only 3 logical states for a number. The isfinite is a
single function call rather than multiple leaving scope for compiler
/architecture optimization.

Changed the logic as follows in a few files.

my_isinf(square) || my_isnan(square) -> !isfinite(square)

Signed-off-by: Daniel Black <daniel.black@au.ibm.com>
2016-12-05 09:22:00 +11:00
Alexey Botchkov
78dc7c3a6e MDEV-11461 JSON_TYPE does not recognize integer/double types.
Integer/Double recognition added.
2016-12-05 01:03:31 +04:00
Alexey Botchkov
5454500562 MDEV-11452 JSON_CONTAINS accepts wrong number of arguments.
Create_func_json_contains::create_native fixed.
2016-12-05 01:03:31 +04:00
Alexey Botchkov
c89c514ed3 MDEV-11445 JSON_MERGE requires at least two arguments in MySQL, but not in MariaDB.
Create_func_json_merge::create_native fixed.
2016-12-05 01:03:30 +04:00
Alexey Botchkov
12897a5bba MDEV-11437 JSON_QUOTE function does not quote and uses wrong character set.
json_quote fixed.
2016-12-05 01:03:30 +04:00
Alexey Botchkov
b4cbaf0b7c MDEV-11436 CREATE TABLE .. AS SELECT JSON_OBJECT truncates data.
fix_length_and_dec() didn't calculate the length of the result
        properly.
2016-12-05 01:03:30 +04:00
Alexey Botchkov
f391ab4f01 MDEV-11438 Assertion `null_value' failed in Item::send(Protocol*, String*) upon casting NULL as JSON.
test added.
2016-12-05 01:03:30 +04:00
Alexey Botchkov
f105014e9b MDEV-11464 Server crashes in mark_object upon JSON_VALID.
Depth of nested objects should be controlled.
2016-12-03 12:41:19 +04:00
Alexey Botchkov
7fca133028 MDEV-11463 Server crashes in mark_array upon JSON_VALID.
The depth of nested arrays should be controlled, as it's limited.
2016-12-03 12:36:10 +04:00
Alexey Botchkov
edc75c9c16 MDEV-11450 Assertion `!null_value' failed invirtual bool Item::send on json_search.
Item_func_json_search::val_str didn't set the null_value
        properly. So that affected the next record in the resultset.
2016-12-03 12:11:06 +04:00
Alexey Botchkov
a8467e2fab MDEV-11449 Server crashes in Item_func_or_sum::agg_item_collations.
JSON_ARRAY didn't expect 0 arguments.
2016-12-03 11:45:24 +04:00
Alexey Botchkov
eca1579051 MDEV-11444 Server crashes in String::ptr / Item_func_json_depth::val_int.
CAST AS JSON didn't set the null_value mark properly.
2016-12-03 11:32:47 +04:00
Alexey Botchkov
4ad0813a55 MDEV-11143 Server crashes in json_string_set_cs.
Some JSON functions didn't expect NULL as a path.
2016-12-03 11:22:42 +04:00
Alexey Botchkov
e8c419570f MDEV-11442 Server crashes in String::length / parse_one_or_all /Item_func_json_contains_path::val_int
Didn't expect 'one_or_all' parameter to be NULL.
2016-12-03 11:02:28 +04:00
Alexey Botchkov
b28626e842 MDEV-11441 Server crashes in String::append /Item_func_json_extract::val_str.
Wrong 'value_lengh' taken
2016-12-03 10:53:12 +04:00