@@ -4991,8 +4991,6 @@ class btr_est_cur_t
4991
4991
page_id_t m_page_id;
4992
4992
/* * Current block */
4993
4993
buf_block_t *m_block;
4994
- /* * mtr savepoint of the current block */
4995
- ulint m_savepoint;
4996
4994
/* * Page search mode, can differ from m_mode for non-leaf pages, see c-tor
4997
4995
comments for details */
4998
4996
page_cur_mode_t m_page_mode;
@@ -5051,17 +5049,17 @@ class btr_est_cur_t
5051
5049
bool fetch_child (ulint level, mtr_t &mtr, const buf_block_t *right_parent)
5052
5050
{
5053
5051
buf_block_t *parent_block= m_block;
5054
- ulint parent_savepoint= m_savepoint;
5055
5052
5056
5053
m_block= btr_block_get (*index (), m_page_id.page_no (), RW_S_LATCH, !level,
5057
5054
&mtr, nullptr );
5058
5055
if (!m_block)
5059
5056
return false ;
5060
5057
5061
5058
if (parent_block && parent_block != right_parent)
5062
- mtr.rollback_to_savepoint (parent_savepoint, parent_savepoint + 1 );
5063
-
5064
- m_savepoint= mtr.get_savepoint () - 1 ;
5059
+ {
5060
+ ut_ad (mtr.get_savepoint () >= 2 );
5061
+ mtr.rollback_to_savepoint (1 , 2 );
5062
+ }
5065
5063
5066
5064
return level == ULINT_UNDEFINED ||
5067
5065
btr_page_get_level (m_block->page .frame ) == level;
@@ -5123,10 +5121,10 @@ class btr_est_cur_t
5123
5121
return true ;
5124
5122
}
5125
5123
5126
- /* * Gets page id of the current record child.
5124
+ /* * Read page id of the current record child.
5127
5125
@param offsets offsets array.
5128
5126
@param heap heap for offsets array */
5129
- void get_child (rec_offs **offsets, mem_heap_t **heap)
5127
+ void read_child_page_id (rec_offs **offsets, mem_heap_t **heap)
5130
5128
{
5131
5129
const rec_t *node_ptr= page_cur_get_rec (&m_page_cur);
5132
5130
@@ -5196,11 +5194,7 @@ class btr_est_cur_t
5196
5194
/* * Copies block pointer and savepoint from another btr_est_cur_t in the case
5197
5195
if both left and right border cursors point to the same block.
5198
5196
@param o reference to the other btr_est_cur_t object. */
5199
- void set_block (const btr_est_cur_t &o)
5200
- {
5201
- m_block= o.m_block ;
5202
- m_savepoint= o.m_savepoint ;
5203
- }
5197
+ void set_block (const btr_est_cur_t &o) { m_block= o.m_block ; }
5204
5198
5205
5199
/* * @return current record number. */
5206
5200
ulint nth_rec () const { return m_nth_rec; }
@@ -5239,7 +5233,6 @@ static ha_rows btr_estimate_n_rows_in_range_on_level(
5239
5233
pages before reaching right_page_no, then we estimate the average from the
5240
5234
pages scanned so far. */
5241
5235
static constexpr uint n_pages_read_limit= 9 ;
5242
- ulint savepoint= 0 ;
5243
5236
buf_block_t *block= nullptr ;
5244
5237
const dict_index_t *index= left_cur.index ();
5245
5238
@@ -5269,19 +5262,18 @@ static ha_rows btr_estimate_n_rows_in_range_on_level(
5269
5262
{
5270
5263
page_t *page;
5271
5264
buf_block_t *prev_block= block;
5272
- ulint prev_savepoint= savepoint;
5273
-
5274
- savepoint= mtr.get_savepoint ();
5275
5265
5276
5266
/* Fetch the page. */
5277
5267
block= btr_block_get (*index, page_id.page_no (), RW_S_LATCH, !level, &mtr,
5278
5268
nullptr );
5279
5269
5280
5270
if (prev_block)
5281
5271
{
5282
- mtr.rollback_to_savepoint (prev_savepoint, prev_savepoint + 1 );
5283
- if (block)
5284
- savepoint--;
5272
+ ulint savepoint = mtr.get_savepoint ();
5273
+ /* Index s-lock, p1, p2 latches, can also be p1 and p2 parent latch if
5274
+ they are not diverged */
5275
+ ut_ad (savepoint >= 3 );
5276
+ mtr.rollback_to_savepoint (savepoint - 2 , savepoint - 1 );
5285
5277
}
5286
5278
5287
5279
if (!block || btr_page_get_level (buf_block_get_frame (block)) != level)
@@ -5312,8 +5304,8 @@ static ha_rows btr_estimate_n_rows_in_range_on_level(
5312
5304
5313
5305
if (block)
5314
5306
{
5315
- ut_ad (block == mtr.at_savepoint (savepoint ));
5316
- mtr.rollback_to_savepoint (savepoint, savepoint + 1 );
5307
+ ut_ad (block == mtr.at_savepoint (mtr. get_savepoint () - 1 ));
5308
+ mtr.rollback_to_savepoint (mtr. get_savepoint () - 1 );
5317
5309
}
5318
5310
5319
5311
return (n_rows);
@@ -5322,8 +5314,8 @@ static ha_rows btr_estimate_n_rows_in_range_on_level(
5322
5314
5323
5315
if (block)
5324
5316
{
5325
- ut_ad (block == mtr.at_savepoint (savepoint ));
5326
- mtr.rollback_to_savepoint (savepoint, savepoint + 1 );
5317
+ ut_ad (block == mtr.at_savepoint (mtr. get_savepoint () - 1 ));
5318
+ mtr.rollback_to_savepoint (mtr. get_savepoint () - 1 );
5327
5319
}
5328
5320
5329
5321
is_n_rows_exact= false ;
@@ -5517,8 +5509,12 @@ ha_rows btr_estimate_n_rows_in_range(dict_index_t *index,
5517
5509
{
5518
5510
ut_ad (height > 0 );
5519
5511
height--;
5520
- p1.get_child (&offsets, &heap);
5521
- p2.get_child (&offsets, &heap);
5512
+ ut_ad (mtr.memo_contains (p1.index ()->lock , MTR_MEMO_S_LOCK));
5513
+ ut_ad (mtr.memo_contains_flagged (p1.block (), MTR_MEMO_PAGE_S_FIX));
5514
+ p1.read_child_page_id (&offsets, &heap);
5515
+ ut_ad (mtr.memo_contains (p2.index ()->lock , MTR_MEMO_S_LOCK));
5516
+ ut_ad (mtr.memo_contains_flagged (p2.block (), MTR_MEMO_PAGE_S_FIX));
5517
+ p2.read_child_page_id (&offsets, &heap);
5522
5518
goto search_loop;
5523
5519
}
5524
5520
0 commit comments