mirror of
				https://github.com/MariaDB/server.git
				synced 2025-11-04 04:46:15 +01:00 
			
		
		
		
	btr_cur_t: Zero-initialize all fields in the default constructor. btr_cur_t::index: Remove; it duplicated page_cur.index. Many functions: Remove arguments that were duplicating page_cur_t::index and page_cur_t::block. page_cur_open_level(), btr_pcur_open_level(): Replaces btr_cur_open_at_index_side() for dict_stats_analyze_index(). At the end, release all latches except the dict_index_t::lock and the buf_page_t::lock on the requested page. dict_stats_analyze_index(): Rely on mtr_t::rollback_to_savepoint() to release all uninteresting page latches. btr_search_guess_on_hash(): Simplify the logic, and invoke mtr_t::rollback_to_savepoint(). We will use plain C++ std::vector<mtr_memo_slot_t> for mtr_t::m_memo. In this way, we can avoid setting mtr_memo_slot_t::object to nullptr and instead just remove garbage from m_memo. mtr_t::rollback_to_savepoint(): Shrink the vector. We will be needing this in dict_stats_analyze_index(), where we will release page latches and only retain the index->lock in mtr_t::m_memo. mtr_t::release_last_page(): Release the last acquired page latch. Replaces btr_leaf_page_release(). mtr_t::release(const buf_block_t&): Release a single page latch. Used in btr_pcur_move_backward_from_page(). mtr_t::memo_release(): Replaced with mtr_t::release(). mtr_t::upgrade_buffer_fix(): Acquire a latch for a buffer-fixed page. This replaces the double bookkeeping in btr_cur_t::open_leaf(). Reviewed by: Vladislav Lesin
		
			
				
	
	
		
			111 lines
		
	
	
	
		
			3.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
	
		
			3.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*****************************************************************************
 | 
						|
 | 
						|
Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
 | 
						|
Copyright (c) 2015, 2022, MariaDB Corporation.
 | 
						|
 | 
						|
This program is free software; you can redistribute it and/or modify it under
 | 
						|
the terms of the GNU General Public License as published by the Free Software
 | 
						|
Foundation; version 2 of the License.
 | 
						|
 | 
						|
This program is distributed in the hope that it will be useful, but WITHOUT
 | 
						|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 | 
						|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 | 
						|
 | 
						|
You should have received a copy of the GNU General Public License along with
 | 
						|
this program; if not, write to the Free Software Foundation, Inc.,
 | 
						|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
 | 
						|
 | 
						|
*****************************************************************************/
 | 
						|
 | 
						|
/**************************************************//**
 | 
						|
@file include/btr0btr.ic
 | 
						|
The B-tree
 | 
						|
 | 
						|
Created 6/2/1994 Heikki Tuuri
 | 
						|
*******************************************************/
 | 
						|
 | 
						|
#include "mtr0log.h"
 | 
						|
 | 
						|
/**************************************************************//**
 | 
						|
Gets the index id field of a page.
 | 
						|
@return index id */
 | 
						|
UNIV_INLINE
 | 
						|
index_id_t
 | 
						|
btr_page_get_index_id(
 | 
						|
/*==================*/
 | 
						|
	const page_t*	page)	/*!< in: index page */
 | 
						|
{
 | 
						|
	return(mach_read_from_8(page + PAGE_HEADER + PAGE_INDEX_ID));
 | 
						|
}
 | 
						|
 | 
						|
/** Set PAGE_LEVEL.
 | 
						|
@param[in,out]  block  buffer block
 | 
						|
@param[in]      level  page level
 | 
						|
@param[in,out]  mtr    mini-transaction */
 | 
						|
inline
 | 
						|
void btr_page_set_level(buf_block_t *block, ulint level, mtr_t *mtr)
 | 
						|
{
 | 
						|
  ut_ad(level <= BTR_MAX_NODE_LEVEL);
 | 
						|
  constexpr uint16_t field= PAGE_HEADER + PAGE_LEVEL;
 | 
						|
  byte *b= my_assume_aligned<2>(&block->page.frame[field]);
 | 
						|
  if (mtr->write<2,mtr_t::MAYBE_NOP>(*block, b, level) &&
 | 
						|
      UNIV_LIKELY_NULL(block->page.zip.data))
 | 
						|
    memcpy_aligned<2>(&block->page.zip.data[field], b, 2);
 | 
						|
}
 | 
						|
 | 
						|
/** Set FIL_PAGE_NEXT.
 | 
						|
@param[in,out]  block  buffer block
 | 
						|
@param[in]      next   number of successor page
 | 
						|
@param[in,out]  mtr    mini-transaction */
 | 
						|
inline void btr_page_set_next(buf_block_t *block, ulint next, mtr_t *mtr)
 | 
						|
{
 | 
						|
  constexpr uint16_t field= FIL_PAGE_NEXT;
 | 
						|
  byte *b= my_assume_aligned<4>(&block->page.frame[field]);
 | 
						|
  if (mtr->write<4,mtr_t::MAYBE_NOP>(*block, b, next) &&
 | 
						|
      UNIV_LIKELY_NULL(block->page.zip.data))
 | 
						|
    memcpy_aligned<4>(&block->page.zip.data[field], b, 4);
 | 
						|
}
 | 
						|
 | 
						|
/** Set FIL_PAGE_PREV.
 | 
						|
@param[in,out]  block  buffer block
 | 
						|
@param[in]      prev   number of predecessor page
 | 
						|
@param[in,out]  mtr    mini-transaction */
 | 
						|
inline void btr_page_set_prev(buf_block_t *block, ulint prev, mtr_t *mtr)
 | 
						|
{
 | 
						|
  constexpr uint16_t field= FIL_PAGE_PREV;
 | 
						|
  byte *b= my_assume_aligned<4>(&block->page.frame[field]);
 | 
						|
  if (mtr->write<4,mtr_t::MAYBE_NOP>(*block, b, prev) &&
 | 
						|
      UNIV_LIKELY_NULL(block->page.zip.data))
 | 
						|
    memcpy_aligned<4>(&block->page.zip.data[field], b, 4);
 | 
						|
}
 | 
						|
 | 
						|
/**************************************************************//**
 | 
						|
Gets the child node file address in a node pointer.
 | 
						|
NOTE: the offsets array must contain all offsets for the record since
 | 
						|
we read the last field according to offsets and assume that it contains
 | 
						|
the child page number. In other words offsets must have been retrieved
 | 
						|
with rec_get_offsets(n_fields=ULINT_UNDEFINED).
 | 
						|
@return child node address */
 | 
						|
UNIV_INLINE
 | 
						|
uint32_t
 | 
						|
btr_node_ptr_get_child_page_no(
 | 
						|
/*===========================*/
 | 
						|
	const rec_t*	rec,	/*!< in: node pointer record */
 | 
						|
	const rec_offs*	offsets)/*!< in: array returned by rec_get_offsets() */
 | 
						|
{
 | 
						|
	const byte*	field;
 | 
						|
	ulint		len;
 | 
						|
 | 
						|
	ut_ad(!rec_offs_comp(offsets) || rec_get_node_ptr_flag(rec));
 | 
						|
 | 
						|
	/* The child address is in the last field */
 | 
						|
	field = rec_get_nth_field(rec, offsets,
 | 
						|
				  rec_offs_n_fields(offsets) - 1, &len);
 | 
						|
 | 
						|
	ut_ad(len == 4);
 | 
						|
 | 
						|
	uint32_t page_no = mach_read_from_4(field);
 | 
						|
	ut_ad(page_no > 1);
 | 
						|
 | 
						|
	return(page_no);
 | 
						|
}
 |