Skip to content

Commit 1e7d451

Browse files
committed
MDEV-37404 InnoDB: Failing assertion: node->pcur->rel_pos == BTR_PCUR_ON
Caused by optimization done in 2e2b2a0. Cannot use lookup_handler in default branch of locate_dup_record() as InnoDB update depends on positioned record and update is done in table main handler. The patch reverts some non-pure changes done by 2e2b2a0 to original logic from 72429ca. There was no long_unique_table condition to init search on table->file, so we get into default branch with long unique and table->file search uninitialized. ha_rnd_init_with_error() on demand for HA_DUPLICATE_POS branch was original logic as well. More info: 2e2b2a0 reverts 5e34528, but it seems to be OK as MDEV-3888 test case passes. mysql-5.6.13 has the original code with HA_WHOLE_KEY as well.
1 parent 32e9871 commit 1e7d451

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

mysql-test/main/long_unique_bugs.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,3 +843,11 @@ insert into t (a) values (1);
843843
update t set a=2;
844844
drop table t;
845845
# End of 10.6 tests
846+
#
847+
# MDEV-37404 InnoDB: Failing assertion: node->pcur->rel_pos == BTR_PCUR_ON
848+
#
849+
create table t(c int primary key, c2 blob unique) engine=innodb;
850+
insert into t values (0, '');
851+
replace into t values (0, '123');
852+
drop table t;
853+
# End of 10.11 tests

mysql-test/main/long_unique_bugs.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,3 +767,13 @@ update t set a=2;
767767
drop table t;
768768

769769
--echo # End of 10.6 tests
770+
771+
--echo #
772+
--echo # MDEV-37404 InnoDB: Failing assertion: node->pcur->rel_pos == BTR_PCUR_ON
773+
--echo #
774+
create table t(c int primary key, c2 blob unique) engine=innodb;
775+
insert into t values (0, '');
776+
replace into t values (0, '123');
777+
drop table t;
778+
779+
--echo # End of 10.11 tests

sql/sql_insert.cc

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,7 @@ int prepare_for_replace(TABLE *table, enum_duplicates handle_duplicates,
702702
{
703703
create_lookup_handler= true;
704704
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
705-
if (table->file->ha_table_flags() & HA_DUPLICATE_POS ||
706-
table->s->long_unique_table)
705+
if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
707706
{
708707
if (table->file->ha_rnd_init_with_error(false))
709708
return 1;
@@ -2018,28 +2017,34 @@ int vers_insert_history_row(TABLE *table)
20182017
*/
20192018
int Write_record::locate_dup_record()
20202019
{
2021-
handler *h= table->file;
20222020
int error= 0;
2023-
if (h->ha_table_flags() & HA_DUPLICATE_POS || h->lookup_errkey != (uint)-1)
2021+
if (table->file->ha_table_flags() & HA_DUPLICATE_POS ||
2022+
table->file->lookup_errkey != (uint)-1)
20242023
{
20252024
DBUG_PRINT("info", ("Locating offending record using rnd_pos()"));
20262025

2027-
error= h->ha_rnd_pos(table->record[1], h->dup_ref);
2026+
const bool init_lookup_handler= (table->file->inited == handler::NONE);
2027+
if (init_lookup_handler)
2028+
{
2029+
error= table->file->ha_rnd_init_with_error(false);
2030+
if (error)
2031+
return error;
2032+
}
2033+
error= table->file->ha_rnd_pos(table->record[1], table->file->dup_ref);
2034+
if (init_lookup_handler)
2035+
table->file->ha_rnd_end();
20282036
if (unlikely(error))
20292037
{
20302038
DBUG_PRINT("info", ("rnd_pos() returns error %d",error));
2031-
h->print_error(error, MYF(0));
2039+
table->file->print_error(error, MYF(0));
20322040
}
20332041
}
20342042
else
20352043
{
20362044
DBUG_PRINT("info",
20372045
("Locating offending record using ha_index_read_idx_map"));
20382046

2039-
if (h->lookup_handler)
2040-
h= h->lookup_handler;
2041-
2042-
error= h->extra(HA_EXTRA_FLUSH_CACHE);
2047+
error= table->file->extra(HA_EXTRA_FLUSH_CACHE);
20432048
if (unlikely(error))
20442049
{
20452050
DBUG_PRINT("info",("Error when setting HA_EXTRA_FLUSH_CACHE"));
@@ -2058,12 +2063,12 @@ int Write_record::locate_dup_record()
20582063

20592064
key_copy(key, table->record[0], table->key_info + key_nr, 0);
20602065

2061-
error= h->ha_index_read_idx_map(table->record[1], key_nr, key,
2066+
error= table->file->ha_index_read_idx_map(table->record[1], key_nr, key,
20622067
HA_WHOLE_KEY, HA_READ_KEY_EXACT);
20632068
if (unlikely(error))
20642069
{
20652070
DBUG_PRINT("info", ("index_read_idx() returns %d", error));
2066-
h->print_error(error, MYF(0));
2071+
table->file->print_error(error, MYF(0));
20672072
}
20682073
}
20692074

0 commit comments

Comments
 (0)