LOAD INDEX doesn't initialize Lex->check_opt and mysql_preload_keys doesn't use
it. However, Check_table_prelocking_strategy did, and it's always used in
opening table.
One solution could be using a different prelocking strategy for
mysql_preload_keys.
Let's instead just pass a correct check_opt to Check_table_prelocking_strategy.
Base task: MDEV-34309
... TABLE with FK
The normal order of things in prepared statement is:
1. open tables during prepare
2. use them during all the executions
Currently, tables are opened in the body of CHECK TABLE's execution part.
This is motivated by the nature of this statement: we have to run the checks for
all the tables specified in the list, event if some of them fail to open.
Rewriting it as in normal order is possible, but is out of scope of this task.
That is, we shouldn't activate stmt_arena when constructing the referential
tables list.
It's not enough, since the next statement execution will try to reuse all the
TABLE_LIST's in lex->query_list, but the referential tables are allocated on the
normal query arena, so they should be cleaned up from that list.
Given how specific the open_only_one_table work is, we only have to re-link
table lists as they were before the tables are opened. It's enough to just
assign next_local to next_global for each table specified by
user, i.e. in lex->first_select_lex().
lex->query_tables_last and other lex fields are already maintained by that
function.
Base task: MDEV-34309
In BIT -> TIME reference, BIT length is 1, and TIME length is 4.
It's likely a quirk, that such relation is possible, since 0 -> 0 is not a valid
reference.
However, some parts of key_copy should be fixed:
1. Make sure that key_length is deduced according to to_key_info key_parts.
2. Mind the case when to_key_part is NOT NULL, but key_part is NULL.
3. Use correct length in field->get_key_image call.
Also fix the double run of checks of self-referencing keys.
Base task: MDEV-34309
### Preamble
C++ initializes objects in three stages:
1. Optionally, zero-initializes the object fields.
2. Member-initializes fields that are explicitly set.
3. If applicable, calls a constructor.
The following expressions:
x = new T[N];
x = new T;
T x;
only member-initialize and call a default constructor. Stage 1 is skipped,
because () braces are omitted.
This is known as default-initialization.
Apart from Stage 2, the following:
x = new T[N]();
x = new T();
const T &x = T();
Is known as value-initialization:
If no default constructor is present, infer zero-initialization.
Otherwise, the default constructor is called.
Note that it's not possible to write `T x();`, as it is ambiguous to a function
call.
Since C++11, it's also possible to zero initialize objects with '{}' braces:
x = new T[N]{};
x = new T{};
T x{};
This also both zero-initializes and calls a default constructor.
There is no much difference in between empty-braced () and {}. Both call a
default constructor or initializer-list constructor, when available. Having both
constructors is ambiguous.
Scalars (i.e. fundamental data types) and POD types have no constructor.
Therefore, stage 2 for them is skipped.
Other than that, there is no much difference in the result
Exambles:
new char[123] -- would return an uninitialized array of char.
new char[123]() -- forces zero-initialization
new char[123]{} -- forces zero-initialization
new char[123]{123} -- forces zero-initialization, and also value-initializes
the first element to 123
struct A {
int x = 0xaf;
int y;
}
All of the following:
A a;
A *a = new A;
A *a = new A[123];
Causes member A::x be initialized to 0xaf, since it happens at
value-initialization stage. A::y is left uninitialized.
A *a = new A[123] {};
and other similars result in {.x=0xaf, .y=0}.
### In this commit
Change all the calls to thd->calloc() to new(thd) T[N]{}, or new(thd) T{}.
POD types will be zero-initialized, so a special attention should be put to
classes with default constructors.
Among all uses, two cases of interest were found:
1. TABLE_LIST: has a default constructor TABLE_LIST() = default. This infers
zero-initialization behavior (i.e. as if there's no constructor).
2. USER_AUTH: has a default constructor, that initializes all fields. Strings
are initialized to "", which is fine.
3. Security_context: had a custom default constructor, initializing only two
fields. It was removed, and fields are made member-initialized.
QUICK_RANGE_SELECT::clone is never used, and besides it does not inherit
Sql_alloc, so the usage of `new` without agruments would be leak-prone.
So, remove it.
Remove THD:alloc() completely.
THD::calloc will still stay. It's still possible to use thd_alloc() as a plain C
replacement.
my_bitmap.h: add my_bitmap_array_size(bits) to count in my_bitmap_map, which is
ulonglong
All the bitmap arrays are now allocated with new my_bitmap_map[size]. This is
bigger than it was before, but essentially aligns the allocated array to
my_bitmap_map size, which was violated before.
sql_select: replace thd->alloc() with thd_alloc()
table_status_by_host_context: add default
sql_parse.cc: add_proc_to_list: add struct Order_Item
Made as a part of MDEV-34309
Note that List and QUICK_RANGE inherit Sql_alloc, so they use new (mem_root).
sql_select.cc: remove rollup_fields->empty() since it's now done by a List
constructor.
Made as a part of MDEV-34309
Sql_alloc: add operator new(size_t, const THD *) noexcept. Also change throw()
to noexcept in other Sql_alloc operators.
Item: add operator new(size_t, const THD *).
The implementations are in the bottom of item.cc and sql_class.cc.
Made as a part of MDEV-34309
- mariadb-dump utility performs logical backups by producing
set of sql statements that can be executed. By enabling this
no-autocommit option, InnoDB can load the data in an efficient
way and writes the only one undo log for the whole operation.
Only first insert statement undergoes bulk insert operation,
remaining insert statement doesn't write undo log and undergoes
normal insert code path.
row_purge_remove_sec_if_poss_leaf(): If there is an active transaction
that is not newer than PAGE_MAX_TRX_ID, return the bogus value 1
so that row_purge_remove_sec_if_poss_tree() is guaranteed to recheck if
the record needs to be purged. It could be the case that an active
transaction would insert this record between the time this check
completed and row_purge_remove_sec_if_poss_tree() acquired a latch
on the secondary index leaf page again.
row_purge_del_mark_error(), row_purge_check(): Some unlikely code
refactored into separate non-inline functions.
trx_sys_t::find_same_or_older_low(): Move the unlikely and bulky
part of trx_sys_t::find_same_or_older() to a non-inline function.
trx_sys_t::find_same_or_older_in_purge(): A variant of
trx_sys_t::find_same_or_older() for use in the purge subsystem,
with potential concurrent access of the same trx_t object from
multiple threads.
trx_t::max_inactive_id_atomic: An Atomic_relaxed alias of the
regular data field trx_t::max_inactive_id, which we
use on systems that have native 64-bit loads or stores.
On any 64-bit system that seems to be supported by GCC, Clang or MSVC,
relaxed atomic loads and stores use the regular load and store
instructions. On -march=i686 the 64-bit atomic loads and stores
would use an XMM register.
This fixes a regression that had been introduced in
commit b7b9f3ce82 (MDEV-34515).
There would be messages
[ERROR] InnoDB: tried to purge non-delete-marked record in index
in the server error log, and an assertion ut_ad(0) would cause a
crash of debug instrumented builds. This could also cause incorrect
results for MVCC reads and corrupted secondary indexes.
The debug instrumented test case was written by Debarun Banerjee.
Reviewed by: Debarun Banerjee
Make galera_sr.GCF-572 behave the same with and without option
innodb-snapshot-isolation. It is sufficient to remove a SELECT
statement from a transaction to delay the creation of the read
view in innodb. Avoiding the detection of a write-write conflict
under innodb-snapshot-isolation.
Ignore snapshot isolation conflict during fragment removal, before
streaming transaction commits. This happens when a streaming
transaction creates a read view that precedes the INSERTion of
fragments into the streaming_log table. Fragments are INSERTed
using a different transaction. These fragment are then removed
as part of COMMIT of the streaming transaction. This fragment
removal operation could fail when the fragments were not part
the transaction's read view, thus violating snapshot isolation.
Item_char_typecast::val_str_generic() uses Item::str_value as a buffer.
Item::val_str_ascii() also used Item::str_value as a buffer.
As a result, str_value tried to copy to itself.
Fixing val_str_ascii() to use a local buffer instead of str_value.
Make sure that node_1 remains in primary view by increasing it's
weight. Add suppression on expected warnings because we kill
node_2.
Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
We periodically observe assertion failures in the mtr tests,
specifically in the /storage/innobase/row/row0ins.cc file,
following a WSREP error. The error message is: 'WSREP: record
locking is disabled in this thread, but the table being modified
is not mysql/wsrep_streaming_log: mysql/innodb_table_stats.'"
This issue seems to occur because, upon opening the table,
innodb_stats_auto_recalc may trigger, which Galera does not
anticipate. This commit should fix this bug.
Backport of 2f5174e556:
MDEV-33075 Resolve server shutdown issues on macOS, Solaris, and FreeBSD.
This commit addresses multiple server shutdown problems observed on macOS,
Solaris, and FreeBSD:
1. Corrected a non-portable assumption where socket shutdown was expected
to wake up poll() with listening sockets in the main thread.
Use more robust self-pipe to wake up poll() by writing to the pipe's write
end.
Signed-off-by: Ivan Prisyazhnyy <john.koepi@gmail.com>
Backport of 2f5174e556:
MDEV-33075 Resolve server shutdown issues on macOS, Solaris, and FreeBSD.
This commit addresses multiple server shutdown problems observed on macOS,
Solaris, and FreeBSD:
2. Fixed a random crash on macOS from pthread_kill(signal_handler)
when the signal_handler was detached and the thread had already exited.
Use more robust `kill(getpid(), SIGTERM)` to wake up the signal handler
thread.
Additionally, the shutdown code underwent light refactoring
for better readability and maintainability:
- Modified `break_connect_loop()` to no longer wait for the main thread,
aligning behavior with Windows (since 10.4).
Backport of 2f5174e556:
MDEV-33075 Resolve server shutdown issues on macOS, Solaris, and FreeBSD.
This commit addresses multiple server shutdown problems observed on macOS,
Solaris, and FreeBSD:
3. Made sure, that signal handler thread always exits once `abort_loop` is
set, and also calls `my_thread_end()` and clears `signal_thread_in_use`
when exiting.
This fixes warning "1 thread did not exit" by `my_global_thread_end()`
seen on FreeBSD/macOS when the process is terminated via signal.
Additionally, the shutdown code underwent light refactoring
for better readability and maintainability:
- Removed dead code related to the unused `USE_ONE_SIGNAL_HAND`
preprocessor constant.
Signed-off-by: Ivan Prisyazhnyy <john.koepi@gmail.com>
Backport of 2f5174e556:
MDEV-33075 Resolve server shutdown issues on macOS, Solaris, and FreeBSD.
Eliminated support for `#ifndef HAVE_POLL` in `handle_connection_sockets`
This code is also dead, since 10.4
Signed-off-by: Ivan Prisyazhnyy <john.koepi@gmail.com>
Problem was that at wsrep_to_isolation_end saved_lock_wait_timeout
variable was set to thd->variables.lock_wait_timeout when RSU
is used and variable value was 0 leading sporadic lock wait timeout
errors. Fixed by removing incorrect variable set.
Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
- Innochecksum misinterprets the freed pages as active one.
This leads the user to think there are too many valid
pages exist.
- To avoid this confusion, innochecksum introduced one
more option --skip-freed-pages and -r to avoid the freed
pages while dumping or printing the summary of the tablespace.
- Innochecksum can safely assume the page is freed if
the respective extent doesn't belong to a segment and marked as
freed in XDES_BITMAP in extent descriptor page.
- Innochecksum shouldn't assume that zero-filled page as extent
descriptor page.
Reviewed-by: Marko Mäkelä
The existing default value 1000 is too big and could result in
"hanging" when failing to connect a remote server. Three tries in
total is a more sensible default.
The bug was that backup_file_op_fail() was using a static variable
initialized by arguments. This does not work as static variables
will only be initialized on the first call and not change for future
calls, even when the arguments changes.
Fixed by removing 'static'.
Last time, commit b9f579317 (MDEV-9101) has updated HA_ERR_LAST, breaking the
rocksdb error codes. According to the commit history, this happens each time a
new HA error is added.
This patch fixes the range to start from '500', hopefully resolving the problem
for the close future.
In addition, fix incorrect error codes enumeration.
--mariadbd and --mysqld are now synonymes for my_print_defaults
Other things
- Removed safemalloc warnings when using an unknown argument to
my_print_defaults