Commit graph

23203 commits

Author SHA1 Message Date
Mikhail Chalov
567b681299 Minimize unsafe C functions usage - replace strcat() and strcpy() (and strncat() and strncpy()) with custom safe_strcat() and safe_strcpy() functions
The MariaDB code base uses strcat() and strcpy() in several
places. These are known to have memory safety issues and their usage is
discouraged. Common security scanners like Flawfinder flags them. In MariaDB we
should start using modern and safer variants on these functions.

This is similar to memory issues fixes in 19af1890b5
and 9de9f105b5 but now replace use of strcat()
and strcpy() with safer options strncat() and strncpy().

However, add '\0' forcefully to make sure the result string is correct since
for these two functions it is not guaranteed what new string will be null-terminated.

Example:

    size_t dest_len = sizeof(g->Message);
    strncpy(g->Message, "Null json tree", dest_len); strncat(g->Message, ":",
    sizeof(g->Message) - strlen(g->Message)); size_t wrote_sz = strlen(g->Message);
    size_t cur_len = wrote_sz >= dest_len ? dest_len - 1 : wrote_sz;
    g->Message[cur_len] = '\0';

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the BSD-new
license. I am contributing on behalf of my employer Amazon Web Services

-- Reviewer and co-author Vicențiu Ciorbaru <vicentiu@mariadb.org>
-- Reviewer additions:
* The initial function implementation was flawed. Replaced with a simpler
  and also correct version.
* Simplified code by making use of snprintf instead of chaining strcat.
* Simplified code by removing dynamic string construction in the first
  place and using static strings if possible. See connect storage engine
  changes.
2023-01-20 15:18:52 +02:00
Marko Mäkelä
489b556947 MDEV-30422 Merge new release of InnoDB 5.7.41 to 10.3
MySQL 5.7.41 includes one InnoDB change
mysql/mysql-server@d2d6b2dd00
that seems to be applicable to MariaDB Server 10.3 and 10.4.
Even though commit 5b9ee8d819
seems to have fixed sporadic failures on our CI systems, it is
theoretically possible that another race condition remained.

buf_flush_page_cleaner_coordinator(): In the final loop,
wait also for buf_get_n_pending_read_ios() to reach 0.
In this way, if a secondary index leaf page was read into the
buffer pool and ibuf_merge_or_delete_for_page() modified that
page or some change buffer pages, the flush loop would execute
until the buffer pool really is in a clean state.

This potential data corruption bug does not affect MariaDB Server 10.5
or later, thanks to commit b42294bc64
which removed change buffer merges that are not explicitly requested.
2023-01-17 17:52:16 +02:00
Nikita Malyavin
7a98d232e4 MDEV-30378 Versioned REPLACE succeeds with ON DELETE RESTRICT constraint
node->is_delete was incorrectly set to NO_DELETE for a set of operations.

In general we shouldn't rely on sql_command and look for more abstract ways
to control the behavior.

trg_event_map seems to be a suitable way. To mind replica nodes, it is ORed
with slave_fk_event_map, which stores trg_event_map when replica has
triggers disabled.
2023-01-12 21:51:48 +03:00
lilinjie
eb145e5ad7 fix typos
Signed-off-by: lilinjie <lilinjie@uniontech.com>
2023-01-12 14:02:20 +11:00
Marko Mäkelä
b218dfead2 Remove an unused parameter
lock_rec_has_to_wait(): Remove the unused parameter for_locking
that had been originally added
in commit df4dd593f2
2023-01-11 08:37:27 +02:00
Daniel Black
56948ee54c clang15 warnings - unused vars and old prototypes
clang15 finally errors on old prototype definations.

Its also a lot fussier about variables that aren't used
as is the case a number of time with loop counters that
aren't examined.

RocksDB was complaining that its get_range function was
declared without the array length in ha_rocksdb.h. While
a constant is used rather than trying to import the
Rdb_key_def::INDEX_NUMBER_SIZE header (was causing a lot of
errors on the defination of other orders). If the constant
does change can be assured that the same compile warnings will
tell us of the error.

