Commit graph

188334 commits

Author SHA1 Message Date
Varun Gupta
0a5668f512 MDEV-22556: Incorrect result for window function when using encrypt-tmp-files=ON
The issue here is that end_of_file for encrypted temporary IO_CACHE (used by filesort) is updated
using lseek.
Encryption adds storage overhead and hides it from the caller by recalculating offsets and lengths.
Two different IO_CACHE cannot possibly modify the same file
because the encryption key is randomly generated and stored in the IO_CACHE.
So when the tempfiles are encrypted DO NOT use lseek to change end_of_file.

Further observations about updating end_of_file using lseek
1) The end_of_file update is only used for binlog index files
2) The whole point is to update file length when the file was modified via a different file descriptor.
3) The temporary IO_CACHE files can never be modified via a different file descriptor.
4) For encrypted temporary IO_CACHE, end_of_file should not be updated with lseek
2020-05-17 15:26:18 +05:30
Marko Mäkelä
66f1e288a1 Merge 10.3 into 10.4 2020-05-16 07:54:09 +03:00
Marko Mäkelä
9e6e43551f Merge 10.3 into 10.4
We will expose some more std::atomic internals in Atomic_counter,
so that dict_index_t::lock will support the default assignment operator.
2020-05-16 07:39:15 +03:00
Marko Mäkelä
38d62189a8 Merge 10.2 into 10.3 2020-05-16 06:37:24 +03:00
Marko Mäkelä
4f29d776c7 Merge 10.3 into 10.4 2020-05-16 06:27:55 +03:00
Marko Mäkelä
85651269b6 MDEV-18100: Clean up test 2020-05-16 06:24:09 +03:00
Marko Mäkelä
3f12a5968a MDEV-13626: Make test more robust
In commit b1742a5c95 we forgot
FLUSH TABLES, potentially causing errors for MyISAM system tables.
2020-05-15 22:54:05 +03:00
Marko Mäkelä
fc0960aa96 Merge 10.1 into 10.2 2020-05-15 22:43:33 +03:00
Marko Mäkelä
c8dd411781 MDEV-22544 Inconsistent and Incorrect rw-lock stats
The rw_lock_stats were incorrectly updated.
While global statistics have limited usefulness, we cannot
remove them from a GA version. This contribution is slightly
improving performance in write workloads.
2020-05-15 22:18:11 +03:00
Marko Mäkelä
3d0bb2b7f1 Merge 10.2 into 10.3 2020-05-15 19:11:57 +03:00
Marko Mäkelä
6a6bcc53b8 Merge 10.2 into 10.3 2020-05-15 17:55:01 +03:00
Marko Mäkelä
ad6171b91c MDEV-22456 Dropping the adaptive hash index may cause DDL to lock up InnoDB
If the InnoDB buffer pool contains many pages for a table or index
that is being dropped or rebuilt, and if many of such pages are
pointed to by the adaptive hash index, dropping the adaptive hash index
may consume a lot of time.

The time-consuming operation of dropping the adaptive hash index entries
is being executed while the InnoDB data dictionary cache dict_sys is
exclusively locked.

It is not actually necessary to drop all adaptive hash index entries
at the time a table or index is being dropped or rebuilt. We can let
the LRU replacement policy of the buffer pool take care of this gradually.
For this to work, we must detach the dict_table_t and dict_index_t
objects from the main dict_sys cache, and once the last
adaptive hash index entry for the detached table is removed
(when the garbage page is evicted from the buffer pool) we can free
the dict_table_t and dict_index_t object.

Related to this, in MDEV-16283, we made ALTER TABLE...DISCARD TABLESPACE
skip both the buffer pool eviction and the drop of the adaptive hash index.
We shifted the burden to ALTER TABLE...IMPORT TABLESPACE or DROP TABLE.
We can remove the eviction from DROP TABLE. We must retain the eviction
in the ALTER TABLE...IMPORT TABLESPACE code path, so that in case the
discarded table is being re-imported with the same tablespace identifier,
the fresh data from the imported tablespace will replace any stale pages
in the buffer pool.

rpl.rpl_failed_drop_tbl_binlog: Remove the test. DROP TABLE can
no longer be interrupted inside InnoDB.

fseg_free_page(), fseg_free_step(), fseg_free_step_not_header(),
fseg_free_page_low(), fseg_free_extent(): Remove the parameter
that specifies whether the adaptive hash index should be dropped.

btr_search_lazy_free(): Lazily free an index when the last
reference to it is dropped from the adaptive hash index.

buf_pool_clear_hash_index(): Declare static, and move to the
same compilation unit with the bulk of the adaptive hash index
code.

dict_index_t::clone(), dict_index_t::clone_if_needed():
Clone an index that is being rebuilt while adaptive hash index
entries exist. The original index will be inserted into
dict_table_t::freed_indexes and dict_index_t::set_freed()
will be called.

