1 /***************************************************************************** 2 3 Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify it under 6 the terms of the GNU General Public License as published by the Free Software 7 Foundation; version 2 of the License. 8 9 This program is distributed in the hope that it will be useful, but WITHOUT 10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 this program; if not, write to the Free Software Foundation, Inc., 15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA 16 17 *****************************************************************************/ 18 19 /**************************************************//** 20 @file include/page0types.h 21 Index page routines 22 23 Created 2/2/1994 Heikki Tuuri 24 *******************************************************/ 25 26 #ifndef page0types_h 27 #define page0types_h 28 29 #include "dict0types.h" 30 #include "mtr0types.h" 31 #include "rem0types.h" 32 33 #include <map> 34 35 /** Eliminates a name collision on HP-UX */ 36 #define page_t ib_page_t 37 /** Type of the index page */ 38 typedef byte page_t; 39 #ifndef UNIV_INNOCHECKSUM 40 /** Index page cursor */ 41 struct page_cur_t; 42 43 /** Compressed index page */ 44 typedef byte page_zip_t; 45 46 /* The following definitions would better belong to page0zip.h, 47 but we cannot include page0zip.h from rem0rec.ic, because 48 page0*.h includes rem0rec.h and may include rem0rec.ic. */ 49 50 /** Number of bits needed for representing different compressed page sizes */ 51 #define PAGE_ZIP_SSIZE_BITS 3 52 53 /** Maximum compressed page shift size */ 54 #define PAGE_ZIP_SSIZE_MAX \ 55 (UNIV_ZIP_SIZE_SHIFT_MAX - UNIV_ZIP_SIZE_SHIFT_MIN + 1) 56 57 /* Make sure there are enough bits available to store the maximum zip 58 ssize, which is the number of shifts from 512. */ 59 #if PAGE_ZIP_SSIZE_MAX >= (1 << PAGE_ZIP_SSIZE_BITS) 60 # error "PAGE_ZIP_SSIZE_MAX >= (1 << PAGE_ZIP_SSIZE_BITS)" 61 #endif 62 63 /* Page cursor search modes; the values must be in this order! */ 64 enum page_cur_mode_t { 65 PAGE_CUR_UNSUPP = 0, 66 PAGE_CUR_G = 1, 67 PAGE_CUR_GE = 2, 68 PAGE_CUR_L = 3, 69 PAGE_CUR_LE = 4, 70 71 /* PAGE_CUR_LE_OR_EXTENDS = 5,*/ /* This is a search mode used in 72 "column LIKE 'abc%' ORDER BY column DESC"; 73 we have to find strings which are <= 'abc' or 74 which extend it */ 75 76 /* These search mode is for search R-tree index. */ 77 PAGE_CUR_CONTAIN = 7, 78 PAGE_CUR_INTERSECT = 8, 79 PAGE_CUR_WITHIN = 9, 80 PAGE_CUR_DISJOINT = 10, 81 PAGE_CUR_MBR_EQUAL = 11, 82 PAGE_CUR_RTREE_INSERT = 12, 83 PAGE_CUR_RTREE_LOCATE = 13, 84 PAGE_CUR_RTREE_GET_FATHER = 14 85 }; 86 87 88 /** The information used for compressing a page when applying 89 TRUNCATE log record during recovery */ 90 struct redo_page_compress_t { 91 ulint type; /*!< index type */ 92 index_id_t index_id; /*!< index id */ 93 ulint n_fields; /*!< number of index fields */ 94 ulint field_len; /*!< the length of index field */ 95 const byte* fields; /*!< index field information */ 96 ulint trx_id_pos; /*!< position of trx-id column. */ 97 }; 98 99 /** Compressed page descriptor */ 100 struct page_zip_des_t 101 { 102 page_zip_t* data; /*!< compressed page data */ 103 104 #ifdef UNIV_DEBUG 105 unsigned m_start:16; /*!< start offset of modification log */ 106 bool m_external; /*!< Allocated externally, not from the 107 buffer pool */ 108 #endif /* UNIV_DEBUG */ 109 unsigned m_end:16; /*!< end offset of modification log */ 110 unsigned m_nonempty:1; /*!< TRUE if the modification log 111 is not empty */ 112 unsigned n_blobs:12; /*!< number of externally stored 113 columns on the page; the maximum 114 is 744 on a 16 KiB page */ 115 unsigned ssize:PAGE_ZIP_SSIZE_BITS; 116 /*!< 0 or compressed page shift size; 117 the size in bytes is 118 (UNIV_ZIP_SIZE_MIN >> 1) << ssize. */ 119 }; 120 121 /** Compression statistics for a given page size */ 122 struct page_zip_stat_t { 123 /** Number of page compressions */ 124 ulint compressed; 125 /** Number of successful page compressions */ 126 ulint compressed_ok; 127 /** Number of page decompressions */ 128 ulint decompressed; 129 /** Duration of page compressions in microseconds */ 130 ib_uint64_t compressed_usec; 131 /** Duration of page decompressions in microseconds */ 132 ib_uint64_t decompressed_usec; page_zip_stat_tpage_zip_stat_t133 page_zip_stat_t() : 134 /* Initialize members to 0 so that when we do 135 stlmap[key].compressed++ and element with "key" does not 136 exist it gets inserted with zeroed members. */ 137 compressed(0), 138 compressed_ok(0), 139 decompressed(0), 140 compressed_usec(0), 141 decompressed_usec(0) 142 { } 143 }; 144 145 /** Compression statistics types */ 146 typedef std::map< 147 index_id_t, 148 page_zip_stat_t, 149 std::less<index_id_t>, 150 ut_allocator<std::pair<const index_id_t, page_zip_stat_t> > > 151 page_zip_stat_per_index_t; 152 153 /** Statistics on compression, indexed by page_zip_des_t::ssize - 1 */ 154 extern page_zip_stat_t page_zip_stat[PAGE_ZIP_SSIZE_MAX]; 155 /** Statistics on compression, indexed by dict_index_t::id */ 156 extern page_zip_stat_per_index_t page_zip_stat_per_index; 157 158 /**********************************************************************//** 159 Write the "deleted" flag of a record on a compressed page. The flag must 160 already have been written on the uncompressed page. */ 161 void 162 page_zip_rec_set_deleted( 163 /*=====================*/ 164 page_zip_des_t* page_zip,/*!< in/out: compressed page */ 165 const byte* rec, /*!< in: record on the uncompressed page */ 166 ulint flag) /*!< in: the deleted flag (nonzero=TRUE) */ 167 MY_ATTRIBUTE((nonnull)); 168 169 /**********************************************************************//** 170 Write the "owned" flag of a record on a compressed page. The n_owned field 171 must already have been written on the uncompressed page. */ 172 void 173 page_zip_rec_set_owned( 174 /*===================*/ 175 page_zip_des_t* page_zip,/*!< in/out: compressed page */ 176 const byte* rec, /*!< in: record on the uncompressed page */ 177 ulint flag) /*!< in: the owned flag (nonzero=TRUE) */ 178 MY_ATTRIBUTE((nonnull)); 179 180 /**********************************************************************//** 181 Shift the dense page directory when a record is deleted. */ 182 void 183 page_zip_dir_delete( 184 /*================*/ 185 page_zip_des_t* page_zip,/*!< in/out: compressed page */ 186 byte* rec, /*!< in: deleted record */ 187 dict_index_t* index, /*!< in: index of rec */ 188 const rec_offs* offsets,/*!< in: rec_get_offsets(rec) */ 189 const byte* free) /*!< in: previous start of the free list */ 190 MY_ATTRIBUTE((nonnull(1,2,3,4))); 191 192 /**********************************************************************//** 193 Add a slot to the dense page directory. */ 194 void 195 page_zip_dir_add_slot( 196 /*==================*/ 197 page_zip_des_t* page_zip, /*!< in/out: compressed page */ 198 ulint is_clustered) /*!< in: nonzero for clustered index, 199 zero for others */ 200 MY_ATTRIBUTE((nonnull)); 201 #endif /* !UNIV_INNOCHECKSUM */ 202 #endif 203