Home - Waterfall Grid T-Grid Console Builders Recent Builds Buildslaves Changesources - JSON API - About

Console View


Categories: connectors experimental galera main
Legend:   Passed Failed Warnings Failed Again Running Exception Offline No data

connectors experimental galera main
Andrei Elkin
MDEV-NNNNN: Parallel slave deadlocks with BACKUP STAGE BLOCK_COMMIT

This is a poc commit to the described problem; find 'Not addressed here'
for details left out.

On a parallel slave BACKUP STAGE BLOCK_COMMIT can deadlock with the
slave workers. The cause is the same as in MDEV-36025: a worker
releases MDL_BACKUP_COMMIT (L) while it waits for a prior commit,
after its engine prepare, and re-acquires it later. In MDEV-36025 a
backup granted inside that window captures prepared transactions.
Here a backup request arriving inside it deadlocks three threads.

Let B be the backup session, T1 the group commit leader and T2 one
follower, T1 preceding T2 in the binlog order:

  B  --> T2  B requests MDL_BACKUP_WAIT_COMMIT; it conflicts with the
            granted L of T2
  T2 --> T1  T2 waits in wait_for_wakeup_ready() for the leader
  T1 --> B  T1 re-acquires L at the end of queue_for_group_commit();
            the request queues behind the pending request of B

The middle edge is a condition variable wait, so the MDL deadlock
detector does not see the cycle. Replication stalls and STOP SLAVE
does not complete until the BACKUP STAGE session is killed.

Fix: a parallel slave worker whose transaction is binlogged and
commits in two phases no longer holds L while it waits for anything.
In ha_commit_trans() it only publishes the request, as
thd->backup_commit_lock with no ticket. The binlog group commit
leader acquires L for the whole group, after the engine prepare and
before it takes LOCK_log, in the new
MYSQL_BIN_LOG::trx_group_commit_backup_lock(), called first in
trx_group_commit_leader(). The leader's own ha_commit_trans()
releases it as it does for any other thread. B waits only for
holders of L and no member of a group of workers holds it while
parked, so the cycle is gone.

All other transactions take L where they did before the engine
prepare: user threads, a slave without binlog or with
--log-slave-updates=0, filtered events, and one-phase commits.

If the leader cannot get L (killed, lock wait timeout), nothing has
been binlogged. The leader fails the whole group with its own error
and wakes the members, and each rolls back in its own thread. In
optimistic mode the group is retried; with no retries left the
slave stops with the error. write_transaction_to_binlog_events()
reports the leader's error for the default case and does not log
"Error writing transaction to binary log" when the worker retries.

Consequences:
* BLOCK_COMMIT no longer excludes slave transactions that are
  prepared in the engine and not yet binlogged, so a backup can
  contain them prepared. Restore has to roll them back
  (--tc-heuristic-recover=AUTO).
* L is held through the leader's commit, not through the commit the
  other members do in their own threads after they are woken.

Not addressed here
==================
* One-phase and XA slave transactions keep taking L before the
  prepare. A one-phase worker holds it across the prior-commit wait
  in ha_commit_one_phase().
* The release and re-acquire of L in queue_for_group_commit() and
  wait_for_prior_commit2() is left for a follow-up, as is the
  THD::backup_commit_lock related cleanup.

Tests: rpl.parallel_backup_leader_hold (the deadlock, with a debug
hook that holds the leader) and rpl.parallel_backup_leader_kill
(the leader killed while it waits for L).
Alessandro Vetere
MDEV-42454 Assertion buf_fix_count(state) <= 2 with read-ahead

buf_page_init_for_read() buffer-fixed a page that already exists in
buf_pool.page_hash. An asynchronous read and buf_read_recover() released
that buffer-fix without accessing the page. buf_read_ahead_random() and
buf_read_ahead_linear() invoke buf_read_page_low() for every page of the
read-ahead area, so each resident page got a short buffer-fix. If such a
page had been freed and was being allocated again, buf_page_create_low()
could count this buffer-fix together with another one (for example, of
btr_blob_free()), and the debug assertion buf_fix_count(state) <= 2
failed. Release builds were not affected.

buf_page_init_for_read(): Add the parameter fix. Only buffer-fix an
existing page if fix holds. Otherwise, return nullptr | 1. Add the
DEBUG_SYNC point buf_page_init_for_read_freed for a freed page.

buf_read_page_low(): Only request a buffer-fix for a synchronous read.

