Commit graph

245 commits

Author SHA1 Message Date
Aleksey Midenkov
7c0779da7c MDEV-16102 Wrong ER_DUP_ENTRY upon ADD UNIQUE KEY on versioned table
* ignore CHECK constraint for historical rows;
* FOREIGN KEY test case.

TODO:
MDEV-16301 IB: use real table name for error messages on ALTER

Closes tempesta-tech/mariadb#491
Closes #748
2018-06-30 16:12:45 +02:00
Alexander Barkov
724a5105cb MDEV-16584 SP with a cursor inside a loop wastes THD memory aggressively
Problem:

push_handler() created sp_handler_entry instances on THD::main_mem_root,
which is freed only after the SP instructions execution.
So in case of a CONTINUE HANDLER inside a loop (e.g. WHILE) this approach
leaked thread memory on every loop iteration.

Changes:
- Removing sp_handler_entry declaration, it's not really needed.
- Fixing the data type of sp_rcontext::m_handlers from
  Dynamic_array<sp_handler_entry*> to Dynamic_array<sp_instr_hpush_jump*>
- Fixing sp_rcontext::push_handler() to push the pointer to
  an sp_instr_hpush_jump instance to the handler stack.
  This instance contains everything we need.
  There is no a need to allocate anything else.
2018-06-28 16:55:42 +04:00
Alexander Barkov
56145be295 MDEV-16584 SP with a cursor inside a loop wastes THD memory aggressively
Problem:

push_cursor() created sp_cursor instances on THD::main_mem_root,
which is freed only after the SP instructions loop.

Changes:
- Moving sp_cursor declaration from sp_rcontext.h to sql_class.h
- Deriving sp_instr_cpush from sp_cursor. So now sp_cursor is created
  only once (at the SP parse time) and then reused on all loop iterations
- Adding a new method reset() into sp_cursor (and its parent classes)
  to reset an sp_cursor instance before reuse.
- Moving former sp_cursor members m_fetch_count, m_row_count, m_found
  into a separate class sp_cursor_statistics. This helps to reuse
  the code in sp_cursor constructors, and in sp_cursor::reset()
- Adding a helper method sp_rcontext::pop_cursor().
- Adding "THD*" parameter to so_rcontext::pop_cursors() and pop_all_cursors()
- Removing "new" and "delete" from sp_rcontext::push_cursor() and
  sp_rconext::pop_cursor().
- Fixing sp_cursor not to derive from Sql_alloc, as it's now allocated
  only as a part of sp_instr_cpush (and not allocated separately).
- Moving lex_keeper->disable_query_cache() from sp_cursor::sp_cursor()
  to sp_instr_cpush::execute().
- Adding tests
2018-06-27 12:54:05 +04:00
Thirunarayanan Balathandayuthapani
88aaf590ac MDEV-16365 Setting a column NOT NULL fails to return error for
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.
2018-06-25 14:52:38 +05:30
Alexander Barkov
1abd877e2d MDEV-8049 name_const() is not consistent about its signess 2018-06-22 11:28:02 +04:00
Alexander Barkov
bcc2100f9d MDEV-16471 mysqldump throws "Variable 'sql_mode' can't be set to the value of 'NULL' (1231)" 2018-06-21 12:54:28 +04:00
Alexander Barkov
ff09512e07 MDEV-16489 when lead() returns null on a datetime field, the result is treated as the literal string '[NULL]' 2018-06-20 19:36:37 +04:00
Alexander Barkov
9c53cbdd88 MDEV-15941 Explicit cursor FOR loop does not close the cursor 2018-06-20 13:29:11 +04:00
Oleksandr Byelkin
b534a7b89e Merge branch '10.3' into bb-10.3-fix_len_dec 2018-06-20 08:29:07 +02:00
Oleksandr Byelkin
083279f783 Merge commit '6b8802e8dd5467556a024d807a1df23940b00895' into bb-10.3-fix_len_dec 2018-06-19 14:51:50 +02:00
Igor Babaev
956b296248 MDEV-16420 View stop working after upgrade from 10.1.15 to 10.3.7
This bug happened for queries that used a materialized view that
renamed columns of the specifying query in an inner table of
an outer join. For such a query name resolution for a column
belonging the view could fail if the underlying column was
non-nullable.
When creating the defintion of the the temporary table for
the materialized view used in the inner part of an outer join
the definition of the non-nullable columns are created by the
function create_tmp_field_from_item() that names the columns
according to the names of the underlying columns. So these names
should be changed for the view column names.

