Skip to content

Commit 26d4623

Browse files
committed
MDEV-28478: INSERT into SPATIAL INDEX in TEMPORARY table writes log
This is based on commit 20ae481 with some adjustments for MDEV-12353. row_ins_sec_index_entry_low(): If a separate mini-transaction is needed to adjust the minimum bounding rectangle (MBR) in the parent page, we must disable redo logging if the table is a temporary table. For temporary tables, no log is supposed to be written, because the temporary tablespace will be reinitialized on server restart. rtr_update_mbr_field(), rtr_merge_and_update_mbr(): Changed the return type to void and removed unreachable code. In older versions, these used to return a different value for temporary tables. page_id_t: Add constexpr to most member functions. mtr_t::log_write(): Catch log writes to invalid tablespaces so that the test case would crash without the fix to row_ins_sec_index_entry_low().
1 parent 1421d1f commit 26d4623

File tree

11 files changed

+87
-92
lines changed

11 files changed

+87
-92
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,3 @@ select count(*) from t1 where MBRWithin(t1.c2, @g1);
6161
count(*)
6262
57344
6363
drop table t1;
64-
#
65-
# MDEV-27417 Spatial index tries to update
66-
# change buffer bookkeeping page
67-
#
68-
CREATE TEMPORARY TABLE t1 (c POINT NOT NULL, SPATIAL(c)) ENGINE=InnoDB;
69-
INSERT INTO t1 SELECT PointFromText('POINT(0 0)') FROM seq_1_to_366;
70-
DROP TABLE t1;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# MDEV-27417 Spatial index tries to update
3+
# change buffer bookkeeping page
4+
#
5+
CREATE TEMPORARY TABLE t1 (c POINT NOT NULL, SPATIAL(c)) ENGINE=InnoDB;
6+
INSERT INTO t1 SELECT PointFromText('POINT(0 0)') FROM seq_1_to_366;
7+
DROP TABLE t1;
8+
#
9+
# MDEV-28478 Assertion mtr->get_log_mode() == MTR_LOG_NO_REDO
10+
#
11+
CREATE TEMPORARY TABLE t1 (c POINT NOT NULL,SPATIAL (c)) ENGINE=InnoDB;
12+
INSERT INTO t1 SELECT POINT(0,0) FROM seq_1_to_366;
13+
INSERT INTO t1 VALUES (POINT(1e-270,1e-130));
14+
DROP TABLE t1;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,3 @@ select count(*) from t1 where MBRWithin(t1.c2, @g1);
7373

7474
# Clean up.
7575
drop table t1;
76-
77-
--echo #
78-
--echo # MDEV-27417 Spatial index tries to update
79-
--echo # change buffer bookkeeping page
80-
--echo #
81-
CREATE TEMPORARY TABLE t1 (c POINT NOT NULL, SPATIAL(c)) ENGINE=InnoDB;
82-
INSERT INTO t1 SELECT PointFromText('POINT(0 0)') FROM seq_1_to_366;
83-
DROP TABLE t1;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--source include/have_innodb.inc
2+
--source include/have_sequence.inc
3+
4+
--echo #
5+
--echo # MDEV-27417 Spatial index tries to update
6+
--echo # change buffer bookkeeping page
7+
--echo #
8+
CREATE TEMPORARY TABLE t1 (c POINT NOT NULL, SPATIAL(c)) ENGINE=InnoDB;
9+
INSERT INTO t1 SELECT PointFromText('POINT(0 0)') FROM seq_1_to_366;
10+
DROP TABLE t1;
11+
12+
--echo #
13+
--echo # MDEV-28478 Assertion mtr->get_log_mode() == MTR_LOG_NO_REDO
14+
--echo #
15+
CREATE TEMPORARY TABLE t1 (c POINT NOT NULL,SPATIAL (c)) ENGINE=InnoDB;
16+
INSERT INTO t1 SELECT POINT(0,0) FROM seq_1_to_366;
17+
INSERT INTO t1 VALUES (POINT(1e-270,1e-130));
18+
DROP TABLE t1;

