Commit graph

198057 commits

Author SHA1 Message Date
Marko Mäkelä
3e2ad0e918 Merge 10.5 into 10.6 2023-02-27 13:17:35 +02:00
Monty
3b9e8dfa84 Fixed (non crtitial) memory segment overrun
This was discovered as part of adding a protected memory area between
each area allocated by multi_alloc().

The patch that adds the protection will be pushed in 10.5.
This patch adds fixes that are unique for 10.10
2023-02-26 18:44:18 +02:00
Marko Mäkelä
0de3be8cfd MDEV-30671 InnoDB undo log truncation fails to wait for purge of history
It is not safe to invoke trx_purge_free_segment() or execute
innodb_undo_log_truncate=ON before all undo log records in
the rollback segment has been processed.

A prominent failure that would occur due to premature freeing of
undo log pages is that trx_undo_get_undo_rec() would crash when
trying to copy an undo log record to fetch the previous version
of a record.

If trx_undo_get_undo_rec() was not invoked in the unlucky time frame,
then the symptom would be that some committed transaction history is
never removed. This would be detected by CHECK TABLE...EXTENDED that
was impleented in commit ab0190101b.
Such a garbage collection leak should be possible even when using
innodb_undo_log_truncate=OFF, just involving trx_purge_free_segment().

trx_rseg_t::needs_purge: Change the type from Boolean to a transaction
identifier, noting the most recent non-purged transaction, or 0 if
everything has been purged. On transaction start, we initialize this
to 1 more than the transaction start ID. On recovery, the field may be
adjusted to the transaction end ID (TRX_UNDO_TRX_NO) if it is larger.

The field TRX_UNDO_NEEDS_PURGE becomes write-only; only some debug
assertions that would validate the value. The field reflects the old
inaccurate Boolean field trx_rseg_t::needs_purge.

trx_undo_mem_create_at_db_start(), trx_undo_lists_init(),
trx_rseg_mem_restore(): Remove the parameter max_trx_id.
Instead, store the maximum in trx_rseg_t::needs_purge,
where trx_rseg_array_init() will find it.

trx_purge_free_segment(): Contiguously hold a lock on
trx_rseg_t to prevent any concurrent allocation of undo log.

trx_purge_truncate_rseg_history(): Only invoke trx_purge_free_segment()
if the rollback segment is empty and there are no pending transactions
associated with it.

trx_purge_truncate_history(): Only proceed with innodb_undo_log_truncate=ON
if trx_rseg_t::needs_purge indicates that all history has been purged.

Tested by: Matthias Leich
2023-02-24 14:24:44 +02:00
Alexander Barkov
b62123e0d5 MDEV-30716 Wrong casefolding in xxx_unicode_520_ci for U+0700..U+07FF
The array my_unicase_pages_unicode520[7] erroneously mapped to plane06
instead of plane07.
2023-02-23 23:40:45 +04:00
Andrew Hutchings
b24b3cea7d Fix CODING_STANDARDS link in PR template
Relative links do not work in pull request templates, so use an explicit
link instead.
2023-02-23 16:44:29 +11:00
Daniel Bartholomew
b4ef9f766d
bump the VERSION 2023-02-22 15:42:47 -05:00
Helmut Grohne
6f6fa3bec2 MDEV-30694: Cross building on x86_64 to arch i686 fails
Currently cross compilation on x86_64 to arch i686 fails
with error:

> ctype-uca1400data.h
/bin/sh: 1: uca-dump: not found