buf_read_recover(): Do not request a buffer-fix.

btr_blob_free(): Add the DEBUG_SYNC point btr_blob_free_after_commit.

The test innodb.read_ahead_freed_page stops a ROLLBACK in
btr_blob_free() after it freed a BLOB page, and a random read-ahead when
it finds that page. CREATE TABLE then allocates the page. Without the
fix, buf_page_create_low() finds 3 buffer-fixes on it.

Assisted-by: Claude:claude-opus-5-5
Alessandro Vetere
MDEV-21725 Log page reorganization as the ranges by which records moved

btr_page_reorganize_low() logged the payload as one WRITE from the first
to the last changed byte. When the reorganization removes a gap near the
start of the page, it moves all the later records, and this WRITE covers
almost the whole page.

btr_page_reorganize_log_payload(): Log the payload with MEMMOVE for the
runs of records that only moved, and WRITE for the rest. The function
first copies the runs that moved towards the end of the page, in
descending order of destination. Then it copies the runs that moved
towards the start of the page, in ascending order of destination. In
each order, no copy changes the source of a later copy. If a copy of the
first order changed a part of a source, the function does not copy that
part. Instead, it logs with WRITE the bytes at the destination of that
part that differ from the old page. The function does not copy a run
that is shorter than 8 bytes. It also does not copy the shortest runs
that moved towards the end of the page when the working memory is full.
It logs the changed bytes of these runs with WRITE. The log format does
not change. With the debug keyword page_reorganize_log_max_up_2, the
working memory holds at most 2 runs that moved towards the end of the
page.

btr_page_reorganize_low(): Reserve a second scratch frame for the
working memory of btr_page_reorganize_log_payload(). Start a new
same_page chain before the log records of the reorganization. After
them, write an OPT_PAGE_CHECKSUM record, so that recovery detects a
payload that does not rebuild the page.

mtr_t::page_checksum(): Make it callable from btr_page_reorganize_low().

mtr_t::reset_last_page(): New function. Make the next log record write
its page identifier.

page_copy_rec_list_end_no_locks(): Add the output parameter extra.

In all versions since the 10.8 redo log format, the recovery parser has
an error. For a same_page record that follows a MEMSET or MEMMOVE
record, it calculates an offset that is too low. It can then reject a
valid MEMMOVE whose source is below its destination as "Malformed log
record". The new payload logging avoids this. The reorganization starts
a new same_page chain, and writes only WRITE records before the first
MEMMOVE whose source is below its destination. Each later such MEMMOVE
has its destination below the end of the previous record, so it has the
page identifier, and the parser reads its offset correctly. Older
servers and backup tools can thus recover the log.

recv_sys_t::parse_tail(): Add a FIXME for the parser error.

innodb.page_reorganize_log: Reorganize the index pages of 4 tables with
page_reorganize_log_max_up_2, kill the server before a checkpoint, and
check the recovered tables. The pages contain a record with no data
bytes, runs that the working memory cannot hold, and runs that are
shorter than 8 bytes. In the page of the fourth table, all records after
the first one moved down by the same distance. The test checks that the
INSERT that reorganizes this page writes less redo log than a quarter of
the page size. Before this change, the INSERT writes 3,051 bytes at 4k,
12,297 bytes at 16k and 49,280 bytes at 64k.
innodb.alter_copy and innodb.instant_alter_crash also recover page
reorganizations.

innodb.index_lock_upgrade,on with 4k pages (Debug) writes 2,818,205
bytes of redo log instead of 3,293,565 (shutdown LSN minus startup LSN).

Assisted-by: Claude:claude-opus-5-5
mariadb-PranavTiwari
MDEV-41151- cleanup required
rusher
[ODBC-524] SQLFetch does not fill buffers if no column is bound
Alessandro Vetere
MDEV-21725 Log page reorganization as the ranges by which records moved

btr_page_reorganize_low() logged the payload as one WRITE from the first
to the last changed byte. When the reorganization removes a gap near the
start of the page, it moves all the later records, and this WRITE covers
almost the whole page.

btr_page_reorganize_log_payload(): Log the payload with MEMMOVE for the
runs of records that only moved, and WRITE for the rest. The function
first copies the runs that moved towards the end of the page, in
descending order of destination. Then it copies the runs that moved
towards the start of the page, in ascending order of destination. In
each order, no copy changes the source of a later copy. If a copy of the
first order changed a part of a source, the function does not copy that
part. Instead, it logs with WRITE the bytes at the destination of that
part that differ from the old page. The function does not copy a run
that is shorter than 8 bytes. It also does not copy the shortest runs
that moved towards the end of the page when the working memory is full.
It logs the changed bytes of these runs with WRITE. The log format does
not change. With the debug keyword page_reorganize_log_max_up_2, the
working memory holds at most 2 runs that moved towards the end of the
page.