This bug cannot be reproduced in 10.2 because there setup_fields()
called when preparing joins in the view specification effectively
renames the underlying columns in the function find_field_in_view().
In 10.3 this renaming was removed as improper
(see Monty's commit b478276b04).
2018-06-18 23:04:17 -07:00
Marko Mäkelä
0121d5a790 Merge 10.2 into 10.3 2018-06-18 15:43:59 +03:00
Alexander Barkov
f61909e19e MDEV-10182 Bad value when inserting COALESCE(CURRENT_TIMESTAMP) into a DECIMAL column
This problem was earlier fixed by the patch cb16d753b2
for MDEV-11337 Split Item::save_in_field() into virtual methods in Type_handler.

Adding tests only.
2018-06-15 06:33:34 +04:00
Alexander Barkov
106f0b5798 MDEV-16385 ROW SP variable is allowed in unexpected context
The problem described in the bug report happened because the code
did not test check_cols(1) after fix_fields() in a few places.

Additionally, fix_fields() could be called multiple times for SP variables,
because they are all fixed at a early stage in append_for_log().

Solution:
1. Adding a few helper methods
   - fix_fields_if_needed()
   - fix_fields_if_needed_for_scalar()
   - fix_fields_if_needed_for_bool()
   - fix_fields_if_needed_for_order_by()
  and using it in many cases instead of fix_fields() where
  the "fixed" status is not definitely known to be "false".

2. Adding DBUG_ASSERT(!fixed) into Item_splocal*::fix_fields()
   to catch double execution.

3. Adding tests.

As a good side effect, the patch removes a lot of duplicate code (~60 lines):

   if (!item->fixed &&
       item->fix_fields(..) &&
       item->check_cols(1))
     return true;
2018-06-05 10:25:39 +04:00
Marko Mäkelä
b50685af82 Merge 10.2 into 10.3 2018-06-04 16:12:00 +03:00
Marko Mäkelä
a3539bbb2a Merge 10.2 into 10.3 2018-05-29 17:34:49 +03:00
Andrei Elkin
3bbc30c73b MDEV-13727 top-level query timestamp reset at stored func/trigger internal statements
Being executed under slow_log is ON the test revealed a "side-effect"
in MDEV-8305 implementation which inadvertently made the trigger or
stored function statements to reset the top-level query's
THD::start_time et al. (Details of the test failure analysis are footnoted).
Unlike the SP case the SF and Trigger's internal statement should not
do that.

Fixed with revising the MDEV-8305 decision to backup/reset/restore
the session timestamp inside sp_instr_stmt::execute(). The timestamp
actually remains reset in the SP case by its caller per statement basis by ever
existing logics.

Timestamps related tests are extended to cover the trigger and stored function case.

Note, commit 3395ab7324 is reverted as its struct QUERY_START_TIME_INFO
declaration is not in use anymore after this patch.

Footnote:
--------
Specifically to the failing test, a query on the master was logged
okay with a timestamp of the query's top-level statement but its post
update trigger managed to compute one more (later) timestamp which got
inserted into another table. The latter table master-vs-slave
no fractional part timestamp discrepancy became evident
thanks to different execution time of the trigger combined with the
fact of the logged with micro-second fractional part master timestamp
was truncated on the slave. On master when the fractional part was
close to 1 the trigger execution added up its own latency to overflow
to next second value. That's how the master timestamp surprisingly
turned out to bigger than the slave's one.
2018-05-25 14:57:48 +03:00
Marko Mäkelä
6686dfcbbf Merge 10.2 into 10.3 2018-05-24 11:27:15 +03:00
Sergei Golubchik
4ec8598c1d Merge branch 'github/10.2' into 10.3 2018-05-22 11:47:09 +02:00
Varun Gupta
36779e624d MDEV-14623: Output of show function code does not show FETCH GROUP NEXT ROW for custom aggregates
The print() function was missing from the FETCH GROUP NEXT ROW instrunction class, so there was no
output for this particular instruction when we use the query SHOW FUNCTION CODE function_name
2018-05-19 15:12:15 +05:30
Varun Gupta
89b1c2712a MDEV-14520: Custom aggregate functions work incorrectly with WITH ROLLUP clause
Queries involving rollup need all aggregate function to have copy_or_same function where we create a copy
of item_sum items for each sum level.
Implemented copy_or_same function for the custom aggregate function class (Item_sum_sp)
2018-05-19 15:12:15 +05:30
sachin
395c8ca708 MDEV-14853 Grant does not work correctly when table contains...
SYSTEM_INVISIBLE or COMPLETELY_INVISIBLE

This commit does multiple things to solve this mdev
1st add field into the parameter of check_column_grant_in_table_ref, so that
we can find out field invisibility.
2nd If field->invisible >= INVISIBLE_SYSTEM skip access check and simple
grant access.
2018-05-18 08:22:41 +05:30
Alexander Barkov
10d44db5d4 MDEV-16202 Latest changes made erroneously some keywords reserved in sql_mode=ORACLE 2018-05-17 16:01:20 +04:00
Marko Mäkelä
66afb5ecb7 MDEV-16172: Enable skipped tests 2018-05-17 09:37:01 +03:00
Marko Mäkelä
4c7608aeb1 Merge 10.2 into 10.3 2018-05-17 08:42:53 +03:00
Alexander Barkov
c2df4e9d62 MDEV-16186 Concatenation operator || returns wrong results in sql_mode=ORACLE 2018-05-16 17:21:31 +04:00
Oleksandr Byelkin
dd0e960f4d Fix of the test after null processing fix. 2018-05-15 19:52:28 +02:00
Oleksandr Byelkin
0dd1ebcb27 MDEV-15576: Server crashed in Cached_item_str::cmp / sortcmp or Assertion `item->null_value' failed in Type_handler_temporal_result::make_sort_key upon SELECT with NULLIF and ROLLUP
Fixed null_value processing and is_null() usage.
2018-05-15 14:20:54 +02:00
Monty
8a9048bcf3 MDEV-16170 Server crashes in Item_null_result::type_handler on SELECT with ROLLUP
Problem was that I in a previous patch enabled ifdef:ed code intended for
10.3 but that never worked.

Reverted to original code
2018-05-15 13:51:03 +03:00
Alexey Botchkov
e06c029849 MDEV-15465 Server crash or ASAN heap-use-after-free in Item_func_match::cleanup upon using FT search with partitioning.
Partition engine FT keys are implemented in such a way that
the FT function's cleanup() methods use table's internals.
So calling them after close_thread_tables is unsafe.
2018-05-15 14:10:19 +04:00
Sachin Setiya
9ee5406e2f MDEV-15965 Invisible columns and LOAD DATA don't work well together:... ER_WARN_TOO_FEW_RECORDS
Fix mysql_load iterator to skip invisible fields.
2018-05-15 12:38:44 +05:30
Jacob Mathew
86f9932e80 MDEV-16101: ADD PARTITION on table partitioned by list does not work with more than 32 list values.
This problem occured because the reorganization of the list of values when the
number of elements exceeds 32 was not handled correctly.  I have fixed the
problem by fixing the way that the list values are reorganized when the number
of list values exceeds 32.

Author:
  Jacob Mathew.

Reviewer:
  Alexey Botchkov.

Merged From:
  Branch bb-10.3-MDEV-16101
2018-05-14 15:12:40 -07:00
Igor Babaev
e74181e3c2 MDEV-15159 NULL is treated as 0 in CTE
Forced columns of recursive CTEs to be nullable. SQL standard
requires this only from recursive columns, but in our code
so far we do not differentiate between recursive and non-recursive
columns when aggregating types of the union that specifies a
recursive CTE.
2018-05-14 14:38:17 -07:00
Jacob Mathew
8e01598620 MDEV-16101: ADD PARTITION on table partitioned by list does not work with more than 32 list values.
This problem occured because the reorganization of the list of values when the
number of elements exceeds 32 was not handled correctly.  I have fixed the
problem by fixing the way that the list values are reorganized when the number
of list values exceeds 32.

Author:
  Jacob Mathew.

Reviewer:
  Alexey Botchkov.
2018-05-14 13:25:41 -07:00
Alexander Barkov
4a5e23e257 MDEV-16152 Expressions with INTERVAL return bad results in some cases 2018-05-14 11:36:22 +04:00
Michael Widenius
be6ae0bb6b Don't report errors from open_table() twice 2018-05-14 10:08:05 +03:00
Marko Mäkelä
15419a5583 Merge 10.2 into 10.3 2018-05-12 22:14:59 +03:00
Aleksey Midenkov
fddaaf7295 MDEV-15978 Add Feature_system_versioning status variable 2018-05-12 10:16:46 +02:00
Eugene Kosov
da25860d4a MDEV-15995 Drop extra semicolon in VARIABLE_COMMENT for SYSTEM_VERSIONING_ALTER_HISTORY 2018-05-12 10:16:46 +02:00
Sergei Golubchik
4203f572ae MDEV-15923 option to control who can set session @@timestamp
--secure-timestamp=NO|SUPER|REPLICATION|YES
2018-05-12 10:16:45 +02:00
Sergei Golubchik
0f956a0676 cleanup: hide HA_ERR_RECORD_DELETED in ha_rnd_next()
it's internal storage engine error, don't let it leak
into the upper layer.
2018-05-12 10:16:45 +02: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
Sergei Golubchik
c9717dc019 Merge branch '10.2' into 10.3 2018-05-11 13:15:10 +02:00
Alexander Barkov
33721d9138 MDEV-16134 Wrong I_S.COLUMNS.CHARACTER_XXX_LENGTH value for compressed columns 2018-05-10 19:30:43 +04:00
Alexander Barkov
fc63c1e17a MDEV-16117 SP with a single FOR statement creates but further fails to load
The code in the "sp_tail" rule in sql_yacc.yy always
used YYLIP->get_cpp_tok_start() as the start of the body,
and did not check for possible lookahead which happens
for keywords "FOR", "VALUES" and "WITH" for LALR(2)
resolution in Lex_input_stream::lex_token().

In case of the lookahead token presence,
get_tok_start_prev() should have been used instead
of get_cpp_tok_start() as the beginning of the SP body.

Change summary:

This patch hides the implementation of the lookahead
token completely inside Lex_input_stream.
The users of Lex_input_stream now just get token-by-token
transparently and should not care about lookahead any more.
Now external users of Lex_input_stream
are not aware of the lookahead token at all.

Change details:

- Moving Lex_input_stream::has_lookahead() into the "private" section.

- Removing Lex_input_stream::get_tok_start_prev() and
  Lex_input_stream::get_cpp_start_prev().

- Fixing the external code to call get_tok_start() and get_cpp_tok_start()
  in all places where get_tok_start_prev() and get_cpp_start_prev()
  where used.

- Adding a test for has_lookahead() right inside
  get_tok_start() and get_cpp_tok_start().
  If there is a lookahead token, these methods now
  return the position of the previous token automatically:

   const char *get_tok_start()
   {
     return has_lookahead() ? m_tok_start_prev : m_tok_start;
   }

   const char *get_cpp_tok_start()
   {
    return has_lookahead() ? m_cpp_tok_start_prev : m_cpp_tok_start;
   }

- Fixing the internal code inside Lex_input_stream methods
  to use m_tok_start and m_cpp_tok_start directly,
  instead of calling get_tok_start() and get_cpp_tok_start(),
  to make sure to access to the *current* token position
  (independently of a lookahead token presence).
2018-05-10 15:55:33 +04:00
Marko Mäkelä
85ccdd9ff0 Rename a test (fix merge error) 2018-05-09 17:06:27 +03:00
Marko Mäkelä
9be99dac90 MDEV-15437 POWER8 implementation of CRC-32C in C 2018-05-09 16:12:08 +03:00
Igor Babaev
fc0f5adb7f MDEV-16104 Server crash in JOIN::fix_all_splittings_in_plan
upon select with view and subqueries

This bug occurred when a splittable materialized derived/view
were used inside another splittable materialized derived/view.
The bug happened because the function JOIN::fix_all_splittings_in_plan()
was called at the very beginning of the optimization phase 2 at
the moment when the plan structure of the embedding derived/view
were not valid. The proper position for this call is the very
end of the optimization phase 1.
2018-05-08 23:32:29 -07:00
Marko Mäkelä
1b8749f73b Merge 10.2 into 10.3 2018-05-08 17:18:55 +03:00
Thirunarayanan Balathandayuthapani
85cc6b70bd MDEV-13134 Introduce ALTER TABLE attributes ALGORITHM=NOCOPY and ALGORITHM=INSTANT
Introduced new alter algorithm type called NOCOPY & INSTANT for
inplace alter operation.

NOCOPY - Algorithm refuses any alter operation that would
rebuild the clustered index. It is a subset of INPLACE algorithm.

INSTANT - Algorithm allow any alter operation that would
modify only meta data. It is a subset of NOCOPY algorithm.

Introduce new variable called alter_algorithm. The values are
DEFAULT(0), COPY(1), INPLACE(2), NOCOPY(3), INSTANT(4)

Message to deprecate old_alter_table variable and make it alias
for alter_algorithm variable.

alter_algorithm variable for slave is always set to default.
2018-05-07 14:58:11 +05:30
Daniel Black
9748659981 mtr: extend func_math (CRC32) 2018-05-07 17:04:18 +10:00
Daniel Black
891f202193 tests: extend func_math crc32 to a larger size to hit crc32-vpmsum accelerated functions
Signed-off-by: Daniel Black <daniel.black@au.ibm.com>
2018-05-07 09:25:30 +10:00
Varun Gupta
724ab9a1cb MDEV-16057: Using optimization Splitting with Group BY we see an unnecessary attached condition
t1.pk IS NOT NULL where pk is a PRIMARY KEY

For equalites in the WHERE clause we create a keyuse array that contains the set of all equalities.
For each KEYUSE inside the keyuse array we have a field "null_rejecting"
which tells that the equality will not hold if either the left or right
hand side of the equality is NULL.
If the equality is NULL rejecting then we accordingly add a NOT NULL condition for the field present in
the item val(present in the KEYUSE struct) when we are doing ref access.

For the optimization of splitting with GROUP BY we always set the null_rejecting to TRUE and we are doing ref access on
the GROUP by field. This does create a problem when the equality is NOT NULL rejecting. This happens in this case as
in the equality we have the right hand side as t1.pk where pk is a PRIMARY KEY , hence it is NOT NULLABLE. So we should have
null rejecting set to FALSE for such a case.
2018-05-06 23:05:37 +05:30
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
Sergey Vojtovich
9a84980668 MDEV-12645 - mysql_install_db: no install test db option
Added --skip-test-db option to mysql_install_db. If specified, no test
database created and relevant grants issued.

Removed --skip-auth-anonymous-user option of mysql_install_db. Now it is
covered by --skip-test-db.

Dropped some Debian patches that did the same.

Removed unused make_win_bin_dist.1, make_win_bin_dist and
mysql_install_db.pl.in.
2018-04-30 19:34:08 +04:00
Igor Babaev
6c5e60f1b1 MDEV-16038 Assertion `map->n_bits > 0' failed (my_bitmap.c:386: bitmap_is_clear_all)
Rows with no elements are not allowed in a table value constructor
unless it is used in an INSERT statement.
2018-04-26 16:38:56 -07:00
Alexey Botchkov
6e42d19f25 MDEV-15915 Add Feature_json status variable.
Related implementations.
2018-04-26 23:12:51 +04:00
Daniel Black
7f89d9c9e3 tests: func_math, correct crc32 for mariadb
Differences:

MariaDB doesn't support a JSON type therefore the crc32 on those values
are different.

JSON extract syntax is different.

loaddata_utf8 has 3 duplicate lines removed compared to MySQL version.
2018-04-26 16:33:09 +04:00
Shivashankar Nagaraj
1a011e5b5a BUG#26495791: CONTRIBUTION: EXPAND TEST SUITE TO INCLUDE CRC32 TESTS
From mysql-server:
09fdfad50764ff6809e7dd5300e9ce1ab727b62a
e90ae1707e0ca46abc775d1680d1856c4be38b66

described in http://github.com/mysql/mysql-server/pull/157

Apart from external contribution I have added few more additional testcases
for CRC32() function, which are given below.

New Testcases added:
  ->Verify the crc value of various numeric and string data types(int,
      double, blob, text, json, enum, set)
  ->Verify the crc value when expressions having comparison_operators
      and logical_operators
  ->Verify the crc value for the expression having string_functions,
      arithmetic_functions, json_functions
  ->Verify the crc value for the expression having Geometry functions
      like POINT, LINESTRING, MULTILINESTRING, POLYGON, MULTIPOLYGON
  ->Verify the crc value generated from stored procedures, functions,
      triggers, prepare statement, views.

Fix:
Patch based on contribution by Daniel Black (Github user: grooverdan)

Reviewed-by: Anitha Gopi anitha.gopi@oracle.com
Reviewed-by: Srikanth B R srikanth.b.r@oracle.com

RB: 17294
2018-04-26 16:33:09 +04:00
Oleksandr Byelkin
b4ee699a89 MDEV-11975: SQLCOM_PREPARE of EXPLAIN & ANALYZE statement do not return correct metadata info
Added metadate info after prepare EXPLAIN/ANALYZE.
2018-04-25 17:16:33 +02:00
Oleksandr Byelkin
0544d7c457 MDEV-13695: INTERSECT precedence is not in line with Oracle even in SQL_MODE=Oracle
Switch off automatic INTERSECT  priority for ORACLE MODE
2018-04-25 14:45:18 +02:00
Marko Mäkelä
9477a2a9ba Merge 10.2 into 10.3 2018-04-25 07:59:25 +03:00
Marko Mäkelä
7396dfcca7 Merge 10.2 into 10.3 2018-04-24 20:59:57 +03:00
Alexander Barkov
461de7edea MDEV-15946 MEDIUMINT(N<8) creates a wrong data type on conversion to string 2018-04-23 18:34:06 +04:00
Oleksandr Byelkin
14f84d2071 MDEV-13232: Assertion `(&(&share->intern_lock)->m_mutex)->count > 0 && pthread_equal(pthread_self(), (&(&share->intern_lock)->m_mutex)->thread)' failed in _ma_state_info_write
Limit length of result of "negative" operation to something reasonable
2018-04-23 12:48:13 +02:00
Alexander Barkov
6426b52ed4 MDEV-15957 Unexpected "Data too long" when doing CREATE..SELECT with stored func
Problems:

1. Unlike Item_field::fix_fields(),
  Item_sum_sp::fix_length_and_dec() and Item_func_sp::fix_length_and_dec()
  did not run the code which resided in adjust_max_effective_column_length(),
  therefore they did not extend max_length for the integer return data types
  from the user-specified length to the maximum length according to
  the data type capacity.

2. The code in adjust_max_effective_column_length() was not correct
   for TEXT data, because Field_blob::max_display_length()
   multiplies to mbmaxlen. So TEXT variants were unintentionally
   promoted to the next longer data type for multi-byte character
   sets: TINYTEXT->TEXT, TEXT->MEDIUMTEXT, MEDIUMTEXT->LONGTEXT.

3. Item_sum_sp::create_table_field_from_handler()
   Item_func_sp::create_table_field_from_handler()
   erroneously called tmp_table_field_from_field_type(),
   which converted VARCHAR(>512) to TEXT variants.
   So "CREATE..SELECT spfunc()" erroneously converted
   VARCHAR to TEXT. This was wrong, because stored
   functions have explicitly declared data types,
   which should be preserved.

Solution:

- Removing Type_std_attributes(const Field *)
  and using instead Type_std_attributes::set() in combination
  with field->type_str_attributes() all around the code, e.g.:
     Type_std_attributes::set(field->type_std_attributes())

  These two ways of copying attributes from a Field
  to an Item duplicated each other, and were slightly
  different in how to mix max_length and mbmaxlen.

- Removing adjust_max_effective_column_length() and
  fixing Field::type_std_attributes() to do all necessary
  type-specific calculations , so no further adjustments
  is needed.
  Field::type_std_attributes() is now called from all affected methods:
   Item_field::fix_fields()
   Item_sum_sp::fix_length_and_dec()
   Item_func_sp::fix_length_and_dec()
  This fixes the problem N1.

- Making Field::type_std_attributes() virtual, to make
  sure that type-specific adjustments a properly done
  by individual Field_xxx classes. Implementing
  Field_blob::type_std_attributes() in the way that
  no TEXT promotion is done.
  This fixes the problem N2.

- Fixing Item_sum_sp::create_table_field_from_handler()
  Item_func_sp::create_table_field_from_handler() to
  call create_table_field_from_handler() instead of
  tmp_table_field_from_field_type() to avoid
  VARCHAR->TEXT conversion on "CREATE..SELECT spfunc()".

- Recording mysql-test/suite/compat/oracle/r/sp-param.result
  as "CREATE..SELECT spfunc()" now correctly
  preserve the data type as specified in the RETURNS clause.

- Adding new tests
2018-04-23 09:31:17 +04:00
Alexander Barkov
9f84451d87 MDEV-15960 Wrong data type on CREATE..SELECT char_or_enum_or_text_spvar 2018-04-22 15:52:46 +04:00
Igor Babaev
6242036f27 MDEV-15940 Crash when using CURSOR with VALUES()
The function st_select_lex_unit::get_column_types() should
take into account that a unit may contain only a table
value constructor and nothing more.
2018-04-21 17:20:33 -07:00
Varun Gupta
6b1a8b2c72 MDEV-15846: Sever crashed with MEDIAN() window function
Fixed by MDEV-15902, just added the test case for this issue.
2018-04-21 18:41:14 +05:30
Alexander Barkov
c058117c6c Adding more tests for IN/EXIST subqueries for better coverage
Adding tests with IN/EXISTS subqueries in various rarely unexpected places:

- non-SELECT statements
- SP control
- cursors

etc.
2018-04-20 23:15:27 +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
38c799c9a5 MDEV-15763 - VARCHAR(1) COMPRESSED crashes the server
Storing 1 byte long string in VARCHAR() COMPRESSED column may trigger
integer overflow when calculating available space for zlib output.
2018-04-20 17:05:28 +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
Sachin Setiya
43ab88f0ea Buildbot fixes
1 Added typecast
2 Included have_debug.inc
2018-04-20 16:52:51 +05:30
Igor Babaev
615ad709a3 MDEV-15902 Assertion `n < m_size' failed, sql_array.h:64:
Element_type& Bounds_checked_array<Element_type>::operator[]
(size_t) [with Element_type = Item*; size_t = long unsigned int]

In sql_yacc.yy the semantic actions for the MEDIAN window function
lacked a call of st_select_lex::prepare_add_window_spec().
This function saves the head of the thd->lex->order_list into
lex->save_order_list in order this head to be restored in
st_select_lex::add_window_spec after the specification of the
window function has been parsed.
Without a call of prepare_add_window_spec() when add_window_spec()
was called the head of an empty list was copied into
thd->lex->order_list (instead of assumed saved head this list).
This made the list thd->lex->order_list invalid and potentially
could cause many different problems.

Corrected the result set in the test case for MDEV-15899 that
used the MEDIAN window function and could not be correct
without this fix.
2018-04-19 18:41:05 -07:00
Sachin Setiya
cd8b8169b6 MDEV-15167 Server crashes in in bitmap_bits_set upon REPAIR PARTITION...
after rebuilding under test_pseudo_invisible

If we are doing alter related to partitioning then simple alter stmt
like adding column(or any alter stmt) can't be combined with partition
alter, this will generate a syntax error.

But IF we add
SET debug_dbug="+d,test_pseudo_invisible";
or test_completely_invisible
this will add a column to table  with have an already partitioning related
alter. This execution of wrong stmt will crash the server on later stages.
(like on repair partition).

So we will simply return 1 (and ER_INTERNAL_ERROR) if we any of these
debug_dbug flags turned on.
2018-04-19 22:30:32 +05:30
Marko Mäkelä
d71a8855ee Merge 10.2 to 10.3
Temporarily disable main.cte_recursive due to hang in
an added test related to MDEV-15575.
2018-04-19 15:23:21 +03:00
Sachin Setiya
dde0ba5aaa MDEV-15754 Server crashes in fill_record_n_invoke_before_triggers upon ...
insert into table with TIMESTAMP INVISIBLE

Problem:- The segfault occurs because value is null but since timestamp field
is VISIBLE it expects a value , and it tries to call value->save_in_field(..
Timestamp field should not be visible this is the problem.

Solution:- While we clone field for record0_field we don't honor the field
_visibility , this patch changes that.
2018-04-19 12:29:23 +05:30
Igor Babaev
cff60be7fe MDEV-15899 Server crashes in st_join_table::is_inner_table_of_outer_join
The crash happened because JOIN::check_for_splittable_materialized()
called by mistake the function JOIN_TAB::is_inner_table_of_outer_join()
instead of the function TABLE_LIST::is_inner_table_of_outer_join().
The former cannot be called before the call of make_outerjoin_info().
2018-04-17 23:39:40 -07:00
Alexey Botchkov
bb5f4967f5 MDEV-13584 Assertion `!part_elem->tablespace_name && !table_create_info->tablespace' failed during EXCHANGE PARTITION with different TABLESPACE.
Wrong DBUG_ASSERT just removed.
2018-04-17 16:10:47 +04:00
Daniel Black
c9839cb0b3 MDEV-13336: mysqldump --ignore-database address review comments 2018-04-16 13:39:41 +04:00
Sergei Golubchik
1f6bd88c24 MDEV-15728 main.thread_id_overflow fails in ps-protocol
mark CONNECTION_ID() as returning *unsigned* number
2018-04-12 21:20:02 +02:00
Vicențiu Ciorbaru
65eefcdc60 Merge remote-tracking branch '10.2' into 10.3 2018-04-12 12:41:19 +03:00
Vladislav Vaintroub
8334aced00 MDEV-14380 Reduce possibility to timing-induced error in test
Also, shorten the test so it usually runs 2 seconds, not 3.
2018-04-10 16:17:15 +01:00
Michael Widenius
1d7b4c2689 MDEV-15738 Server crashes in my_strcasecmp_utf8 on query from I_S with UNION executed as PS
Problem was the Item_field::Item_field(THD*, Field*) had old code
that put a null pointer in orig_field_names. Now, when we have
proper re-prepare if table definition changes, this is not needed
anymore.
2018-04-05 13:55:28 +03:00
Varun Gupta
7c8c9a8bfa MDEV-15241: make SIGNAL maximum MESSAGE_TEXT length a larger value
Increasing the length of MESSAGE_TEXT from 128 to MYSQL_ERRMSG_SIZE which is the max length of the
error message
2018-04-04 19:04:14 +05:30
Marko Mäkelä
a5da1c64f8 Merge 10.2 into 10.3 2018-04-04 08:24:57 +03:00
Alexander Barkov
b7ea563491 Cleanup in the system variable parsing code
- Adding "return true" into LEX::set_system_variable()
  and LEX::set_default_system_variable() after my_error().
  This makes the parser exit on error immediately.
  Previously, the error was caught only in mysql_parser(),
  a few lines after the parse_sql() call.
- Fixing "--error 1272" to "--error ER_VARIABLE_IS_NOT_STRUCT" in tests
2018-04-03 20:06:57 +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
Sergei Golubchik
17bbab5fb0 cleanup: remove get_datetime_value()
this is a 10.3 version of 27d94b7e03

It disables caching of the first argument of IN,
if it's of a temporal type. Because other types are not
cached in this context.
2018-03-30 09:45:05 +02:00
Sergei Golubchik
c43a0e0a77 bugfix: Item_cache_temporal::convert_to_basic_const_item assumed DATETIME
this is a 10.3 version of 1c6f6dc892
2018-03-30 09:45:04 +02:00
Sergei Golubchik
7a903784b7 cleanup: Item_func_case
reorder items in args[] array. Instead of

  when1,then1,when2,then2,...[,case][,else]

sort them as

  [case,]when1,when2,...,then1,then2,...[,else]

in this case all items used for comparison take a continuous part
of the array and can be aggregated directly. and all items that
can be returned take a continuous part of the array and can be
aggregated directly. Old code had to copy them to a temporary
array before aggreation, and then copy back (thd->change_item_tree)
everything that was changed.

this is a 10.3 version of bf1ca14ff3
2018-03-30 09:45:03 +02:00
Varun Gupta
cbc45d2914 MDEV-14592: Custom Aggregates Usage Status Variable
Introduced new status variable for custom aggregate functions.
2018-03-30 01:25:48 +03:00
Michael Widenius
108ed22854 Move mysql-test-run/extra/binlog to suite/binlog/include 2018-03-29 13:59:44 +03:00
Michael Widenius
a7abddeffa Create 'main' test directory and move 't' and 'r' there 2018-03-29 13:59:44 +03:00