dict_index_t::set_freed(), dict_index_t::freed(): Note that
or check whether the index has been freed. We will use the
impossible page number 1 to denote this condition.

dict_index_t::n_ahi_pages(): Replaces btr_search_info_get_ref_count().

dict_index_t::detach_columns(): Move the assignment n_fields=0
to ha_innobase_inplace_ctx::clear_added_indexes().
We must have access to the columns when freeing the
adaptive hash index. Note: dict_table_t::v_cols[] will remain
valid. If virtual columns are dropped or added, the table
definition will be reloaded in ha_innobase::commit_inplace_alter_table().

buf_page_mtr_lock(): Drop a stale adaptive hash index if needed.

We will also reduce the number of btr_get_search_latch() calls
and enclose some more code inside #ifdef BTR_CUR_HASH_ADAPT
in order to benefit cmake -DWITH_INNODB_AHI=OFF.
2020-05-15 17:23:08 +03:00
Marko Mäkelä
ff66d65a09 Amend af784385b4: Avoid vtable overhead
When neither MSAN nor Valgrind are enabled, declare
Field::mark_unused_memory_as_defined() as an empty inline function,
instead of declaring it as a virtual function.
2020-05-15 17:23:08 +03:00
Eugene Kosov
1cac6d4828 span cleanup 2020-05-15 16:25:32 +03:00
Aleksey Midenkov
a4996f951d MDEV-22563 Segfault on duplicate free of Item_func_in::array
Same array instance in two Item_func_in instances. First Item_func_in
instance is freed on table close. Second one is freed on
cleanup_after_query().

get_copy() depends on copy ctor for copying an item and hence does
shallow copy for default copy ctor. Use build_clone() for deep copy of
Item_func_in.
2020-05-15 16:17:15 +03:00
Monty
3eadb135fd Fixed access to uninitalized memory found by valgrind 2020-05-15 15:20:42 +03:00
Monty
a7c4e85dd6 Use history.h include file if readline is used
This allows us to remove our own declarations of functions and structures
that are declared in the history.h file.
2020-05-15 15:20:42 +03:00
Monty
72789e4b2b Fixed access to not initalized memory
Most of the volations came from:
sel_arg_range_seq_next(void*, st_key_multi_range*) (opt_range_mrr.cc:342)
2020-05-15 15:14:08 +03:00
Monty
af784385b4 Fix for using uninitialized memory
MDEV-22073 MSAN use-of-uninitialized-value in
collect_statistics_for_table()

Other things:
innodb.analyze_table was changed to mainly test statistic
collection. Was discussed with Marko.
2020-05-15 15:10:58 +03:00
Varun Gupta
d49233caf6 MDEV-18100: User defined aggregate functions not working correctly when the schema is changed
The issue here was that when the schema was changed the value for the THD::server_status
is ored with SERVER_SESSION_STATE_CHANGED.
For custom aggregate functions, currently we check if the server_status is equal to
SERVER_STATUS_LAST_ROW_SENT then we should terminate the execution of the custom
aggregate function as there are no more rows to fetch.
So the check should be that if the server status has the bit set for
SERVER_STATUS_LAST_ROW_SENT then we should terminate the execution of the
custom aggregate function.
2020-05-15 15:13:06 +05:30
Monty
277aa85c9b Fixed bugs found by valgrind
Other things:
- Removed innodb_encryption_tables.test from valgrind as it
  takes a REALLY long time
2020-05-15 10:44:05 +03:00
Jan Lindström
523d67a272 MDEV-22494 : Galera assertion lock_sys.mutex.is_owned() at lock_trx_handle_wait_low
Problem was that trx->lock.was_chosen_as_wsrep_victim variable was
not set back to false after it was set true.

wsrep_thd_bf_abort
	Add assertions for correct mutex status and take necessary
	mutexes before calling thd->awake_no_mutex().

innobase_rollback_trx()
	Reset trx->lock.was_chosen_as_wsrep_victim

wsrep_abort_slave_trx()
	Removed unused function.

wsrep_innobase_kill_one_trx()
	Added function comment, removed unnecessary parameters
	and added debug assertions to enforce correct usage. Added
	more debug output to help out on error analysis.

wsrep_abort_transaction()
	Added debug assertions and removed unused variables.

trx0trx.h
	Removed assert_trx_is_free macro and replaced it with
	assert_freed() member function.

trx_create()
	Use above assert_free() and initialize wsrep variables.

trx_free()
	Use assert_free()

trx_t::commit_in_memory()
	Reset lock.was_chosen_as_wsrep_victim

trx_rollback_for_mysql()
	Reset trx->lock.was_chosen_as_wsrep_victim