btr_page_reorganize_low(): Reserve a second scratch frame for the
working memory of btr_page_reorganize_log_payload(). Start a new
same_page chain before the log records of the reorganization. After
them, write an OPT_PAGE_CHECKSUM record, so that recovery detects a
payload that does not rebuild the page.

mtr_t::page_checksum(): Make it callable from btr_page_reorganize_low().

mtr_t::reset_last_page(): New function. Make the next log record write
its page identifier.

page_copy_rec_list_end_no_locks(): Add the output parameter extra.

In all versions since the 10.8 redo log format, the recovery parser has
an error. For a same_page record that follows a MEMSET or MEMMOVE
record, it calculates an offset that is too low. It can then reject a
valid MEMMOVE whose source is below its destination as "Malformed log
record". The new payload logging avoids this. The reorganization starts
a new same_page chain, and writes only WRITE records before the first
MEMMOVE whose source is below its destination. Each later such MEMMOVE
has its destination below the end of the previous record, so it has the
page identifier, and the parser reads its offset correctly. Older
servers and backup tools can thus recover the log.

recv_sys_t::parse_tail(): Add a FIXME for the parser error.

innodb.page_reorganize_log: Reorganize the index pages of 4 tables with
page_reorganize_log_max_up_2, kill the server before a checkpoint, and
check the recovered tables. The pages contain a record with no data
bytes, runs that the working memory cannot hold, and runs that are
shorter than 8 bytes. In the page of the fourth table, all records after
the first one moved down by the same distance. The test checks that the
INSERT that reorganizes this page writes less redo log than a quarter of
the page size. Before this change, the INSERT writes 3,051 bytes at 4k,
12,297 bytes at 16k and 49,280 bytes at 64k.
innodb.alter_copy and innodb.instant_alter_crash also recover page
reorganizations.

innodb.index_lock_upgrade,on with 4k pages (Debug) writes 2,818,205
bytes of redo log instead of 3,293,565 (shutdown LSN minus startup LSN).

Assisted-by: Claude:claude-opus-5-5
rusher
[ODBC-522] IRD record takes a single allocation for all column names

On each execution of a query returning a result set, the IRD records are
filled with the column metadata. That took 6 allocations per column: one
for each of the catalog, table, column, base table and base column names,
and one for the type name. And as many deallocations when the cursor is
closed.

The five names are now copied into a single buffer owned by the record,
which is re-used when the record is filled again. The type name is not
copied any more, as it always refers to a string constant. The charset
of the column is also searched once instead of twice.

Reading one row of 100 int columns is about 12% faster.
Marko Mäkelä
MDEV-39091 BACKUP SERVER of ENGINE=RocksDB

RocksDB is based on log structured merge trees (LSM trees)
that are immutable files. A consistent point-in-time snapshot
is obtained at BACKUP_LOCK_COMMIT cheaply via rdb_create_checkpoint(),
which is also what mariadb-backup is invoking via
SET GLOBAL rocksdb_create_checkpoint.