The ha_rocksdb::index_read_map_impl DBUG_EXECUTE_IF was similar
to the existing endless functions used in replication tests.
Its rather moot point as the rocksdb.force_shutdown test that
uses myrocks_busy_loop_on_row_read is currently disabled.
2023-01-10 17:10:43 +00:00
lilinjie
758c24dae2 fix typos
Signed-off-by: lilinjie <lilinjie@uniontech.com>
2023-01-05 07:57:51 +11:00
Oleksandr Byelkin
60f646e2f3 MDEV-29988: (spider fix) Major performance regression with 10.6.11
Make Item_direct_ref_to_item transparent for Spider
2023-01-02 00:04:03 +01:00
Marko Mäkelä
72e2d1d220 MDEV-25004 Refactorings
* Avoid some pessimization
  * Slightly smaller upgrade dataset
  * Simplify vers_row_same_trx() and its caller
2022-12-27 00:02:02 +03:00
Aleksey Midenkov
e056efdd6c MDEV-25004 Missing row in FTS_DOC_ID_INDEX during DELETE HISTORY
1. In case of system-versioned table add row_end into FTS_DOC_ID index
   in fts_create_common_tables() and innobase_create_key_defs().
   fts_n_uniq() returns 1 or 2 depending on whether the table is
   system-versioned.

   After this patch recreate of FTS_DOC_ID index is required for
   existing system-versioned tables. If you see this message in error
   log or server warnings: "InnoDB: Table db/t1 contains 2 indexes
   inside InnoDB, which is different from the number of indexes 1
   defined in the MariaDB" use this command to fix the table:

      ALTER TABLE db.t1 FORCE;

2. Fix duplicate history for secondary unique index like it was done
   in MDEV-23644 for clustered index (932ec586aa). In case of
   existing history row which conflicts with currently inseted row we
   check in row_ins_scan_sec_index_for_duplicate() whether that row
   was inserted as part of current transaction. In that case we
   indicate with DB_FOREIGN_DUPLICATE_KEY that new history row is not
   needed and should be silently skipped.

3. Some parts of MDEV-21138 (7410ff436e) reverted. Skipping of
   FTS_DOC_ID index for history rows made problems with purge
   system. Now this is fixed differently by p.2.

4. wait_all_purged.inc checks that we didn't affect non-history rows
   so they are deleted and purged correctly.

Additional FTS fixes

  fts_init_get_doc_id(): exclude history rows from max_doc_id
  calculation. fts_init_get_doc_id() callback is used only for crash
  recovery.

  fts_add_doc_by_id(): set max value for row_end field.

  fts_read_stopword(): stopwords table can be system-versioned too. We
  now read stopwords only for current data.

  row_insert_for_mysql(): exclude history rows from doc_id validation.

  row_merge_read_clustered_index(): exclude history_rows from doc_id
  processing.

  fts_load_user_stopword(): for versioned table retrieve row_end field
  and skip history rows. For non-versioned table we retrieve 'value'
  field twice (just for uniformity).

FTS tests for System Versioning now include maybe_versioning.inc which
adds 3 combinations:

'vers'     for debug build sets sysvers_force and
	   sysvers_hide. sysvers_force makes every created table
	   system-versioned, sysvers_hide hides WITH SYSTEM VERSIONING
	   for SHOW CREATE.

	   Note: basic.test, stopword.test and versioning.test do not
	   require debug for 'vers' combination. This is controlled by
	   $modify_create_table in maybe_versioning.inc and these
	   tests run WITH SYSTEM VERSIONING explicitly which allows to
	   test 'vers' combination on non-debug builds.

'vers_trx' like 'vers' sets sysvers_force_trx and sysvers_hide. That
	   tests FTS with trx_id-based System Versioning.

'orig' 	   works like before: no System Versioning is added, no debug is
	   required.

Upgrade/downgrade test for System Versioning is done by
innodb_fts.versioning. It has 2 combinations:

'prepare' makes binaries in std_data (requires old server and OLD_BINDIR).
	  It tests upgrade/downgrade against old server as well.

'upgrade' tests upgrade against binaries in std_data.

Cleanups:

