MySQL 8.0.40
Source Code Documentation
Rec_offsets Class Reference

A helper RAII wrapper for otherwise difficult to use sequence of: More...

#include <rem0rec.h>

Inheritance diagram for Rec_offsets:
[legend]

Public Member Functions

 Rec_offsets ()
 Prepares offsets to initially point to the fixed-size buffer, and marks the memory as allocated, but uninitialized. More...
 
const ulintcompute (const rec_t *rec, const dict_index_t *index, const ulint n_fields=ULINT_UNDEFINED)
 Computes offsets for given record. More...
 
 ~Rec_offsets ()
 Deallocated dynamically allocated memory, if any. More...
 

Private Attributes

mem_heap_tm_heap {nullptr}
 Pointer to heap used by rec_get_offsets(). More...
 
ulint m_preallocated_buffer [REC_OFFS_NORMAL_SIZE]
 Buffer with size large enough to handle common cases without having to use heap. More...
 
ulintm_offsets {m_preallocated_buffer}
 

Additional Inherited Members

- Private Member Functions inherited from ut::Non_copyable
 Non_copyable (const Non_copyable &)=delete
 
Non_copyableoperator= (const Non_copyable &)=delete
 
 Non_copyable ()=default
 
 ~Non_copyable ()=default
 

Detailed Description

A helper RAII wrapper for otherwise difficult to use sequence of:

ulint offsets_[REC_OFFS_NORMAL_SIZE]; rec_offs_init(offsets_); mem_heap_t *heap = nullptr;

const ulint *offsets = rec_get_offsets(rec, index, offsets_, ULINT_UNDEFINED, &heap);

DO_SOMETHING(offsets);

if (heap != nullptr) { mem_heap_free(heap); }

With this helper you can simply do:

DO_SOMETHING(Rec_offsets().compute(rec,index));

And if you need to reuse the memory allocated offsets several times you can: Rec_offsets offsets; for(rec: recs) DO_SOMTHING(offsets.compute(rec,index))

Constructor & Destructor Documentation

◆ Rec_offsets()

Rec_offsets::Rec_offsets ( )
inline

Prepares offsets to initially point to the fixed-size buffer, and marks the memory as allocated, but uninitialized.

You first need to call compute() to use it

◆ ~Rec_offsets()

Rec_offsets::~Rec_offsets ( )
inline

Deallocated dynamically allocated memory, if any.

Member Function Documentation

◆ compute()

const ulint * Rec_offsets::compute ( const rec_t rec,
const dict_index_t index,
const ulint  n_fields = ULINT_UNDEFINED 
)
inline

Computes offsets for given record.

Returned array is owned by this instance. You can use its value as long as this object does not go out of scope (which can free the buffer), and you don't call compute() again (which can overwrite the offsets).

Parameters
[in]recThe record for which you want to compute the offsets
[in]indexThe index which contains the record
[in]n_fieldsNumber of columns to scan
Returns
A pointer to offsets array owned by this instance. Valid till next call to compute() or end of this instance lifetime.

Member Data Documentation

◆ m_heap

mem_heap_t* Rec_offsets::m_heap {nullptr}
private

Pointer to heap used by rec_get_offsets().

Initially nullptr. If row is really big, rec_get_offsets() may need to allocate new buffer for offsets. At, first, when heap is null, rec_get_offsets() will create new heap, and pass it back via reference. On subsequent calls, we will pass this heap, so it is reused if needed. Therefore all allocated buffers are in this heap, if it is not nullptr

◆ m_offsets

ulint* Rec_offsets::m_offsets {m_preallocated_buffer}
private

◆ m_preallocated_buffer

ulint Rec_offsets::m_preallocated_buffer[REC_OFFS_NORMAL_SIZE]
private

Buffer with size large enough to handle common cases without having to use heap.

This is the initial value of m_offsets.


The documentation for this class was generated from the following file: