Commit graph

69505 commits

Author SHA1 Message Date
Marko Mäkelä
2d0dd62cf7 Merge 10.2 into 10.3 2019-03-08 00:26:55 +02:00
Alexander Barkov
5f34513c2a MDEV-18813 PROCEDURE and anonymous blocks silently ignore FETCH GROUP NEXT ROW
Part#2 (final): rewritting the code to pass the correct enum_sp_aggregate_type
to the sp_head constructor, so sp_head never changes its aggregation type
later on. The grammar has been simplified and defragmented.
This allowed to check aggregate specific instructions right after
a routine body has been scanned, by calling new LEX methods:
  sp_body_finalize_{procedure|function|trigger|event}()

Moving some C++ code from *.yy to a few new helper methods in LEX.
2019-03-07 18:48:15 +04:00
Alexander Barkov
a71d185a9a MDEV-18813 PROCEDURE and anonymous blocks silently ignore FETCH GROUP NEXT ROW
Part#1: moving opt_if_not_exists from "sf_tail" and "sp_tail" to "create".
2019-03-07 14:35:01 +04:00
Galina Shalygina
2faefe5f7f MDEV-18383: Missing rows with pushdown condition defined with IF-function
using Item_cond

This bug is similar to the bug MDEV-16765.
It appears because of the wrong pushdown into HAVING clause while this
pushdown shouldn't be made at all.
This happens because function that checks if Item_cond can be pushed
always returns that it can be pushed.

To fix it new method Item_cond::excl_dep_on_table() was added.
2019-03-07 12:35:18 +03:00
Marko Mäkelä
aa4b2c1509 Merge 10.3 into 10.4 2019-03-07 08:02:33 +02:00
mkaruza
32badae31f Fix for galera_3nodes.galera_var_dirty_reads2
Call desync_and_pause() and resync_and_resume() only if state is s_synced.
2019-03-07 07:59:44 +02:00
Alexander Barkov
f0cd707503 After-merge fix for MDEV-18333 Slow_queries count doesn't increase when slow_query_log is turned off 2019-03-06 23:44:58 +04:00
Igor Babaev
7b9981fbdf MDEV-18816 Assertion `sel->quick' failed in JOIN::make_range_rowid_filters
Do not build range filters with detected impossible WHERE.
Anyway conditions cannot be used anymore to extract ranges for filters.
2019-03-06 09:12:21 -08:00
Oleksandr Byelkin
a36ac52f93 MDEV-18339: ASAN heap-buffer-overflow in Item_exists_subselect::is_top_level_item
Right argument of Item_in_optimizer can not be cast to Item_in_subselect in invisible mode.
2019-03-06 17:50:54 +01:00
Marko Mäkelä
77103e9832 Merge 10.2 into 10.3 2019-03-06 16:20:13 +02:00
Marko Mäkelä
c155946c90 Merge 10.1 into 10.2 2019-03-06 15:15:59 +02:00
Alexander Barkov
26f0d72a3f A cleanup for MDEV-18333 Slow_queries count doesn't increase when slow_query_log is turned off
thd->lex->m_sql_cmd was not cleared between queries.
log_slow_query() could crash (when running mtr --ps) because of this.
2019-03-06 17:08:03 +04:00
Sergey Vojtovich
2b711d231a Adieu slave_list
slave_list was used to provide data for SHOW SLAVE HOSTS and
Slaves_connected status variable.

Introduced binlog_dump_thread_count which is exposed via Slaves_connected
(replaces slave_list.records).

Store Slave_info on THD and access it by iterating server_threads
(replaces slave_list).

Added:
THD::slave_info
binlog_dump_thread_count
show_slave_hosts_callback()

Removed:
slave_list
SLAVE_LIST_CHUNK
SLAVE_ERRMSG_SIZE
slave_list_key()
slave_info_free()
init_slave_list()
end_slave_list()
all_slave_list_mutexes
init_all_slave_list_mutexes()
key_LOCK_slave_list
LOCK_slave_list

Moved:
SLAVE_INFO -> Slave_info
register_slave() -> THD::register_slave()
unregister_slave() -> THD::unregister_slave()

Also removed redundant end_slave() from close_connections(): it is called
again soon afterwards by clean_up().

Pre-requisite for clean MDEV-18450 solution.
2019-03-06 17:06:09 +04:00
Sergey Vojtovich
68c765d313 Cleanup remnants of rpl_recovery_rank 2019-03-06 17:06:09 +04:00
Marko Mäkelä
2a791c53ad Merge 10.3 into 10.4 2019-03-06 09:00:52 +02:00
Julius Goryavsky
723ffdb32e MDEV-9519: After-merge fix for 10.3 2019-03-05 14:11:42 +01:00
Marko Mäkelä
446b3ebdfc Merge 10.2 into 10.3
FIXME: Properly resolve conflicts between MDEV-18883
and MDEV-7742/MDEV-8305, and record the correct result for
main.log_slow
2019-03-05 12:56:05 +02:00
Oleksandr Byelkin
b5c72a843a MDEV-18358: Server crash when using SET STATEMENT max_statement_time
Do not init lex before choosing main select.
2019-03-05 11:03:51 +01:00
Igor Babaev
8f4de38f65 MDEV-18467 Server crashes in fix_semijoin_strategies_for_picked_join_order
If a splittable materialized derived table / view T is used in a inner nest
of an outer join with impossible ON condition then T is marked as a
constant table. Yet the execution plan to build T is still searched for
in spite of the fact that is not needed. So it should be set.
2019-03-04 23:11:18 -08:00
Marko Mäkelä
a2fc36989e Merge 10.2 into 10.3 2019-03-04 17:01:00 +02:00
Marko Mäkelä
9835f7b80f Merge 10.1 into 10.2 2019-03-04 16:46:58 +02:00
Marko Mäkelä
74d648db12 Make a size_t-to-uint conversion explicit 2019-03-04 16:25:14 +02:00
Alexander Barkov
1bcb66c597 MDEV-18806 Synchronize ALTER TABLE EXCHANGE PARTITION and PURGE grammar in sql_yacc.yy and sql_yacc_ora.yy 2019-03-04 14:38:21 +04:00
Alexander Barkov
19df45a705 MDEV-18333 Slow_queries count doesn't increase when slow_query_log is turned off 2019-03-04 13:49:15 +04:00
Teemu Ollakka
a8ff4f243d MDEV-18631 Fix streaming replication with wsrep_gtid_mode=ON
With wsrep_gtid_mode=ON, the appropriate commit hooks were not
called in all cases for applied streaming transactions.

As a fix, removed all special handling of commit order critical
section from Wsrep_high_priority_service and Wsrep_storage_service.
Now commit order critical section is always entered in ha_commit_trans().

Check for wsrep_run_commit_hook is now done in handler.cc, log.cc.
This makes it explicit that the transaction is an active wsrep
transaction which must go through commit hooks.
2019-03-04 09:00:25 +02:00
Alexander Barkov
47b7ca629f MDEV-18796 Synchronize PS grammar between sql_yacc.yy and sql_yacc_ora.yy 2019-03-03 07:20:15 +04:00
Alexander Barkov
3b47587f41 MDEV-18789 Port "MDEV-7773 Aggregate stored functions" to sql_yacc_ora.yy 2019-03-01 23:55:55 +04:00
Sergei Golubchik
5e2d2053d8 bugfix: set mysql_real_data_home_len correctly
after mysql_real_data_home was updated in get_options()
2019-03-01 12:41:05 -05:00
Oleksandr Byelkin
f2e1451740 Merge branch '10.0' into 10.1 2019-03-01 15:52:06 +01:00
Alexander Barkov
01d7727b76 MDEV-18779 Port sp_suid implementation from sql_yacc_ora.yy to sql_yacc.yy 2019-03-01 17:02:58 +04:00
Igor Babaev
5a0874449a MDEV-18755 Assertion `inited==INDEX' failed in handler::ha_index_read_map
When the chosen execution plan accesses a join table employing a range
rowid filter a quick select to scan this range has to be built. This
quick select is built by a call of SQL_SELECT::test_quick_select().
At this call the function should allow to evaluate only single index
range scans. In order to be able to do this a new parameter was added
to this function.
2019-02-28 14:45:01 -08:00
Oleksandr Byelkin
7b5c63856b Merge branch '5.5' into 10.0 2019-02-28 21:50:00 +01:00
Oleksandr Byelkin
cb11b3fbe9 MDEV-17055: Server crashes in find_order_in_list upon 2nd (3rd) execution of SP with UPDATE
1. Always drop merged_for_insert flag on cleanup (there could be errors which prevent TABLE to be assigned)
2. Make more precise cleanup of select parts which was touched
2019-02-28 18:14:53 +01:00
Alexander Barkov
0ad598a00b A cleanup in derived table handling: removing duplicate code from st_select_lex::handle_derived()
st_select_lex::handle_derived() and mysql_handle_list_of_derived() had
exactly the same implementations.

- Adding a new method LEX::handle_list_of_derived() instead
- Removing public function mysql_handle_list_of_derived()
- Reusing LEX::handle_list_of_derived() in st_select_lex::handle_derived()
2019-02-28 18:13:28 +04:00
Jan Lindström
f65f40bb35 Merge remote-tracking branch 'origin/10.1' into 10.2 2019-02-28 13:08:11 +02:00
Jan Lindström
5a87e3ee87 Revert offending part of MDEV-9519: Data corruption will happen on the Galera cluster size change
This will allow test binlog.binlog_stm_binlog to pass more often.
Note that this is not a real fix to that test failure.
2019-02-28 09:29:19 +02:00
Sergei Golubchik
b10340998f MDEV-18748 REPLACE doesn't work with unique blobs on MyISAM table
on long unique conflict, set table->file->dup_ref for
engines that support it
2019-02-27 23:27:43 -05:00
Sergei Golubchik
9fd3e810e8 MDEV-18747 InnoDB: Failing assertion: table->get_ref_count() == 0 upon dropping temporary table with unique blob
delete update handler clone also for temporary tables
2019-02-27 23:27:43 -05:00
Sergei Golubchik
304f0084ef MDEV-18720 Assertion `inited==NONE' failed in ha_index_init upon update on versioned table with key on blob
* update system versioning fields before generaled columns
* don't presume that ha_write_row() means INSERT. It could still be UPDATE
* use the correct handler in check_duplicate_long_entry_key()
2019-02-27 23:27:43 -05:00
Sergei Golubchik
3f53515425 MDEV-18713 Assertion `strcmp(share->unique_file_name,filename) || share->last_version' failed in test_if_reopen upon REPLACE into table with key on blob
close table->update_handler in close_thread_tables().
it's not enough to do it in sql_update.cc only, because
sql_insert.cc can also do updates (REPLACE) and even
sql_delete.cc can (DELETE ... FOR PORTION OF)
2019-02-27 23:27:43 -05:00
Sergei Golubchik
20c89f9f37 MDEV-18712 InnoDB indexes are inconsistent with what defined in .frm for table after rebuilding table with index on blob
when auto-adding a virtual LONG_UNIQUE_HASH_FIELD, fill in
a Virtual_column_info for it, so that fill_alter_inplace_info()
would know we're adding a virtual field (ALTER_ADD_VIRTUAL_COLUMN).
2019-02-27 23:27:43 -05:00
Sergei Golubchik
5adf11250a MDEV-18707 Server crash in my_hash_sort_bin, ASAN heap-use-after-free in Field::is_null, server hang, corrupted double-linked list
adjust share->stored_rec_length for LONG_UNIQUE_HASH_FIELD,
just like it's done for normal virtual fields
2019-02-27 23:27:43 -05:00
sachin
0477e80522 Long Index is only allowed for unique keys not normal index. 2019-02-27 23:23:18 -05:00
Sergei Golubchik
8084eeaa66 cleanup: set HA_PART_KEY_SEG properly
do it for all key types uniformly. In particular,
don't give "prefix keyseg" treatment for hash keys where
field->key_length() == key_part->length
2019-02-27 23:15:28 -05:00
Sergei Golubchik
593e869742 cleanup: reserve one keypart for for LONG_UNIQUE_HASH_FIELD 2019-02-27 23:15:28 -05:00
Sergei Golubchik
387b690eab cleanup: cosmetic fixes 2019-02-27 23:15:28 -05:00
Sergei Golubchik
72ee180512 cleanup: set HA_PART_KEY_SEG for HA_KEY_ALG_LONG_HASH prefix keys
because they *are* prefix keys, even if long and hashed
2019-02-27 23:15:28 -05:00
Alexander Barkov
09d29dfc76 MDEV-18767 Port "MDEV-16294: INSTALL PLUGIN IF NOT EXISTS / UNINSTALL PLUGIN IF EXISTS" to sql_yacc_ora.yy 2019-02-28 07:17:47 +04:00
Igor Babaev
9bd47835d0 MDEV-18679 Server crashes in JOIN::optimize
The bug manifested itself when executing a query with materialized
view/derived/CTE whose specification was a SELECT query contained
another materialized derived and impossible WHERE/HAVING condition
was detected for this SELECT.
As soon as such condition is detected the join structures of all
derived tables used in the SELECT are destroyed. So optimization
of the queries specifying these derived tables is impossible. Besides
it's not needed.