Removed innodb-fts-stopword.test as it duplicates stopword.test
2022-12-27 00:02:02 +03:00
Aleksey Midenkov
5d506ac201 MDEV-25004 vers_force_trx option to force transactional System Versioning
Works like vers_force but forces trx_id-based system-versioned tables
if the storage supports it (currently InnoDB-only). Otherwise creates
timestamp-based system-versioned table.
2022-12-27 00:02:01 +03:00
musvaage
7c5609fb64 typos 2022-12-21 12:46:52 +11:00
Vlad Lesin
3ddc00dc3b MDEV-30225 RR isolation violation with locking unique search
Before the fix next-key lock was requested only if a record was
delete-marked for locking unique search in RR isolation level.
There can be several delete-marked records for the same unique key,
that's why InnoDB scans the records until eighter non-delete-marked record
is reached or all delete-marked records with the same unique key are
scanned.

For range scan next-key locks are used for RR to protect scanned range from
inserting new records by other transactions. And this is the reason of why
next-key locks are used for delete-marked records for unique searches.

If a record is not delete-marked, the requested lock type was "not-gap".
When a record is not delete-marked during lock request by trx 1, and
some other transaction holds conflicting lock, trx 1 creates waiting
not-gap lock on the record and suspends. During trx 1 suspending the
record can be delete-marked. And when the lock is granted on conflicting
transaction commit or rollback, its type is still "not-gap". So we have
"not-gap" lock on delete-marked record for RR. And this let some other
transaction to insert some record with the same unique key when trx 1 is
not committed, what can cause isolation level violation.

The fix is to set next-key locks for both delete-marked and
non-delete-marked records for unique search in RR.
2022-12-20 11:31:49 +03:00
Yuchen Pei
3f63aa18a7
MDEV-29562 Spider table charset error should happen correctly.
When trying to create a spider table with banned charsets including
utf32, utf16, ucs2 and utf16le[1], spider should emit an error
immediately, rather than wait until a separate statement that
establishes a connection (e.g. SELECT). This also applies to ALTER
TABLE statement that changes charsets.

[1] https://mariadb.com/kb/en/server-system-variables/#character_set_client

Signed-off-by: Yuchen Pei <yuchen.pei@mariadb.com>
Reviewed-by: Nayuta Yanagisawa <nayuta.yanagisawa@mariadb.com>
2022-12-20 13:08:49 +11:00
Marko Mäkelä
782b2a7500 MDEV-29144 ER_TABLE_SCHEMA_MISMATCH or crash on DISCARD/IMPORT
mysql_discard_or_import_tablespace(): On successful
ALTER TABLE...DISCARD TABLESPACE, evict the table handle from the
table definition cache, so that ha_innobase::close() will be invoked,
like InnoDB expects to be the case. This will avoid an assertion failure
ut_a(table->get_ref_count() == 0) during IMPORT TABLESPACE.

ha_innobase::open(): Do not issue any ER_TABLESPACE_DISCARDED warning.
Member functions for DML will do that.

ha_innobase::truncate(), ha_innobase::check_if_supported_inplace_alter():
Issue ER_TABLESPACE_DISCARDED warnings, to compensate for the removal of
the warning in ha_innobase::open().

row_quiesce_write_indexes(): Only write information about committed
indexes. The ALTER TABLE t NOWAIT ADD INDEX(c) in the nondeterministic
test case will most of the time fail due to a metadata lock (MDL) timeout
and leave behind an uncommitted index.

Reviewed by: Sergei Golubchik
2022-12-09 10:42:19 +02:00
Nayuta Yanagisawa
2beede9ba4 MDEV-29636 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed in ha_partition::set_auto_increment_if_higher upon REPLACE with partition pruning
The bug is caused by a similar mechanism as MDEV-21027.

The function, check_insert_or_replace_autoincrement, failed to open
all the partitions on REPLACE SELECT statements and it results in the
assertion error.
2022-12-07 16:34:56 +09:00
Sergei Golubchik
d08f2ab6d6 MDEV-28855 SEGV around dict_free_vc_templ during DROP INDEX
protect shared dict_table_t::vc_templ with a mutex,
same as in ha_innobase::open
2022-12-02 16:19:12 +01:00
Sergei Golubchik
4fb8f7d07a cleanup: clarify innobase_init_vc_templ usage 2022-12-02 16:19:12 +01:00
Anel Husakovic
6c973be2e9 MDEV-28299: Server crashes in XINDXS::Range/CntIndexRange (Connect engine)
- Bug happens only in case when the range function on empty key single
column index (XINDEXS) is used.
- Solution is to return with empty result in this scenario.

