Commit graph

177756 commits

Author SHA1 Message Date
Galina Shalygina
615da8f70b New structure Table Value Constructor added in grammar.
TVC can be used in UNION-statement, in view and in subquery.

Files where TVC is defined and its methods are stored added.
Methods exec and prepare for TVC added.
Tests for TVC added.
2017-06-29 15:36:07 +03:00
Sergey Vojtovich
0fe7d8a2a2 MDEV-12292 - port "Report timing with more precision" by @dveeden
CLOCKS_PER_SEC not used anymore.
start_timer()/mysql_end_timer() don't make much sense.
Buffer size requirement increased by 1 byte.
2017-06-13 12:50:31 +04:00
Eric Herman
1a873fb865 replace my_timer_microseconds with microsecond_interval_timer
As svoj points out, my_timer_microseconds uses gettimeofday which is
affected by "discontinuous jumps in the system time", according to
man.

This patch changes to use microsecond_interval_timer which is "not
perfect, but is less affected by these jumps", and also does not
require an include of my_rdtsc.h header.

https://github.com/MariaDB/server/pull/332#discussion_r114708923
2017-06-13 12:50:31 +04:00
Eric Herman
eede812f05 Fix whitespace in new code
"No space before "=" and space after cast please"
https://github.com/MariaDB/server/pull/332#discussion_r114708923
2017-06-13 12:50:31 +04:00
Eric Herman
6486bac29f Callers of start_timer should have ulonglong data type
Oversight spotted by svoj:
https://github.com/MariaDB/server/pull/332#discussion_r114708923
2017-06-13 12:50:31 +04:00
Eric Herman
ca2d9546c8 port "Report timing with more precision" by @dveeden
based upon: d5e4642807

MariaDB [test]> select sleep(0.123);
+--------------+
| sleep(0.123) |
+--------------+
|            0 |
+--------------+
1 row in set (0.123 sec)

"More exact timing for mysql client based on my_timer_microseconds"

Based on suggestion from @grooverdan on https://github.com/mysql/mysql-server/pull/112

This patch is slightly bigger because the original did not preserve the
return type of my_timer_microseconds and this patch does.
   (my_timer_microseconds returns ulonglong, not simply ulong)

Also I believe the correct place to do the division of microseconds to
seconds is better in the caller of nice_time because nice_time takes a
"double sec" param, so we should convert before calling; the other caller
of nice_time does not call with microseconds.
2017-06-13 12:50:31 +04:00
=Ian Gilfillan
86b9417035 10.3 man pages 2017-06-06 12:54:06 +04:00
Marko Mäkelä
0c92794db3 Remove deprecated InnoDB file format parameters
The following options will be removed:

innodb_file_format
innodb_file_format_check
innodb_file_format_max
innodb_large_prefix

They have been deprecated in MySQL 5.7.7 (and MariaDB 10.2.2) in WL#7703.

The file_format column in two INFORMATION_SCHEMA tables will be removed:

innodb_sys_tablespaces
innodb_sys_tables

Code to update the file format tag at the end of page 0:5
(TRX_SYS_PAGE in the InnoDB system tablespace) will be removed.
When initializing a new database, the bytes will remain 0.

All references to the Barracuda file format will be removed.
Some references to the Antelope file format (meaning
ROW_FORMAT=REDUNDANT or ROW_FORMAT=COMPACT) will remain.

This basically ports WL#7704 from MySQL 8.0.0 to MariaDB 10.3.1:

commit 4a69dc2a95995501ed92d59a1de74414a38540c6
Author: Marko Mäkelä <marko.makela@oracle.com>
Date:   Wed Mar 11 22:19:49 2015 +0200
2017-06-02 09:36:14 +03:00
Marko Mäkelä
3d615e4b1a Merge branch 'bb-10.2-ext' into 10.3
This excludes MDEV-12472 (InnoDB should accept XtraDB parameters,
warning that they are ignored). In other words, MariaDB 10.3 will not
recognize any XtraDB-specific parameters.
2017-06-02 09:36:04 +03:00
Monty
959891662d MDEV-12930 Testing SEQUENCE object
Fixed the following things from the above MDEV:
- Ensure the user has INSERT privilege when generating new sequence values
  with NEXT VALUE FOR or SETVAL()
