Skip to content

Commit 0b6b7d2

Browse files
MDEV-35420 Server aborts while deleting the record in spatial index
- This issue caused by commit a032f14(MDEV-33559). In MDEV-33559, matched_rec::block was changed to pointer and assinged with the help of buf_block_alloc(). But patch fails to check for the block can be nullptr in rtr_check_discard_page(). rtr_cur_search_with_match(): Acquire rtr_match_mutex before creating shadow block for the matched records rtr_pcur_move_to_next(): Copy the shadow block to page cursor block under rtr_match_mutex
1 parent 868bc46 commit 0b6b7d2

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

mysql-test/suite/innodb_gis/r/rollback.result

+13
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,16 @@ update t1 set a=point(5,5), b=point(5,5), c=5 where i < 3;
412412
ERROR HY000: Lost connection to MySQL server during query
413413
insert into t1 values(5, point(5,5), point(5,5), 5);
414414
drop table t1;
415+
#
416+
# MDEV-35420 Server aborts while deleting the record
417+
# in spatial index
418+
#
419+
CREATE TABLE t1 (c POINT NOT NULL, SPATIAL(c)) engine=InnoDB;
420+
CHECK TABLE t1;
421+
Table Op Msg_type Msg_text
422+
test.t1 check status OK
423+
SET STATEMENT unique_checks=0,foreign_key_checks=0 FOR
424+
START TRANSACTION;
425+
INSERT INTO t1 SELECT ST_GeomFromText('POINT(114368751 656950466)') FROM seq_1_to_512;
426+
ROLLBACK;
427+
DROP TABLE t1;

mysql-test/suite/innodb_gis/t/rollback.test

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Avoid CrashReporter popup on Mac
99
--source include/not_crashrep.inc
1010
--source include/have_innodb_16k.inc
11+
--source include/have_sequence.inc
1112

1213
CREATE TABLE t4 (id bigint(12) unsigned NOT NULL auto_increment,
1314
c2 varchar(15) collate utf8_bin default NULL,
@@ -475,3 +476,15 @@ update t1 set a=point(5,5), b=point(5,5), c=5 where i < 3;
475476
insert into t1 values(5, point(5,5), point(5,5), 5);
476477

477478
drop table t1;
479+
480+
--echo #
481+
--echo # MDEV-35420 Server aborts while deleting the record
482+
--echo # in spatial index
483+
--echo #
484+
CREATE TABLE t1 (c POINT NOT NULL, SPATIAL(c)) engine=InnoDB;
485+
CHECK TABLE t1;
486+
SET STATEMENT unique_checks=0,foreign_key_checks=0 FOR
487+
START TRANSACTION;
488+
INSERT INTO t1 SELECT ST_GeomFromText('POINT(114368751 656950466)') FROM seq_1_to_512;
489+
ROLLBACK;
490+
DROP TABLE t1;

storage/innobase/gis/gis0sea.cc

+18-8
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,10 @@ rtr_pcur_move_to_next(
495495
rtr_rec_t rec;
496496
rec = rtr_info->matches->matched_recs->back();
497497
rtr_info->matches->matched_recs->pop_back();
498+
cursor->btr_cur.page_cur.block = rtr_info->matches->block;
498499
mutex_exit(&rtr_info->matches->rtr_match_mutex);
499500

500501
cursor->btr_cur.page_cur.rec = rec.r_rec;
501-
cursor->btr_cur.page_cur.block = rtr_info->matches->block;
502502

503503
DEBUG_SYNC_C("rtr_pcur_move_to_next_return");
504504
return(true);
@@ -1204,8 +1204,11 @@ rtr_check_discard_page(
12041204
if (rtr_info->matches) {
12051205
mutex_enter(&rtr_info->matches->rtr_match_mutex);
12061206

1207-
if (rtr_info->matches->block->page.id().page_no()
1208-
== pageno) {
1207+
/* matches->block could be nullptr when cursor
1208+
encounters empty table */
1209+
if (rtr_info->matches->block
1210+
&& rtr_info->matches->block->page.id().page_no()
1211+
== pageno) {
12091212
if (!rtr_info->matches->matched_recs->empty()) {
12101213
rtr_info->matches->matched_recs->clear();
12111214
}
@@ -1849,21 +1852,28 @@ rtr_cur_search_with_match(
18491852
ut_ad(orig_mode
18501853
!= PAGE_CUR_RTREE_LOCATE);
18511854

1855+
/* Collect matched records on page */
1856+
offsets = rec_get_offsets(
1857+
rec, index, offsets,
1858+
index->n_fields,
1859+
ULINT_UNDEFINED, &heap);
1860+
1861+
mutex_enter(
1862+
&rtr_info->matches->rtr_match_mutex);
1863+
18521864
if (!match_init) {
18531865
rtr_init_match(
18541866
rtr_info->matches,
18551867
block, page);
18561868
match_init = true;
18571869
}
18581870

1859-
/* Collect matched records on page */
1860-
offsets = rec_get_offsets(
1861-
rec, index, offsets,
1862-
index->n_fields,
1863-
ULINT_UNDEFINED, &heap);
18641871
rtr_leaf_push_match_rec(
18651872
rec, rtr_info, offsets,
18661873
page_is_comp(page));
1874+
1875+
mutex_exit(
1876+
&rtr_info->matches->rtr_match_mutex);
18671877
}
18681878

18691879
last_match_rec = rec;

0 commit comments

Comments
 (0)