Skip to content

Commit

Permalink
MDEV-20950 Reduce size of record offsets
Browse files Browse the repository at this point in the history
offset_t: this is a type which represents one record offset.
It's unsigned short int.

a lot of functions: replace ulint with offset_t

btr_pcur_restore_position_func(),
page_validate(),
row_ins_scan_sec_index_for_duplicate(),
row_upd_clust_rec_by_insert_inherit_func(),
row_vers_impl_x_locked_low(),
trx_undo_prev_version_build():
  allocate record offsets on the stack instead of waiting for rec_get_offsets()
  to allocate it from mem_heap_t. So, reducing  memory allocations.

RECORD_OFFSET, INDEX_OFFSET:
  now it's less convenient to store pointers in offset_t*
  array. One pointer occupies now several offset_t. And those constant are start
  indexes into array to places where to store pointer values

REC_OFFS_HEADER_SIZE: adjusted for the new reality

REC_OFFS_NORMAL_SIZE:
  increase size from 100 to 300 which means less heap allocations.
  And sizeof(offset_t[REC_OFFS_NORMAL_SIZE]) now is 600 bytes which
  is smaller than previous 800 bytes.

REC_OFFS_SEC_INDEX_SIZE: adjusted for the new reality

rem0rec.h, rem0rec.ic, rem0rec.cc:
  various arguments, return values and local variables types were changed to
  fix numerous integer conversions issues.

enum field_type_t:
  offset types concept was introduces which replaces old offset flags stuff.
  Like in earlier version, 2 upper bits are used to store offset type.
  And this enum represents those types.

REC_OFFS_SQL_NULL, REC_OFFS_MASK: removed

get_type(), set_type(), get_value(), combine():
  these are convenience functions to work with offsets and it's types

rec_offs_base()[0]:
  still uses an old scheme with flags REC_OFFS_COMPACT and REC_OFFS_EXTERNAL

rec_offs_base()[i]:
  these have type offset_t now. Two upper bits contains type.
  • Loading branch information