storage/innobase/btr/btr0btr.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,17 +3588,9 @@ btr_compress(
35883588
}
35893589

35903590
if (mbr_changed) {
3591-
#ifdef UNIV_DEBUG
3592-
bool success = rtr_update_mbr_field(
3593-
&cursor2, offsets2, &father_cursor,
3594-
merge_page, &new_mbr, NULL, mtr);
3595-
3596-
ut_ad(success);
3597-
#else
35983591
rtr_update_mbr_field(
35993592
&cursor2, offsets2, &father_cursor,
36003593
merge_page, &new_mbr, NULL, mtr);
3601-
#endif
36023594
} else {
36033595
rtr_node_ptr_delete(&father_cursor, mtr);
36043596
}

storage/innobase/btr/btr0cur.cc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5834,7 +5834,6 @@ btr_cur_pessimistic_delete(
58345834
rec_t* father_rec;
58355835
btr_cur_t father_cursor;
58365836
rec_offs* offsets;
5837-
bool upd_ret;
58385837
ulint len;
58395838

58405839
rtr_page_get_father_block(NULL, heap, index,
@@ -5848,17 +5847,8 @@ btr_cur_pessimistic_delete(
58485847
rtr_read_mbr(rec_get_nth_field(
58495848
father_rec, offsets, 0, &len), &father_mbr);
58505849

5851-
upd_ret = rtr_update_mbr_field(&father_cursor, offsets,
5852-
NULL, page, &father_mbr,
5853-
next_rec, mtr);
5854-
5855-
if (!upd_ret) {
5856-
*err = DB_ERROR;
5857-
5858-
mem_heap_free(heap);
5859-
return(FALSE);
5860-
}
5861-
5850+
rtr_update_mbr_field(&father_cursor, offsets, NULL,
5851+
page, &father_mbr, next_rec, mtr);
58625852
ut_d(parent_latched = true);
58635853
} else {
58645854
/* Otherwise, if we delete the leftmost node pointer

storage/innobase/gis/gis0rtree.cc

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/*****************************************************************************
22
33
Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
4+
<<<<<<< HEAD
45
Copyright (c) 2018, 2021, MariaDB Corporation.
6+
||||||| parent of 20ae4816bba (MDEV-28478: INSERT into SPATIAL INDEX in TEMPORARY table writes log)
7+
Copyright (c) 2019, 2020, MariaDB Corporation.
8+
=======
9+
Copyright (c) 2019, 2022, MariaDB Corporation.
10+
>>>>>>> 20ae4816bba (MDEV-28478: INSERT into SPATIAL INDEX in TEMPORARY table writes log)
511
612
This program is free software; you can redistribute it and/or modify it under
713
the terms of the GNU General Public License as published by the Free Software
@@ -185,9 +191,8 @@ rtr_index_build_node_ptr(
185191
}
186192

187193
/**************************************************************//**
188-
Update the mbr field of a spatial index row.
189-
@return true if update is successful */
190-
bool
194+
Update the mbr field of a spatial index row. */
195+
void
191196
rtr_update_mbr_field(
192197
/*=================*/
193198
btr_cur_t* cursor, /*!< in/out: cursor pointed to rec.*/
@@ -535,8 +540,6 @@ rtr_update_mbr_field(
535540
page_is_comp(page))));
536541

537542
mem_heap_free(heap);
538-
539-
return(true);
540543
}
541544

542545
/**************************************************************//**
@@ -1264,12 +1267,8 @@ rtr_ins_enlarge_mbr(
12641267
page = buf_block_get_frame(block);
12651268

12661269
/* Update the mbr field of the rec. */
1267-
if (!rtr_update_mbr_field(&cursor, offsets, NULL, page,
1268-
&new_mbr, NULL, mtr)) {
1269-
err = DB_ERROR;
1270-
break;
1271-
}
1272-
1270+
rtr_update_mbr_field(&cursor, offsets, NULL, page,
1271+
&new_mbr, NULL, mtr);
12731272
page_cursor = btr_cur_get_page_cur(&cursor);
12741273
block = page_cur_get_block(page_cursor);
12751274
}
@@ -1579,7 +1578,7 @@ rtr_merge_mbr_changed(
15791578

15801579
/****************************************************************//**
15811580
Merge 2 mbrs and update the the mbr that cursor is on. */
1582-
dberr_t
1581+
void
15831582
rtr_merge_and_update_mbr(
15841583
/*=====================*/
15851584
btr_cur_t* cursor, /*!< in/out: cursor */
@@ -1589,27 +1588,15 @@ rtr_merge_and_update_mbr(
15891588
page_t* child_page, /*!< in: the page. */
15901589
mtr_t* mtr) /*!< in: mtr */
15911590
{
1592-
dberr_t err = DB_SUCCESS;
15931591
rtr_mbr_t new_mbr;
1594-
bool changed = false;
1595-
1596-
ut_ad(dict_index_is_spatial(cursor->index));
15971592

1598-
changed = rtr_merge_mbr_changed(cursor, cursor2, offsets, offsets2,
1599-
&new_mbr);
1600-
1601-
/* Update the mbr field of the rec. And will delete the record
1602-
pointed by cursor2 */
1603-
if (changed) {
1604-
if (!rtr_update_mbr_field(cursor, offsets, cursor2, child_page,
1605-
&new_mbr, NULL, mtr)) {
1606-
err = DB_ERROR;
1607-
}
1593+
if (rtr_merge_mbr_changed(cursor, cursor2, offsets, offsets2,
1594+
&new_mbr)) {
1595+
rtr_update_mbr_field(cursor, offsets, cursor2, child_page,
1596+
&new_mbr, NULL, mtr);
16081597
} else {
16091598
rtr_node_ptr_delete(cursor2, mtr);
16101599
}
1611-
1612-
return(err);
16131600
}
16141601

16151602
/*************************************************************//**

storage/innobase/include/buf0types.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ The database buffer pool global types for the directory
2424
Created 11/17/1995 Heikki Tuuri
2525
*******************************************************/
2626

27-
#ifndef buf0types_h
28-
#define buf0types_h
29-
27+
#pragma once
3028
#include "univ.i"
3129

3230
/** Buffer page (uncompressed or compressed) */
@@ -122,18 +120,22 @@ class page_id_t
122120
/** Constructor from (space, page_no).
123121
@param[in] space tablespace id
124122
@param[in] page_no page number */
125-
page_id_t(ulint space, uint32_t page_no) : m_id(uint64_t{space} << 32 | page_no)
126-
{
127-
ut_ad(space <= 0xFFFFFFFFU);
128-
}
129-
130-
page_id_t(uint64_t id) : m_id(id) {}
131-
bool operator==(const page_id_t& rhs) const { return m_id == rhs.m_id; }
132-
bool operator!=(const page_id_t& rhs) const { return m_id != rhs.m_id; }
133-
bool operator<(const page_id_t& rhs) const { return m_id < rhs.m_id; }
134-
bool operator>(const page_id_t& rhs) const { return m_id > rhs.m_id; }
135-
bool operator<=(const page_id_t& rhs) const { return m_id <= rhs.m_id; }
136-
bool operator>=(const page_id_t& rhs) const { return m_id >= rhs.m_id; }
123+
constexpr page_id_t(ulint space, uint32_t page_no) :
124+
m_id(uint64_t{space} << 32 | page_no) {}
125+
126+
constexpr page_id_t(uint64_t id) : m_id(id) {}
127+
constexpr bool operator==(const page_id_t& rhs) const
128+
{ return m_id == rhs.m_id; }
129+
constexpr bool operator!=(const page_id_t& rhs) const
130+
{ return m_id != rhs.m_id; }
131+
constexpr bool operator<(const page_id_t& rhs) const
132+
{ return m_id < rhs.m_id; }
133+
constexpr bool operator>(const page_id_t& rhs) const
134+
{ return m_id > rhs.m_id; }
135+
constexpr bool operator<=(const page_id_t& rhs) const
136+
{ return m_id <= rhs.m_id; }
137+
constexpr bool operator>=(const page_id_t& rhs) const
138+
{ return m_id >= rhs.m_id; }
137139
page_id_t &operator--() { ut_ad(page_no()); m_id--; return *this; }
138140
page_id_t &operator++()
139141
{
@@ -154,15 +156,16 @@ class page_id_t
154156

155157
/** Retrieve the tablespace id.
156158
@return tablespace id */
157-
uint32_t space() const { return static_cast<uint32_t>(m_id >> 32); }
159+
constexpr uint32_t space() const { return static_cast<uint32_t>(m_id >> 32); }
158160

159161
/** Retrieve the page number.
160162
@return page number */
161-
uint32_t page_no() const { return static_cast<uint32_t>(m_id); }
163+
constexpr uint32_t page_no() const { return static_cast<uint32_t>(m_id); }
162164

163165
/** Retrieve the fold value.
164166
@return fold value */
165-
ulint fold() const { return (ulint{space()} << 20) + space() + page_no(); }
167+
constexpr ulint fold() const
168+
{ return (ulint{space()} << 20) + space() + page_no(); }
166169

167170
/** Reset the page number only.
168171
@param[in] page_no page number */
@@ -171,7 +174,8 @@ class page_id_t
171174
m_id= (m_id & ~uint64_t{0} << 32) | page_no;
172175
}
173176

174-
ulonglong raw() { return m_id; }
177+
constexpr ulonglong raw() { return m_id; }
178+
175179
private:
176180
/** The page identifier */
177181
uint64_t m_id;
@@ -221,5 +225,3 @@ class page_hash_latch : public rw_lock
221225
};
222226

223227
#endif /* !UNIV_INNOCHECKSUM */
224-
225-
#endif /* buf0types.h */

storage/innobase/include/gis0rtree.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ rtr_page_copy_rec_list_start_no_locks(
379379

380380
/****************************************************************//**
381381
Merge 2 mbrs and update the the mbr that cursor is on. */
382-
dberr_t
382+
void
383383
rtr_merge_and_update_mbr(
384384
/*=====================*/
385385
btr_cur_t* cursor, /*!< in/out: cursor */
@@ -411,9 +411,8 @@ rtr_merge_mbr_changed(
411411

412412

413413
/**************************************************************//**
414-
Update the mbr field of a spatial index row.
415-
@return true if successful */
416-
bool
414+
Update the mbr field of a spatial index row. */
415+
void
417416
rtr_update_mbr_field(
418417
/*=================*/
419418
btr_cur_t* cursor, /*!< in: cursor pointed to rec.*/

storage/innobase/include/mtr0log.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2019, 2020, MariaDB Corporation.
3+
Copyright (c) 2019, 2022, MariaDB Corporation.
44
55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -24,6 +24,9 @@ Mini-transaction log record encoding and decoding
2424
#pragma once
2525
#include "mtr0mtr.h"
2626

27+
/** The smallest invalid page identifier for persistent tablespaces */
28+
constexpr page_id_t end_page_id{SRV_SPACE_ID_UPPER_BOUND, 0};
29+
2730
/** The minimum 2-byte integer (0b10xxxxxx xxxxxxxx) */
2831
constexpr uint32_t MIN_2BYTE= 1 << 7;
2932
/** The minimum 3-byte integer (0b110xxxxx xxxxxxxx xxxxxxxx) */
@@ -388,6 +391,7 @@ inline byte *mtr_t::log_write(const page_id_t id, const buf_page_t *bpage,
388391
type <= FILE_CHECKPOINT, "invalid type");
389392
ut_ad(type >= FILE_CREATE || is_named_space(id.space()));
390393
ut_ad(!bpage || bpage->id() == id);
394+
ut_ad(id < end_page_id);
391395
constexpr bool have_len= type != INIT_PAGE && type != FREE_PAGE;
392396
constexpr bool have_offset= type == WRITE || type == MEMSET ||
393397
type == MEMMOVE;

0 commit comments

Comments
 (0)