Add test case galera_bf_kill
2020-05-15 09:04:02 +03:00
Alexander Barkov
1408e26d0b MDEV-22560 Crash on a table value constructor with an SP variable
fix_fields_for_tvc() could call fix_fields() for Items that have
already been fixed before. Changing fix_fields() to fix_fields_if_needed().
2020-05-15 06:15:10 +04:00
Varun Gupta
efd68f5e31 MDEV-22498: SIGSEGV in Bitmap<64u>::merge on SELECT
For the case when the optimizer does the IN-EXISTS transformation,
the equality condition is injected in the WHERE OR HAVING clause of
the subquery. If the select list of the subquery has a reference to
the parent select make sure to use the reference and not the original
item.
2020-05-14 23:24:10 +05:30
Marko Mäkelä
1b16572074 Merge 10.1 into 10.2 2020-05-14 17:48:06 +03:00
Marko Mäkelä
ee5152fc4b MDEV-22070 MSAN use-of-uninitialized-value in encryption.innodb-redo-badkey
On a checksum failure of a ROW_FORMAT=COMPRESSED page,
buf_LRU_free_one_page() would invoke buf_LRU_block_remove_hashed()
which will read the uncompressed page frame, although it would not
be initialized. With bad enough luck, fil_page_get_type(page)
could return an unrecognized value and cause the server to abort.

buf_page_io_complete(): On the corruption of a ROW_FORMAT=COMPRESSED
page, zerofill the uncompressed page frame.
2020-05-14 17:41:37 +03:00
Vladislav Vaintroub
3bfe305c5c MDEV-22555 Windows, packaging: binaries depend on vcruntime140_1.dll, which is not in MSI
When server is compiled with recent VS2019, then executables,
have dependency on  vcruntime140_1.dll

While we include the VC redistributable merge modules into our MSI package,
those merge modules were stale (taken from older VS version, 2017)

Since VS2019 brough new DLL dependency by introducing new exception handling
https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64
thus the old MSMs were not enough.

The fix is to change logic in win/packaging/CMakeLists.txt to look up for
the correct, new MSMs.

The bug only affects 10.4,as we compile with static CRT before 10.4,
and partly-statically(just vcruntime stub is statically linked, but not UCRT)
after 10.4

For the fix to work, it required also some changes on the build machine
(vs_installer, modify VS2019 installation, add Individual Component
"C++ 2019 Redistributable MSMs")
2020-05-14 15:55:18 +02:00
Marko Mäkelä
fc58c17216 MDEV-21336 Memory leaks related to innodb_debug_sync
This essentially reverts commit b393e2cb0c.

The leak might have been fixed, but because the
DEBUG_SYNC instrumentation for InnoDB purge threads was reverted
in 10.5 commit 5e62b6a5e0
as part of introducing a thread pool, it is easiest to revert
the entire change.
2020-05-14 13:36:11 +03:00
Marko Mäkelä
a12aed0398 Fix GCC 9.3.0 -Wunused-but-set-variable 2020-05-14 13:36:11 +03:00
Marko Mäkelä
7d51c35988 Fix GCC -Wnonnull 2020-05-14 13:36:10 +03:00
Marko Mäkelä
11147bea20 Fix GCC -Wstringop-truncation 2020-05-14 13:36:10 +03:00
Marko Mäkelä
3c773cd855 MDEV-19622: Fix a TokuDB result 2020-05-14 13:36:10 +03:00
Alexander Barkov
f7cf60991d Merge remote-tracking branch 'origin/10.2' into 10.3 2020-05-14 12:33:22 +04:00
Alexander Barkov
4dc690dc28 Merge remote-tracking branch 'origin/10.1' into 10.2 2020-05-14 11:57:47 +04:00
Alexander Barkov
31f34b20f3 MDEV-22502 MDB crashes in CREATE TABLE AS SELECT when the precision of returning type = 0.
TRUNCATE(decimal_5_5) erroneously tried to create a DECIMAL(0,0) column.
Creating a DECIMAL(1,0) column instead.
2020-05-14 11:41:27 +04:00
Krunal Bauskar
dcb0bd59ce MDEV-22544: Inconsistent and Incorrect rw-lock stats
- There are multiple inconsistency and incorrect way in which rw-lock
  stats are calculated.

- shared rw-lock stats:
  "rounds" counter is incremented only once for N rounds done
  in spin-cycle.

- all rw-lock stats:
  If the spin-cycle is short-circuited then attempts are re-counted.
  [If spin-cycle is interrupted, before it completes
   srv_n_spin_wait_rounds (default 30) rounds, spin_count is incremented
   to consider this. If thread resumes spin-cycle (due to unavailability
   of the locks) and is again interrupted or completed, spin_count
   is again incremented with the total count, failing to adjust the
   previous attempt increment].