Under BACKUP_LOCK_COMMIT, a backup snapshot is created in #rocksdb under
rocksdb_datadir (by default, #rocksdb/#rocksdb in the server datadir).
This snapshot will be made available in #rocksdb subdirectory of the
backup target. The default rocksdb_datadir="./#rocksdb" makes restore
transparent: just point datadir to the backup directory or a restored
copy of it.

The transfer of the snapshot is deferred to BACKUP_FINISHED, after the
backup lock has been released, and finally the checkpoint is removed
from rocksdb_datadir.

Co-developed by: Thirunarayanan Balathandayuthapani
Reviewed by: Alessandro Vetere
Assisted-by: Claude:claude-opus-5-5
Vladislav Vaintroub
Add a tpool mode for parallel query

The optimizer team wants to use tpool for optional parallel work.
A query needs a snapshot of worker usage to choose its fan-out and
avoid leaving work queued behind busy workers. Workers blocked inside
a task still occupy a thread. The pool should have no background
maintenance or worker threads before the feature is used.

Create a dedicated pool with create_thread_pool_generic(0, max_threads,
thread_pool_policy::no_maintenance). Set worker callbacks before the
first submission. This policy wakes idle workers or creates workers
on demand up to the hard cap, without a maintenance timer, startup
throttling, or a soft concurrency limit. Idle workers retire after
the existing timeout, down to the configured minimum.

Use get_worker_stats() before submitting to inspect used and idle
workers, queue depth, and the hard cap.
The snapshot is advisory and reserves no capacity. Callers can
serialize the check and submission among cooperating submitters.
submit_task() still queues work, so use the snapshot to decide
whether to fan out or keep the work on the calling thread.

Assisted-by: Codex:gpt-6.2-sol
Vladislav Vaintroub
CI: ARM64 - save the winflexbison cache only after a successful build

A successful build proves the cached bison works. Save before MTR, so slow or flaky tests cannot block the save.

Assisted-by: Claude:claude-sonnet-5-5
Vladislav Vaintroub
CI: ARM64 - use MSYS2 bison instead of choco, switch to VS2026 runner

Install bison via msys2/setup-msys2 (CLANGARM64) rather than choco's winflexbison3, and run on windows-11-vs2026-arm. Experimental, for testing on a wlad branch.

Assisted-by: Claude:claude-sonnet-5-5
rusher
Merge remote-tracking branch 'rusher/odbc-3.2-perf-getdata-reset' into odbc-3.2-perf
Hemant Dangi
MDEV-42446: Galera test failure on galera_sst_mariabackup_plugin_dir

Issue:
MDEV-41158 made the joiner require a per-transfer auth secret
unconditionally. This test (MDEV-42091) forges the SST wire protocol
by hand and predates that change, so the joiner now rejects its
payload with "Donor does not know my secret!" before mariadb-backup
--prepare ever runs.

Solution:
This test is about plugin_dir trust, not donor auth, so tell the
joiner to skip the secret requirement instead of forging that
unrelated protocol too, via sst-mariabackup-allow-unauthenticated-donor.
Oleg Smirnov
MDEV-40439 Evaluate cheap subconditions before expensive ones in WHERE and ON conditions

The arguments of AND and OR are evaluated left to right with
short-circuiting, in the order written in the query. An expensive
subcondition written first is therefore evaluated even for rows that
a cheap one would reject (AND) or accept (OR).

Reorder the arguments of each AND/OR so that the expensive ones come
after the cheap ones, keeping the relative order within each group.
The walk goes down into nested AND/OR and into trigger conditions.
A subcondition is expensive if it contains a subquery, a stored
function call, or an item that marks itself as expensive through
is_expensive_processor() (a UDF, MATCH()).

An AND/OR that has a non-deterministic argument (one with RAND_TABLE_BIT)
keeps its order, to prevent unwanted change of behavior. Nested lists
are still reordered.

The reordering is applied to:
- the conditions attached to tables (select_cond, select->cond,
  on_precond), at the end of make_join_select() and before the
  attached_conditions_summary trace, so the trace shows the final
  order;
- BNL/BNLH scan filters, in make_scan_filter(). They are built from
  the original WHERE/ON, and check_join_cache_usage() may build them
  after make_join_select();
- outer_ref_cond and pseudo_bits_cond, the conditions a subquery
  checks once per execution before running its join.
The steps that later build new conditions from these (index condition
pushdown, removal of duplicate BNL conditions) take subsets and keep
the order.

Not covered yet: HAVING, exec_const_cond, terms added after
make_join_select() (the index condition remainder rejected by an
engine, HAVING moved to a table's condition). Reordering HAVING would
need care with Item_is_not_null_test and Item_ref_null_helper, which
record NULLs for IN->EXISTS.
rusher
Merge remote-tracking branch 'rusher/odbc-3.2-perf-stmt-handle-alloc' into odbc-3.2-perf
rusher
Merge remote-tracking branch 'rusher/odbc-3.2-perf-fetch-no-bound-columns' into odbc-3.2-perf
Vladislav Vaintroub
CI: ARM64 - cache choco's winflexbison3, use VS2026 runner

Cache the choco-installed winflexbison3 (refreshed weekly) to avoid hitting choco on every run, and run on windows-11-vs2026-arm.

Assisted-by: Claude:claude-sonnet-5-5
bsrikanth-mariadb
MDEV-38303: Stop scanning early when an aggregate HAVING cannot become true

For a query without GROUP BY, such as

  SELECT COUNT(*) FROM t1 HAVING COUNT(*) < 10

the whole table was read even after the count reached 10 and the
condition could no longer be true.

Add Item_sum::having_false_is_final(op, c), which tells whether a
HAVING condition "aggregate op constant", once false, stays false as
more rows are added. Item_sum_count implements it for COUNT(..) < c,
COUNT(..) <= c and COUNT(..) = 0. Other aggregates return false, so
they are read in full as before.

JOIN::setup_having_stop_conds() collects such AND-parts of HAVING (at
most 4) at the end of JOIN::make_aggr_tables_info(), in the optimizer.
end_send_group() checks them after
each row and returns NESTED_LOOP_QUERY_LIMIT, the same way LIMIT stops a
scan, once one is false. The end-of-records step still runs, so HAVING
is checked on the final state.

Only used when it is safe:
- implicit grouping, with no temporary table, ROLLUP, window functions
  or correlated HAVING
- COUNT(DISTINCT) is excluded, as its value is known only at the end
- the comparison must be numeric. COUNT compared with a DATE is not
  monotonic, so it is not used
- the constant must be a literal or a cached value. A user variable
  changed by a stored function during the scan is not used.
- a NULL result does not stop the scan

Like LIMIT, stopping early means the remaining rows are not read, so
errors and side effects from them no longer happen.

The code is in the new file sql/opt_having_shortcut.cc. Since the
decision is made at optimization time, it is also reported:
- EXPLAIN FORMAT=JSON shows "having_shortcut": true
- the optimizer trace has a "having_shortcut" object with the
  stop_conditions

The plan only says the scan may stop. The tests also cover queries where
the plan shows the shortcut, but the scan is not stopped, or is stopped
late.
Hemant Dangi
MDEV-42446: Galera test failure on galera_sst_mariabackup_plugin_dir

Issue:
MDEV-41158 made the joiner require a per-transfer auth secret
unconditionally. This test (MDEV-42091) forges the SST wire protocol
by hand and predates that change, so the joiner now rejects its
payload with "Donor does not know my secret!" before mariadb-backup
--prepare ever runs.

Solution:
This test is about plugin_dir trust, not donor auth, so tell the
joiner to skip the secret requirement instead of forging that
unrelated protocol too, via sst-mariabackup-allow-unauthenticated-donor.
Vladislav Vaintroub
CI: ARM64 - save the winflexbison cache right after install

Use cache/restore and cache/save, so the cache is stored even if the build or tests fail.

Assisted-by: Claude:claude-sonnet-5-5
rusher
[ODBC-525] SQLCancel does not touch the statement used by other thread
Jan Lindström
MDEV-42444 mariabackup SST fails with "Donor does not know my secret!"

When ssl-mode is DISABLED or REQUIRED, a mariabackup SST fails on the
joiner with "Donor does not know my secret!" and the joiner node does
not start. The joiner sends its secret to the donor as
"<CN>:<secret>@<address>". The CN is set only when ssl-mode is
VERIFY_CA or VERIFY_IDENTITY. Since MDEV-41158 the joiner sends a
secret in every ssl-mode, so in the other modes the CN part is empty.

write_auth_info() gives the remote credentials to the donor script
only when the remote user name is not empty. With an empty CN the
secret is not given to the donor, the donor does not send it back,
and the joiner stops the SST.

Give the remote credentials to the donor script when the user name
or the password is not empty.

Assisted-by: Claude:claude-4.6-sonnet
bsrikanth-mariadb
MDEV-38303: Stop scanning early when an aggregate HAVING cannot become true

For a query without GROUP BY, such as

  SELECT COUNT(*) FROM t1 HAVING COUNT(*) < 10

the whole table was read even after the count reached 10 and the
condition could no longer be true.

Add Item_sum::having_false_is_final(op, c), which tells whether a
HAVING condition "aggregate op constant", once false, stays false as
more rows are added. Item_sum_count implements it for COUNT(..) < c,
COUNT(..) <= c and COUNT(..) = 0. Other aggregates return false, so
they are read in full as before.

JOIN::setup_having_stop_conds() collects such AND-parts of HAVING (at
most 4) at the end of JOIN::make_aggr_tables_info(), in the optimizer.
end_send_group() checks them after
each row and returns NESTED_LOOP_QUERY_LIMIT, the same way LIMIT stops a
scan, once one is false. The end-of-records step still runs, so HAVING
is checked on the final state.

Only used when it is safe:
- implicit grouping, with no temporary table, ROLLUP, window functions
  or correlated HAVING
- COUNT(DISTINCT) is excluded, as its value is known only at the end
- the comparison must be numeric. COUNT compared with a DATE is not
  monotonic, so it is not used
- the constant must be a literal or a cached value. A user variable
  changed by a stored function during the scan is not used.
- a NULL result does not stop the scan

Like LIMIT, stopping early means the remaining rows are not read, so
errors and side effects from them no longer happen.

The code is in the new file sql/opt_having_shortcut.cc. Since the
decision is made at optimization time, it is also reported:
- EXPLAIN FORMAT=JSON shows "having_shortcut": true
- the optimizer trace has a "having_shortcut" object with the
  stop_conditions

The plan only says the scan may stop. The tests also cover queries where
the plan shows the shortcut, but the scan is not stopped, or is stopped
late.
Marko Mäkelä
squash! 491224a5e415564d9797219bbaf3dd8aa956d9bd

In BACKUP SERVER TO, innodb_undo_directory will be stripped.
In BACKUP SERVER WITH, the InnoDB file names will appear as is.
rusher
[ODBC-521] SQLGetData resets only the previously read column

MA_SQLGetData went through all columns of the result set on each call to
reset their offsets and to free the IRD internal buffers. That made reading
a row with SQLGetData quadratic in the number of columns, while columns
are usually read in order, once each, and have nothing to reset.
Thirunarayanan Balathandayuthapani
MDEV-38252 Fail online ALTER TABLE when DML cannot read a page of the table

Problem:
=========
  While an online ALTER TABLE is running, a concurrent DML transaction
logs its changes for the ALTER by applying its undo log records
at commit time.

UndorecApplier::get_old_rec() looks up the clustered index record
that the undo log record modified, and asserted that the record
must be found. The record cannot be found when the page cannot
be read, In this case when the page is corrupted or fails to
decompress or decrypt. The DML transaction then crashed the server,
although only the concurrent online ALTER TABLE needs to fail.

Two related problems were found in the online log abort handling:

1) row_log_mark_other_online_index_abort() unconditionally cleared
clust_index->online_log. That is only valid when the clustered index
holds the dummy log. During an online table rebuild, it is the real
log that row_log_table_apply() is still using,
which led to a null pointer dereference in the ALTER TABLE thread.

2) row_log_apply() did not handle an index whose online creation was
already aborted by a DML thread. It tried to mark such index as
ONLINE_INDEX_COMPLETE, which could make things worse.