In 10.3 optimization of a materialized derived table is performed before
detection of impossible WHERE/HAVING condition in the embedding SELECT.
2019-02-26 18:03:39 -08:00
Vladislav Vaintroub
bba4e7f287 MDEV-18694 : Do not call close_connection() on active connections in
server shutdown code.

Fix fixes a race condition, if an active connection either writes,
or will be writing to the socket after it is closed.

Previous call to socket shutdown() is fully enough to wake up and idle
connection, so that close_connection is obsolete and dangerous.
2019-02-26 23:04:42 +04:00
Sergey Vojtovich
f92b7b1a27 Adieu LOCK_thread_count, COND_thread_count 2019-02-26 22:44:38 +04:00
seppo
785092ee23 LOCK_thread_count and COND_thread_count removed from wsrep modules (#1197)
Refactored wsrep patch to not use LOCK_thread_count and COND_thread_count anymore.
This has partially been replaced by using old LOCK_wsrep_slave_threads mutex.
For slave thread count change waiting, new COND_wsrep_slave_threads signal has been added

Added LOCK_wsrep_cluster_config mutex to control that cluster address change cannot happen in parallel

Protected wsrep_slave_threads variable changes with LOCK_cluster_config mutex
This is for avoiding concurrent slave thread count and cluster joining operations to happen

Fixes according to Teemu's review
2019-02-26 13:39:05 -05:00
Alexander Barkov
cac14b9225 MDEV-17725 Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' failed in Diagnostics_area::set_ok_status upon ALTER failing due to error from engine 2019-02-26 15:41:27 +04:00
Oleksandr Byelkin
82da98556c MDEV-18605: Loss of column aliases by using view and group
Preserv column name with copy fields even if it is function and Co.
2019-02-26 08:32:02 +01:00
Julius Goryavsky
50b3632fa4 MDEV-9519: Data corruption will happen on the Galera cluster size change
If we have a 2+ node cluster which is replicating from an async master
and the binlog_format is set to STATEMENT and multi-row inserts are executed
on a table with an auto_increment column such that values are automatically
generated by MySQL, then the server node generates wrong auto_increment
values, which are different from what was generated on the async master.

In the title of the MDEV-9519 it was proposed to ban start slave on a Galera
if master binlog_format = statement and wsrep_auto_increment_control = 1,
but the problem can be solved without such a restriction.

The causes and fixes:

1. We need to improve processing of changing the auto-increment values
after changing the cluster size.

2. If wsrep auto_increment_control switched on during operation of
the node, then we should immediately update the auto_increment_increment
and auto_increment_offset global variables, without waiting of the next
invocation of the wsrep_view_handler_cb() callback. In the current version
these variables retain its initial values if wsrep_auto_increment_control
is switched on during operation of the node, which leads to inconsistent
results on the different nodes in some scenarios.

3. If wsrep auto_increment_control switched off during operation of the node,
then we must return the original values of the auto_increment_increment and
auto_increment_offset global variables, as the user has set. To make this
possible, we need to add a "shadow copies" of these variables (which stores
the latest values set by the user).

https://jira.mariadb.org/browse/MDEV-9519
2019-02-26 08:09:04 +02:00
Julius Goryavsky
2c734c980e MDEV-9519: Data corruption will happen on the Galera cluster size change
If we have a 2+ node cluster which is replicating from an async master
and the binlog_format is set to STATEMENT and multi-row inserts are executed
on a table with an auto_increment column such that values are automatically
generated by MySQL, then the server node generates wrong auto_increment
values, which are different from what was generated on the async master.

In the title of the MDEV-9519 it was proposed to ban start slave on a Galera
if master binlog_format = statement and wsrep_auto_increment_control = 1,
but the problem can be solved without such a restriction.

The causes and fixes:

1. We need to improve processing of changing the auto-increment values
after changing the cluster size.

2. If wsrep auto_increment_control switched on during operation of
the node, then we should immediately update the auto_increment_increment
and auto_increment_offset global variables, without waiting of the next
invocation of the wsrep_view_handler_cb() callback. In the current version
these variables retain its initial values if wsrep_auto_increment_control
is switched on during operation of the node, which leads to inconsistent
results on the different nodes in some scenarios.

3. If wsrep auto_increment_control switched off during operation of the node,
then we must return the original values of the auto_increment_increment and
auto_increment_offset global variables, as the user has set. To make this
possible, we need to add a "shadow copies" of these variables (which stores
the latest values set by the user).

https://jira.mariadb.org/browse/MDEV-9519
2019-02-26 07:45:11 +02:00
Julius Goryavsky
243f829c1c MDEV-9519: Data corruption will happen on the Galera cluster size change
If we have a 2+ node cluster which is replicating from an async master
and the binlog_format is set to STATEMENT and multi-row inserts are executed
on a table with an auto_increment column such that values are automatically
generated by MySQL, then the server node generates wrong auto_increment
values, which are different from what was generated on the async master.

In the title of the MDEV-9519 it was proposed to ban start slave on a Galera
if master binlog_format = statement and wsrep_auto_increment_control = 1,
but the problem can be solved without such a restriction.

The causes and fixes:

1. We need to improve processing of changing the auto-increment values
after changing the cluster size.

2. If wsrep auto_increment_control switched on during operation of
the node, then we should immediately update the auto_increment_increment
and auto_increment_offset global variables, without waiting of the next
invocation of the wsrep_view_handler_cb() callback. In the current version
these variables retain its initial values if wsrep_auto_increment_control
is switched on during operation of the node, which leads to inconsistent
results on the different nodes in some scenarios.

3. If wsrep auto_increment_control switched off during operation of the node,
then we must return the original values of the auto_increment_increment and
auto_increment_offset global variables, as the user has set. To make this
possible, we need to add a "shadow copies" of these variables (which stores
the latest values set by the user).

https://jira.mariadb.org/browse/MDEV-9519
2019-02-25 11:19:07 +02:00
Alexander Barkov
b25ad1bc47 MDEV-18408 Assertion `0' failed in Item::val_native_result / Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null upon mysqld_list_fields after crash recovery
The problem happened because Item_ident_for_show did not implement val_native().

Solution:

- Removing class Item_ident_for_show
- Implementing a new method Protocol::send_list_fields() instead,
  which accepts a List<Field> instead of List<Item> as input.
  Now no any Item creation is done during mysqld_list_fields().

Adding helper methods, to reuse the code easier:
- Moved a part of Protocol::send_result_set_metadata(),
  responsible for sending an individual field metadata,
  into a new method Protocol_text::store_field_metadata().
  Reusing it in both send_list_fields() and send_result_set_metadata().
- Adding Protocol_text::store_field_metadata()
- Adding Protocol_text::store_field_metadata_for_list_fields()

Note, this patch also automatically fixed another bug:

MDEV-18685 mysql_list_fields() returns DEFAULT 0 instead of DEFAULT NULL for view columns

The reason for this bug was that Item_ident_for_show::val_xxx() and get_date()
did not check field->is_null() before calling field->val_xxx()/get_date().
Now the default value is correctly sent by Protocol_text::store(Field*).
2019-02-25 12:29:42 +04:00
Teemu Ollakka
24be84384c Simplified Wsrep_client_service::interrupted()
Wsrep-lib is now guaranteed to hold the underlying mutex
which is wrapped in lock object passed to Wsrep_client_service
interrupted() call. The library part will now take care of
checking the wsrep::transaction specific state, so it is
enough to check the thd->killed state for the result.
2019-02-25 08:31:52 +02:00
Teemu Ollakka
6edfeb82fd Fixes to streaming replication BF aborts
The InnoDB DeadlockChecker::check_and_resolve() was missing a
call to wsrep_handle_SR_rollback() in the case when the
transaction running deadlock detection was chosen as victim.

Refined wsrep_handle_SR_rollback() to skip store_globals() calls
if the transaction was BF aborting itself.

Made mysql-wsrep-features#165 more deterministic by waiting until
the update is in progress before sending next update.
2019-02-25 08:31:52 +02:00
Daniel Black
31b65d3dd2 stop covering_keys from being set to the same thing twice 2019-02-24 10:47:15 -05:00
Igor Babaev
25870f48cf MDEV-18668 Server crash or ASAN use-after-poison in Item_equal_iterator /
st_select_lex::pushdown_from_having_into_where upon query
           with impossible WHERE condition

Do not push from HAVING into impossible WHERE
2019-02-24 02:02:07 -08:00
Igor Babaev
31deef0953 MDEV-18681 Server crashes in embedding_sjm
Do not do substitution for best equal field in HAVING conditions.
It's not needed.
2019-02-24 01:55:51 -08:00
Alexander Barkov
80c3fd184d Backporting MDEV-15597 Add class Load_data_outvar and avoid using Item::STRING_ITEM for Item_user_var_as_out_param detection
This is a part of "MDEV-18045 Backporting the MDEV-15497 changes to 10.2 branch"
2019-02-23 17:43:59 +04:00
Alexander Barkov
8036ad541e Backporting MDEV-15497 Wrong empty value in a GEOMETRY column on LOAD DATA
This is a part of "MDEV-18045 Backporting the MDEV-15497 changes to 10.2 branch"
2019-02-23 17:43:59 +04:00
Alexander Barkov
0ef8848526 Backporting MDEV-14628 Wrong autoinc value assigned by LOAD XML in the NO_AUTO_VALUE_ON_ZERO mode
This is a part of "MDEV-18045 Backporting the MDEV-15497 changes to 10.2 branch"
2019-02-23 17:43:59 +04:00
Igor Babaev
09bd213852 MDEV-18700 EXPLAIN EXTENDED shows a wrong operation for query
with UNION ALL after INTERSECT

EXPLAIN EXTENDED erroneously showed UNION instead of UNION ALL in
the warning if UNION ALL followed INTERSECT or EXCEPT operations.
The bug was in the function st_select_lex_unit::print() that printed
the text of the query used in the warning.
2019-02-22 21:38:55 -08:00
Oleksandr Byelkin
fb01193ce9 make windows compiler happy 2019-02-22 17:03:14 +01:00
sachin
0372f98cb5 Fix buildbot Windows and bintar compile failure 2019-02-22 12:33:08 +01:00
Sergei Golubchik
bd7f7b1416 MDEV-371 Unique Index for long columns
post-merge fixes
2019-02-22 12:33:08 +01:00
Sergei Golubchik
f6000782fb mysql_prepare_create_table() inconsistency
sql_field->key_length was 0 for blob fields when a field was
being added, but Field_blob::character_octet_length() on
subsequent ALTER TABLE's (when the Field object in the old table
already existed). This means mysql_prepare_create_table() couldn't
reliably detect if the keyseg was a prefix.
2019-02-22 12:32:49 +01:00
Sachin
d00f19e832 MDEV-371 Unique Index for long columns
This patch implements engine independent unique hash index.

Usage:- Unique HASH index can be created automatically for blob/varchar/test column whose key
 length > handler->max_key_length()
or it can be explicitly specified.

  Automatic Creation:-
   Create TABLE t1 (a blob unique);
  Explicit Creation:-
   Create TABLE t1 (a int , unique(a) using HASH);

Internal KEY_PART Representations:-
 Long unique key_info will have 2 representations.
 (lets understand this with an example create table t1(a blob, b blob , unique(a, b)); )

 1. User Given Representation:- key_info->key_part array will be similar to what user has defined.
 So in case of example it will have 2 key_parts (a, b)

 2. Storage Engine Representation:- In this case there will be only one key_part and it will point to
 HASH_FIELD. This key_part will be always after user defined key_parts.

 So:- User Given Representation          [a] [b] [hash_key_part]
                  key_info->key_part ----^
  Storage Engine Representation          [a] [b] [hash_key_part]
                  key_info->key_part ------------^

 Table->s->key_info will have User Given Representation, While table->key_info will have Storage Engine
 Representation.Representation can be changed into each other by calling re/setup_keyinfo_hash function.

Working:-

1. So when user specifies HASH_INDEX or key_length is > handler->max_key_length(), In mysql_prepare_create_table
One extra vfield is added (for each long unique key). And key_info->algorithm is set to HA_KEY_ALG_LONG_HASH.

2. In init_from_binary_frm_image values for hash_keypart is set (like fieldnr , field and flags)

3. In parse_vcol_defs, HASH_FIELD->vcol_info is created. Item_func_hash is used with list of Item_fields,
   When Explicit length is given by user then Item_left is used to concatenate Item_field values.

4. In ha_write_row/ha_update_row check_duplicate_long_entry_key is called which will create the hash key from
table->record[0] and then call ha_index_read_map , if we found duplicated hash , we will compare the result
field by field.
2019-02-22 00:35:40 +01:00
Sergei Golubchik
132216faf7 don't invoke error interceptors for fatal errors
and, again, *don't use thd->clear_error()*

this fixed main.sp_notembedded failure on various amd64 platforms
(where ER_STACK_OVERRUN_NEED_MORE happens to fire in open_stat_tables()
under Dummy_error_handler)
2019-02-21 15:04:03 +01:00
Sergei Golubchik
4386d93500 MDEV-18297 How to reset a forgotten root password
After FLUSH PRIVILEGES remember if the connection started under
--skip-grant-tables and keep it all-powerful, not a lowly anonymous.

One could use this connection to reset passwords as needed.

Also fix a crash in SHOW CREATE USER
2019-02-21 15:04:03 +01:00
Sergei Golubchik
a94b20a8e0 don't consider the password "expired" if authentication is passwordless 2019-02-21 15:04:03 +01:00
Sergei Golubchik
1e6210161d MDEV-7597 Expiration of user passwords
post-merge changes:
* handle password expiration on old tables like everything else -
  make changes in memory, even if they cannot be done on disk
* merge "debug" tests with non-debug tests, they don't use dbug anyway
* only run rpl password expiration in MIXED mode, it doesn't replicate
  anything, so no need to repeat it thrice
* restore update_user_table_password() prototype, it should not change
  ACL_USER, this is done in acl_user_update()
* don't parse json twice in get_password_lifetime and get_password_expired
* remove LEX_USER::is_changing_password, see if there was any auth instead
* avoid overflow in expiration calculations
* don't initialize Account_options in the constructor, it's bzero-ed later
* don't create ulong sysvars - they're not portable, prefer uint or ulonglong
* misc simplifications
2019-02-21 15:04:03 +01:00
Robert Bindar
90ad4dbd17 MDEV-7597 Expiration of user passwords
This patch adds support for expiring user passwords.
The following statements are extended:
  CREATE USER user@localhost PASSWORD EXPIRE [option]
  ALTER USER user@localhost PASSWORD EXPIRE [option]
If no option is specified, the password is expired with immediate
effect. If option is DEFAULT, global policy applies according to
the default_password_lifetime system var (if 0, password never
expires, if N, password expires every N days). If option is NEVER,
the password never expires and if option is INTERVAL N DAY, the
password expires every N days.
The feature also supports the disconnect_on_expired_password system
var and the --connect-expired-password client option.

Closes #1166
2019-02-21 15:04:03 +01:00
Sergei Golubchik
81ecc2b2b5 store string lengths in frm in 1-3 bytes 2019-02-21 14:57:10 +01:00
Sergei Golubchik
8ad23ff498 don't allow TIME columns in PERIOD specification 2019-02-21 14:57:10 +01:00
Sergei Golubchik
7b48724dcc UPDATE FOR PERIOD OF: don't crash on multi-table views 2019-02-21 14:57:10 +01:00
Sergei Golubchik
9718e374a2 update sql_yacc_ora.yy to match sql_yacc.yy 2019-02-21 14:57:10 +01:00
Sergei Golubchik
81e4b9b3bb misc cleanups 2019-02-21 14:57:10 +01:00
Nikita Malyavin
6294516a56 MDEV-16975 Application-time periods: ALTER TABLE
* implicit period constraint is hidden and cannot be dropped independently
* create...like and create...select support
2019-02-21 14:57:09 +01:00
Nikita Malyavin
b2bd52290a MDEV-16974 Application-time periods: UPDATE 2019-02-21 14:48:04 +01:00
Nikita Malyavin
47e28a94d5 MDEV-16973 Application-time periods: DELETE
* inject portion of time updates into mysql_delete main loop
* triggered case emits delete+insert, no updates
* PORTION OF `SYSTEM_TIME` is forbidden
* `DELETE HISTORY .. FOR PORTION OF ...` is forbidden as well
2019-02-21 14:48:04 +01:00
Nikita Malyavin
073c93b194 MDEV-17082 Application-time periods: CREATE
* add syntax `CREATE TABLE ... PERIOD FOR <apptime>`
* add table period entity
2019-02-21 14:48:04 +01:00
Oleksandr Byelkin
93ac7ae70f Merge branch '10.3' into 10.4 2019-02-21 14:40:52 +01:00
Vladislav Vaintroub
d9f7b6be5a MDEV-17942 fixup : protect rebuild_check_host() / rebuild_role_grants() with acl_cache->lock mutex 2019-02-20 22:35:21 +01:00
Vladislav Vaintroub
a2f82b649d MDEV-17942 Assertion `found' failed in remove_ptr_from_dynarray after failed CREATE OR REPLACE
Failed CREATE OR REPLACE for existing user removes that user
from acl_users array. Thus dependend structures (roles, check_host) must
be rebuilt.
2019-02-20 16:23:10 +01:00
Oleksandr Byelkin
c65daf02f0 make compatible parser in sync with main one 2019-02-19 19:11:40 +01:00
Marko Mäkelä
fc124778ea Merge 10.2 into 10.3 2019-02-19 17:41:13 +02:00
Alexander Barkov
93984ff6d6 Fixing compilation problems with this DBUG_ASSERT_AS_PRINTF
For example, with this cmake command line:

cmake . -DCMAKE_C_FLAGS="-DDBUG_ASSERT_AS_PRINTF" \
        -DCMAKE_CXX_FLAGS="-DDBUG_ASSERT_AS_PRINTF"
2019-02-19 19:36:54 +04:00
Sergey Vojtovich
abd3c202f6 Fixed build failure
Apparently DBUG_ASSERT() can co-exist with DBUG_OFF when
-DCMAKE_CXX_FLAGS="-DDBUG_ASSERT_AS_PRINTF".

Removed assertion as it is useless now, since the type is unsigned.
2019-02-19 19:20:16 +04:00
Teemu Ollakka
7ae685d032 Fixed replaying bugs found with multimaster load
The replayer did not signal replaying waiters. Added
mysql_cond_broadcast() after replaying is over.

Assertion on client error failed after replay attempt failed due
to certification failure. At this point the transaction does not
go through client state, so the client error cannot be overridden.
Assign ER_LOCK_DEADLOCK to thd directly instead.

Use timed cond wait when waiting for replayers to finish and
check if the transaction has been BF aborted during the wait.
2019-02-19 17:09:19 +02:00
Igor Babaev
2a935329bc Merge branch '10.4' into bb-10.4-mdev7486 2019-02-19 05:12:56 -08:00
mkaruza
ddc983394d Fix for galera_3nodes.galera_gtid_2_cluster
Temporary disable WSREP while executing RESET MASTER. In situation when 2 nodes are both master/slave first stop slave on both and than reset master.
Enforce stricter causality check with wsrep_sync_wait.
2019-02-19 14:25:01 +02:00
Igor Babaev
2e73c56120 Merge branch '10.4' into bb-10.4-mdev7486 2019-02-19 03:18:17 -08:00
Igor Babaev
8283d7d2c0 MDEV-7486: Condition pushdown from HAVING into WHERE
Optimized the code that removed multiple equalities pushed from HAVING
into WHERE. Now this removal is postponed until all multiple equalities
are eliminated in substitute_for_best_equal_field().
2019-02-19 02:45:24 -08:00
Vicențiu Ciorbaru
764429271d Implement avg_frequency unsmoothed jacknife estimator
When sampling data through ANALYZE TABLE, use the estimator to get a
better estimation of avg_frequency instead of just using the raw sampled data.
2019-02-19 12:01:21 +02:00
Vicențiu Ciorbaru
f0773b7842 Introduce analyze_sample_percentage variable
The variable controls the amount of sampling analyze table performs.

If ANALYZE table with histogram collection is too slow, one can reduce the
time taken by setting analyze_sample_percentage to a lower value of the
total number of rows.
Setting it to 0 will use a formula to compute how many rows to sample:

The number of rows collected is capped to a minimum of 50000 and
increases logarithmically with a coffecient of 4096. The coffecient is
chosen so that we expect an error of less than 3% in our estimations
according to the paper:
"Random Sampling for Histogram Construction: How much is enough?”
– Surajit Chaudhuri, Rajeev Motwani, Vivek Narasayya, ACM SIGMOD, 1998.

The drawback of sampling is that avg_frequency number is computed
imprecisely and will yeild a smaller number than the real one.
2019-02-19 12:01:21 +02:00
Vicențiu Ciorbaru
47f15ea73c Simplify column data adding method
The add method does not need to provide the row order number. It was
only used to detect if the minimum/maximum value was populated once or not, so
as to force an update for the first encounter of a value.
2019-02-19 12:01:21 +02:00
Vladislav Vaintroub
3dc6f0410b MDEV-15693 Stop packaging data directory into ZIPs
Remove CMake INSTALL command for COMPONENT DataFiles.

mysql_install_db.exe will calculate default datadir, so that it can be
called without any parameters.
2019-02-19 10:12:08 +01:00
Varun Gupta
2e6d8fcc17 MDEV-18551: New defaults for eq_range_index_dive_limit
The value for eq_range_index_dive_limit is increased to 200.
2019-02-19 14:27:24 +05:30
Varun Gupta
d6db6df995 MDEV-17903: New optimizer defaults: change optimize_join_buffer_size to be ON
optimize_join_buffer_size is switched ON.
2019-02-19 14:27:24 +05:30
Galina Shalygina
7fe1ca7ed6 Merge branch '10.4' into bb-10.4-mdev7486 2019-02-19 11:00:39 +03:00
Vladislav Vaintroub
f2f0c20044 MDEV-18439 Windows builds should have core_file=1 by default 2019-02-19 08:12:56 +01:00
Igor Babaev
4de3fd4ea2 MDEV-7486: Cosmetic changes
- Removed dead code
- Renamed a function
- Removed a parameter that not needed.
- Corrected comments
2019-02-18 22:11:25 -08:00
Teemu Ollakka
4baab8697a MDEV-18587 Don't reject DDLs if streaming replication is on
The check for streaming replication logging format in
THD::decide_logging_format() did the check also for DDLs running
in TOI mode. This caused DROP DATABASE to fail if streaming
replication was enabled.

Added check for THD wsrep execution mode and perform the check
only if the THD is in local processing mode (i.e. not TOI).

Added galera_sr_create_drop test to verify that CREATE/DROP
statements pass even if streaming replication is on.
2019-02-19 07:58:03 +02:00
Galina Shalygina
9741930490 MDEV-18636 The test case for bug mdev-16765 crashes the server
in the tree bb-10.4-mdev7486

The crash was caused because of the similar problem as in mdev-16765:
Item_cond::excl_dep_on_group_fields_for_having_pushdown() was missing.
2019-02-19 01:05:56 +03:00
Galina Shalygina
d25af33116 MDEV-18635 The test case for bug mdev-16727 crashes the server
in the tree bb-10.4-mdev7486

The crash was caused because after merge of bb-10.4-mdev7486 and
10.4 branches changes for mdev-16727 were missing.
2019-02-18 23:27:11 +03:00
Galina Shalygina
e4f1094c50 MDEV-7468 Fix for crash caused by connect.json_udf test
It was allowed to push UDF functions and that caused a crash.
To fix it it was forbidden to push UDF functions from HAVING into WHERE.
2019-02-18 20:37:23 +03:00
Marko Mäkelä
2c74799d64 MDEV-18627 Wrong result after instant size change of integer
If we instantly change the size of a fixed-length field
and treat it as kind-of variable-length, then we will need
conversions between old column values and new ones.

I tried adding such a conversion to row_build(), but then I
noticed that more conversions would be needed, because
old values still appeared in a freshly rebuilt secondary index,
causing a mismatch when trying to search with the correct
longer value that was converted in my provisional fix to row_build().

So, we will revert the essential part of
MDEV-15563: Instant ROW_FORMAT=REDUNDANT column extension
(commit 22feb179ae), but not
remove any tests.
2019-02-18 18:30:01 +02:00
Teemu Ollakka
f0b65102b2 MDEV-18585 Avoid excessive Annotate_rows_log_events in binlog
Make sure that the Annotate_rows_log_events is written into
binlog only for the first fragment of the current statement.
Also avoid flusing pending rows event when calculating bytes
generated by the transaction.

Added and recorded a test which verifies that the binlog
contains only one Annotate_rows_log_event per statement
with various SR settings. Recrded mysql-wsrep-features#136
which produced different output with excession log events
suppressed.
2019-02-18 15:04:38 +02:00
Varun Gupta
9cb55143ac Minor cleanup in the optimizer trace code.
More test coverage added for the optimizer trace.
2019-02-18 17:11:20 +05:30
Sergei Petrunia
15a77a1a2c MDEV-18608: Defaults for 10.4: histogram size should be set
Change the defaults:

-histogram_size=0
+histogram_size=254

-histogram_type=SINGLE_PREC_HB
+histogram_type=DOUBLE_PREC_HB

Adjust the testcases:
- Some have ignorable changes in EXPLAIN outputs and
  more counter increments due to EITS table reads.
- Testcases that meaningfully depend on the old defaults
  are changed to use the old values.
2019-02-18 13:37:57 +03:00
Marko Mäkelä
869ce67f59 Disable unused function 2019-02-18 11:44:20 +02:00
Marko Mäkelä
2bd7f32980 MDEV-16188: Remove redundant !this ||
Fix clang warning: 'this' pointer cannot be null in well-defined C++ code;
pointer may be assumed to always convert to true

The only caller of TABLE::best_range_rowid_filter_for_partial_join()
already seems to be assuming that s->table != NULL.
2019-02-18 11:44:20 +02:00
mkaruza
54ffc4996a MDEV-18588 Segfault during SST on joiner with bin-log, no bin-log-index
When node is JOINER and bin-log is enabled but bin-log-index is not set in configuration, we use NULL pointer which causes segfault. 
Fixed by checking for NULL pointer before using variable.
2019-02-18 11:05:40 +02:00
Galina Shalygina
7a77b221f1 MDEV-7486: Condition pushdown from HAVING into WHERE
Condition can be pushed from the HAVING clause into the WHERE clause
if it depends only on the fields that are used in the GROUP BY list
or depends on the fields that are equal to grouping fields.
Aggregate functions can't be pushed down.

How the pushdown is performed on the example:

SELECT t1.a,MAX(t1.b)
FROM t1
GROUP BY t1.a
HAVING (t1.a>2) AND (MAX(c)>12);

=>

SELECT t1.a,MAX(t1.b)
FROM t1
WHERE (t1.a>2)
GROUP BY t1.a
HAVING (MAX(c)>12);

The implementation scheme:

1. Extract the most restrictive condition cond from the HAVING clause of
   the select that depends only on the fields that are used in the GROUP BY
   list of the select (directly or indirectly through equalities)
2. Save cond as a condition that can be pushed into the WHERE clause
   of the select
3. Remove cond from the HAVING clause if it is possible

The optimization is implemented in the function
st_select_lex::pushdown_from_having_into_where().

New test file having_cond_pushdown.test is created.
2019-02-17 23:38:44 -08:00
Teemu Ollakka
3be9982f6a MDEV-18571 Fix wsrep PS protocol crash
Calls to wsrep_after_statement() were missing on PS protocol
codepath. Added calls after mysqld_stmt_execute() and
mysqld_stmt_bulk_execute().
2019-02-18 08:26:20 +02:00
Teemu Ollakka
b4c75f685b MDEV-18480 Backwards compatibility in log_view()
Galera versions below 4.x do not generate unique sequence number
for view events. Take this into account when writing the SE checkpoint
to avoid debug assertion in InnoDB.
2019-02-18 08:26:20 +02:00
Marko Mäkelä
790b6f5ae2 MDEV-18598: Wrong results after instant integer conversions
Field_str::is_equal(): Do not allow instant conversions between
BIT (which is stored big-endian) and integer types (which can
be stored big-endian or little-endian, depending on storage engine).

row_sel_field_store_in_mysql_format_func(): Properly extend
narrower integer and DATA_FIXBINARY values to the current format.
DATA_FIXBINARY was incorrectly padded with 0x20 instead of 0.
2019-02-17 01:05:31 +02:00
Sergei Golubchik
28f18aa7a6 Merge branch '10.4' into bb-10.4-mdev16188 2019-02-15 20:31:58 +01:00
Igor Babaev
a44f2c3ee8 Merge branch '10.4' into bb-10.4-mdev16188 2019-02-15 07:48:18 -08:00
Alexander Barkov
62c0ac2da6 A cleanup for MDEV-13916 Enforce check constraint on JSON type
1. Renaming Type_handler_json to Type_handler_json_longtext
   There will be other JSON handlers soon, e.g. Type_handler_json_varchar.

2. Making the code more symmetric for data types:

- Adding a new virtual method
  Type_handler::Column_definition_validate_check_constraint()
- Moving JSON-specific code from sql_yacc.yy to
  Type_handler_json_longtext::Column_definition_validate_check_constraint()

3. Adding new files sql_type_json.cc and sql_type_json.h
   and moving Type_handler+JSON related code into these files.
2019-02-15 19:46:58 +04:00
Marko Mäkelä
2b921845ac Merge 10.3 into 10.4 2019-02-15 12:30:43 +02:00
Igor Babaev
98d55b1366 Merge branch '10.4' into bb-10.4-mdev16188 2019-02-14 22:07:33 -08:00
Igor Babaev
ccce4d3be9 MDEV-16188 Post review fixes
Also adjusted some test files.
2019-02-14 15:23:23 -08:00
Marko Mäkelä
ea0be9e2d6 MDEV-15564 Avoid table rebuild in ALTER TABLE on collation or charset changes
Allow ALGORITHM=INSTANT (or avoid touching any data)
when changing the collation, or in some cases, the character set,
of a non-indexed CHAR or VARCHAR column. There is no penalty
for subsequent DDL or DML operations, and compatibility with
older MariaDB versions will be unaffected.

Character sets may be changed when the old encoding is compatible
with the new one. For example, changing from ASCII to anything
ASCII-based, or from 3-byte to 4-byte UTF-8 can sometimes be
performed instantly.

This is joint work with Eugene Kosov.
The test cases as well as ALTER_CONVERT_TO, charsets_are_compatible(),
Type_handler::Charsets_are_compatible() are his work.
The Field_str::is_equal(), Field_varstring::is_equal() and
the InnoDB changes were mostly rewritten by me due to conflicts
with MDEV-15563.

Limitations:

Changes of indexed columns will still require
ALGORITHM=COPY. We should allow ALGORITHM=NOCOPY and allow
the indexes to be rebuilt inside the storage engine,
without copying the entire table.

Instant column size changes (in bytes) are not supported by
all storage engines.

Instant CHAR column changes are only allowed for InnoDB
ROW_FORMAT=REDUNDANT. We could allow this for InnoDB
when the CHAR internally uses a variable-length encoding,
say, when converting from 3-byte UTF-8 to 4-byte UTF-8.

Instant VARCHAR column changes are allowed for InnoDB
ROW_FORMAT=REDUNDANT, and for others only if the size
in bytes does not change from 128..255 bytes to more
than 256 bytes.

Inside InnoDB, this slightly changes the way how MDEV-15563
works and fixes the result of the innodb.instant_alter_extend test.
We change the way how ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT
is handled. All column extension, type changes and renaming
now go through a common route, except when ctx->is_instant()
is in effect, for example, instant ADD or DROP COLUMN has
been initiated. Only in that case we will go through
innobase_instant_try() and rewrite all column metadata.

get_type(field, prtype, mtype, len): Convert a SQL data type into
InnoDB column metadata.

innobase_rename_column_try(): Remove the update of SYS_COLUMNS.

innobase_rename_or_enlarge_column_try(): New function,
replacing part of innobase_rename_column_try() and all of
innobase_enlarge_column_try(). Also changes column types.

innobase_rename_or_enlarge_columns_cache(): Also change
the column type.
2019-02-14 20:17:14 +02:00
Sergei Golubchik
e5701d8363 cleanup: Account_options
move account options from LEX to Account_options structure
namely, mqh and ssl_*

Also, use LEX_CSTRING for ssl_*/x509_* strings and move
setting of ACL_USER::account_locked where it belongs
2019-02-14 17:30:22 +01:00
Robert Bindar
6c8ce999f8 MDEV-13095 Implement User Account locking
Add server support for user account locking.
This patch extends the ALTER/CREATE USER statements for
denying a user's subsequent login attempts:
  ALTER USER
    user [, user2] ACCOUNT [LOCK | UNLOCK]
  CREATE USER
    user [, user2] ACCOUNT [LOCK | UNLOCK]
The SHOW CREATE USER statement was updated to display the
locking state of an user.

Closes #1006
2019-02-14 17:30:22 +01:00
Sergei Golubchik
84cbd69c9e cleanup: reformat 2019-02-14 17:30:22 +01:00
Sergei Golubchik
c0745e3730 bugfix: CREATE...SELECT lost COMMENT and VERSIONING 2019-02-14 17:30:22 +01:00
Sergei Golubchik
1d8b5524f4 cleanup: remove THD::query_start_timeval()
Too easy to abuse. One tends to use it even when
microseconds are not needed and will be ignored.
2019-02-14 17:30:22 +01:00
Jan Lindström
c568e25379
Merge pull request #1185 from codership/10.4-wsrep_schema_cleanup
Cleanup wsrep_schema and remove all references to wsrep_thd_pool
2019-02-14 14:30:13 +02:00
Jan Lindström
677a1e7c52
Merge pull request #1183 from codership/10.4-wsrep_debug
WSREP debug log levels support
2019-02-14 14:29:01 +02:00
Daniele Sciascia
047754a728 Cleanup wsrep_schema and remove all references to wsrep_thd_pool
* Removed all references related to wsrep_thd_pool (which was removed)

* Removed unused declarations in wsrep_schema.h

* The following would result invalid reads in
  Wsrep_schema::replay_transaction():
  ```
  frag_table->field[4]->val_str(&buf);

  Wsrep_schema_impl::end_index_scan(frag_table);
  Wsrep_schema_impl::finish_stmt(thd);
  ret= wsrep_apply_events(thd, rli, buf.c_ptr_safe(), buf.length());
  ```

  because `buf` was accessed after closing the table. The fix is to
  perform storage reads using a different THD.

* In Wsrep_schema::recover_sr_transactions(), cluster_table was opened
  for write, however it is only read here. And frag_table was opened
  for read, wereas write is potentially needed.
  Also, avoid copy caused by String::c_ptr() to zero terminate the c
  string, use c_ptr_quick instead.
2019-02-14 09:55:14 +01:00
Igor Babaev
e1de23b8d5 MDEV-16188 Introduced the notion of adjusted filter gain.
Due to inconsistent usage of different cost models to calculate
the cost of ref accesses we have to make the calculation of the
gain promising by usage a range filter more complex.
2019-02-14 00:17:20 -08:00
Igor Babaev
7d9f45e072 Merge branch '10.4' into bb-10.4-mdev17096 2019-02-13 14:59:34 -08:00
mkaruza
3e64e7f24c WSREP debug log levels support
Global variable wsrep_debug now can be used to filter wsrep-lib messages based on debug level provided.
Type of wsrep_debug is now set to be unsigned int, so tests and configuration files changed accordingly.
2019-02-13 18:47:27 +01:00
Monty
0f48949439 MDEV-13916 Enforce check constraint on JSON type
When creating a field of type JSON, it will be automatically
converted to TEXT with CHECK (json_valid(`a`)), if there wasn't any
previous check for the column.

Additional things:
- Added two bug fixes that was found while testing JSON. These bug
  fixes has also been pushed to 10.3 (with a test case), but as they
  where minimal and needed to get this task done and tested, the fixes
  are repeated here.
  - CREATE TABLE ... SELECT drops constraints for columns that
    are both in the create and select part.
  - If one has both a default expression and check constraint for a
    column, one can get the error "Expression for field `a` is refering
    to uninitialized field `a`.
- Removed some duplicate MYSQL_PLUGIN_IMPORT symbols
2019-02-13 19:40:26 +02:00
Monty
438811b4b2 Fixed two bugs related to column level constraints
- CREATE TABLE ... SELECT drops constraints for columns that
  are both in the create and select part.
  - Fixed by copying the constraint in
    Column_definiton::redefine_stage1_common()
- If one has both a default expression and check constraint for a
  column, one can get the error "Expression for field `a` is refering
  to uninitialized field `a`.
  - Fixed by ignoring default expressions for current column when checking
    for CHECK constraint
2019-02-13 18:21:19 +02:00
Marko Mäkelä
22feb179ae MDEV-15563: Instant ROW_FORMAT=REDUNDANT column extension
This was developed by Aleksey Midenkov based on my design.

In the original InnoDB storage format (that was retroactively named
ROW_FORMAT=REDUNDANT in MySQL 5.0.3), the length of each index field
is stored explicitly.

Because of this, we can and now will allow instant conversion from
VARCHAR to CHAR or VARBINARY to BINARY of equal or greater size,
as well as instant conversion of TINYINT to SMALLINT to MEDIUMINT
to INT to BIGINT (while not changing between signed and unsigned).

Theoretically, we could allow changing from an unsigned integer to
a bigger unsigned integer, as well as changing CHAR to VARCHAR, but
that would require additional metadata and conversions whenever
reading old records.

Field_str::is_equal(), Field_varstring::is_equal(), Field_num::is_equal():
Return the new result IS_EQUAL_PACK_LENGTH_EXT if the table advertises
HA_EXTENDED_TYPES_CONVERSION capability and we are considering the
above-mentioned conversions.

ALTER_COLUMN_EQUAL_PACK_LENGTH_EXT: A new ALTER TABLE flag, similar
to ALTER_COLUMN_EQUAL_PACK_LENGTH but requiring conversions when
reading the data. The Field::is_equal() result IS_EQUAL_PACK_LENGTH_EXT
will map to this flag.

dtype_get_fixed_size_low(): For BINARY, CHAR and integer columns
in ROW_FORMAT=REDUNDANT, return 0 (variable length) from now on.

dtype_get_sql_null_size(): Keep returning the current size for
BINARY, CHAR and integer columns, so that in ROW_FORMAT=REDUNDANT
it will remain possible to update in place between NULL and NOT NULL
values.

btr_index_rec_validate(): Relax a CHECK TABLE length check for
ROW_FORMAT=REDUNDANT tables.

btr_cur_instant_init_low(): No longer trust fixed_len
for ROW_FORMAT=REDUNDANT tables.

We cannot rely on fixed_len anymore because the record can have shorter
length from before instant extension. Note that importing such tablespace
into earlier MariaDB versions produces ER_TABLE_SCHEMA_MISMATCH when
using a .cfg file.
2019-02-13 17:39:05 +02:00
Marko Mäkelä
0ae3ea7919 MDEV-15563: Instant VARCHAR extension for ROW_FORMAT=REDUNDANT
In the original InnoDB storage format (which was retroactively named
ROW_FORMAT=REDUNDANT in MySQL 5.0.3), the length of each index field
is stored explicitly. Thus, we can and from now on will allow arbitrary
extension of VARBINARY and VARCHAR columns when the table is in
ROW_FORMAT=REDUNDANT.

ha_innobase::open(): Advertise a new HA_EXTENDED_TYPES_CONVERSION
capability for ROW_FORMAT=REDUNDANT tables.

Field_varstring::is_equal(): If the HA_EXTENDED_TYPES_CONVERSION
capability is advertised for the table, return IS_EQUAL_PACK_LENGTH
for any length extension.
2019-02-13 16:42:03 +02:00
Marko Mäkelä
ad17875c0d MDEV-15563: Allow instant VARCHAR extension from <128 bytes
For up to 127 bytes length, InnoDB would use 1 byte for length, and
that byte would always be less than 128. If the maximum length is
longer than 255 bytes, InnoDB would use a variable-length encoding
for the length, using 1 byte for lengths up to 127 bytes, and
2 bytes for longer lengths.

Thus, 1-byte lengths are always compatible when the maximum size
changes from less than 128 bytes to anything longer.

Field_varstring::is_equal(): Return IS_EQUAL_PACK_LENGTH also when
converting from VARCHAR less than 128 bytes to any longer VARCHAR.
2019-02-13 15:46:52 +02:00
Sergey Vojtovich
8a3a332bc0 Cleanup Item_func_sp::fix_fields()
No need to call list.empty(): first one is called by List constructor,
second one doesn't make sense as the object is destroyed immediately
afterwards.
2019-02-13 17:40:03 +04:00
Daniel Black
a3ccad0f21 Aggregate functions: only create list if args exist
Also always empty list rather than only if there is no error.
2019-02-13 17:35:51 +04:00
Jan Lindström
c2c637c583
Merge pull request #1180 from codership/10.4-load-data-splitting
10.4 make wsrep_load_data_splitting use streaming replication
2019-02-13 13:29:51 +02:00
Jan Lindström
6476126cba MDEV-18564: Change wsrep_load_data_splitting off by default
Variable wsrep_load_data_splitting is deprecated and should be off
by default.
2019-02-13 13:19:37 +02:00
Vladislav Vaintroub
d28dab7658 Fix compilation on old gcc 2019-02-13 12:15:14 +01:00
Igor Babaev
953ca199fb Merge branch '10.4' into bb-10.4-mdev17096 2019-02-12 23:19:43 -08:00
Igor Babaev
27c3abde30 MDEV-17096 Pushdown of simple derived tables to storage engines
MDEV-17631 select_handler for a full query pushdown

Added comments and file headers for files introduced in these tasks.
2019-02-12 22:56:24 -08:00
Varun Gupta
be8709eb7b MDEV-6111 Optimizer Trace
This task involves the implementation for the optimizer trace.

This feature produces a trace for any SELECT/UPDATE/DELETE/,
which contains information about decisions taken by the optimizer during
the optimization phase (choice of table access method, various costs,
transformations, etc). This feature would help to tell why some decisions were
taken by the optimizer and why some were rejected.

Trace is session-local, controlled by the @@optimizer_trace variable.
To enable optimizer trace we need to write:
   set @@optimizer_trace variable= 'enabled=on';

To display the trace one can run:
   SELECT trace FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;

This task also involves:
    MDEV-18489: Limit the memory used by the optimizer trace
    introduces a switch optimizer_trace_max_mem_size which limits
    the memory used by the optimizer trace. This was implemented by
    Sergei Petrunia.
2019-02-13 11:52:36 +05:30
Varun Gupta
6b979416e0 Extending the API for json_writer by introdcing
classes for Json_writer_object and Json_writer_array.
These classes will be used for the implementation
of the optimizer trace.
2019-02-13 11:52:35 +05:30
Sergey Vojtovich
4d5f85a3ec Bootstrap cleanups
Remove unused key_thread_bootstrap.
No more global bootstrap_error: it is return value of bootstrap() instead.
2019-02-12 23:07:51 +04:00
Teemu Ollakka
f06a0b5338 Implement wsrep_load_data_splitting with streaming replication
If wsrep_load_data_splitting is configured, change streaming replication
parameters internally to match the original behavior, i.e. replicate
on every 10000 rows. After load data is over, restore original
streaming replication settings.

Removed redundant wsrep_tc_log_commit().
2019-02-12 10:37:05 +02:00
Alexander Barkov
ce6505f890 MDEV-18447 Assertion `!is_zero_datetime()' failed in Timestamp_or_zero_datetime::tv 2019-02-12 11:59:17 +04:00
Marko Mäkelä
9f56dd7382 Merge 10.3 into 10.4 2019-02-11 17:55:25 +02:00
Jan Lindström
cbfbb70dd2
Merge pull request #1170 from codership/10.4-rsync_fix
MDEV-18178, mariabackup script timestamp change, galera suite fixed & re-recorded tests
2019-02-11 13:46:26 +02:00
Teemu Ollakka
f0513de525 Fixed use of uninitialized value in wsrep_TOI_end()
The if/else was a remnant from error voting code which was not
included in the release.
2019-02-11 10:10:55 +02:00
Igor Babaev
cd00d03fe2 MDEV-16188 Fixed the code of ha_partition::multi_range_read_info()
The code was rewritten in the same way as the code of
ha_partition::multi_range_read_info_const() had been rewritten
earlier.

The fix allowed to run spider.partition_mrr.
2019-02-10 21:15:48 -08:00
Galina Shalygina
3955d2a153 MDEV-18413: Find constraint correlated indexes
Find indexes of one table which parts participate in one constraint.
These indexes are called constraint correlated.

New methods: TABLE::find_constraint_correlated_indexes() and
virtual method check_index_dependence() were added.
For each index it's own constraint correlated index map was created
where all indexes that are constraint correlated with the current are
marked.

The results of this task are used for MDEV-16188 (Use in-memory
PK filters built from range index scans).
2019-02-10 22:36:46 +03:00
Igor Babaev
d11be23933 MDEV-17096 Pushdown of simple derived tables to storage engines
Resolved the problem of forming a proper query string for FEDERATEDX.
Added test cases.

Cleanup of extra spaces.
2019-02-09 22:54:26 -08:00
Igor Babaev
15fe81c571 MDEV-16188 Post merge fixes: trying to get rid of Windows warnings. 2019-02-09 10:54:26 -08:00
Igor Babaev
9fe1e83df0 MDEV-16188 Post merge fixes: more for TokuDB 2019-02-08 12:32:31 -08:00
mkaruza
accc7f6029 MDEV-18178 Galera test failure on galera_sst_rsync2
* Donor node will now provide binlog-index argument to wsrep_sst_rsync script if binlog is used.
* Write correct path and binlog file names into joiner binlog-index file
2019-02-08 11:18:18 +01:00
Igor Babaev
651347b6c1 MDEV-16188 Post merge fixes fot TokuDB 2019-02-08 01:07:27 -08:00
Galina Shalygina
6cb2ab5328 MDEV-18144 ANALYZE fixes
Fix bugs caused by changes for ANALYZE
2019-02-07 13:22:07 +03:00
Jan Lindström
c949d61e30
Merge pull request #1152 from codership/10.4-wsrep-lib-update
Updated wsrep-lib to galera cache encryption implementation
2019-02-07 10:28:29 +02:00
Igor Babaev
3f9040085a Merge branch '10.4' into bb-10.4-mdev17096 2019-02-06 18:01:29 -08:00
Igor Babaev
16327fc2e7 MDEV-17096 Pushdown of simple derived tables to storage engines
MDEV-17631 select_handler for a full query pushdown

Interfaces + Proof of Concept for federatedx with test cases.

The interfaces have been developed for integration of ColumnStore engine.
2019-02-06 17:02:44 -08:00
Igor Babaev
9e114455a9 MDEV-16188 Post merge fixes:fixed warnings on Windows
Also adjusted some result files after Galina's last patch for ANALYZE.
2019-02-06 15:56:21 -08:00
Galina Shalygina
447e0f023f MDEV-18144: ANALYZE for statement support for PK filters
ANALYZE and ANALYZE FORMAT=JSON structures are changed in the way that they
show additional information when rowid filter is used:

- r_selectivity_pct - the observed filter selectivity
- r_buffer_size - the size of the rowid filter container buffer
- r_filling_time_ms - how long it took to fill rowid filter container

New class Rowid_filter_tracker was added. This class is needed to collect data
about how rowid filter is executed.
2019-02-06 23:40:07 +03:00
Monty
129b2dcef3 Changed user_variables and sql_sequence to maturity state stable 2019-02-06 22:18:20 +02:00
Alexey Botchkov
a4c687c494 the opt_constraint_no_id should not have the lex_str type. 2019-02-06 16:53:16 +04:00
Marko Mäkelä
e80bcd7f64 Merge 10.3 into 10.4 2019-02-05 12:48:02 +02:00
Alexey Botchkov
f53e795250 MDEV-17599 ALTER TABLE DROP CONSTRAINT does not work for foreign keys.
The list of table constraints doesn't include foreign keys and uniques.
So we replace DROP CONSTRAINT with DROP [FOREIGN] KEY in this case.
2019-02-05 11:24:19 +04:00
Igor Babaev
33907360f5 MDEV-16188 Post-merge corrections and adjustments 2019-02-04 22:44:33 -08:00
Sergei Golubchik
b57ae8b58c MDEV-18239 ASAN use-after-poison in process_str_arg / ... / mark_unsupported_func or unexpected ER_BAD_FIELD_ERROR upon ALTER TABLE
renaming columns in a CHECK constraint during ALTER TABLE
taints the original TABLE and requires m_need_reopen=1.

In this case, though, renaming was redundant, so just don't do it.
2019-02-05 01:34:17 +01:00
Sergei Golubchik
ef4ccb6ce2 MDEV-18083 ASAN heap-use-after-free in Field::set_warning_truncated_wrong_value upon inserting into temporary table
remove TABLE_SHARE::error_table_name() and TABLE_SHARE::orig_table_name
(that was allocated in a wrong memroot in this bug).

instead, simply set TABLE_SHARE::table_name correctly.
2019-02-05 01:34:17 +01:00
Sergei Golubchik
3b7694b7f8 cleanup: don't search for a just-opened tmp table in ALTER
remove thd->find_temporary_table()
2019-02-05 01:34:17 +01:00
Sergei Golubchik
78d5a764b2 compiler warnings 2019-02-05 01:34:17 +01:00
Sergei Golubchik
5b15cc613e MDEV-11340 Allow multiple alternative authentication methods for the same user
introduce the syntax

... IDENTIFIED { WITH | VIA }
      plugin [ { USING | AS } auth ]
 [ OR plugin [ { USING | AS } auth ]
 [ OR ... ]]

Server will try auth plugins in the specified order until the first
success. No protocol changes, server uses the existing "switch plugin"
packet.

The auth chain is stored in json as

  "auth_or":[{"plugin":"xxx","authentication_string":"yyy"},
             {},
             {"plugin":"foo","authentication_string":"bar"},
            ...],
  "plugin":"aaa", "authentication_string":"bbb"

Note:
* "auth_or" implies that there might be "auth_and" someday;
* one entry in the array is an empty object, meaning to take plugin/auth
  from the main json object. This preserves compatibility with
  the existing mysql.global_priv table and with the mysql.user view.
  This entry is preferrably a mysql_native_password plugin for a
  non-empty mysql.user.password column.

SET PASSWORD is supported and changes the password for the *first*
plugin in the chain that has a notion of a "password"
2019-02-04 16:06:57 +01:00
Sergei Golubchik
3416e8ac9a cleanup: sys_vars.cc
add DEPRECATED() warning for variables with "deprecated" in the
help text. Remove redundant initializers.
2019-02-04 15:54:10 +01:00
Sergei Golubchik
b8344be4fa cleanup 2019-02-04 15:54:10 +01:00
Sergei Golubchik
9b3f177c6d avoid unintentional %union size increases 2019-02-04 15:54:10 +01:00
Sergei Golubchik
103a32fdd3 ed25519: better error message for an incorrect password hash 2019-02-04 15:54:10 +01:00
Sergei Golubchik
c94ec9fc67 MDEV-17950 SHOW GRANTS FOR does not work for a user identified with non-existing plugin
Revert the side effect of 7c40996cc8.
Do not convert password hash to its binary representation when a user
entry is loaded. Do it lazily on the first authenticatation attempt.

As a collateral - force all authentication plugins to follow the
protocol and read_packet at least once before accessing info->username
(username is not available before first client handshake packet is read).

Fix PAM and GSSAPI plugins to behave.
2019-02-04 15:54:10 +01:00
Marko Mäkelä
ab2458c61f Merge 10.2 into 10.3 2019-02-04 15:12:14 +02:00
Igor Babaev
37deed3f37 Merge branch '10.4' into bb-10.4-mdev16188 2019-02-03 18:41:18 -08:00
Igor Babaev
658128af43 MDEV-16188 Use in-memory PK filters built from range index scans
This patch contains a full implementation of the optimization
that allows to use in-memory rowid / primary filters built for range  
conditions over indexes. In many cases usage of such filters reduce  
the number of disk seeks spent for fetching table rows.

In this implementation the choice of what possible filter to be applied  
(if any) is made purely on cost-based considerations.

This implementation re-achitectured the partial implementation of
the feature pushed by Galina Shalygina in the commit
8d5a11122c.

Besides this patch contains a better implementation of the generic  
handler function handler::multi_range_read_info_const() that
takes into account gaps between ranges when calculating the cost of
range index scans. It also contains some corrections of the
implementation of the handler function records_in_range() for MyISAM.

This patch supports the feature for InnoDB and MyISAM.
2019-02-03 14:56:12 -08:00
Marko Mäkelä
a249e57b68 Merge 10.1 into 10.2
Temporarily disable a test for
commit 2175bfce3e
because fixing it in 10.2 requires updating libmariadb.
2019-02-03 17:22:05 +02:00
Vladislav Vaintroub
261ce5286f MDEV-18281 COM_RESET_CONNECTION changes the connection encoding
Store original charset during client authentication, and restore it for
COM_RESET_CONNECTION
2019-02-02 17:32:15 +01:00
Vladislav Vaintroub
e214aa1cd3 MDEV-18281 COM_RESET_CONNECTION changes the connection encoding
Store original charset during client authentication, and restore it for
COM_RESET_CONNECTION
2019-02-02 17:29:33 +01:00
Marko Mäkelä
213ece2f2e Merge 10.1 into 10.1
This is joint work with Oleksandr Byelkin.
2019-02-02 13:00:15 +02:00
Marko Mäkelä
c1e1764fc4 Fix embedded innodb_plugin after 560799ebd8
wsrep_certification_rules: Define as a weak global symbol.
While there are separate _embedded.a for statically
linked storage engine plugins, there is only one ha_innodb.so
which is supposed to work with both values of WITH_WSREP.

The merge from 10.0-galera introduced a reference to a global
variable that is only defined when the server is built WITH_WSREP.
We must define that symbol as weak global, so that when
a dynamically linked InnoDB or XtraDB is used with the embedded
server (which never includes write-set replication patches),
the variable will be read as 0, instead of causing a failure to
load the InnoDB or XtraDB plugin.
2019-02-02 12:49:04 +02:00
Marko Mäkelä
081fd8bfa2 Merge 10.1 into 10.2 2019-02-02 11:40:02 +02:00
Varun Gupta
74eb4fc9fc MDEV-17484: New defaults for eq_range_index_dive_limit in 10.4
The default value for eq_range_index_dive_limit is set to 10
2019-02-01 23:43:38 +05:30
mkaruza
239b2dcf6e Updated wsrep-lib to galera cache encryption implementation 2019-02-01 18:08:36 +01:00
Alexey Botchkov
09cea8703f MDEV-17148 DROP DATABASE throw "Directory not empty" after changed lower_case_table_names.
No need to lowercase table names on case-sensitive file systems, as the
cache won't contain the 'lowercased' table anyway. And it prevents the
UPPERCASE.frm from being deleted.
2019-02-01 17:10:27 +04:00
Vladislav Vaintroub
20e19f6975 MDEV-17479 Assertion `mysql_socket.fd != -1' failed in inline_mysql_socket_send on server shutdown
Do not try to write ER_SHUTDOWN error message to socket, when it is forcefully closed by the shutdown.
This will avoid the race condition (attempt to write to closed socket,  if connection shuts down by itself).
2019-01-31 22:12:24 +01:00
Oleksandr Byelkin
a3a4ea9355 postmerge rollbacks and fixes 2019-01-31 19:28:38 +01:00
Oleksandr Byelkin
560799ebd8 Merge branch '10.0-galera' into 10.1 2019-01-31 09:34:34 +01:00
Varun Gupta
6092093cb9 MDEV-15950: LOAD DATA INTO compex_view crashed
For multi-table views with LOAD, updates are not allowed, so
we should just throw an error.
2019-01-30 19:35:40 +05:30
Thirunarayanan Balathandayuthapani
b8aef87221 MDEV-16849 Extending indexed VARCHAR column should be instantaneous
Analysis:
========
Increasing the length of the indexed varchar column is not an instant operation for
innodb.

Fix:
===
- Introduce the new handler flag 'Alter_inplace_info::ALTER_COLUMN_INDEX_LENGTH' to
indicate the index length differs due to change of column length changes.

- InnoDB makes the ALTER_COLUMN_INDEX_LENGTH flag as instant operation.

This is a port of Mysql fix.

    commit 913071c0b16cc03e703308250d795bc381627e37
    Author: Nisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>
    Date:   Wed May 30 14:54:46 2018 +0530

        BUG#26848813: INDEXED COLUMN CAN'T BE CHANGED FROM VARCHAR(15)
                      TO VARCHAR(40) INSTANTANEOUSLY
2019-01-30 15:33:32 +05:30
Marko Mäkelä
923415ffdb Merge bb-10.4-release into 10.4 2019-01-30 09:13:38 +02:00
Varun Gupta
08c05b5f34 MDEV-15744: Assertion `derived->table' failed in mysql_derived_merge_for_insert
For singe-table views, we need to find the bottom most base table in the embedded views
and then update that table
2019-01-29 14:52:24 +02:00
Sergey Vojtovich
4b3656a44d Avoid taking LOCK_thread_count for thread_count protection
Replaced wait on COND_thread_count with busy waiting with 1 millisecond
sleep.

Aim is to reduce usage of LOCK_thread_count and COND_thread_count.
2019-01-29 11:56:35 +04:00
Sergey Vojtovich
8553525931 MDEV-18400 - Move shutdown handling to main thread
Signal handler is now respoinsible for setting abort_loop and breaking
poll() in main thread. The rest is handled by main thread itself.

Removed redundant LOCK_error_log init/destroy wrappers.
Removed redundant unireg_end(): it is trivial and it has only one caller.
Removed unused ready_to_exit from PFS.
Removed kill_in_progress: duplicates abort_loop.
Removed shutdown_in_progress: duplicates abort_loop.
Removed ready_to_exit: was used to make sure main thread waits for
cleanups, which are now done by main thread itself.
Removed SIGNALS_DONT_BREAK_READ, MAYBE_BROKEN_SYSCALL,
kill_broken_server: never defined/used.
Make clean_up() static.
2019-01-29 11:56:35 +04:00
Vladislav Vaintroub
c2318291be MDEV-15135 - Make LOCK_show_status rwlock, to enable parallelism of
fill_status.

Also, remove LOCK_status around calc_sum_of_all_status()

Also, rename LOCK_show_status into LOCK_all_status_vars.
This reflects the variable the lock protects.
2019-01-28 17:49:53 +04:00
Vladislav Vaintroub
8b4fcc434d Use rwlock rather than mutex for protecting THD_list
modifications (insert/erase) are protected by write lock
iteration over list is protected by read lock.

This way, threads that iterate over the list (as in SHOW PROCESSLIST,
SHOW GLOBAL STATUS) do not block each other.
2019-01-28 17:45:35 +04:00
Sergei Golubchik
41a9a677eb downgrade wsrep_plugin_init()/wsrep_plugin_deinit log messages
from info to debug
2019-01-28 14:41:38 +01:00
Sergey Vojtovich
9824ec81aa Removed redundant service_thread_count
In contrast to thread_count, which is decremented by THD destructor,
this one was most probably intended to be decremented after all THD
destructors are done.

THD_count class was added to achieve similar effect with thread_count.

Aim is to reduce usage of LOCK_thread_count and COND_thread_count.
Part of MDEV-15135.
2019-01-28 17:39:08 +04:00
Sergey Vojtovich
3503fbbebf Move THD list handling to THD_list
Implemented and integrated THD_list as a replacement for the global
thread list. It uses own mutex instead of LOCK_thread_count for THD
list protection.

Removed unused first_global_thread() and next_global_thread().

delayed_insert_threads is now protected by LOCK_delayed_insert. Although
this patch doesn't fix very wrong synchronization of this variable.

After this patch there are only 2 legitimate uses of LOCK_thread_count
left, both in mysqld.cc: thread_count and ready_to_exit.

Aim is to reduce usage of LOCK_thread_count and COND_thread_count.
Part of MDEV-15135.
2019-01-28 17:39:07 +04:00
Sergey Vojtovich
891be49a36 Simplified THD::current_linfo locking
LOG_INFO::lock was useless. It could've only protect against concurrent
iterators execution, which was already protected by LOCK_thread_count.

Use LOCK_thd_data instead of LOCK_thread_count as a protection against
THD::current_linfo reset.

Aim is to reduce usage of LOCK_thread_count and COND_thread_count.
Part of MDEV-15135.
2019-01-28 17:39:07 +04:00
Sergey Vojtovich
c88fd54d17 Execute bootstrap in main thread
Bootstrap in a separate thread was introduced in 746f0b3b7 to workaround
OS/2 small stack size. OS/2 support was discontinued in 2006 and modern
operating systems have default stack size a few times larger than
default thread_stack and it is tunable.

Aim is to reduce usage of LOCK_thread_count and COND_thread_count.
Part of MDEV-15135.
2019-01-28 17:39:06 +04:00
Sergey Vojtovich
7ad742b265 Simplified code, no functional changes 2019-01-28 17:39:06 +04:00
Oleksandr Byelkin
a3df9bcadc Merge branch '5.5' into 10.0 2019-01-28 10:36:12 +01:00
Teemu Ollakka
4ea128391b MDEV-15740 Fix wsrep recovery with wsrep_emulate_bin_log
If the TC log did not provide list of XIDs to recover, the
commit by XID was skipped during wsrep recovery if binlog emulation
was on. However, with wsrep we want to commit every prepared transaction
with assigned wsrep XID since the transaction has already been
committed in the cluster.

Added a special condition to always proceed to commit by XID in
xarecover_handlerton() if binlog is off and the recovered transaction
has wsrep XID.
2019-01-27 15:36:36 +02:00
Monty
4007eaba91 Removed declaration of strconvert() from innodb_priv.h 2019-01-26 19:18:22 +02:00
Monty
c0c62196ca Removed \n from sql_print_error() 2019-01-26 19:18:22 +02:00
Sergei Golubchik
574cde9be4 fix failing openssl_1 test
if ssl_cipher is not specified, it must be NULL, not ""
2019-01-26 10:26:20 +01:00
Julius Goryavsky
4aea6b3e3f MDEV-18379: Unification of check for IPv6
This patch contains the port of the MDEV-18379 patch
for 10.1 branch, but also includes a number of changes
made within MDEV-17835, which are necessary for the
normal operation of tests that use IPv6:

1) Fixed flaws in the galera_3nodes mtr suite control scripts,
because of which they could not work with mariabackup.

2) Fixed numerous bugs in the SST scripts and in the mtr test
files (galera_3nodes mtr suite) that prevented the use of Galera
with IPv6 addresses.

3) Fixed flaws in tests for rsync and mysqldump (for galera_3nodes
mtr tests suite). These tests were not performed successfully
without these fixes.

4) Currently, the three-node mtr suite for Galera (galera_3nodes)
uses a separate IPv6 availability check using the "have_ipv6.inc"
file. This check duplicates a more accurate check at suite.pm
level, which can be used by including the file "check_ipv6.inc".
This patch removes this discrepancy between suites.

5) GAL-501 test in the galera_3nodes suite does not contain the
option "--bind-address=::" which is needed for the test to work
correctly with IPv6 (at least on some systems), since without
it the server will not wait for connections on the IPv6 interface.

https://jira.mariadb.org/browse/MDEV-18379
and partially https://jira.mariadb.org/browse/MDEV-17835
2019-01-26 01:15:44 +01:00
Sergei Golubchik
9b76e2843b Merge branch '10.3' into 10.4 2019-01-26 01:13:41 +01:00
Sergei Golubchik
e99e6f29e9 cleanup: trg2bit() helper 2019-01-25 19:59:04 +01:00
Teemu Ollakka
040b840de7 MDEV-15740 Backport wsrep recovery fixes from 10.4.
Clear wsrep XID in innobase_rollback_by_xid() for recovered wsrep
transaction in order to avoid resetting XID storage when rolling back
wsrep transaction during recovery.

Sort wsrep XIDs read from storage engine in ascending order and
erify that the range is continuous during crash recovery. If binlog is off,
commit all recovered transactions for continuous seqno range. This is safe
because all transactions with wsrep XID have been certified and must be
committed in the cluster. On the other hand if binlog is on, respect binlog
as a transaction coordinator in order to avoid missing transactions in binlog
that have been committed into storage engine .
2019-01-25 16:19:20 +02:00
Andrei Elkin
ef0b91ea94 MDEV-17803: ulonglongization of table_mapping entry::table_id to fix windows compilation in particular. 2019-01-25 13:42:27 +02:00
Sergei Golubchik
38ad46e005 cleanup: fill_alter_inplace_info
remove attempts to track "candidate keys", use what was already
decided in create_table_impl().
2019-01-25 10:06:16 +01:00
Sergei Golubchik
013186eb96 compiler warning 2019-01-25 10:06:16 +01:00
Marko Mäkelä
78829a5780 Merge 10.3 into 10.4 2019-01-24 22:42:35 +02:00
Marko Mäkelä
d6ba849617 Remove unused code 2019-01-24 22:22:56 +02:00
Andrei Elkin
5d48ea7d07 MDEV-10963 Fragmented BINLOG query
The problem was originally stated in
  http://bugs.mysql.com/bug.php?id=82212
The size of an base64-encoded Rows_log_event exceeds its
vanilla byte representation in 4/3 times.
When a binlogged event size is about 1GB mysqlbinlog generates
a BINLOG query that can't be send out due to its size.

It is fixed with fragmenting the BINLOG argument C-string into
(approximate) halves when the base64 encoded event is over 1GB size.
The mysqlbinlog in such case puts out

    SET @binlog_fragment_0='base64-encoded-fragment_0';
    SET @binlog_fragment_1='base64-encoded-fragment_1';
    BINLOG @binlog_fragment_0, @binlog_fragment_1;

to represent a big BINLOG.
For prompt memory release BINLOG handler is made to reset the BINLOG argument
user variables in the middle of processing, as if @binlog_fragment_{0,1} = NULL
is assigned.

Notice the 2 fragments are enough, though the client and server still may
need to tweak their @@max_allowed_packet to satisfy to the fragment
size (which they would have to do anyway with greater number of
fragments, should that be desired).

On the lower level the following changes are made:

Log_event::print_base64()
  remains to call encoder and store the encoded data into a cache but
  now *without* doing any formatting. The latter is left for time
  when the cache is copied to an output file (e.g mysqlbinlog output).
  No formatting behavior is also reflected by the change in the meaning
  of the last argument which specifies whether to cache the encoded data.

Rows_log_event::print_helper()
  is made to invoke a specialized fragmented cache-to-file copying function
  which is

copy_cache_to_file_wrapped()
  that takes care of fragmenting also optionally wraps encoded
  strings (fragments) into SQL stanzas.

my_b_copy_to_file()
  is refactored to into my_b_copy_all_to_file(). The former function
  is generalized
  to accepts more a limit argument to constraint the copying and does
  not reinitialize anymore the cache into reading mode.
  The limit does not do any effect on the fully read cache.
2019-01-24 20:44:50 +02:00
Andrei Elkin
f9ac7032cb MDEV-14605 Changes to "ON UPDATE CURRENT_TIMESTAMP" fields are not
always logged properly with binlog_row_image=MINIMAL

There are two issues fixed in this commit.
The first is an observation of a multi-table UPDATE binlogged
in row-format in binlog_row_image=MINIMAL mode. While the UPDATE aims
at a table with an ON-UPDATE attribute its binlog after-image misses
to record also installed default value.
The reason for that turns out missed marking of default-capable fields
in TABLE::write_set.

This is fixed to mark such fields similarly to 10.2's MDEV-10134 patch (db7edfed17)
that introduced it. The marking follows up 93d1e5ce0b841bed's idea
to exploit TABLE:rpl_write_set introduced there though,
and thus does not mess (in 10.1) with the actual MDEV-10134 agenda.
The patch makes formerly arg-less TABLE::mark_default_fields_for_write()
to accept an argument which would be TABLE:rpl_write_set.

The 2nd issue is extra columns in in binlog_row_image=MINIMAL before-image
while merely a packed primary key is enough. The test main.mysqlbinlog_row_minimal
always had a wrong result recorded.
This is fixed to invoke a function that intended for read_set
possible filtering and which is called (supposed to) in all type of MDL, UPDATE
including; the test results have gotten corrected.

At *merging* from 10.1->10.2 the 1st "main" part of the patch is unnecessary
since the bug is not observed in 10.2, so only hunks from

  sql/sql_class.cc

are required.
2019-01-24 20:07:53 +02:00
Varun Gupta
036ca990ab MDEV-18255: Server crashes in Bitmap<64u>::intersect
Calling st_select_lex::update_used_tables in JOIN::optimize_unflattened_subqueries
only when we are sure that the join have not been cleaned up.
This can happen for a case when we have a non-merged semi-join and an impossible
where which would lead to the cleanup of the join which has the non-merged semi-join
2019-01-24 20:47:46 +05:30
Sergei Petrunia
f3ce9edaf9 Fix compilation on Windows 2019-01-24 17:16:38 +03:00
Marko Mäkelä
947b6b849d Merge 10.2 into 10.3 2019-01-24 16:14:12 +02:00
Marko Mäkelä
fab531a150 Fix the build after MDEV-17803
Use the same data type 'ulong' to avoid type mismatch on Windows
and on 32-bit systems.

FIXME: The correct data type should probably be 64-bit.
2019-01-24 15:59:00 +02:00
Alexander Barkov
17c75bd272 MDEV-18195 ASAN use-after-poison in my_strcasecmp_utf8 / Item::eq upon prepared statement with ORDER BY NAME_CONST
ASAN noticed a freed memory access during EXECUTE in this script:
  PREPARE stmt FROM "SELECT 'x' ORDER BY NAME_CONST( 'f', 'foo' )";
  EXECUTE stmt;

In case of a PREPARE statement, all Items, including Item_name_const,
are created on Prepared_statement::main_mem_root.
Item_name_const::fix_fields() did not take this into account
and could allocate the value of Item::name on a wrong memory root,
in this code:

  if (is_autogenerated_name)
  {
    set_name(thd, item_name->c_ptr(), (uint) item_name->length(),
             system_charset_info);
  }

When fix_fields() is called in the reported SQL script, THD's arena already
points to THD::main_mem_root rather than to Prepared_statement::main_mem_root,
so Item::name was allocated on THD::main_mem_root.
Then, at the end of the dispatch_command() for the PREPARE statement,
THD::main_mem_root got cleared. So during EXECUTE, Item::name
pointed to an already freed memory.

This patch changes the code to set the implicit name for Item_name_const
at the constructor time rather than at fix_fields time. This guarantees
that Item_name_const and its Item::name always reside on the same memory root.

Note, this change makes the code for Item_name_const symmetric with other
constant-alike items that set their default implicit names at the constructor
call time rather than at fix_fields() time:
- Item_string
- Item_int
- Item_real
- Item_decimal
- Item_null
- Item_param
2019-01-24 17:54:29 +04:00
Marko Mäkelä
25161e6219 Merge 10.1 into 10.2 2019-01-24 14:43:29 +02:00
Marko Mäkelä
65350042a4 Merge 10.0 into 10.1 2019-01-24 13:24:13 +02:00
Jan Lindström
c3a1cd3555 Silence "WSREP: Server initial position ..." message when wsrep-debug=OFF 2019-01-24 10:47:19 +02:00
Thirunarayanan Balathandayuthapani
a0f3b9f94f MDEV-17376 Server fails to set ADD_PK_INDEX, DROP_PK_INDEX if unique index nominated as PK
Problem:
========
Server fails to notify the engine by not setting the ADD_PK_INDEX and
DROP_PK_INDEX When there is a
 i) Change in candidate for primary key.
 ii) New candidate for primary key.

Fix:
====
Server sets the ADD_PK_INDEX and DROP_PK_INDEX while doing alter for the
above problematic case.
2019-01-24 13:52:51 +05:30
Andrei Elkin
b22354680e merge 10.0 -> 10.1 to resolve MDEV-17803 conflicts. 2019-01-23 20:16:21 +02:00
Sergei Golubchik
c2a4bfad22 MDEV-18119 upgrading from 10.3 to 10.4 can result in the password for a user to be wiped out
10.1 part: SHOW CREATE USER didn't show the password, if plugin was set,
but authentication_string was not
2019-01-23 17:34:22 +01:00
Andrei Elkin
cce2b45c8f MDEV-17803 Row-based event is not applied when table map id is greater
32 bit int

Row-based slave applier could not parse correctly the table id when
the value exceeded the max of 32 bit unsigned int.
The reason turns out in that the being parsed value placeholder
was sized as 4 bytes.

The type is fixed to ulonglong.

Additionally the patch works around Rows_log_event::m_table_id 4 bytes
size on 32 bits platforms. In case of last_table_id value overflows
the 4 byte max, there won't be the zero value for m_table_id generated
and the first wrapped-around value is one, this is thanks to excluding
UINT_MAX32 + 1 from TABLE_SHARE::table_map_id.
2019-01-23 15:48:06 +02:00
Sergei Petrunia
3238f2a6e9 MDEV-18073: get_range_limit_read_cost() doesnt adjust LIMIT for the range access
The computation about which "fraction" of range/ref access cost we will
need to perform, was incorrect.

Adjusted the computation.
2019-01-23 16:26:09 +03:00
Marko Mäkelä
9a7281a703 Merge 10.1 into 10.2 2019-01-23 15:09:06 +02:00
Sergei Petrunia
b7a784ae25 MDEV-17761: Odd optimizer choice with ORDER BY LIMIT and condition selectivity
Make the "ORDER BY ... LIMIT n" optimizer take into account condition
selectivity data from EITS (not just from potential range accesses).
2019-01-23 15:52:21 +03:00
Marko Mäkelä
3b6d2efcb1 Merge 10.0 into 10.1 2019-01-23 14:34:23 +02:00
Sreeharsha Ramanavarapu
b20d94da35 Bug #28499924: INCORRECT BEHAVIOR WITH UNION IN SUBQUERY
Issue:
------
When a subquery contains UNION the count of the number of
subquery columns is calculated incorrectly. Only the first
query block in the subquery's UNION is considered and an
array indexing goes out-of-bounds, and this is caught by an
assert.

Solution:
---------
Sum up the columns from all query blocks of the query
expression.

Change specific to 5.6/5.5:
---------------------------
The "child" points to the last query block of the UNION
(as opposed to 5.7+ where it points to the first member of
UNION). So "child->master_unit()->first_select()" is used
to reach the first query block of UNION.
2019-01-23 12:39:17 +01:00