MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
page0zip.cc File Reference
#include <map>
#include "page0zip.h"
#include "page0page.h"
#include "mtr0log.h"
#include "ut0sort.h"
#include "dict0dict.h"
#include "btr0cur.h"
#include "page0types.h"
#include "log0recv.h"
#include "zlib.h"
#include "buf0buf.h"
#include "buf0lru.h"
#include "btr0sea.h"
#include "dict0boot.h"
#include "lock0lock.h"
#include "srv0mon.h"
#include "srv0srv.h"
#include "ut0crc32.h"
Include dependency graph for page0zip.cc:

Go to the source code of this file.

Macros

#define THIS_MODULE
#define ASSERT_ZERO(b, s)   ut_ad(!memcmp(b, field_ref_zero, ut_min(s, sizeof field_ref_zero)))
#define ASSERT_ZERO_BLOB(b)   ut_ad(!memcmp(b, field_ref_zero, sizeof field_ref_zero))
#define page_zip_fail(fmt_args)   /* empty */
#define page_zip_dir_start_low(page_zip, n_dense)   ((page_zip)->data + page_zip_dir_start_offs(page_zip, n_dense))
#define page_zip_dir_start(page_zip)   page_zip_dir_start_low(page_zip, page_zip_dir_elems(page_zip))
#define FILE_LOGFILE
#define LOGFILE

Functions

UNIV_INTERN ulint page_zip_empty_size (ulint n_fields, ulint zip_size)
UNIV_INLINE ulint page_zip_dir_elems (const page_zip_des_t *page_zip)
UNIV_INLINE ulint page_zip_dir_size (const page_zip_des_t *page_zip)
UNIV_INLINE ulint page_zip_dir_start_offs (const page_zip_des_t *page_zip, ulint n_dense)
UNIV_INLINE ulint page_zip_dir_user_size (const page_zip_des_t *page_zip)
UNIV_INLINE byte * page_zip_dir_find_low (byte *slot, byte *end, ulint offset)
UNIV_INLINE byte * page_zip_dir_find (page_zip_des_t *page_zip, ulint offset)
UNIV_INLINE byte * page_zip_dir_find_free (page_zip_des_t *page_zip, ulint offset)
UNIV_INLINE ulint page_zip_dir_get (const page_zip_des_t *page_zip, ulint slot)
UNIV_INTERN void page_zip_set_alloc (void *stream, mem_heap_t *heap)
UNIV_INTERN ibool page_zip_compress (page_zip_des_t *page_zip, const page_t *page, dict_index_t *index, ulint level, mtr_t *mtr)
UNIV_INLINE ibool page_zip_dir_cmp (const rec_t *rec1, const rec_t *rec2)
UNIV_INTERN ibool page_zip_decompress (page_zip_des_t *page_zip, page_t *page, ibool all)
UNIV_INTERN void page_zip_write_rec (page_zip_des_t *page_zip, const byte *rec, dict_index_t *index, const ulint *offsets, ulint create)
UNIV_INTERN byte * page_zip_parse_write_blob_ptr (byte *ptr, byte *end_ptr, page_t *page, page_zip_des_t *page_zip)
UNIV_INTERN void page_zip_write_blob_ptr (page_zip_des_t *page_zip, const byte *rec, dict_index_t *index, const ulint *offsets, ulint n, mtr_t *mtr)
UNIV_INTERN byte * page_zip_parse_write_node_ptr (byte *ptr, byte *end_ptr, page_t *page, page_zip_des_t *page_zip)
UNIV_INTERN void page_zip_write_node_ptr (page_zip_des_t *page_zip, byte *rec, ulint size, ulint ptr, mtr_t *mtr)
UNIV_INTERN void page_zip_write_trx_id_and_roll_ptr (page_zip_des_t *page_zip, byte *rec, const ulint *offsets, ulint trx_id_col, trx_id_t trx_id, roll_ptr_t roll_ptr)
UNIV_INTERN void page_zip_rec_set_deleted (page_zip_des_t *page_zip, const byte *rec, ulint flag)
UNIV_INTERN void page_zip_rec_set_owned (page_zip_des_t *page_zip, const byte *rec, ulint flag)
UNIV_INTERN void page_zip_dir_insert (page_zip_des_t *page_zip, const byte *prev_rec, const byte *free_rec, byte *rec)
UNIV_INTERN void page_zip_dir_delete (page_zip_des_t *page_zip, byte *rec, const dict_index_t *index, const ulint *offsets, const byte *free)
UNIV_INTERN void page_zip_dir_add_slot (page_zip_des_t *page_zip, ulint is_clustered)
UNIV_INTERN byte * page_zip_parse_write_header (byte *ptr, byte *end_ptr, page_t *page, page_zip_des_t *page_zip)
UNIV_INTERN void page_zip_write_header_log (const byte *data, ulint length, mtr_t *mtr)
UNIV_INTERN ibool page_zip_reorganize (buf_block_t *block, dict_index_t *index, mtr_t *mtr)
UNIV_INTERN void page_zip_copy_recs (page_zip_des_t *page_zip, page_t *page, const page_zip_des_t *src_zip, const page_t *src, dict_index_t *index, mtr_t *mtr)
UNIV_INTERN byte * page_zip_parse_compress (byte *ptr, byte *end_ptr, page_t *page, page_zip_des_t *page_zip)
UNIV_INTERN ulint page_zip_calc_checksum (const void *data, ulint size, srv_checksum_algorithm_t algo)
UNIV_INTERN ibool page_zip_verify_checksum (const void *data, ulint size)