Solution:
========
UndorecApplier::get_old_rec(): Instead of asserting,
return nullptr and set *clust_rec to nullptr when the
clustered index record is not found.

UndorecApplier::log_insert(), UndorecApplier::log_update(): If
the clustered index record was not found, call
row_log_mark_other_online_index_abort() so that the concurrent online
ALTER TABLE fails, while the DML transaction commits normally.

row_log_mark_other_online_index_abort(): Clear the clustered index
online log only if it is the dummy one. For an online table rebuild,
set row_log_t::error to DB_CORRUPTION under row_log_t::mutex
instead, and let the ALTER TABLE thread notice it and free the log.
Set table->drop_aborted only when secondary indexes were aborted.

row_log_apply(): If the index was already aborted, return
DB_INDEX_CORRUPT without changing the online status again.
Vladislav Vaintroub
CI: ARM64 - use windows-11-arm, the vs2026-arm label is being deprecated

Assisted-by: Claude:claude-sonnet-5-5
rusher
[ODBC-526] Cheaper allocation of the statement handle
Mohammad Tafzeel Shams
MDEV-41719 SIGSEGV in dict_load_virtual_col() with innodb_force_recovery=6

MDEV-32042 moved the loading of the InnoDB data dictionary tables from
dict_boot() to srv_start(), into a block that is skipped when
innodb_force_recovery=6. dict_sys.sys_virtual, sys_foreign and
sys_foreign_cols would remain NULL: opening a table with virtual columns
would crash, and FOREIGN KEY constraints would be ignored.