- s/x rw-lock stats:
  spin_loop counter is not incremented at-all instead it is projected
  as 0 (in show engine output) and division to calculate spin-round per
  spin-loop is adjusted.
  As per the original semantics spin_loop counter should be incremented
  once per spin_loop execution.

- sx rw-lock stats:
  sx locks increments spin_loop counter but instead of incrementing it
  once for a spin_loop invocation it does it multiple times based on how
  many time spin_loop flow is repeated for same instance post os-wait.
2020-05-14 15:27:15 +08:00
Alexander Barkov
ef65c39ab3 Merge remote-tracking branch 'origin/10.2' into 10.3 2020-05-14 10:01:54 +04:00
Alexander Barkov
f827ba3b84 Merge remote-tracking branch 'origin/10.1' into 10.2 2020-05-14 08:44:34 +04:00
Alexander Barkov
910c31928e MDEV-22503 MDB limits DECIMAL column precision to 16 doing CTAS with floor/ceil over DECIMAL(X,Y) where X > 16
The DECIMAL data type branch in Item_func_int_val::fix_length_and_dec()
incorrectly used DOUBLE-style length calculation, which resulted in
a smaller data type than the actual result of FLOOR()/CEIL() needs.
2020-05-14 08:40:46 +04:00
Monty
edbf124515 Ensure that auto_increment fields are marked properly on update
MDEV-19622 Assertion failures in
ha_partition::set_auto_increment_if_higher upon UPDATE on Aria
table
2020-05-13 23:30:34 +03:00
Marko Mäkelä
38f6c47f8a Merge 10.3 into 10.4 2020-05-13 12:52:57 +03:00
Marko Mäkelä
15fa70b840 Merge 10.2 into 10.3 2020-05-13 11:45:05 +03:00
Marko Mäkelä
6bc4444d7c Merge 10.1 into 10.2 2020-05-13 11:12:31 +03:00
Alexander Barkov
9f20968169 MDEV-20261 NULL passed to String::eq, SEGV, server crash, regression in 10.4
Type_handler_xxx::Item_const_eq() can handle only non-NULL values.
The code in Item_basic_value::eq() did not take this into account.

Adding a test to detect three different combinations:
- Both values are NULLs, return true.
- Only one value is NULL, return false.
- Both values are not NULL, call Type_handler::Item_const_eq()
  to check equality.
2020-05-12 19:45:21 +04:00
Vlad Lesin
218d20ffe3 MDEV-22398: mariabackup.innodb_xa_rollback fails on repeat
Flush LSN to system tablespace on innodb shutdown if XA is rolled back by
mariabackup.
2020-05-12 18:44:36 +03:00
Marko Mäkelä
0e6a5786d4 Cleanup: Remove InnoDB wrappers of thd_charset(), thd_query_safe()
innobase_get_charset(), innobase_get_stmt_safe(): Remove.
It is more efficient and readable to invoke thd_charset()
and thd_query_safe() directly, without a non-inlined wrapper function.
2020-05-12 10:15:44 +03:00
Marko Mäkelä
a2560b0077 MDEV-22529 thd_query_safe() isn’t, causing InnoDB to hang
The function thd_query_safe() is used in the implementation of the
following INFORMATION_SCHEMA views:

    information_schema.innodb_trx
    information_schema.innodb_locks
    information_schema.innodb_lock_waits
    information_schema.rocksdb_trx

The implementation of the InnoDB views is in trx_i_s_common_fill_table().
This function invokes trx_i_s_possibly_fetch_data_into_cache(),
which will acquire lock_sys->mutex and trx_sys->mutex in order to
protect the set of active transactions and explicit locks.
While holding those mutexes, it will traverse the collection of
InnoDB transactions. For each transaction, thd_query_safe() will be
invoked.

When called via trx_i_s_common_fill_table(), thd_query_safe()
is acquiring THD::LOCK_thd_data while holding the InnoDB locks.
This will cause a deadlock with THD::awake() (such as executing
KILL QUERY), because THD::awake() could invoke lock_trx_handle_wait(),
which attempts to acquire lock_sys->mutex while already holding
THD::lock_thd_data.

thd_query_safe(): Invoke mysql_mutex_trylock() instead of
mysql_mutex_lock(). Return the empty string if the mutex
cannot be acquired without waiting.
2020-05-12 10:15:44 +03:00
Oleksandr Byelkin
db537a8372 Merge branch '10.4-release' into 10.4 2020-05-11 21:32:33 +02:00
Oleksandr Byelkin
19d4e023c6 Merge branch '10.3-release' into 10.3 2020-05-11 20:27:44 +02:00
Oleksandr Byelkin
b57c6cb394 Merge branch '10.2-release' into 10.2 2020-05-11 19:53:35 +02:00