Skip to content

Commit 0fe52ea

Browse files
author
Nisha Gopalakrishnan
committed
Bug#37189985: Crashing and widespread corruption of spatial indexes
after INPLACE alter table ANALYSIS ALTER TABLE, INPLACE operation on a table containing both a spatial index and an auto increment column can cause corruption. This is due to auto increment column value getting overwritten in the old records of spatial index while preparing the new record. The records are accessed through a cursor, cached into a tuple vector m_dtuple_vec in the index_tuple_info_t::add(). The row is built with shallow copying of fields, and the auto-increment value is prepared locally and copied. This process repeats until page traversal is complete. In subsequent iterations, shallow-copied pointers are overwritten, but since the source record remains intact and page is latched, they stay valid. The row continues to reference the old auto-incremented value, causing only the auto-increment field to be overwritten, and older rows to point to the latest auto-incremented value. FIX Perform deep copy of the auto-increment field while processing the spatial index records. Note: This is a 5.7 patch. Change-Id: Ib8852ef5977d881bf06dadcc35d41acfa760c96f
1 parent 551288b commit 0fe52ea

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

storage/innobase/row/row0merge.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2005, 2023, Oracle and/or its affiliates.
3+
Copyright (c) 2005, 2024, Oracle and/or its affiliates.
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License, version 2.0,
@@ -2093,9 +2093,15 @@ row_merge_read_clustered_index(
20932093
ut_ad(add_autoinc
20942094
< dict_table_get_n_user_cols(new_table));
20952095

2096-
const dfield_t* dfield;
2096+
dfield_t *dfield = dtuple_get_nth_field(row, add_autoinc);
2097+
if (num_spatial > 0) {
2098+
/* Perform a deep copy of the field because for
2099+
spatial indexes, the default tuple allocation is
2100+
overwritten, as tuples are processed at the end
2101+
of the page. */
2102+
dfield_dup(dfield, sp_heap);
2103+
}
20972104

2098-
dfield = dtuple_get_nth_field(row, add_autoinc);
20992105
if (dfield_is_null(dfield)) {
21002106
goto write_buffers;
21012107
}

0 commit comments

Comments
 (0)