Variables

UNIV_INTERN page_zip_stat_t page_zip_stat [PAGE_ZIP_SSIZE_MAX]
UNIV_INTERN
page_zip_stat_per_index_t 
page_zip_stat_per_index
UNIV_INTERN ib_mutex_t page_zip_stat_per_index_mutex
UNIV_INTERN uint page_zip_level = DEFAULT_COMPRESSION_LEVEL
UNIV_INTERN my_bool page_zip_log_pages = true

Detailed Description

Compressed page interface

Created June 2005 by Marko Makela

Definition in file page0zip.cc.

Macro Definition Documentation

#define ASSERT_ZERO (   b,
 
)    ut_ad(!memcmp(b, field_ref_zero, ut_min(s, sizeof field_ref_zero)))
Assert that a block of memory is filled with zero bytes.

Compare at most sizeof(field_ref_zero) bytes.

Parameters
bin: memory block
sin: size of the memory block, in bytes

Definition at line 108 of file page0zip.cc.

#define ASSERT_ZERO_BLOB (   b)    ut_ad(!memcmp(b, field_ref_zero, sizeof field_ref_zero))
Assert that a BLOB pointer is filled with zero bytes.
Parameters
bin: BLOB pointer

Definition at line 112 of file page0zip.cc.

#define FILE_LOGFILE

Empty declaration of the logfile parameter

Definition at line 815 of file page0zip.cc.

#define LOGFILE

Missing logfile parameter

Definition at line 817 of file page0zip.cc.

#define page_zip_dir_start (   page_zip)    page_zip_dir_start_low(page_zip, page_zip_dir_elems(page_zip))

Gets a pointer to the compressed page trailer (the dense page directory), including deleted records (the free list).

Parameters
[in]page_zipcompressed page
Returns
pointer to the dense page directory

Definition at line 232 of file page0zip.cc.

#define page_zip_dir_start_low (   page_zip,
  n_dense 
)    ((page_zip)->data + page_zip_dir_start_offs(page_zip, n_dense))

Gets a pointer to the compressed page trailer (the dense page directory), including deleted records (the free list).

Parameters
[in]page_zipcompressed page
[in]n_densenumber of entries in the directory
Returns
pointer to the dense page directory

Definition at line 225 of file page0zip.cc.

#define page_zip_fail (   fmt_args)    /* empty */
Dummy wrapper for page_zip_fail_func()
Parameters
fmt_argsignored: printf(3) format string and arguments

Definition at line 147 of file page0zip.cc.

Function Documentation

UNIV_INTERN ulint page_zip_calc_checksum ( const void *  data,
ulint  size,
srv_checksum_algorithm_t  algo 
)

Calculate the compressed page checksum.

Returns
page checksum
Parameters
datain: compressed page
sizein: size of compressed page
algoin: algorithm to use

Definition at line 4827 of file page0zip.cc.

Here is the caller graph for this function:

UNIV_INTERN ibool page_zip_compress ( page_zip_des_t page_zip,
const page_t page,
dict_index_t index,
ulint  level,
mtr_t mtr 
)

