Skip to content

Commit 7635faf

Browse files
committed
Revert "[storage/innobase] PS-9144 : Missing rows after ALGORITHM=INPLACE ALTER under same workload as PS-9092"
This reverts commit 4614f68.
1 parent 05658fd commit 7635faf

File tree

4 files changed

+73
-50
lines changed

4 files changed

+73
-50
lines changed

mysql-test/suite/innodb/r/percona_alter_debug.result

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
#
2-
# Test for PS-9144 : Missing rows after ALGORITHM=INPLACE ALTER under
3-
# same workload as PS-9092.
2+
# Test for PS-9214 : Alter table online results in "duplicate key"
3+
# error on the primary key (only index).
44
#
55
CREATE TABLE t1 (pk CHAR(5) PRIMARY KEY);
6-
INSERT INTO t1 VALUES ('aaaaa'), ('bbbbb'), ('bbbcc'), ('ccccc'), ('ddddd'), ('eeeee');
7-
set global innodb_purge_stop_now=ON;
8-
DELETE FROM t1 WHERE pk = 'bbbcc';
6+
INSERT INTO t1 VALUES ('aaaaa'), ('bbbbb'), ('ccccc'), ('ddddd'), ('eeeee');
97
connect con1, localhost, root,,;
108
SET DEBUG='+d,ddl_buf_add_two';
119
SET DEBUG_SYNC='ddl_bulk_inserter_latches_released SIGNAL latches_released WAIT_FOR go';
1210
# Send ALTER TABLE INPLACE which rebuilds table.
1311
ALTER TABLE t1 ENGINE=InnoDB, ALGORITHM=INPLACE;
1412
connection default;
1513
SET DEBUG_SYNC='now WAIT_FOR latches_released';
16-
SET GLOBAL innodb_purge_run_now=ON;
14+
INSERT INTO t1 VALUES ('ccaaa');
1715
SET DEBUG_SYNC='now SIGNAL go';
1816
connection con1;
1917
# Reap ALTER TABLE
20-
# Before the fix row 'ddddd' was missing from the table after ALTER.
21-
SELECT * FROM t1;
22-
pk
23-
aaaaa
24-
bbbbb
25-
ccccc
26-
ddddd
27-
eeeee
18+
# Before fix it failed with duplicate key error.
2819
SET DEBUG='-d,ddl_buf_add_two';
2920
disconnect con1;
3021
connection default;
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# Tests in this file use both debug-only facilities as well as debug sync point.
22
--source include/have_debug.inc
33
--source include/have_debug_sync.inc
4+
--enable_connect_log
45

56
--echo #
6-
--echo # Test for PS-9144 : Missing rows after ALGORITHM=INPLACE ALTER under
7-
--echo # same workload as PS-9092.
7+
--echo # Test for PS-9214 : Alter table online results in "duplicate key"
8+
--echo # error on the primary key (only index).
89
--echo #
9-
--enable_connect_log
1010
CREATE TABLE t1 (pk CHAR(5) PRIMARY KEY);
11-
INSERT INTO t1 VALUES ('aaaaa'), ('bbbbb'), ('bbbcc'), ('ccccc'), ('ddddd'), ('eeeee');
12-
13-
set global innodb_purge_stop_now=ON;
14-
DELETE FROM t1 WHERE pk = 'bbbcc';
11+
INSERT INTO t1 VALUES ('aaaaa'), ('bbbbb'), ('ccccc'), ('ddddd'), ('eeeee');
1512

1613
--connect (con1, localhost, root,,)
1714
SET DEBUG='+d,ddl_buf_add_two';
@@ -21,17 +18,14 @@ SET DEBUG_SYNC='ddl_bulk_inserter_latches_released SIGNAL latches_released WAIT_
2118

2219
--connection default
2320
SET DEBUG_SYNC='now WAIT_FOR latches_released';
24-
SET GLOBAL innodb_purge_run_now=ON;
25-
--source include/wait_innodb_all_purged.inc
21+
INSERT INTO t1 VALUES ('ccaaa');
2622
SET DEBUG_SYNC='now SIGNAL go';
2723

2824
--connection con1
2925
--echo # Reap ALTER TABLE
26+
--echo # Before fix it failed with duplicate key error.
3027
--reap
3128

32-
--echo # Before the fix row 'ddddd' was missing from the table after ALTER.
33-
SELECT * FROM t1;
34-
3529
SET DEBUG='-d,ddl_buf_add_two';
3630

3731
--disconnect con1
@@ -41,4 +35,5 @@ SET DEBUG='-d,ddl_buf_add_two';
4135
--echo # Cleanup.
4236
SET DEBUG_SYNC= 'RESET';
4337
DROP TABLE t1;
38+
4439
--disable_connect_log

storage/innobase/ddl/ddl0par-scan.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ dberr_t Parallel_cursor::scan(Builders &builders) noexcept {
237237
thread_ctx->get_state() != Parallel_reader::State::THREAD) {
238238
thread_ctx->savepoint();
239239
latches_released = true;
240-
DEBUG_SYNC_C("ddl_bulk_inserter_latches_released");
241240
}
242241
return DB_SUCCESS;
243242
});

storage/innobase/row/row0pread.cc

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -215,27 +215,6 @@ class PCursor {
215215
PCursor(btr_pcur_t *pcur, mtr_t *mtr, size_t read_level)
216216
: m_mtr(mtr), m_pcur(pcur), m_read_level(read_level) {}
217217

218-
/**
219-
Restore position of cursor created from Scan_ctx::Range object.
220-
Adjust it if starting record of range has been purged.
221-
*/
222-
void restore_position_for_range() noexcept {
223-
/*
224-
Restore position on the record or its predecessor if the record
225-
was purged meanwhile. In the latter case we need to adjust position by
226-
moving one step forward as predecessor belongs to another range.
227-
228-
We rely on return value from restore_position() to detect this scenario.
229-
This can be done when saved position points to user record which is
230-
always the case for saved start of Scan_ctx::Range.
231-
*/
232-
ut_ad(m_pcur->m_rel_pos == BTR_PCUR_ON);
233-
234-
if (!m_pcur->restore_position(BTR_SEARCH_LEAF, m_mtr, UT_LOCATION_HERE)) {
235-
page_cur_move_to_next(m_pcur->get_page_cur());
236-
}
237-
}
238-
239218
/** Create a savepoint and commit the mini-transaction.*/
240219
void savepoint() noexcept;
241220

@@ -247,6 +226,65 @@ class PCursor {
247226
@return DB_SUCCESS or error code. */
248227
[[nodiscard]] dberr_t move_to_next_block(dict_index_t *index);
249228

229+
/** Restore the cursor position. */
230+
void restore_position() noexcept {
231+
constexpr auto MODE = BTR_SEARCH_LEAF;
232+
const auto relative = m_pcur->m_rel_pos;
233+
auto equal = m_pcur->restore_position(MODE, m_mtr, UT_LOCATION_HERE);
234+
235+
#ifdef UNIV_DEBUG
236+
if (m_pcur->m_pos_state == BTR_PCUR_IS_POSITIONED_OPTIMISTIC) {
237+
ut_ad(m_pcur->m_rel_pos == BTR_PCUR_BEFORE ||
238+
m_pcur->m_rel_pos == BTR_PCUR_AFTER);
239+
} else {
240+
ut_ad(m_pcur->m_pos_state == BTR_PCUR_IS_POSITIONED);
241+
ut_ad((m_pcur->m_rel_pos == BTR_PCUR_ON) == m_pcur->is_on_user_rec());
242+
}
243+
#endif /* UNIV_DEBUG */
244+
245+
switch (relative) {
246+
case BTR_PCUR_ON:
247+
if (!equal) {
248+
page_cur_move_to_next(m_pcur->get_page_cur());
249+
}
250+
break;
251+
252+
case BTR_PCUR_UNSET:
253+
case BTR_PCUR_BEFORE_FIRST_IN_TREE:
254+
ut_error;
255+
break;
256+
257+
case BTR_PCUR_AFTER:
258+
case BTR_PCUR_AFTER_LAST_IN_TREE:
259+
break;
260+
261+
case BTR_PCUR_BEFORE:
262+
/* For non-optimistic restoration:
263+
The position is now set to the record before pcur->old_rec.
264+
265+
For optimistic restoration:
266+
The position also needs to take the previous search_mode into
267+
consideration. */
268+
switch (m_pcur->m_pos_state) {
269+
case BTR_PCUR_IS_POSITIONED_OPTIMISTIC:
270+
m_pcur->m_pos_state = BTR_PCUR_IS_POSITIONED;
271+
/* The cursor always moves "up" ie. in ascending order. */
272+
break;
273+
274+
case BTR_PCUR_IS_POSITIONED:
275+
if (m_pcur->is_on_user_rec()) {
276+
m_pcur->move_to_next(m_mtr);
277+
}
278+
break;
279+
280+
case BTR_PCUR_NOT_POSITIONED:
281+
case BTR_PCUR_WAS_POSITIONED:
282+
ut_error;
283+
}
284+
break;
285+
}
286+
}
287+
250288
/** @return the current page cursor. */
251289
[[nodiscard]] page_cur_t *get_page_cursor() noexcept {
252290
return m_pcur->get_page_cur();
@@ -310,7 +348,7 @@ void PCursor::resume() noexcept {
310348
/* Restore position on the record, or its predecessor if the record
311349
was purged meanwhile. */
312350

313-
m_pcur->restore_position(BTR_SEARCH_LEAF, m_mtr, UT_LOCATION_HERE);
351+
restore_position();
314352

315353
if (!m_pcur->is_after_last_on_page()) {
316354
/* Move to the successor of the saved record. */
@@ -588,7 +626,7 @@ dberr_t Parallel_reader::Ctx::traverse() {
588626
auto &from = m_range.first;
589627

590628
PCursor pcursor(from->m_pcur, &mtr, m_scan_ctx->m_config.m_read_level);
591-
pcursor.restore_position_for_range();
629+
pcursor.restore_position();
592630

593631
dberr_t err{DB_SUCCESS};
594632

0 commit comments

Comments
 (0)