Commit makes sure that uca-dump is treated correctly
when cross compiling MariaDB to another architecture
2023-02-22 16:01:46 +00:00
Thirunarayanan Balathandayuthapani
db245e1140 MDEV-25984 Assertion `max_doc_id > 0' failed in fts_init_doc_id()
- rollback_inplace_alter_table() locks the fts internal tables.
At the time, insert tries to fetch the doc id from config table,
fails to lock the config table and returns doc id as 0.

fts_cmp_set_sync_doc_id(): Retry to fetch the doc id again if
it encounter DB_LOCK_WAIT_TIMEOUT error
2023-02-22 18:54:00 +05:30
Thirunarayanan Balathandayuthapani
df9f9ba12b MDEV-29871 innodb_fts.fulltext_misc unexpectedly reports a result
- match()+0 returns the floating result and converts into integer value
and it leads to sporadic failure.
2023-02-21 18:48:59 +05:30
Michael Widenius
158a582458 Added mysql-log-rotate to .gitignore 2023-02-21 15:37:48 +03:00
Monty
15e889c300 MDEV-30699: Updated prev_record_reads() to be more exact
The old code in prev_record_reads() did give wrong estimates when a
join_buffer was used or if the table was depending on more than one
other tables. When join_cache is used, it will cause a re-order of row
combinations, which causes more calls to the engine for tables that
are depending on tables before the join_cached one.

The new prev_records_read() code provides more exact estimates and
should never give a 'too low estimate', assuming that the data to the
function is correct

The definition of prev_record_read() is also updated.
The new definition is:
  "Estimate the number of engine ha_index_read_calls for EQ_REF tables
  when taking into account the one-row-cache in join_read_always_key()"

The cost of using prev_record_reads() value is changed. The value is
now used similar as before to calculate the cost of the storage engine
calls. However the cost of the WHERE cost is changed to take into
account the total number of row combinations as the WHERE has to be
checked even if the one-row-cache is used. This makes the cost
slightly higher than before (for the same prev_record_reads() value).

Other things:
- Cached return value of prev_record_read() in best_access_path() to
  avoid some function calls.
- Fixed bug where position[].use_join_buffer was set in
  best_acess_path() when join buffer was not used. This confused the
  semi join optimizer to try to reoptimize plans that did not need to be
  reoptimized.
  The effect of the bug fix is that we avoid doing some re-optimziations
  with semi-joins when join_buffer is not used. In these cases the value
  shown for the 'Filtering' column in EXPLAIN EXTENDED may change.
- Added 'prev_record.cc' that was used to verify the logic in
  prev_record_reads().

Changes in test suite:
- EQ_REF tables are moved up to be earlier. This is because either the
  higher WHERE cost when EQ_REF is used with more row combination or
  change of cost when using join_cache.
- Filtered has changed (to the better) for some cases using semi-joins
  subselect_sj.test subselect_sj_jcl6.test
2023-02-21 15:36:39 +03:00
Monty
793caf3a27 Added r_table_loops to "ANALYZE FORMAT=JSON statement"
Author: Sergei Petrunia <sergey@mariadb.com>
2023-02-21 15:36:15 +03:00
Monty
3c1b7fb03e Adjust costs for rowid filter
- Use log2() insted of log()
- Added missing ''+' when calculating rowid setup cost
- Adjusted ROWID_FILTER_PER_ELEMENT_MODIFIER (from 3 to 1)

Other things:
- Adjusted cost for index_merge where rows_out < 1.0

The effects of the changes:
- rowid filter will have higher setup cost
- rowid filter will have slightly less costs per row

This can be seen in mtr where some tests, with 'small tables or
that uses rowid filters with many rows, will not use rowid filter anymore.
2023-02-21 15:35:27 +03:00
Sergei Petrunia
9c401c8c39 MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST
Part #2: fix the case where table->stat_records()=1 (due to EITS
statistics), but the range returns rows=0.
2023-02-21 15:35:27 +03:00
Sergei Petrunia
d61bc94fa0 MDEV-30659 Server crash on EXPLAIN SELECT/SELECT on table with engine Aria for LooseScan Strategy
Amended patch from Monty:

The issue was that Loose_scan_opt::save_to_position() did not take
into account records_out from best_access_path()

Make sure that POSITION object filled by Loose_scan_opt::save_to_position()
has records_out not higher than any other possible access method.
2023-02-21 15:27:23 +03:00
Marko Mäkelä
d5d7c8ba96 MDEV-30544 Deprecate innodb_defragment and related parameters
There is a little used option innodb_defragment that would make
OPTIMIZE TABLE not rebuild the table as usual for InnoDB, but
instead cause the index B-trees to be optimized in place.

This option uses excessive locking (exclusively locking index trees).
It never covered SPATIAL INDEX or FULLTEXT INDEX. Storage space
was never reclaimed.

Because this option is not particularly useful and causes a
maintenance burden (most recently in
commit de4030e4d4),
it is best to deprecate it, to prepare for its removal.
2023-02-21 13:33:47 +02:00
Marko Mäkelä
2b13ae1a31 MDEV-29694 fixup: Remove srv_change_buffer_max_size, adjust comments 2023-02-21 12:34:20 +02:00
Alexander Barkov
33f8f92b74 MDEV-30695 Refactor case folding data types in Asian collations
This is a non-functional change and should not change the server behavior.

Casefolding information is now stored in items of a new data type MY_CASEFOLD_CHARACTER:

typedef struct casefold_info_char_t
{
  uint32 toupper;
  uint32 tolower;
} MY_CASEFOLD_CHARACTER;

Before this change, casefolding tables for Asian collations were stored in:

typedef struct unicase_info_char_st
{
  uint32 toupper;
  uint32 tolower;
  uint32 sort;
} MY_UNICASE_CHARACTER;

The "sort" member was not used in the code handling Asian collations,
it only wasted space.
(it's only used by Unicode _general_ci and _general_mysql500_ci collations).

Unicode collations (at least UCA and _bin) should also be refactored later,
but under terms of a separate task.
2023-02-21 14:10:25 +04:00
Alexander Barkov
7e341cc740 MDEV-30692 conf_to_src is not up to date
Fixing conf_to_src.c according to changes made by
 a206658b98

Re-generating ctype-extra.c at once, to fix the indentation
from manually edited to automatic.
2023-02-21 11:07:25 +04:00
Vlad Lesin
a474e3278c MDEV-27701 Race on trx->lock.wait_lock between lock_rec_move() and lock_sys_t::cancel()
The initial issue was in assertion failure, which checked the equality
of lock to cancel with trx->lock.wait_lock in lock_sys_t::cancel().

If we analyze lock_sys_t::cancel() code from the perspective of
trx->lock.wait_lock racing, we won't find the error there, except the
cases when we need to reload it after the corresponding latches
acquiring.

So the fix is just to remove the assertion and reload
trx->lock.wait_lock after acquiring necessary latches.

Reviewed by: Marko Mäkelä <marko.makela@mariadb.com>
2023-02-20 20:31:24 +03:00
Sergei Golubchik
799f75953f bump the maturity 2023-02-20 10:18:45 +01:00
Alexander Barkov
7f6b648d7d MDEV-30661 UPPER() returns an empty string for U+0251 in uca1400 collations for utf8
String length growth during upper/lower conversion
in Unicode collations depends only on the underlying MY_UNICASE_INFO
used in the collation.

Maintaining a separate member CHARSET_INFO::caseup_multiply and
CHARSET_INFO::casedn_multiply duplicated this information
and caused bugs like this (when MY_UNICASE_INFO and case??_multiply
when out of sync because of incomplete CHARSET_INFO initialization).

Fix:

Changing CHARSET_INFO::caseup_multiply and CHARSET_INFO::casedn_multiply
from members to virtual functions.
The virtual functions in Unicode collations calculate case conversion
growth factors from the MY_UNICASE_INFO. This guarantees that the growth
factors are always in sync with the MY_UNICASE_INFO.
2023-02-17 17:33:27 +04:00
Thirunarayanan Balathandayuthapani
f2dc4d4c10 MDEV-30673 InnoDB recovery hangs when buf_LRU_get_free_block
is being called

- Recovery fails to release log_sys.latch for non-last batch
before preallocates the block in recv_read_in_area().
2023-02-17 18:35:13 +05:30
Sergei Golubchik
da114c709b fix for --view-protocol 2023-02-16 20:08:58 +01:00
Daniel Bartholomew
8460eb25d1
bump the VERSION 2023-02-16 10:46:22 -05:00
Marko Mäkelä
a6874341dd MDEV-22570 fixup: Silence clang -Wunneeded-internal-declaration 2023-02-16 13:35:21 +02:00
Marko Mäkelä
2e431ff7e6 Merge 10.11 into 11.0 2023-02-16 13:34:45 +02:00
Marko Mäkelä
1fd0099839 Merge 10.10 into 10.11 2023-02-16 11:41:18 +02:00
Marko Mäkelä
345356b868 Merge 10.9 into 10.10 2023-02-16 11:36:38 +02:00
Marko Mäkelä
0d55914d96 Merge 10.8 into 10.9 2023-02-16 10:25:34 +02:00
Marko Mäkelä
b12cd88ce1 Merge 10.6 into 10.8 2023-02-16 10:24:23 +02:00
Marko Mäkelä
67a6ad0a4a Merge 10.5 into 10.6 2023-02-16 10:17:58 +02:00
Marko Mäkelä
d3f35aa47b MDEV-30552 fixup: Fix the test for non-debug 2023-02-16 10:16:38 +02:00
Marko Mäkelä
0c79ae9462 Fix clang -Winconsistent-missing-override 2023-02-16 10:09:19 +02:00
Marko Mäkelä
34f0433c09 MDEV-27774 fixup: Correct a comment 2023-02-16 09:17:40 +02:00
Marko Mäkelä
5abbe092e6 Merge 10.6 into 10.8 2023-02-16 09:17:06 +02:00
Marko Mäkelä
201cfc33e6 MDEV-30638 Deadlock between INSERT and InnoDB non-persistent statistics update
This is a partial revert of
commit 8b6a308e46 (MDEV-29883)
and a follow-up to the
merge commit 394fc71f4f (MDEV-24569).

The latching order related to any operation that accesses the allocation
metadata of an InnoDB index tree is as follows:

1. Acquire dict_index_t::lock in non-shared mode.
2. Acquire the index root page latch in non-shared mode.
3. Possibly acquire further index page latches. Unless an exclusive
dict_index_t::lock is held, this must follow the root-to-leaf,
left-to-right order.
4. Acquire a *non-shared* fil_space_t::latch.
5. Acquire latches on the allocation metadata pages.
6. Possibly allocate and write some pages, or free some pages.

btr_get_size_and_reserved(), dict_stats_update_transient_for_index(),
dict_stats_analyze_index(): Acquire an exclusive fil_space_t::latch
in order to avoid a deadlock in fseg_n_reserved_pages() in case of
concurrent access to multiple indexes sharing the same "inode page".

fseg_page_is_allocated(): Acquire an exclusive fil_space_t::latch
in order to avoid deadlocks. All callers are holding latches
on a buffer pool page, or an index, or both.
Before commit edbde4a11f (MDEV-24167)
a third mode was available that would not conflict with the shared
fil_space_t::latch acquired by ha_innobase::info_low(),
i_s_sys_tablespaces_fill_table(),
or i_s_tablespaces_encryption_fill_table().
Because those calls should be rather rare, it makes sense to use
the simple rw_lock with only shared and exclusive modes.

fil_crypt_get_page_throttle(): Avoid invoking fseg_page_is_allocated()
on an allocation bitmap page (which can never be freed), to avoid
acquiring a shared latch on top of an exclusive one.

mtr_t::s_lock_space(), MTR_MEMO_SPACE_S_LOCK: Remove.
2023-02-16 08:30:20 +02:00
Marko Mäkelä
54c0ac72e3 MDEV-30134 Assertion failed in buf_page_t::unfix() in buf_pool_t::watch_unset()
buf_pool_t::watch_set(): Always buffer-fix a block if one was found,
no matter if it is a watch sentinel or a buffer page. The type of
the block descriptor will be rechecked in buf_page_t::watch_unset().
Do not expect the caller to acquire the page hash latch. Starting with
commit bd5a6403ca it is safe to release
buf_pool.mutex before acquiring a buf_pool.page_hash latch.

buf_page_get_low(): Adjust to the changed buf_pool_t::watch_set().

This simplifies the logic and fixes a bug that was reproduced when
using debug builds and the setting innodb_change_buffering_debug=1.
2023-02-16 08:29:44 +02:00
Marko Mäkelä
9c15799462 MDEV-30397: MariaDB crash due to DB_FAIL reported for a corrupted page
buf_read_page_low(): Map the buf_page_t::read_complete() return
value DB_FAIL to DB_PAGE_CORRUPTED. The purpose of the DB_FAIL
return value is to avoid error log noise when read-ahead brings
in an unused page that is typically filled with NUL bytes.

If a synchronous read is bringing in a corrupted page where the
page frame does not contain the expected tablespace identifier and
page number, that must be treated as an attempt to read a corrupted
page. The correct error code for this is DB_PAGE_CORRUPTED.
The error code DB_FAIL is not handled by row_mysql_handle_errors().

This was missed in commit 0b47c126e3
(MDEV-13542).
2023-02-16 08:28:14 +02:00
Marko Mäkelä
cc27e5fd0e Merge 10.5 into 10.6 2023-02-16 08:17:54 +02:00
Julius Goryavsky
80b4fa54e1 MDEV-30318: galera error messages in mariadb log without galera enabled
Post-fix to MDEV-30318 and MDEV-22570-related changes:
unified handling of wsrep_provider by code so that "none"
is interpreted as case-insensitive everywhere and that
work with an empty string is supported everywhere.
2023-02-15 17:46:26 +01:00
Marko Mäkelä
5300c0fb76 MDEV-30657 InnoDB: Not applying UNDO_APPEND due to corruption
This almost completely reverts
commit acd23da4c2 and
retains a safe optimization:

recv_sys_t::parse(): Remove any old redo log records for the
truncated tablespace, to free up memory earlier.
If recovery consists of multiple batches, then recv_sys_t::apply()
will must invoke recv_sys_t::trim() again to avoid wrongly
applying old log records to an already truncated undo tablespace.
2023-02-15 18:16:41 +02:00
Vicențiu Ciorbaru
4afa3b64c4 MDEV-30324: Wrong result upon SELECT DISTINCT ... WITH TIES
WITH TIES would not take effect if SELECT DISTINCT was used in a
context where an INDEX is used to resolve the ORDER BY clause.

WITH TIES relies on the `JOIN::order` to contain the non-constant
fields to test the equality of ORDER BY fiels required for WITH TIES.

The cause of the problem was a premature removal of the `JOIN::order`
member during a DISTINCT optimization. This lead to WITH TIES code assuming
ORDER BY only contained "constant" elements.

Disable this optimization when WITH TIES is in effect.

(side-note: the order by removal does not impact any current tests, thus
it will be removed in a future version)

Reviewed by: monty@mariadb.org
2023-02-15 16:58:31 +02:00
Vicențiu Ciorbaru
d2b773d913 Whitespace fix 2023-02-15 15:08:16 +02:00
Vicențiu Ciorbaru
e83ae66e4a Update comments to match new debug_sync implementation 2023-02-15 15:08:16 +02:00
Monty
cc182aca93 Fixed compiler warning in connect/ha_connect.cc
(fp->field_length is always >= 0)
2023-02-15 15:50:31 +03:00
Monty
bd2cebb8b1 Fixed check_costs.pl to always create table if table does not exists
This allows one to always use --skip-create-table for repeated runs.
2023-02-15 15:50:21 +03:00
Monty
192427e37d MDEV-30333 Wrong result with not_null_range_scan and LEFT JOIN with empty table
There was a bug in JOIN::make_notnull_conds_for_range_scans() when
clearing TABLE->tmp_set, which was used to mark fields that could not be
null.

This function was only used if 'not_null_range_scan=on' is set.

The effect was that tmp_set contained a 'random value' and this caused
the optimizer to think that some fields could not be null.
FLUSH TABLES clears tmp_set and because of this things worked temporarily.

Fixed by clearing tmp_set properly.
2023-02-15 13:56:33 +02:00
Sergei Petrunia
587646a476 Do a proper cleanup in testcase for MDEV-30569 2023-02-15 13:33:59 +03:00
Sergei Petrunia
10a974adc9 Merge 11.0-selectivity into 11.0 2023-02-15 12:03:12 +03:00