Compress a page.

Returns
TRUE on success, FALSE on failure; page_zip will be left intact on failure.

< index field information

< compressed payload of the page

< dense page directory, sorted by address

Parameters
page_zipin: size; out: data, n_blobs, m_start, m_end, m_nonempty
pagein: uncompressed page
indexin: index of the B-tree node
levelin: compression level
mtrin: mini-transaction, or NULL

Definition at line 1197 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN void page_zip_copy_recs ( page_zip_des_t page_zip,
page_t page,
const page_zip_des_t src_zip,
const page_t src,
dict_index_t index,
mtr_t mtr 
)

Copy the records of a page byte for byte. Do not copy the page header or trailer, except those B-tree header fields that are directly related to the storage of records. Also copy PAGE_MAX_TRX_ID. NOTE: The caller must update the lock table and the adaptive hash index.

Parameters
page_zipout: copy of src_zip (n_blobs, m_start, m_end, m_nonempty, data[0..size-1])
pageout: copy of src
src_zipin: compressed page
srcin: page
indexin: index of the B-tree
mtrin: mini-transaction

Definition at line 4674 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN ibool page_zip_decompress ( page_zip_des_t page_zip,
page_t page,
ibool  all 
)

Decompress a page. This function should tolerate errors on the compressed page. Instead of letting assertions fail, it will return FALSE if an inconsistency is detected.

Returns
TRUE on success, FALSE on failure

< dense page directory, sorted by address

Parameters
page_zipin: data, ssize; out: m_start, m_end, m_nonempty, n_blobs
pageout: uncompressed page, may be trashed
allin: TRUE=decompress the whole page; FALSE=verify but do not copy some page header fields that should not change after page creation

Definition at line 2939 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN void page_zip_dir_add_slot ( page_zip_des_t page_zip,
ulint  is_clustered 
)

Add a slot to the dense page directory.

Parameters
page_zipin/out: compressed page
is_clusteredin: nonzero for clustered index, zero for others

Definition at line 4425 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE ibool page_zip_dir_cmp ( const rec_t *  rec1,
const rec_t *  rec2 
)

Compare two page directory entries.

Returns
positive if rec1 > rec2
Parameters
rec1in: rec1
rec2in: rec2

Definition at line 1535 of file page0zip.cc.

UNIV_INTERN void page_zip_dir_delete ( page_zip_des_t page_zip,
byte *  rec,
const dict_index_t index,
const ulint *  offsets,
const byte *  free 
)

Shift the dense page directory and the array of BLOB pointers when a record is deleted.

Parameters
page_zipin/out: compressed page
recin: deleted record
indexin: index of rec
offsetsin: rec_get_offsets(rec)
freein: previous start of the free list

Definition at line 4327 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INLINE ulint page_zip_dir_elems ( const page_zip_des_t page_zip)

Gets the number of elements in the dense page directory, including deleted records (the free list).

Returns
number of elements in the dense page directory
Parameters
page_zipin: compressed page

Definition at line 182 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE byte* page_zip_dir_find ( page_zip_des_t page_zip,
ulint  offset 
)

Find the slot of the given non-free record in the dense page directory.

Returns
dense directory slot, or NULL if record not found
Parameters
page_zipin: compressed page
offsetin: offset of user record

Definition at line 279 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE byte* page_zip_dir_find_free ( page_zip_des_t page_zip,
ulint  offset 
)

Find the slot of the given free record in the dense page directory.

Returns
dense directory slot, or NULL if record not found
Parameters
page_zipin: compressed page
offsetin: offset of user record

Definition at line 298 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE byte* page_zip_dir_find_low ( byte *  slot,
byte *  end,
ulint  offset 
)

Find the slot of the given record in the dense page directory.

Returns
dense directory slot, or NULL if record not found
Parameters
slotin: start of records
endin: end of records
offsetin: offset of user record

Definition at line 256 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE ulint page_zip_dir_get ( const page_zip_des_t page_zip,
ulint  slot 
)

Read a given slot in the dense page directory.

Returns
record offset on the uncompressed page, possibly ORed with PAGE_ZIP_DIR_SLOT_DEL or PAGE_ZIP_DIR_SLOT_OWNED
Parameters
page_zipin: compressed page
slotin: slot (0=first user record)