Reviewed by: <>
2022-11-29 19:44:18 +00:00
Nayuta Yanagisawa
4e9206736c MDEV-28996 ASAN errors in String::q_append / spider_string::q_append / spider_db_mbase_util::open_item_func
The server crashed due to the stack-use-after-scope on tmp_str.
tmp_str will be used later so should not point to the local buffer.
2022-11-28 04:38:18 +09:00
Nayuta Yanagisawa
162c150505 MDEV-29855 Crash with SPIDER_DIRECT_SQL and spider_udf_ds_use_real_table=1
The crash occurs because of the following call of TABLE_LIST::init_one_table():

  table_list.init_one_table(
    &table_list.db, &table_list.table_name, 0, TL_WRITE);

One should not pass table_list.db and table_list.table_name to the function
because it update the very members internally.

The function is called previously, and there is no need to call it again.
So, simply removing the call will resolve the problem.
2022-11-24 17:11:41 +09:00
Thirunarayanan Balathandayuthapani
71c93fb8fd MDEV-28462 Race condition between instant alter and AHI access
- InnoDB AHI tries to access the concurrent instant alter column,
leads to asan failure. Instant alter column should acquire the
clustered index search latch in exclusive mode before changing
the table cache definition.

- Removed the default parameter for the function
btr_search_drop_page_hash_index()

- Addressed the DWITH_INNODB_AHI=0 compilation failure
by passing two parameters from all callers of
btr_search_drop_page_hash_index()
2022-11-22 15:24:44 +05:30
Alexander Barkov
6216a2dfa2 MDEV-29473 UBSAN: Signed integer overflow: X * Y cannot be represented in type 'int' in strings/dtoa.c
Fixing a few problems relealed by UBSAN in type_float.test

- multiplication overflow in dtoa.c

- uninitialized Field::geom_type (and Field::srid as well)

- Wrong call-back function types used in combination with SHOW_FUNC.
  Changes in the mysql_show_var_func data type definition were not
  properly addressed all around the code by the following commits:
    b4ff64568c
    18feb62fee
    0ee879ff8a

  Adding a helper SHOW_FUNC_ENTRY() function and replacing
  all mysql_show_var_func declarations using SHOW_FUNC
  to SHOW_FUNC_ENTRY, to catch mysql_show_var_func in the future
  at compilation time.
2022-11-17 17:51:01 +04:00
Thirunarayanan Balathandayuthapani
df4c3d96a4 MDEV-29977 Memory leak in row_log_table_apply_update
- InnoDB fails to free the persistent cursor for the clustered index
when InnoDB replays the update operation on the table that is
being rebuilt.
2022-11-15 12:16:40 +05:30
Andrew Hutchings
043c1d1830 MDEV-28489 CONNECT used incorrect CHAR length
CONNECT engine was using dividing UTF8 columns by 3 to get the length,
but in reality it did need the byte length.

This fixes MDEV-26722 too.
2022-11-11 11:30:09 +11:00
Daniel Black
dc6a017111 MDEV-27882 Innodb - recognise MySQL-8.0 innodb flags and give a specific error message
Per fsp0types.h, SDI is on tablespace flags position 14 where MariaDB
stores its pagesize. Flag at position 13, also in MariaDB pagesize
flags, is a MySQL encryption flag.

These are checked only if fsp_flags_is_valid fails, so valid MariaDB
pages sizes don't become errors.

The error message "Cannot reset LSNs in table" was rather specific and
not always true to replaced with more generic error.

ALTER TABLE tbl IMPORT TABLESPACE now reports Unsupported on MySQL
tablespace (rather than index corrupted) along with a server error
message.

MySQL innodb Errors are with with UNSUPPORTED rather than CORRUPTED
to avoid user anxiety.

Reviewer: Marko Mäkelä
2022-11-11 10:21:28 +11:00
Marko Mäkelä
6b91792a08 MDEV-29883 Deadlock between InnoDB statistics update and BLOB insert
This is a backport of commit 8b6a308e46
from MariaDB Server 10.6.11. No attempt to reproduce the hang
in earlier an earlier version of MariaDB Server than 10.6 was made.