- Fixed bug in InnoDB when generating several sequence values in one statement
- Ensure that read_set is up to date before calling ha_sequence::ha_write_row()
  - This is only a potential bug with storage engines that trusts the column maps completely
2017-05-30 21:31:30 +03:00
Monty
d5d8fa6e04 Updated test case 2017-05-30 12:55:58 +03:00
Monty
267bd4cc7b Add automatic updating of sub modules to BUILD scripts 2017-05-29 16:40:24 +03:00
Monty
7e5bd1500f Add locks for sequence's to ensure that there is only one writer or many readers
This is needed for MyISAM and other storage engines which normally
relies on THR_LOCK's to ensure that one is not writing the same block
one could be reading from.
2017-05-29 16:08:49 +03:00
halfspawn
d7e3120da8 SP stack trace 2017-05-29 15:46:29 +04:00
Alexander Barkov
8b68263a53 MDEV-12803 Improve function parameter data type control 2017-05-29 10:29:46 +04:00
Alexander Barkov
0f0bced885 Adding tests for MDEV-9410 VIEW over a ROLLUP query reports too large columns
The fix for MDEV-12866 fixed this problem as well. Adding tests only.
2017-05-27 16:45:22 +04:00
Alexander Barkov
a9b79bf710 Adding tests for MDEV-12861 FIRST_VALUE() does not preserve the exact data type
Recent changes in Type_handler fixed this problem. Adding tests only.
2017-05-27 16:39:20 +04:00
Alexander Barkov
241d5edcf9 Adding tests for MDEV-9408 CREATE TABLE SELECT MAX(int_column) creates different columns for table vs view
Recent fixes in Type_handler fixed this problem. Adding tests only.
2017-05-27 16:21:20 +04:00
Alexander Barkov
86b5be0e16 Adding tests for MDEV-9406 CREATE TABLE..SELECT creates different columns for IFNULL() and equivalent COALESCE,CASE,IF
Recent changes in Type_handler fixed this problem as well.
Adding tests only.
2017-05-27 16:13:58 +04:00
Alexander Barkov
13c6b0d534 MDEV-10309 COALESCE(12345678900) makes a column of a wrong type and truncates the data
Previous fixes in Type_handler
(see the patch for MDEV-12875, MDEV-12886, MDEV-12916)
fixed this problem as well. Adding only the test from the report.
2017-05-27 16:03:18 +04:00
Alexander Barkov
9d834c76af MDEV-12932 Remove enum Cast_target and use Type_handler to handle CAST 2017-05-27 11:12:14 +04:00
Alexander Barkov
f462bfc1f7 A post-merge fix: loadxml failed on Windows (due to a wrong parameter to my_error).
Fixing to pass item->name.str rather than item->name to my_error().
2017-05-27 07:05:16 +04:00
Alexander Barkov
9bc3225642 Merge tag 'mariadb-10.2.6' into bb-10.2-ext 2017-05-26 19:32:28 +04:00
Marko Mäkelä
77b2f55f61 Follow-up fixes for MDEV-10139 Support for InnoDB SEQUENCE objects
row_search_mvcc(): Relax debug assertions. For NO_ROLLBACK tables,
a transaction or a read view will not be started at the start of
a statement.

row_upd_clust_step(): Support CREATE TEMPORARY SEQUENCE or
CREATE TEMPORARY TABLE…NO_ROLLBACK.
2017-05-26 09:42:11 +03:00
Alexander Barkov
e1f81822c3 A cleanup for MDEV-11514, MDEV-11497, MDEV-11554, MDEV-11555 - IN and CASE type aggregation problems
Removing cmp_item::get_comparator() and calling instead
Type_handler::make_cmp_item(), which was earlier introduced by this patch:

74891ed257
2017-05-25 17:19:35 +04:00
Alexander Barkov
109bc47084 Fixing a few data type related problems: MDEV-12875, MDEV-12886, MDEV-12916
This is a joint patch fixing the following problems:

