Skip to content

Commit

Permalink
MDEV-35312 page_cur_search_with_match() could avoid rec_get_offsets()
Browse files Browse the repository at this point in the history
page_cur_search_with_match(): Remove rec_get_offsets(), and instead
determine the start and end of each field while comparing.

page_dir_slot_get_rec(), page_dir_slot_get_rec_validate():
Add a parameter to avoid invoking page_align().

page_cur_dtuple_cmp(): Replaces cmp_dtuple_rec_leaf() for both
leaf and non-leaf pages. In SPATIAL INDEX, non-leaf records are
special, because the child page number may be part of the comparison.

Reviewed by: Vladislav Lesin
  • Loading branch information
dr-m committed Jan 10, 2025
1 parent 793a2fc commit 3761a7f
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 278 deletions.
31 changes: 13 additions & 18 deletions storage/innobase/include/page0cur.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,18 @@ bool page_apply_delete_dynamic(const buf_block_t &block, ulint prev,
size_t hdr_size, size_t data_size);

MY_ATTRIBUTE((warn_unused_result))
/****************************************************************//**
Searches the right position for a page cursor. */
bool
page_cur_search_with_match(
/*=======================*/
const dtuple_t* tuple, /*!< in: data tuple */
page_cur_mode_t mode, /*!< in: PAGE_CUR_L,
PAGE_CUR_LE, PAGE_CUR_G, or
PAGE_CUR_GE */
uint16_t* iup_matched_fields,
/*!< in/out: already matched
fields in upper limit record */
uint16_t* ilow_matched_fields,
/*!< in/out: already matched
fields in lower limit record */
page_cur_t* cursor, /*!< in/out: page cursor */
rtr_info_t* rtr_info);/*!< in/out: rtree search stack */
/** Search the right position for a page cursor.
@param tuple search key
@param mode search mode
@param iup_fields matched fields in the upper limit record
@param ilow_fields matched fields in the low limit record
@param cursor page cursor
@param rtr_info R-tree search stack, or nullptr
@return whether the page is corrupted */
bool page_cur_search_with_match(const dtuple_t *tuple, page_cur_mode_t mode,
uint16_t *iup_fields, uint16_t *ilow_fields,
page_cur_t *cursor, rtr_info_t *rtr_info)
noexcept;

/** Search the right position for a page cursor.
@param tuple search key
Expand All @@ -238,7 +233,7 @@ page_cur_search_with_match(
@param cursor page cursor
@param iup_bytes matched bytes after iup_fields
@param ilow_bytes matched bytes after ilow_fields
@return whether the first partially matched field in the lower limit record,
@return whether the first partially matched field is in the lower limit record,
or the page is corrupted */
bool page_cur_search_with_match_bytes(const dtuple_t &tuple,
page_cur_mode_t mode,
Expand Down
38 changes: 31 additions & 7 deletions storage/innobase/include/page0page.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,31 +636,55 @@ page_rec_check(
/** Get the record pointed to by a directory slot.
@param[in] slot directory slot
@return pointer to record */
inline rec_t *page_dir_slot_get_rec(page_dir_slot_t *slot)
inline rec_t *page_dir_slot_get_rec(page_t *page, page_dir_slot_t *slot)
noexcept
{
return page_align(slot) + mach_read_from_2(my_assume_aligned<2>(slot));
return page + mach_read_from_2(my_assume_aligned<2>(slot));
}
inline const rec_t *page_dir_slot_get_rec(const page_dir_slot_t *slot)
inline const rec_t *page_dir_slot_get_rec(const page_t *page,
const page_dir_slot_t *slot) noexcept
{
return page_dir_slot_get_rec(const_cast<page_t*>(page),
const_cast<rec_t*>(slot));
}

inline rec_t *page_dir_slot_get_rec(page_dir_slot_t *slot) noexcept
{
return page_dir_slot_get_rec(page_align(slot), slot);
}
inline const rec_t *page_dir_slot_get_rec(const page_dir_slot_t *slot) noexcept
{
return page_dir_slot_get_rec(const_cast<rec_t*>(slot));
}

inline rec_t *page_dir_slot_get_rec_validate(page_dir_slot_t *slot)
inline rec_t *page_dir_slot_get_rec_validate(page_t *page,
page_dir_slot_t *slot) noexcept
{
const size_t s= mach_read_from_2(my_assume_aligned<2>(slot));
page_t *page= page_align(slot);

return UNIV_LIKELY(s >= PAGE_NEW_INFIMUM &&
s <= page_header_get_field(page, PAGE_HEAP_TOP))
? page + s
: nullptr;
}

inline const rec_t *page_dir_slot_get_rec_validate(const page_t *page,
const page_dir_slot_t *slot)
noexcept
{
return page_dir_slot_get_rec_validate(const_cast<page_t*>(page),
const_cast<page_dir_slot_t*>(slot));
}

inline rec_t *page_dir_slot_get_rec_validate(page_dir_slot_t *slot) noexcept
{
return page_dir_slot_get_rec_validate(page_align(slot), slot);
}
inline const rec_t *page_dir_slot_get_rec_validate(const page_dir_slot_t *slot)
noexcept
{
return page_dir_slot_get_rec_validate(const_cast<rec_t*>(slot));
}


/***************************************************************//**
Gets the number of records owned by a directory slot.
@return number of records */
Expand Down
Loading

0 comments on commit 3761a7f

Please sign in to comment.