In each caller of fseg_n_reserved_pages() except ibuf_init_at_db_start()
which is a special case for ibuf.index at database startup, we must hold
an index latch that prevents concurrent allocation or freeing of index
pages.

Any operation that allocates or free pages that belong to an index tree
must first acquire an index latch in non-shared mode, and while
holding that, acquire an index root page latch in non-shared mode.

btr_get_size(), btr_get_size_and_reserved(): Assert that a strong enough
index latch is being held.

dict_stats_update_transient_for_index(),
dict_stats_analyze_index(): Acquire a strong enough index latch.

These operations had followed the same order of acquiring latches in
every InnoDB version since the very beginning
(commit c533308a15).

The hang was introduced in
commit 2e814d4702 which imported
mysql/mysql-server@ac74632293
which failed to strengthen the locking requirements of the function
btr_get_size().
2022-11-09 09:23:18 +02:00
Andrew Hutchings
fda5846704
MDEV-29397 CONNECT engine: Fix note turning into error (#2325)
* MDEV-29397 Fix note turning into error

ODBC Rewind triggered an error with no SQL, but this is sometimes a
valid condition (as can be seen with other classes). Setting this to a 0
return stops errors firing when they shouldn't.

Also fixes ASAN hits from in MDEV-29687 tabext.cpp.
2022-11-08 15:49:52 +00:00
Marko Mäkelä
2ef2e2322a MDEV-29856 heap-use-after-poison in row_merge_spatial_rows() w/ column prefix
spatial_index_info: Replaces index_tuple_info_t. Always take
a memory heap as a parameter to the member functions.
Remove pointer indirection for m_dtuple_vec.

spatial_index_info::add(): Duplicate any PRIMARY KEY fields that would
point to within ext->buf because that buffer will be allocated in
a shorter-lifetime memory heap.
2022-11-08 15:26:34 +02:00
Marko Mäkelä
b737d09dbc MDEV-29905 Change buffer operations fail to check for log file overflow
Every operation that is going to write redo log is supposed to
invoke log_free_check() before acquiring any latches. If there
is a risk of log buffer overrun, a log checkpoint would be
triggered by that call.

ibuf_merge_space(), ibuf_merge_in_background(),
ibuf_delete_for_discarded_space(): Invoke log_free_check()
when the current thread is not holding any page latches.

Unfortunately, in lower-level code called from ibuf_insert()
or ibuf_merge_or_delete_for_page(), some page latches may be
held and a call to log_free_check() could hang.

ibuf_set_bitmap_for_bulk_load(): Use the caller's mini-transaction.
The caller should have invoked log_free_check() while not holding
any page latches.
2022-11-08 11:37:43 +02:00
Marko Mäkelä
49a0ad695b MDEV-23371: Crash in _db_doprnt_ via que_thr_step()
Something appears to be broken in the DBUG subsystem.
Let us remove frequent calls to it from the InnoDB internal SQL interpreter
that is used in the purge of transaction history.

The DBUG_PRINT in que_eval_sql() can remain for now, because those
operations are much less frequent.
2022-11-08 11:24:49 +02:00
Marko Mäkelä
9ac8be4e29 Include some advice in the crash-upgrade message 2022-11-08 10:39:29 +02:00
Marko Mäkelä
456d4a508c Remove an unused file
The file plugin_exports became unused in
commit fec844aca8
2022-11-08 08:54:07 +02:00
Marko Mäkelä
eabb3b35d5 MDEV-27121 fixup: mariabackup.mdev-14447 fault injection 2022-11-08 08:53:49 +02:00
Andrew Hutchings
fa5f26b422 MDEV-29578 Fix CONNECT build warnings
Fix a couple of build warnings that fire with CONNECT engine.
2022-10-26 16:50:46 +11:00
Brad Smith
055cb3fcd1 Rocksdb: Add initial OpenBSD support 2022-10-26 15:33:10 +11:00
Lawrin Novitsky
1ff476b415 MDEV-29490 Renaming internally used client API to avoid name conflicts
with C/C.
The patch introduces mariadb_capi_rename.h which is included into
mysql.h. The hew header contains macro definitions for the names being
renamed. In versions 10.6+(i.e. where sql service exists) the renaming
condition in the mariadb_capi_rename.h should be added with
&& !defined(MYSQL_DYNAMIC_PLUGIN)
and look like
The patch also contains removal of mysql.h from the api check.

Disabling false_duper-6543 test for embedded.

ha_federated.so uses C API. C API functions are being renamed in the server,
but not renamed in embedded, since embedded server library should have proper
C API, as expected by programs using it.
Thus the same ha_federated.so cannot work both for server and embedded
server library.

As all federated tests are already disabled for embedded,
federated isn't supposed to work for embedded anyway, and thus the test
is being disabled.
2022-10-25 14:00:21 +02:00
Sergei Golubchik
16d4431ab6 CONNECT: compile with libxml2 2.10.x
storage/connect/libdoc.cpp:603:17: error: 'void xmlXPathInit()' is deprecated [-Werror=deprecated-declarations]
2022-10-22 11:48:45 +02:00
Anel
0c06320ae9
MDEV-29687:ODBC tables do not quote identifier names correctly (#2295)
Reviewer: andrew@mariadb.org
2022-10-21 13:26:06 +01:00
Thirunarayanan Balathandayuthapani
e1414fc7e3 MDEV-29778 Having Unique index interference with MATCH from a FULLTEXT
InnoDB fails to fetch FTS_DOC_ID if the select query uses secondary
index. So always do extra lookup on clustered index in case of fts
query
2022-10-21 09:54:46 +03:00
Anel
b20f608d4f
Update ODBC instructions for Connect SE and update ODBC result file (#2284)
* ODBC Connect cosmetic fixes

- Update command for connection for default `peer` authentication for user
`postgres` (unless changed in `pg_hba.conf`).
- Update command for privilege to be more verbose.
- Update path for `.sql` file
- Update instructions for `pg_hba.conf` file to use unix socket
(`local`) type as well as TCP/IP type `host`.
- Update instruction about usage of user dsn (data source file) over
system dsn.
- Update path of `odbc-postgresql` driver path in comment

* Connect SE: update ODBC result file
2022-10-16 19:38:04 +01:00
Marko Mäkelä
78030b67b9 Do not use C++11 before MariaDB 10.4
This fixes up 3d9b350a9c
2022-10-14 11:54:05 +03:00
Marko Mäkelä
3d9b350a9c Fix clang -Wunused-but-set-variable 2022-10-14 11:00:34 +03:00
Nikita Malyavin
128356b4b1 MDEV-29753 An error is wrongly reported during INSERT with vcol index
See also commits aa8a31da and 64678c for a Bug #22990029 fix.

In this scenario INSERT chose to check if delete unmarking is available for
a just deleted record. To build an update vector, it needed to calculate
the vcols as well. Since this INSERT was not IGNORE-flagged, recalculation
failed.

Solutiuon: temporarily set abort_on_warning=true, while calculating the
column for delete-unmarked insert.
2022-10-12 20:49:45 +03:00
Nikita Malyavin
3cd2c1e8b6 MDEV-29299 SELECT from table with vcol index reports warning
As of now innodb does not store trx_id for each record in secondary index.
The idea behind is following: let us store only per-page max_trx_id, and
delete-mark the records when they are deleted/updated.

If the read starts, it rememders the lowest id of currently active
transaction. Innodb refers to it as trx->read_view->m_up_limit_id.
See also ReadView::open.

When the page is fetched, its max_trx_id is compared to m_up_limit_id.
If the value is lower, and the secondary index record is not delete-marked,
then this page is just safe to read as is. Else, a clustered index could be
needed ato access. See page_get_max_trx_id call in row_search_mvcc, and the
corresponding switch (row_search_idx_cond_check(...)) below.

Virtual columns are required to be updated in case if the record was
delete-marked. The motivation behind it is documented in
Row_sel_get_clust_rec_for_mysql::operator() near
row_sel_sec_rec_is_for_clust_rec call.

This was basically a description why virtual column computation can
normally happen during SELECT, and, generally, a vcol index access.

Sometimes stats tables are updated by innodb. This starts a new
transaction, and it can happen that it didn't finish to the moment of
SELECT execution, forcing virtual columns recomputation. If the result was
a something that normally outputs a warning, like division by zero, then
it could be outputted in a racy manner.

The solution is to suppress the warnings when a column is computed
for the described purpose.
ignore_wrnings argument is added innobase_get_computed_value.
Currently, it is only true for a call from
row_sel_sec_rec_is_for_clust_rec.
2022-10-12 20:49:45 +03:00
Marko Mäkelä
e05ab0cfc5 Silence clang 13 -Wunused-but-set-variable for Bison 2022-10-10 09:36:43 +03:00
Marko Mäkelä
56b97ca03a MDEV-29742 heap number overflow
A previous fix in commit efd8af535a
failed to cover ALTER TABLE.

PageBulk::isSpaceAvailable(): Check for record heap number overflow.
2022-10-10 09:12:55 +03:00
Vlad Lesin
c0eda62aec MDEV-27927 row_sel_try_search_shortcut_for_mysql() does not latch a page, violating read view isolation
btr_search_guess_on_hash() would only acquire an index page latch if it
is invoked with ahi_latch=NULL. If it's invoked from
row_sel_try_search_shortcut_for_mysql() with ahi_latch!=NULL, a page
will not be latched, and row_search_mvcc() will get a pointer to the
record, which can be changed by some other transaction before the record
was stored in result buffer with row_sel_store_mysql_rec() call.

ahi_latch argument of btr_cur_search_to_nth_level_func() and
btr_pcur_open_with_no_init_func() is used only for
row_sel_try_search_shortcut_for_mysql().
btr_cur_search_to_nth_level_func(..., ahi_latch !=0, ...) is invoked
only from btr_pcur_open_with_no_init_func(..., ahi_latch !=0, ...),
which, in turns, is invoked only from
row_sel_try_search_shortcut_for_mysql().

I suppose that separate case with ahi_latch!=0 was intentionally
implemented to protect row_sel_store_mysql_rec() call in
row_search_mvcc() just after row_sel_try_search_shortcut_for_mysql()
call. After the ahi_latch was moved from row_seach_mvcc() to
row_sel_try_search_shortcut_for_mysql(), there is no need in it at all
if btr_search_guess_on_hash() latches a page unconditionally. And if
btr_search_guess_on_hash() latched the page, any access to the record in
row_sel_try_search_shortcut_for_mysql() after btr_pcur_open_with_no_init()
call will be protected with the page latch.

The fix is to remove ahi_latch argument from
btr_pcur_open_with_no_init_func(), btr_cur_search_to_nth_level_func()
and btr_search_guess_on_hash().

There will not be test, as to test it we need to freeze some SELECT
execution in the point between row_sel_try_search_shortcut_for_mysql()
and row_sel_store_mysql_rec() calls in row_search_mvcc(), and to change
the record in some other transaction to let row_sel_store_mysql_rec() to
store changed record in result buffer. Buf we can't do this with the
fix, as the page will be latched in btr_search_guess_on_hash() call.
2022-10-05 17:35:21 +03:00
Marko Mäkelä
1562b2c20b MDEV-29666 InnoDB fails to purge secondary index records when indexed virtual columns exist
row_purge_get_partial(): Replaces trx_undo_rec_get_partial_row().
Also copy the purge_node_t::ref to the purge_node_t::row.
In this way, the clustered index key fields will always be
available, even if thanks to
commit d384ead0f0 (MDEV-14799)
they would no longer be repeated in the remaining part of the
undo log record.
2022-10-05 09:30:33 +03:00
Vlad Lesin
c0817dac99 MDEV-29575 Access to innodb_trx, innodb_locks and innodb_lock_waits along with detached XA's can cause SIGSEGV
trx->mysql_thd can be zeroed-out between thd_get_thread_id() and
thd_query_safe() calls in fill_trx_row(). trx_disconnect_prepared() zeroes out
trx->mysql_thd. And this can cause null pointer dereferencing in
fill_trx_row().

fill_trx_row() is invoked from fetch_data_into_cache() under trx_sys.mutex.

Bug fix is in reseting trx_t::mysql_thd in trx_disconnect_prepared() under
trx_sys.mutex lock too.

MTR test case can't be created for the fix, as we need to wait for
trx_t::mysql_thd reseting in fill_trx_row() after trx_t::mysql_thd was
checked for null while trx_sys.mutex is held. But trx_t::mysql_thd must be
reset in trx_disconnect_prepared() under trx_sys.mutex. There will be deadlock.
2022-10-03 14:41:06 +03:00