MDEV-12875 Wrong VIEW column data type for COALESCE(int_column)
MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP
MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable

All above problem happened because the global function ::create_tmp_field()
called the top-level Item::create_tmp_field(), which made some tranformation
for INT-result data types. For example, INT(11) became BIGINT(11), because 11
is a corner case and it's not known if it fits or does not fit into INT range,
so Item::create_tmp_field() converted it to BIGINT(11) for safety.

The main idea of this patch is to avoid such tranformations.

1. Fixing Item::create_tmp_field() not to have a special case for INT_RESULT.

   Item::create_tmp_field() is changed not to have a special case
   for INT_RESULT (which earlier made a decision based on Item's max_length).
   It now calls tmp_table_field_from_field_type() for INT_RESULT,
   therefore preserves the original data type (e.g. INT, YEAR) without
   conversion to BIGINT.

   This change is valid, because a number of recent fixes
   (e.g. in Item_func_int, Item_hybrid_func, Item_int, Item_splocal)
   guarantee that item->type_handler() now properly returns
   type_handler_long vs type_handler_longlong. So no adjustment by length
   is needed any more for Items returning INT_RESULT.

   After this change, Item::create_tmp_field() calls
   tmp_table_field_from_field_type() for all XXX_RESULT, except REAL_RESULT.

2. Fixing Item::create_tmp_field() not to have a special case for REAL_RESULT.

   Note, the reason for a special case for REAL_RESULT is to have a special
   constructor for Field_double(), forcing Field_real::not_fixed to be set
   to true.

   Taking into account that only Item_sum descendants actually need a special
   constructor call Field_double(not_fixed=true), not too loose precision
   when mixing individual rows to the aggregate result:
   - renaming Item::create_tmp_field() to Item_sum::create_tmp_field().
   - changing Item::create_tmp_field() just to call
     tmp_table_field_from_field_type() for all XXX_RESULT types.

   A special case for REAL_RESULT in Item::create_tmp_field() is now gone.
   Item::create_tmp_field() is now symmetric for all XXX_RESULT types,
   and now just calls tmp_table_field_from_field_type().

3. Fixing Item_func::create_field_for_create_select() not to have
   a special case for STRING_RESULT.

   After changes #1 and #2, the code in
   Item_func::create_field_for_create_select(), testing result_type(),
   becomes useless, because: now Item::create_tmp_field() and
   tmp_table_field_from_field_type() do exactly the same thing for all
   XXX_RESULT types for Item_func descendants:
   a. It calls tmp_table_field_from_field_type for STRING_RESULT directly.
   b. For other XXX_RESULT, it goes through Item::create_tmp_field(),
      which calls the global function ::create_tmp_field(),
      which calls item->create_tmp_field() for FUNC_ITEM,
      which calls tmp_table_field_from_field_type() again.

   So removing the virtual implementation of
   Item_func::create_field_for_create_select().
   The inherited Item::create_field_for_create_select() now perfectly
   does the job, as it also calls tmp_table_field_from_field_type()
   for FUNC_ITEM, independently from XXX_RESULT type.

4. Taking into account #1 and #2, as well as some recent changes,
   removing virtual implementations:
   - Item_hybrid_func::create_tmp_field()
   - Item_hybrid_func::create_field_for_create_select()
   - Item_int_func::create_tmp_field()
   - Item_int_func::create_field_for_create_select()
   - Item_temporal_func::create_field_for_create_select()
   The derived versions from Item now perfectly work.

5. Moving a piece of code from create_tmp_field_from_item()
   to a new function create_tmp_field_from_item_finalize(),
   to reuse it in two places (see #6).

6. Changing the code responsible for BIT->INT/BIGIN tranformation
   (which is called for the cases when the created table, e.g. HEAP,
    does not fully support BIT) not to call create_tmp_field_from_item(),
   because the latter now calls tmp_table_field_from_field_type() instead
   of create_tmp_field() and thefore cannot do BIT transformation.
   So rewriting this code using a sequence of these calls:
   - item->type_handler_long_or_longlong()
   - handler->make_and_init_table_field()
   - create_tmp_field_from_item_finalize()

7. Miscelaneous changes:
   - Moving type_handler_long_or_longlong() from "protected" to "public",
     as it's now needed in the global function create_tmp_field().

8. The above changes fixed MDEV-12875, MDEV-12886, MDEV-12916.
   So adding tests for these bugs.
2017-05-25 15:15:39 +04:00
Alexander Barkov
54e29712a3 Adding tests for MDEV-12917 Wrong data type for CREATE..SELECT year_sp_variable
The fix for MDEV-12876 fixed this problem as well.
So adding tests only.
2017-05-25 14:12:18 +04:00
Monty
a4789f52d8 More tests for SEQUENCE's
- Test with LOCK TABLES
- Test mysqldump
- Don't update rows for sequence tables if values doesn't change. This is
  needed as InnoDB gives an error for updates where values doesn't change.
2017-05-24 18:57:47 +03:00
Marko Mäkelä
8acf4d6f78 Follow-up fixes for MDEV-10139 Support for InnoDB SEQUENCE objects
Because SEQUENCE objects or NO_ROLLBACK tables do not support locking
or MVCC or transactions, avoid starting a transaction.

row_upd_step(): Do not start a transaction. Let the caller do that.

que_thr_step(): Call trx_start_if_not_started_xa() for QUE_NODE_UPDATE.
(The InnoDB SQL parser is not used for accessing NO_ROLLBACK tables.)

row_ins_step(): Correct a too strict assertion and comment about
concurrency. Multiple concurrent readers are allowed.

row_update_for_mysql_using_upd_graph(): Do not start the transaction
for NO_ROLLBACK tables.

row_search_mvcc(): For NO_ROLLBACK tables, skip locking even inside
LOCK TABLES. Only call trx_start_if_not_started() at the start
of a statement, not for each individual request.
2017-05-24 18:23:16 +03:00
Monty
9497a64679 Fixed failing test sql_sequence.replication 2017-05-24 15:39:56 +03:00
Monty
d60e5fe391 Simple replication test for sequences 2017-05-24 15:39:56 +03:00
Alexander Barkov
e5145a5ac3 MDEV-12546 Wrong metadata or data type for string user variables 2017-05-24 15:43:09 +04:00
Alexander Barkov
90f06818b3 MDEV-12876 Wrong data type for CREATE..SELECT sp_var 2017-05-23 23:13:54 +04:00
Alexander Barkov
62b62319bf A cleanup for the patch for MDEV-12852, MDEV-12853, MDEV-12869
The patch broke expressions like CAST(1.0e+300 AS SIGNED INT)
in binary protocol, e.g.:
  mtr --ps cast

Short real numbers like 1.0e+300 can return huge values,
so using args[0]->max_length is not reliable to choose properly the result
type for Item_func_signed and Item_func_unsigned (between INT and BIGINT).

Setting Item_[un]signed_typecast::max_length to MAX_BIGINT_WIDTH
when doing CAST from FLOAT/DOUBLE, to force type_handler() return
&type_handler_longlong rather than &type_handler_long.
2017-05-23 23:11:31 +04:00
Monty
6a779a6d28 Make SEQUENCE working with replication
- Old sequence code forced row based replication for any statements that
  refered to a sequence table. What is new is that row based replication
  is now sequence aware:
   - NEXT VALUE is now generating a short row based event with only
     next_value and round being replicated.
   - Short row based events are now on the slave updated as trough
     SET_VALUE(sequence_name)
   - Full row based events are on the slave updated with a full insert,
     which is practically same as ALTER SEQUENCE.
- INSERT on a SEQUENCE table does now a EXCLUSIVE LOCK to ensure that
  it is logged in binary log before any following NEXT VALUE calls.
- Enable all sequence tests and fixed found bugs
- ALTER SEQUENCE doesn't anymore allow changes that makes the next_value
  outside of allowed range
- SEQUENCE changes are done with TL_WRITE_ALLOW_WRITE. Because of this
  one can generate a statement for MyISAM with both
  TL_WRITE_CONCURRENT_INSERT and TL_WRITE_ALLOW_WRITE. To fix a warning
  I had to add an extra test in thr_lock.c for this.
- Removed UPDATE of SEQUENCE (no need to support this as we
  have ALTER SEQUENCE, which takes the EXCLUSIVE lock properly.
- Removed DBUG_ASSERT() in MDL_context::upgrade_shared_lock. This was
  removed upstream in MySQL 5.6 in 72f823de453.
- Simplified test in decided_logging_format() by using sql_command_flags()
- Fix that we log DROP SEQUENCE correctly.
- Fixed that Aria works with SEQUENCE
2017-05-23 21:12:27 +03:00
Alexander Barkov
d9304914be Fixing a few problems with data type and metadata for INT result functions (MDEV-12852, MDEV-12853, MDEV-12869)
This is a joint patch for:
MDEV-12852 Out-of-range errors when CAST(1-2 AS UNSIGNED
MDEV-12853 Out-of-range errors when CAST('-1' AS UNSIGNED
MDEV-12869 Wrong metadata for integer additive and multiplicative operators

1. Fixing all Item_func_numhybrid descendants to set the precise
   data type handler (type_handler_long or type_handler_longlong)
   at fix_fields() time. This fixes MDEV-12869.

2. Fixing Item_func_unsigned_typecast to set the precise data type handler
   at fix_fields() time. This fixes MDEV-12852 and MDEV-12853.
   This is done by:
   - fixing Type_handler::Item_func_unsigned_fix_length_and_dec()
     and Type_handler_string_result::Item_func_unsigned_fix_length_and_dec()
     to properly detect situations when a negative epxression is converted
     to UNSIGNED. In this case, length of the result is now always set to
     MAX_BIGINT_WIDTH without trying to use args[0]->max_length, as very
     short arguments can produce very long result in such conversion:
        CAST(-1 AS UNSIGNED) -> 18446744073709551614
   - adding a new virtual method "longlong Item::val_int_max() const",
     to preserve the old behavior for expressions like this:
        CAST(1 AS UNSIGNED)
     to stay under the INT data type (instead of BIGINT) for small
     positive integer literals. Using Item::unsigned_flag would not help,
     because Item_int does not set unsigned_flag to "true" for positive
     numbers.

3. Adding helper methods:
  * Item::type_handler_long_or_longlong()
  * Type_handler::type_handler_long_or_longlong()
  and reusing them in a few places, to reduce code duplication.

4. Making reorganation in create_tmp_field() and
   create_field_for_create_select() for Item_hybrid_func and descendants,
   to reduce duplicate code. They all now have a similar behavior in
   respect of creating fields. Only Item_func_user_var descendants have
   a different behavior. So moving the default behvior to Item_hybrid_func,
   and overriding behavior on Item_func_user_var level.
2017-05-23 12:45:47 +04:00
Alexander Barkov
9b79888df8 MDEV-12866 Out-of-range error with CREATE..SELECT..TO_SECONDS(NOW()) 2017-05-22 17:13:15 +04:00
Alexander Barkov
c84bbeda7f MDEV-12858 + MDEV+12859 + MDEV-12862 - a join patch fixing a few data type problems with CREATE..SELECT
MDEV-12858 Out-of-range error for CREATE..SELECT unsigned_int_column+1
MDEV-12859 Out-of-range error for CREATE..SELECT @a:=EXTRACT(MINUTE_MICROSECOND FROM..)
MDEV-12862 Data type of @a:=1e0 depends on the session character set

1. Moving a part of Item::create_tmp_field() into a new helper method
   Item::create_tmp_field_int() and reusing it in Item::create_tmp_field()
   and Item_func_signed::create_tmp_field().
   Fixing the code in Item::create_tmp_field_int() to call
   Type_handler::make_table_field() instead of doing "new Field_long[long]"
   directly. This change revealed a problem reported in MDEV-12862.

2. Changing the "long vs longlong" cut-off length for
     - Item_func::create_tmp_field()
     - Item_sum::create_tmp_field()
     - Item_func_get_user_var::create_tmp_field()
   from MY_INT32_NUM_DECIMAL_DIGITS to (MY_INT32_NUM_DECIMAL_DIGITS - 2).
   This fixes MDEV-12858.
   After this change, the "convert_int_length" parameter to
   Item::create_tmp_field() is not needed any more, because
   (MY_INT32_NUM_DECIMAL_DIGITS - 2) is always passed.
   So removing the "convert_int_length" parameter.

3. Fixing Item::create_tmp_field() to pass max_char_length() instead
   of max_length to the constructor of Field_double().
   This fixes MDEV-12862.

4. Additionally, fixing
   - Type_handler_{tiny|short|int24|long|longlong}::make_table_field()
   - Type_handler_{float|double}::make_table_field()
   to pass max_char_length() instead of max_length to Field contructors.
   This is needed by the change (1).

5. Adding new tests, and recording new correct results in the old tests in:
   - mysql-test/r/type_ranges.result
   - storage/tokudb/mysql-test/tokudb/r/type_ranges.result
2017-05-22 13:44:26 +04:00
Alexander Barkov
feb15f4e45 MDEV-12860 Out-of-range error on CREATE..SELECT with a view using MAX and EXTRACT(MINUTE_MICROSECOND..) 2017-05-22 10:27:05 +04:00
Alexander Barkov
8c479820da MDEV-12856 Wrong .. metadata for DIV + MDEV-12857..errors on CREATE..SELECT..DIV
This is a joint patch for:

MDEV-12856 Wrong result set metadata for DIV
MDEV-12857 Out-of-range errors on CREATE..SELECT 2222222222 DIV 1
2017-05-21 09:28:12 +04:00
Alexander Barkov
a8caa8e04a MDEV-12854 Synchronize CREATE..SELECT data type and result set metadata data type for INT functions 2017-05-20 16:29:11 +04:00
Alexander Barkov
d2fec340d2 An after-fix for MDEV-12849 Out-of-range errors when casting hex-hybrid to SIGNED and UNSIGNED
1. Adding the forgotten "SET sql_mode=STRICT_ALL_TABLES" into the test.
2. STRICT_ALL_TABLES revealed that CAST(0xFFFFFFFF AS SIGNED),
   e.g. with a hex number with 8 hex digits, did not work well.
   Fixing Item_func_unsigned::create_tmp_field() and
   Item_func_unsigned::create_field_for_create_select() to handle
   this corner case.
2017-05-19 21:39:41 +04:00
Alexander Barkov
ac4ce47b09 MDEV-12849 Out-of-range errors when casting hex-hybrid to SIGNED and UNSIGNED 2017-05-19 18:45:01 +04:00
Alexander Barkov
732cfabafd Merge branch 'halfspawn-bb-10.2-ext' into bb-10.2-ext 2017-05-18 14:23:14 +04:00
halfspawn
87d952746f MDEV-12783 : sql_mode=ORACLE: Functions LENGTH() and LENGTHB() 2017-05-18 11:43:24 +02: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
278c3ea756 MDEV-12826 Add Type_handler::val_int_signed_typecast() and Type_handler::val_int_unsigned_typecast() 2017-05-17 14:02:25 +04:00
Alexander Barkov
896c2c73a0 Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2017-05-17 12:59:07 +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
Monty
6378c95ee0 Fix that end_bulk_insert() doesn't write to to-be-deleted files
This affected mainly MyISAM and Aria engines.
Also fixed that end_bulk_insert() detects errors from
internal mi_end_bulk_insert() and ma_end_bulk_insert()

- delete_tree() and delete_tree_element() now has an
  extra argument that marks if future calls to
  tree->free should be ignored.
- tree->free changed to function returning int, to be
  able to signal errors.
- Restored deleting flag in MyISAM that was accidently
  disabled in mi_extra(PREPARE_FOR_DROP)
2017-05-17 00:34:48 +03:00