srv_start(): Invoke srv_load_tables() also when the redo log apply is
skipped, like dict_boot() did before MDEV-32042.

dict_load_virtual_col(): If SYS_VIRTUAL is not available, report
ER_UNKNOWN_TABLE and return DB_CORRUPTION.

innobase_build_v_templ(): Report a warning instead of asserting that the
.frm file and the data dictionary agree on a virtual column name. They
can disagree if the .frm file was replaced.

dict_sys_t::load_sys_tables(): Add the debug injection skip_sys_virtual.
Kristian Nielsen
Fix backup for undo and binlogs outside of datadir

When undo files (--innodb-undo-directory) or binlog (--binlog-directory)
files are placed in a different directory than the datadir, then have
BACKUP_SERVER put them in the basedir of the backup. The user can move them
to the appropriate place after restoring the backup, as appropriate.

Signed-off-by: Kristian Nielsen <[email protected]>
Thirunarayanan Balathandayuthapani
MDEV-38252 Fail online ALTER TABLE when DML cannot read a page of the table

Problem:
=========
  While an online ALTER TABLE is running, a concurrent DML transaction
logs its changes for the ALTER by applying its undo log records
at commit time.

UndorecApplier::get_old_rec() looks up the clustered index record
that the undo log record modified, and asserted that the record
must be found. The record cannot be found when the page cannot
be read, In this case when the page is corrupted or fails to
decompress or decrypt. The DML transaction then crashed the server,
although only the concurrent online ALTER TABLE needs to fail.