kevgs committed Dec 12, 2019
1 parent beec9c0 commit f0aa073
Show file tree
Hide file tree
Showing 66 changed files with 792 additions and 745 deletions.
54 changes: 27 additions & 27 deletions storage/innobase/btr/btr0btr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ btr_node_ptr_set_child_page_no(
rec_t* rec, /*!< in: node pointer record */
page_zip_des_t* page_zip,/*!< in/out: compressed page whose uncompressed
part will be updated, or NULL */
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
const offset_t* offsets,/*!< in: array returned by rec_get_offsets() */
ulint page_no,/*!< in: child node address */
mtr_t* mtr) /*!< in: mtr */
{
Expand Down Expand Up @@ -812,7 +812,7 @@ btr_node_ptr_get_child(
/*===================*/
const rec_t* node_ptr,/*!< in: node pointer */
dict_index_t* index, /*!< in: index */
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
const offset_t* offsets,/*!< in: array returned by rec_get_offsets() */
mtr_t* mtr) /*!< in: mtr */
{
ut_ad(rec_offs_validate(node_ptr, index, offsets));
Expand All @@ -830,10 +830,10 @@ Returns the upper level node pointer to a page. It is assumed that mtr holds
an sx-latch on the tree.
@return rec_get_offsets() of the node pointer record */
static
ulint*
offset_t*
btr_page_get_father_node_ptr_func(
/*==============================*/
ulint* offsets,/*!< in: work area for the return value */
offset_t* offsets,/*!< in: work area for the return value */
mem_heap_t* heap, /*!< in: memory heap to use */
btr_cur_t* cursor, /*!< in: cursor pointing to user record,
out: cursor on node pointer record,
Expand Down Expand Up @@ -937,10 +937,10 @@ Returns the upper level node pointer to a page. It is assumed that mtr holds
an x-latch on the tree.
@return rec_get_offsets() of the node pointer record */
static
ulint*
offset_t*
btr_page_get_father_block(
/*======================*/
ulint* offsets,/*!< in: work area for the return value */
offset_t* offsets,/*!< in: work area for the return value */
mem_heap_t* heap, /*!< in: memory heap to use */
dict_index_t* index, /*!< in: b-tree index */
buf_block_t* block, /*!< in: child page in the index */
Expand Down Expand Up @@ -1814,7 +1814,7 @@ btr_root_raise_and_insert(
on the root page; when the function returns,
the cursor is positioned on the predecessor
of the inserted record */
ulint** offsets,/*!< out: offsets on inserted record */
offset_t** offsets,/*!< out: offsets on inserted record */
mem_heap_t** heap, /*!< in/out: pointer to memory heap, or NULL */
const dtuple_t* tuple, /*!< in: tuple to insert */
ulint n_ext, /*!< in: number of externally stored columns */
Expand Down Expand Up @@ -2125,7 +2125,7 @@ btr_page_get_split_rec(
rec_t* next_rec;
ulint n;
mem_heap_t* heap;
ulint* offsets;
offset_t* offsets;

page = btr_cur_get_page(cursor);

Expand Down Expand Up @@ -2231,7 +2231,7 @@ btr_page_insert_fits(
const rec_t* split_rec,/*!< in: suggestion for first record
on upper half-page, or NULL if
tuple to be inserted should be first */
ulint** offsets,/*!< in: rec_get_offsets(
offset_t** offsets,/*!< in: rec_get_offsets(
split_rec, cursor->index); out: garbage */
const dtuple_t* tuple, /*!< in: tuple to insert */
ulint n_ext, /*!< in: number of externally stored columns */
Expand Down Expand Up @@ -2331,8 +2331,8 @@ btr_insert_on_non_leaf_level_func(
dberr_t err;
rec_t* rec;
mem_heap_t* heap = NULL;
ulint offsets_[REC_OFFS_NORMAL_SIZE];
ulint* offsets = offsets_;
offset_t offsets_[REC_OFFS_NORMAL_SIZE];
offset_t* offsets = offsets_;
rec_offs_init(offsets_);
rtr_info_t rtr_info;

Expand Down Expand Up @@ -2441,7 +2441,7 @@ btr_attach_half_pages(
if (direction == FSP_DOWN) {

btr_cur_t cursor;
ulint* offsets;
offset_t* offsets;

lower_page = buf_block_get_frame(new_block);
lower_page_no = new_block->page.id.page_no();
Expand Down Expand Up @@ -2564,7 +2564,7 @@ btr_page_tuple_smaller(
/*===================*/
btr_cur_t* cursor, /*!< in: b-tree cursor */
const dtuple_t* tuple, /*!< in: tuple to consider */
ulint** offsets,/*!< in/out: temporary storage */
offset_t** offsets,/*!< in/out: temporary storage */
ulint n_uniq, /*!< in: number of unique fields
in the index page records */
mem_heap_t** heap) /*!< in/out: heap for offsets */
Expand Down Expand Up @@ -2604,7 +2604,7 @@ rec_t*
btr_insert_into_right_sibling(
ulint flags,
btr_cur_t* cursor,
ulint** offsets,
offset_t** offsets,
mem_heap_t* heap,
const dtuple_t* tuple,
ulint n_ext,
Expand Down Expand Up @@ -2741,7 +2741,7 @@ btr_page_split_and_insert(
btr_cur_t* cursor, /*!< in: cursor at which to insert; when the
function returns, the cursor is positioned
on the predecessor of the inserted record */
ulint** offsets,/*!< out: offsets on inserted record */
offset_t** offsets,/*!< out: offsets on inserted record */
mem_heap_t** heap, /*!< in/out: pointer to memory heap, or NULL */
const dtuple_t* tuple, /*!< in: tuple to insert */
ulint n_ext, /*!< in: number of externally stored columns */
Expand Down Expand Up @@ -3302,7 +3302,7 @@ btr_lift_page_up(

{
btr_cur_t cursor;
ulint* offsets = NULL;
offset_t* offsets = NULL;
mem_heap_t* heap = mem_heap_create(
sizeof(*offsets)
* (REC_OFFS_HEADER_SIZE + 1 + 1 + index->n_fields));
Expand Down Expand Up @@ -3487,7 +3487,7 @@ btr_compress(
page_t* page;
btr_cur_t father_cursor;
mem_heap_t* heap;
ulint* offsets;
offset_t* offsets;
ulint nth_rec = 0; /* remove bogus warning */
bool mbr_changed = false;
#ifdef UNIV_DEBUG
Expand Down Expand Up @@ -3631,7 +3631,7 @@ btr_compress(
if (is_left) {
btr_cur_t cursor2;
rtr_mbr_t new_mbr;
ulint* offsets2 = NULL;
offset_t* offsets2 = NULL;

/* For rtree, we need to update father's mbr. */
if (dict_index_is_spatial(index)) {
Expand Down Expand Up @@ -3829,7 +3829,7 @@ btr_compress(

/* For rtree, we need to update father's mbr. */
if (dict_index_is_spatial(index)) {
ulint* offsets2;
offset_t* offsets2;
ulint rec_info;

offsets2 = rec_get_offsets(
Expand Down Expand Up @@ -4276,7 +4276,7 @@ btr_print_recursive(
ulint width, /*!< in: print this many entries from start
and end */
mem_heap_t** heap, /*!< in/out: heap for rec_get_offsets() */
ulint** offsets,/*!< in/out: buffer for rec_get_offsets() */
offset_t** offsets,/*!< in/out: buffer for rec_get_offsets() */
mtr_t* mtr) /*!< in: mtr */
{
const page_t* page = buf_block_get_frame(block);
Expand Down Expand Up @@ -4340,8 +4340,8 @@ btr_print_index(
mtr_t mtr;
buf_block_t* root;
mem_heap_t* heap = NULL;
ulint offsets_[REC_OFFS_NORMAL_SIZE];
ulint* offsets = offsets_;
offset_t offsets_[REC_OFFS_NORMAL_SIZE];
offset_t* offsets = offsets_;
rec_offs_init(offsets_);

fputs("--------------------------\n"
Expand Down Expand Up @@ -4375,7 +4375,7 @@ btr_check_node_ptr(
{
mem_heap_t* heap;
dtuple_t* tuple;
ulint* offsets;
offset_t* offsets;
btr_cur_t cursor;
page_t* page = buf_block_get_frame(block);

Expand Down Expand Up @@ -4457,8 +4457,8 @@ btr_index_rec_validate(
ulint i;
const page_t* page;
mem_heap_t* heap = NULL;
ulint offsets_[REC_OFFS_NORMAL_SIZE];
ulint* offsets = offsets_;
offset_t offsets_[REC_OFFS_NORMAL_SIZE];
offset_t* offsets = offsets_;
rec_offs_init(offsets_);

page = page_align(rec);
Expand Down Expand Up @@ -4691,8 +4691,8 @@ btr_validate_level(
bool ret = true;
mtr_t mtr;
mem_heap_t* heap = mem_heap_create(256);
ulint* offsets = NULL;
ulint* offsets2= NULL;
offset_t* offsets = NULL;
offset_t* offsets2= NULL;
#ifdef UNIV_ZIP_DEBUG
page_zip_des_t* page_zip;
#endif /* UNIV_ZIP_DEBUG */
Expand Down
14 changes: 7 additions & 7 deletions storage/innobase/btr/btr0bulk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ PageBulk::init()
void
PageBulk::insert(
const rec_t* rec,
ulint* offsets)
offset_t* offsets)
{
ulint rec_size;

Expand All @@ -190,7 +190,7 @@ PageBulk::insert(
/* Check whether records are in order. */
if (!page_rec_is_infimum(m_cur_rec)) {
rec_t* old_rec = m_cur_rec;
ulint* old_offsets = rec_get_offsets(
offset_t* old_offsets = rec_get_offsets(
old_rec, m_index, NULL, page_rec_is_leaf(old_rec),
ULINT_UNDEFINED, &m_heap);

Expand Down Expand Up @@ -402,7 +402,7 @@ rec_t*
PageBulk::getSplitRec()
{
rec_t* rec;
ulint* offsets;
offset_t* offsets;
ulint total_used_size;
ulint total_recs_size;
ulint n_recs;
Expand Down Expand Up @@ -448,7 +448,7 @@ PageBulk::copyIn(
{

rec_t* rec = split_rec;
ulint* offsets = NULL;
offset_t* offsets = NULL;

ut_ad(m_rec_no == 0);
ut_ad(page_rec_is_user_rec(rec));
Expand Down Expand Up @@ -494,7 +494,7 @@ PageBulk::copyOut(
ut_ad(n > 0);

/* Set last record's next in page */
ulint* offsets = NULL;
offset_t* offsets = NULL;
rec = page_rec_get_prev(split_rec);
offsets = rec_get_offsets(rec, m_index, offsets,
page_rec_is_leaf(split_rec),
Expand Down Expand Up @@ -604,7 +604,7 @@ the blob data is logged first, then the record is logged in bulk mode.
dberr_t
PageBulk::storeExt(
const big_rec_t* big_rec,
ulint* offsets)
offset_t* offsets)
{
/* Note: not all fileds are initialized in btr_pcur. */
btr_pcur_t btr_pcur;
Expand Down Expand Up @@ -864,7 +864,7 @@ BtrBulk::insert(
ulint rec_size = rec_get_converted_size(m_index, tuple, n_ext);
big_rec_t* big_rec = NULL;
rec_t* rec = NULL;
ulint* offsets = NULL;
offset_t* offsets = NULL;

if (page_bulk->needExt(tuple, rec_size)) {
/* The record is so big that we have to store some fields
Expand Down
Loading

0 comments on commit f0aa073

Please sign in to comment.