| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2005, 2026, Oracle and/or its affiliates. |
| 4 |
Copyright (c) 2012, Facebook Inc. |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify it under |
| 7 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 8 |
Free Software Foundation. |
| 9 |
|
| 10 |
This program is designed to work with certain software (including |
| 11 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 12 |
as designated in a particular file or component or in included license |
| 13 |
documentation. The authors of MySQL hereby grant you an additional |
| 14 |
permission to link the program and your derivative works with the |
| 15 |
separately licensed software that they have either included with |
| 16 |
the program or referenced in the documentation. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 19 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 20 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 21 |
for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License along with |
| 24 |
this program; if not, write to the Free Software Foundation, Inc., |
| 25 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 |
|
| 27 |
*****************************************************************************/ |
| 28 |
|
| 29 |
/** @file page/zipdecompress.ic |
| 30 |
Compressed page interface |
| 31 |
|
| 32 |
Created June 2005 by Marko Makela |
| 33 |
*******************************************************/ |
| 34 |
|
| 35 |
/** NOTE: The functions in this file should only use functions from |
| 36 |
other files in library. The code in this file is used to make a library for |
| 37 |
external tools. */ |
| 38 |
|
| 39 |
#ifndef zip_decompress_ic |
| 40 |
#define zip_decompress_ic |
| 41 |
|
| 42 |
#include "btr0types.h" |
| 43 |
#include "fil0types.h" |
| 44 |
#include "page0types.h" |
| 45 |
|
| 46 |
#include "page/page.ic" |
| 47 |
/** Size of an compressed page directory entry */ |
| 48 |
constexpr uint32_t PAGE_ZIP_DIR_SLOT_SIZE = 2; |
| 49 |
|
| 50 |
/** Gets a pointer to the compressed page trailer (the dense page directory), |
| 51 |
including deleted records (the free list). |
| 52 |
@param[in] page_zip compressed page |
| 53 |
@param[in] n_dense number of entries in the directory |
| 54 |
@return pointer to the dense page directory */ |
| 55 |
#define page_zip_dir_start_low(page_zip, n_dense) \ |
| 56 |
((page_zip)->data + page_zip_dir_start_offs(page_zip, n_dense)) |
| 57 |
/** Gets a pointer to the compressed page trailer (the dense page directory), |
| 58 |
including deleted records (the free list). |
| 59 |
@param[in] page_zip compressed page |
| 60 |
@return pointer to the dense page directory */ |
| 61 |
#define page_zip_dir_start(page_zip) \ |
| 62 |
page_zip_dir_start_low(page_zip, page_zip_dir_elems(page_zip)) |
| 63 |
|
| 64 |
/** Determine the size of a compressed page in bytes. |
| 65 |
@return size in bytes */ |
| 66 |
static inline ulint page_zip_get_size( |
| 67 |
const page_zip_des_t *page_zip) /*!< in: compressed page */ |
| 68 |
{ |
| 69 |
ulint size; |
| 70 |
|
| 71 |
if (!page_zip->ssize) { |
| 72 |
return (0); |
| 73 |
} |
| 74 |
|
| 75 |
size = (UNIV_ZIP_SIZE_MIN >> 1) << page_zip->ssize; |
| 76 |
|
| 77 |
ut_ad(size >= UNIV_ZIP_SIZE_MIN); |
| 78 |
ut_ad(size <= UNIV_PAGE_SIZE); |
| 79 |
|
| 80 |
return (size); |
| 81 |
} |
| 82 |
|
| 83 |
#ifdef UNIV_DEBUG |
| 84 |
/** Validate a compressed page descriptor. |
| 85 |
@return true if ok */ |
| 86 |
static inline bool page_zip_simple_validate( |
| 87 |
const page_zip_des_t *page_zip) /*!< in: compressed page descriptor */ |
| 88 |
{ |
| 89 |
ut_ad(page_zip); |
| 90 |
ut_ad(page_zip->data); |
| 91 |
ut_ad(page_zip->ssize <= PAGE_ZIP_SSIZE_MAX); |
| 92 |
ut_ad(page_zip_get_size(page_zip) > PAGE_DATA + PAGE_ZIP_DIR_SLOT_SIZE); |
| 93 |
ut_ad(page_zip->m_start <= page_zip->m_end); |
| 94 |
ut_ad(page_zip->m_end < page_zip_get_size(page_zip)); |
| 95 |
ut_ad(page_zip->n_blobs < |
| 96 |
page_zip_get_size(page_zip) / BTR_EXTERN_FIELD_REF_SIZE); |
| 97 |
return true; |
| 98 |
} |
| 99 |
#endif /* UNIV_DEBUG */ |
| 100 |
|
| 101 |
/** Gets the number of elements in the dense page directory, |
| 102 |
including deleted records (the free list). |
| 103 |
@return number of elements in the dense page directory */ |
| 104 |
static inline ulint page_zip_dir_elems( |
| 105 |
const page_zip_des_t *page_zip) /*!< in: compressed page */ |
| 106 |
{ |
| 107 |
/* Exclude the page infimum and supremum from the record count. */ |
| 108 |
return (page_dir_get_n_heap(page_zip->data) - PAGE_HEAP_NO_USER_LOW); |
| 109 |
} |
| 110 |
|
| 111 |
/** Gets the size of the compressed page trailer (the dense page directory), |
| 112 |
including deleted records (the free list). |
| 113 |
@return length of dense page directory, in bytes */ |
| 114 |
static inline ulint page_zip_dir_size( |
| 115 |
const page_zip_des_t *page_zip) /*!< in: compressed page */ |
| 116 |
{ |
| 117 |
return (PAGE_ZIP_DIR_SLOT_SIZE * page_zip_dir_elems(page_zip)); |
| 118 |
} |
| 119 |
|
| 120 |
/** Read a given slot in the dense page directory. |
| 121 |
@return record offset on the uncompressed page, possibly ORed with |
| 122 |
PAGE_ZIP_DIR_SLOT_DEL or PAGE_ZIP_DIR_SLOT_OWNED */ |
| 123 |
static inline ulint page_zip_dir_get( |
| 124 |
const page_zip_des_t *page_zip, /*!< in: compressed page */ |
| 125 |
ulint slot) /*!< in: slot |
| 126 |
(0=first user record) */ |
| 127 |
{ |
| 128 |
ut_ad(page_zip_simple_validate(page_zip)); |
| 129 |
ut_ad(slot < page_zip_dir_size(page_zip) / PAGE_ZIP_DIR_SLOT_SIZE); |
| 130 |
return (mach_read_from_2(page_zip->data + page_zip_get_size(page_zip) - |
| 131 |
PAGE_ZIP_DIR_SLOT_SIZE * (slot + 1))); |
| 132 |
} |
| 133 |
#endif |