Two related problems were found in the online log abort handling:

1) row_log_mark_other_online_index_abort() unconditionally cleared
clust_index->online_log. That is only valid when the clustered index
holds the dummy log. During an online table rebuild, it is the real
log that row_log_table_apply() is still using,
which led to a null pointer dereference in the ALTER TABLE thread.

2) row_log_apply() did not handle an index whose online creation was
already aborted by a DML thread. It tried to mark such index as
ONLINE_INDEX_COMPLETE, which could make things worse.

Solution:
========
UndorecApplier::get_old_rec(): Instead of asserting,
return nullptr and set *clust_rec to nullptr when the
clustered index record is not found.

UndorecApplier::log_insert(), UndorecApplier::log_update(): If
the clustered index record was not found, call
row_log_mark_other_online_index_abort() so that the concurrent online
ALTER TABLE fails, while the DML transaction commits normally.

row_log_mark_other_online_index_abort(): Clear the clustered index
online log only if it is the dummy one. For an online table rebuild,
set row_log_t::error to DB_CORRUPTION under row_log_t::mutex
instead, and let the ALTER TABLE thread notice it and free the log.
Set table->drop_aborted only when secondary indexes were aborted.

row_log_apply(): If the index was already aborted, return
DB_INDEX_CORRUPT without changing the online status again.
rusher
Merge remote-tracking branch 'rusher/odbc-3.2-perf-ird-metadata' into odbc-3.2-perf
Alessandro Vetere
MDEV-42454 Assertion buf_fix_count(state) <= 2 with read-ahead

buf_page_init_for_read() buffer-fixed a page that already exists in
buf_pool.page_hash. An asynchronous read and buf_read_recover() released
that buffer-fix without accessing the page. buf_read_ahead_random() and
buf_read_ahead_linear() invoke buf_read_page_low() for every page of the
read-ahead area, so each resident page got a short buffer-fix. If such a
page had been freed and was being allocated again, buf_page_create_low()
could count this buffer-fix together with another one (for example, of
btr_blob_free()), and the debug assertion buf_fix_count(state) <= 2
failed. Release builds were not affected.

buf_page_init_for_read(): Add the parameter fix. Only buffer-fix an
existing page if fix holds. Otherwise, return nullptr | 1. Add the
DEBUG_SYNC point buf_page_init_for_read_freed for a freed page.

buf_read_page_low(): Only request a buffer-fix for a synchronous read.

buf_read_recover(): Do not request a buffer-fix.

btr_blob_free(): Add the DEBUG_SYNC point btr_blob_free_after_commit.

The test innodb.read_ahead_freed_page stops a ROLLBACK in
btr_blob_free() after it freed a BLOB page, and a random read-ahead when
it finds that page. CREATE TABLE then allocates the page. Without the
fix, buf_page_create_low() finds 3 buffer-fixes on it.

Assisted-by: Claude:claude-opus-5-5
Alessandro Vetere
MDEV-42454 Assertion buf_fix_count(state) <= 2 with read-ahead

buf_page_init_for_read() buffer-fixed a page that already exists in
buf_pool.page_hash. An asynchronous read and buf_read_recover() released
that buffer-fix without accessing the page. buf_read_ahead_random() and
buf_read_ahead_linear() invoke buf_read_page_low() for every page of the
read-ahead area, so each resident page got a short buffer-fix. If such a
page had been freed and was being allocated again, buf_page_create_low()
could count this buffer-fix together with another one (for example, of
btr_blob_free()), and the debug assertion buf_fix_count(state) <= 2
failed. Release builds were not affected.