Definition at line 318 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void page_zip_dir_insert ( page_zip_des_t page_zip,
const byte *  prev_rec,
const byte *  free_rec,
byte *  rec 
)

Insert a record to the dense page directory.

Parameters
page_zipin/out: compressed page
prev_recin: record after which to insert
free_recin: record from which rec was allocated, or NULL
recin: record to insert

Definition at line 4248 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE ulint page_zip_dir_size ( const page_zip_des_t page_zip)

Gets the size of the compressed page trailer (the dense page directory), including deleted records (the free list).

Returns
length of dense page directory, in bytes
Parameters
page_zipin: compressed page

Definition at line 196 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE ulint page_zip_dir_start_offs ( const page_zip_des_t page_zip,
ulint  n_dense 
)

Gets an offset to the compressed page trailer (the dense page directory), including deleted records (the free list).

Returns
offset of the dense page directory
Parameters
page_zipin: compressed page
n_densein: directory size

Definition at line 209 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INLINE ulint page_zip_dir_user_size ( const page_zip_des_t page_zip)

Gets the size of the compressed page trailer (the dense page directory), only including user records (excluding the free list).

Returns
length of dense page directory comprising existing records, in bytes
Parameters
page_zipin: compressed page

Definition at line 241 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN ulint page_zip_empty_size ( ulint  n_fields,
ulint  zip_size 
)

Determine the guaranteed free space on an empty page.

Returns
minimum payload size on the page
Parameters
n_fieldsin: number of columns in the index
zip_sizein: compressed page size in bytes

Definition at line 156 of file page0zip.cc.

UNIV_INTERN byte* page_zip_parse_compress ( byte *  ptr,
byte *  end_ptr,
page_t page,
page_zip_des_t page_zip 
)

Parses a log record of compressing an index page.

Returns
end of log record or NULL
Parameters
ptrin: buffer
end_ptrin: buffer end
pageout: uncompressed page
page_zipout: compressed page

Definition at line 4766 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN byte* page_zip_parse_write_blob_ptr ( byte *  ptr,
byte *  end_ptr,
page_t page,
page_zip_des_t page_zip 
)

Parses a log record of writing a BLOB pointer of a record.

Returns
end of log record or NULL
Parameters
ptrin: redo log buffer
end_ptrin: redo log buffer end
pagein/out: uncompressed page
page_zipin/out: compressed page

Definition at line 3761 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN byte* page_zip_parse_write_header ( byte *  ptr,
byte *  end_ptr,
page_t page,
page_zip_des_t page_zip 
)

Parses a log record of writing to the header of a page.

Returns
end of log record or NULL
Parameters
ptrin: redo log buffer
end_ptrin: redo log buffer end
pagein/out: uncompressed page
page_zipin/out: compressed page

Definition at line 4482 of file page0zip.cc.

UNIV_INTERN byte* page_zip_parse_write_node_ptr ( byte *  ptr,
byte *  end_ptr,
page_t page,
page_zip_des_t page_zip 
)

Parses a log record of writing the node pointer of a record.

Returns
end of log record or NULL
Parameters
ptrin: redo log buffer
end_ptrin: redo log buffer end
pagein/out: uncompressed page
page_zipin/out: compressed page

Definition at line 3904 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN void page_zip_rec_set_deleted ( page_zip_des_t page_zip,
const byte *  rec,
ulint  flag 
)

Write the "deleted" flag of a record on a compressed page. The flag must already have been written on the uncompressed page.

Parameters
page_zipin/out: compressed page
recin: record on the uncompressed page
flagin: the deleted flag (nonzero=TRUE)

Definition at line 4204 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN void page_zip_rec_set_owned ( page_zip_des_t page_zip,
const byte *  rec,
ulint  flag 
)

Write the "owned" flag of a record on a compressed page. The n_owned field must already have been written on the uncompressed page.

Parameters
page_zipin/out: compressed page
recin: record on the uncompressed page
flagin: the owned flag (nonzero=TRUE)

Definition at line 4228 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN ibool page_zip_reorganize ( buf_block_t block,
dict_index_t index,
mtr_t mtr 
)