buf_page_init_for_read(): Add the parameter fix. Only buffer-fix an
existing page if fix holds. Otherwise, return nullptr | 1. Add the
DEBUG_SYNC point buf_page_init_for_read_freed for a freed page.

buf_read_page_low(): Only request a buffer-fix for a synchronous read.

buf_read_recover(): Do not request a buffer-fix.

btr_blob_free(): Add the DEBUG_SYNC point btr_blob_free_after_commit.

The test innodb.read_ahead_freed_page stops a ROLLBACK in
btr_blob_free() after it freed a BLOB page, and a random read-ahead when
it finds that page. CREATE TABLE then allocates the page. Without the
fix, buf_page_create_low() finds 3 buffer-fixes on it.

Assisted-by: Claude:claude-opus-5-5
rusher
Merge remote-tracking branch 'rusher/odbc-3.2-sqlcancel-fix' into odbc-3.2-perf
Mohammad Tafzeel Shams
MDEV-41719 SIGSEGV in dict_load_virtual_col() with innodb_force_recovery=6

MDEV-32042 moved the loading of the InnoDB data dictionary tables from
dict_boot() to srv_start(), into a block that is skipped when
innodb_force_recovery=6. dict_sys.sys_virtual, sys_foreign and
sys_foreign_cols would remain NULL: opening a table with virtual columns
would crash, and FOREIGN KEY constraints would be ignored.

srv_start(): Invoke srv_load_tables() also when the redo log apply is
skipped, like dict_boot() did before MDEV-32042.

dict_load_virtual_col(): If SYS_VIRTUAL is not available, report
ER_UNKNOWN_TABLE and return DB_CORRUPTION.

innobase_build_v_templ(): Report a warning instead of asserting that the
.frm file and the data dictionary agree on a virtual column name. They
can disagree if the .frm file was replaced.

dict_sys_t::load_sys_tables(): Add the debug injection skip_sys_virtual.
bsrikanth-mariadb
MDEV-38303: Stop scan early when aggregate HAVING cannot become true

For a query without GROUP BY, such as

  SELECT COUNT(*) FROM t1 HAVING COUNT(*) < 10

the whole table was read even after the count reached 10 and the
condition could no longer be true.

Add Item_sum::having_false_is_final(op, c), which tells whether a
HAVING condition "aggregate op constant", once false, stays false as
more rows are added. Item_sum_count implements it for COUNT(..) < c,
COUNT(..) <= c and COUNT(..) = 0. Other aggregates return false, so
they are read in full as before.

JOIN::setup_having_stop_conds() collects such AND-parts of HAVING in a
List at the end of JOIN::make_aggr_tables_info(), in the optimizer.
An error there is returned to the caller. end_send_group() checks the
conditions after each row and returns NESTED_LOOP_QUERY_LIMIT, the same
way LIMIT stops a scan, once one is false. The end-of-records step
still runs, so HAVING is checked on the final state.

Only used when it is safe:
- implicit grouping, with no temporary table, ROLLUP, window functions
  or correlated HAVING
- COUNT(DISTINCT) is excluded, as its value is known only at the end
- the comparison must be numeric. COUNT compared with a DATE is not
  monotonic, so it is not used
- the constant must be a literal. A <cache> item, such as an expression
  with a user variable (@v + 0) or a folded 5 + 5, is filled on its first
  read, which the shortcut would move to the first row. A user variable
  changed by a stored function during the scan would give a wrong result.
- a NULL result does not stop the scan

Like LIMIT, stopping early means the remaining rows are not read, so
errors and side effects from them no longer happen.

The code is in the new file sql/opt_having_shortcut.cc. Since the
decision is made at optimization time, it is also reported:
- EXPLAIN FORMAT=JSON shows "having_shortcut": true
- the optimizer trace has a "having_shortcut" object with the
  stop_conditions

The plan only says the scan may stop. The tests also cover queries where
the plan shows the shortcut, but the scan is not stopped, or is stopped
late.
Marko Mäkelä
squash! 84bdb8b69d63a00cde7b4372cca34edc2d9cef35

Only in BACKUP SERVER TO, disregard binlog_directory
and write the *.ibb files directly to the backup directory.