Reorganize and compress a page. This is a low-level operation for compressed pages, to be used when page_zip_compress() fails. On success, a redo log entry MLOG_ZIP_PAGE_COMPRESS will be written. The function btr_page_reorganize() should be preferred whenever possible. IMPORTANT: if page_zip_reorganize() is invoked on a leaf page of a non-clustered index, the caller must update the insert buffer free bits in the same mini-transaction in such a way that the modification will be redo-logged.

Returns
TRUE on success, FALSE on failure; page_zip will be left intact on failure, but page will be overwritten.
Parameters
blockin/out: page with compressed page; on the compressed page, in: size; out: data, n_blobs, m_start, m_end, m_nonempty
indexin: index of the B-tree node
mtrin: mini-transaction

Definition at line 4585 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void page_zip_set_alloc ( void *  stream,
mem_heap_t heap 
)

Configure the zlib allocator to use the given memory heap.

Parameters
streamin/out: zlib stream
heapin: memory heap to use

Definition at line 749 of file page0zip.cc.

Here is the caller graph for this function:

UNIV_INTERN ibool page_zip_verify_checksum ( const void *  data,
ulint  size 
)

Verify a compressed page's checksum.

Returns
TRUE if the stored checksum is valid according to the value of innodb_checksum_algorithm
Parameters
datain: compressed page
sizein: size of compressed page

Definition at line 4881 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void page_zip_write_blob_ptr ( page_zip_des_t page_zip,
const byte *  rec,
dict_index_t index,
const ulint *  offsets,
ulint  n,
mtr_t mtr 
)

Write a BLOB pointer of a record on the leaf page of a clustered index. The information must already have been updated on the uncompressed page.

Parameters
page_zipin/out: compressed page
recin/out: record whose data is being written
indexin: index of the page
offsetsin: rec_get_offsets(rec, index)
nin: column index
mtrin: mini-transaction handle, or NULL if no logging is needed

Definition at line 3820 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN void page_zip_write_header_log ( const byte *  data,
ulint  length,
mtr_t mtr 
)

Write a log record of writing to the uncompressed header portion of a page.

Parameters
datain: data on the uncompressed page
lengthin: length of the data
mtrin: mini-transaction

Definition at line 4540 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN void page_zip_write_node_ptr ( page_zip_des_t page_zip,
byte *  rec,
ulint  size,
ulint  ptr,
mtr_t mtr 
)

Write the node pointer of a record on a non-leaf compressed page.

Parameters
page_zipin/out: compressed page
recin/out: record
sizein: data size of rec
ptrin: node pointer
mtrin: mini-transaction, or NULL

Definition at line 3978 of file page0zip.cc.

Here is the call graph for this function:

UNIV_INTERN void page_zip_write_rec ( page_zip_des_t page_zip,
const byte *  rec,
dict_index_t index,
const ulint *  offsets,
ulint  create 
)

Write an entire record on the compressed page. The data must already have been written to the uncompressed page.

Parameters
page_zipin/out: compressed page
recin: record being written
indexin: the index the record belongs to
offsetsin: rec_get_offsets(rec, index)
createin: nonzero=insert, zero=update

Definition at line 3575 of file page0zip.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void page_zip_write_trx_id_and_roll_ptr ( page_zip_des_t page_zip,
byte *  rec,
const ulint *  offsets,
ulint  trx_id_col,
trx_id_t  trx_id,
roll_ptr_t  roll_ptr 
)

Write the trx_id and roll_ptr of a record on a B-tree leaf node page.

Parameters
page_zipin/out: compressed page
recin/out: record
offsetsin: rec_get_offsets(rec, index)
trx_id_colin: column number of TRX_ID in rec
trx_idin: transaction identifier
roll_ptrin: roll_ptr

Definition at line 4045 of file page0zip.cc.

Here is the call graph for this function:

Variable Documentation

UNIV_INTERN page_zip_stat_t page_zip_stat[PAGE_ZIP_SSIZE_MAX]

Statistics on compression, indexed by page_zip_des_t::ssize - 1

Definition at line 61 of file page0zip.cc.

UNIV_INTERN page_zip_stat_per_index_t page_zip_stat_per_index

Statistics on compression, indexed by index->id

Definition at line 63 of file page0zip.cc.

UNIV_INTERN ib_mutex_t page_zip_stat_per_index_mutex

Mutex protecting page_zip_stat_per_index

Definition at line 65 of file page0zip.cc.