641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
1 |
/*****************************************************************************
|
2 |
||
3 |
Copyright (c) 2005, 2009, Innobase Oy. 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., 59 Temple
|
|
15 |
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
*****************************************************************************/
|
|
18 |
||
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
19 |
/******************************************************
|
20 |
Compressed page interface
|
|
21 |
||
22 |
Created June 2005 by Marko Makela
|
|
23 |
*******************************************************/
|
|
24 |
||
25 |
#ifndef page0zip_h
|
|
26 |
#define page0zip_h
|
|
27 |
||
28 |
#ifdef UNIV_MATERIALIZE
|
|
29 |
# undef UNIV_INLINE
|
|
30 |
# define UNIV_INLINE
|
|
31 |
#endif
|
|
32 |
||
33 |
#include "mtr0types.h" |
|
34 |
#include "page0types.h" |
|
35 |
#include "buf0types.h" |
|
36 |
#include "dict0types.h" |
|
37 |
#include "mem0mem.h" |
|
38 |
||
39 |
/**************************************************************************
|
|
40 |
Determine the size of a compressed page in bytes. */
|
|
41 |
UNIV_INLINE
|
|
42 |
ulint
|
|
43 |
page_zip_get_size( |
|
44 |
/*==============*/
|
|
45 |
/* out: size in bytes */
|
|
46 |
const page_zip_des_t* page_zip) /* in: compressed page */ |
|
47 |
__attribute__((nonnull, pure)); |
|
48 |
/**************************************************************************
|
|
49 |
Set the size of a compressed page in bytes. */
|
|
50 |
UNIV_INLINE
|
|
51 |
void
|
|
52 |
page_zip_set_size( |
|
53 |
/*==============*/
|
|
54 |
page_zip_des_t* page_zip, /* in/out: compressed page */ |
|
55 |
ulint size); /* in: size in bytes */ |
|
56 |
||
57 |
/**************************************************************************
|
|
58 |
Determine if a record is so big that it needs to be stored externally. */
|
|
59 |
UNIV_INLINE
|
|
60 |
ibool
|
|
61 |
page_zip_rec_needs_ext( |
|
62 |
/*===================*/
|
|
63 |
/* out: FALSE if the entire record
|
|
64 |
can be stored locally on the page */
|
|
65 |
ulint rec_size, /* in: length of the record in bytes */ |
|
66 |
ulint comp, /* in: nonzero=compact format */ |
|
641.2.1
by Monty Taylor
InnoDB Plugin 1.0.2 |
67 |
ulint n_fields, /* in: number of fields in the record; |
68 |
ignored if zip_size == 0 */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
69 |
ulint zip_size) /* in: compressed page size in bytes, or 0 */ |
641.1.4
by Monty Taylor
Merged in InnoDB changes. |
70 |
__attribute__((__const__)); |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
71 |
|
72 |
/**************************************************************************
|
|
73 |
Determine the guaranteed free space on an empty page. */
|
|
74 |
UNIV_INTERN
|
|
75 |
ulint
|
|
76 |
page_zip_empty_size( |
|
77 |
/*================*/
|
|
78 |
/* out: minimum payload size on the page */
|
|
79 |
ulint n_fields, /* in: number of columns in the index */ |
|
80 |
ulint zip_size) /* in: compressed page size in bytes */ |
|
81 |
__attribute__((const)); |
|
82 |
||
83 |
/**************************************************************************
|
|
84 |
Initialize a compressed page descriptor. */
|
|
85 |
UNIV_INLINE
|
|
86 |
void
|
|
87 |
page_zip_des_init( |
|
88 |
/*==============*/
|
|
89 |
page_zip_des_t* page_zip); /* in/out: compressed page |
|
90 |
descriptor */
|
|
91 |
||
92 |
/**************************************************************************
|
|
93 |
Configure the zlib allocator to use the given memory heap. */
|
|
94 |
UNIV_INTERN
|
|
95 |
void
|
|
96 |
page_zip_set_alloc( |
|
97 |
/*===============*/
|
|
98 |
void* stream, /* in/out: zlib stream */ |
|
99 |
mem_heap_t* heap); /* in: memory heap to use */ |
|
100 |
||
101 |
/**************************************************************************
|
|
102 |
Compress a page. */
|
|
103 |
UNIV_INTERN
|
|
104 |
ibool
|
|
105 |
page_zip_compress( |
|
106 |
/*==============*/
|
|
107 |
/* out: TRUE on success, FALSE on failure;
|
|
108 |
page_zip will be left intact on failure. */
|
|
109 |
page_zip_des_t* page_zip,/* in: size; out: data, n_blobs, |
|
110 |
m_start, m_end, m_nonempty */
|
|
111 |
const page_t* page, /* in: uncompressed page */ |
|
112 |
dict_index_t* index, /* in: index of the B-tree node */ |
|
113 |
mtr_t* mtr) /* in: mini-transaction, or NULL */ |
|
114 |
__attribute__((nonnull(1,2,3))); |
|
115 |
||
116 |
/**************************************************************************
|
|
117 |
Decompress a page. This function should tolerate errors on the compressed
|
|
118 |
page. Instead of letting assertions fail, it will return FALSE if an
|
|
119 |
inconsistency is detected. */
|
|
120 |
UNIV_INTERN
|
|
121 |
ibool
|
|
122 |
page_zip_decompress( |
|
123 |
/*================*/
|
|
124 |
/* out: TRUE on success, FALSE on failure */
|
|
125 |
page_zip_des_t* page_zip,/* in: data, ssize; |
|
126 |
out: m_start, m_end, m_nonempty, n_blobs */
|
|
127 |
page_t* page) /* out: uncompressed page, may be trashed */ |
|
128 |
__attribute__((nonnull)); |
|
129 |
||
130 |
#ifdef UNIV_DEBUG
|
|
131 |
/**************************************************************************
|
|
132 |
Validate a compressed page descriptor. */
|
|
133 |
UNIV_INLINE
|
|
134 |
ibool
|
|
135 |
page_zip_simple_validate( |
|
136 |
/*=====================*/
|
|
137 |
/* out: TRUE if ok */
|
|
138 |
const page_zip_des_t* page_zip); /* in: compressed page |
|
139 |
descriptor */
|
|
140 |
#endif /* UNIV_DEBUG */ |
|
141 |
||
142 |
#ifdef UNIV_ZIP_DEBUG
|
|
143 |
/**************************************************************************
|
|
144 |
Check that the compressed and decompressed pages match. */
|
|
145 |
UNIV_INTERN
|
|
146 |
ibool
|
|
641.2.1
by Monty Taylor
InnoDB Plugin 1.0.2 |
147 |
page_zip_validate_low( |
148 |
/*==================*/
|
|
149 |
/* out: TRUE if valid, FALSE if not */
|
|
150 |
const page_zip_des_t* page_zip,/* in: compressed page */ |
|
151 |
const page_t* page, /* in: uncompressed page */ |
|
152 |
ibool sloppy) /* in: FALSE=strict, |
|
153 |
TRUE=ignore the MIN_REC_FLAG */
|
|
154 |
__attribute__((nonnull)); |
|
155 |
/**************************************************************************
|
|
156 |
Check that the compressed and decompressed pages match. */
|
|
157 |
UNIV_INTERN
|
|
158 |
ibool
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
159 |
page_zip_validate( |
160 |
/*==============*/
|
|
161 |
const page_zip_des_t* page_zip,/* in: compressed page */ |
|
162 |
const page_t* page) /* in: uncompressed page */ |
|
163 |
__attribute__((nonnull)); |
|
164 |
#endif /* UNIV_ZIP_DEBUG */ |
|
165 |
||
166 |
/**************************************************************************
|
|
167 |
Determine how big record can be inserted without recompressing the page. */
|
|
168 |
UNIV_INLINE
|
|
169 |
lint
|
|
170 |
page_zip_max_ins_size( |
|
171 |
/*==================*/
|
|
172 |
/* out: a positive number
|
|
173 |
indicating the maximum size of
|
|
174 |
a record whose insertion is
|
|
175 |
guaranteed to succeed, or
|
|
176 |
zero or negative */
|
|
177 |
const page_zip_des_t* page_zip,/* in: compressed page */ |
|
178 |
ibool is_clust)/* in: TRUE if clustered index */ |
|
179 |
__attribute__((nonnull, pure)); |
|
180 |
||
181 |
/**************************************************************************
|
|
182 |
Determine if enough space is available in the modification log. */
|
|
183 |
UNIV_INLINE
|
|
184 |
ibool
|
|
185 |
page_zip_available( |
|
186 |
/*===============*/
|
|
187 |
/* out: TRUE if page_zip_write_rec()
|
|
188 |
will succeed */
|
|
189 |
const page_zip_des_t* page_zip,/* in: compressed page */ |
|
190 |
ibool is_clust,/* in: TRUE if clustered index */ |
|
191 |
ulint length, /* in: combined size of the record */ |
|
192 |
ulint create) /* in: nonzero=add the record to |
|
193 |
the heap */
|
|
194 |
__attribute__((nonnull, pure)); |
|
195 |
||
196 |
/**************************************************************************
|
|
197 |
Write an entire record on the compressed page. The data must already
|
|
198 |
have been written to the uncompressed page. */
|
|
199 |
UNIV_INTERN
|
|
200 |
void
|
|
201 |
page_zip_write_rec( |
|
202 |
/*===============*/
|
|
203 |
page_zip_des_t* page_zip,/* in/out: compressed page */ |
|
204 |
const byte* rec, /* in: record being written */ |
|
205 |
dict_index_t* index, /* in: the index the record belongs to */ |
|
206 |
const ulint* offsets,/* in: rec_get_offsets(rec, index) */ |
|
207 |
ulint create) /* in: nonzero=insert, zero=update */ |
|
208 |
__attribute__((nonnull)); |
|
209 |
||
210 |
/***************************************************************
|
|
211 |
Parses a log record of writing a BLOB pointer of a record. */
|
|
212 |
UNIV_INTERN
|
|
213 |
byte* |
|
214 |
page_zip_parse_write_blob_ptr( |
|
215 |
/*==========================*/
|
|
216 |
/* out: end of log record or NULL */
|
|
217 |
byte* ptr, /* in: redo log buffer */ |
|
218 |
byte* end_ptr,/* in: redo log buffer end */ |
|
219 |
page_t* page, /* in/out: uncompressed page */ |
|
220 |
page_zip_des_t* page_zip);/* in/out: compressed page */ |
|
221 |
||
222 |
/**************************************************************************
|
|
223 |
Write a BLOB pointer of a record on the leaf page of a clustered index.
|
|
224 |
The information must already have been updated on the uncompressed page. */
|
|
225 |
UNIV_INTERN
|
|
226 |
void
|
|
227 |
page_zip_write_blob_ptr( |
|
228 |
/*====================*/
|
|
229 |
page_zip_des_t* page_zip,/* in/out: compressed page */ |
|
230 |
const byte* rec, /* in/out: record whose data is being |
|
231 |
written */
|
|
232 |
dict_index_t* index, /* in: index of the page */ |
|
233 |
const ulint* offsets,/* in: rec_get_offsets(rec, index) */ |
|
234 |
ulint n, /* in: column index */ |
|
235 |
mtr_t* mtr) /* in: mini-transaction handle, |
|
236 |
or NULL if no logging is needed */
|
|
237 |
__attribute__((nonnull(1,2,3,4))); |
|
238 |
||
239 |
/***************************************************************
|
|
240 |
Parses a log record of writing the node pointer of a record. */
|
|
241 |
UNIV_INTERN
|
|
242 |
byte* |
|
243 |
page_zip_parse_write_node_ptr( |
|
244 |
/*==========================*/
|
|
245 |
/* out: end of log record or NULL */
|
|
246 |
byte* ptr, /* in: redo log buffer */ |
|
247 |
byte* end_ptr,/* in: redo log buffer end */ |
|
248 |
page_t* page, /* in/out: uncompressed page */ |
|
249 |
page_zip_des_t* page_zip);/* in/out: compressed page */ |
|
250 |
||
251 |
/**************************************************************************
|
|
252 |
Write the node pointer of a record on a non-leaf compressed page. */
|
|
253 |
UNIV_INTERN
|
|
254 |
void
|
|
255 |
page_zip_write_node_ptr( |
|
256 |
/*====================*/
|
|
257 |
page_zip_des_t* page_zip,/* in/out: compressed page */ |
|
258 |
byte* rec, /* in/out: record */ |
|
259 |
ulint size, /* in: data size of rec */ |
|
260 |
ulint ptr, /* in: node pointer */ |
|
261 |
mtr_t* mtr) /* in: mini-transaction, or NULL */ |
|
262 |
__attribute__((nonnull(1,2))); |
|
263 |
||
264 |
/**************************************************************************
|
|
265 |
Write the trx_id and roll_ptr of a record on a B-tree leaf node page. */
|
|
266 |
UNIV_INTERN
|
|
267 |
void
|
|
268 |
page_zip_write_trx_id_and_roll_ptr( |
|
269 |
/*===============================*/
|
|
270 |
page_zip_des_t* page_zip,/* in/out: compressed page */ |
|
271 |
byte* rec, /* in/out: record */ |
|
272 |
const ulint* offsets,/* in: rec_get_offsets(rec, index) */ |
|
273 |
ulint trx_id_col,/* in: column number of TRX_ID in rec */ |
|
274 |
dulint trx_id, /* in: transaction identifier */ |
|
275 |
dulint roll_ptr)/* in: roll_ptr */ |
|
276 |
__attribute__((nonnull)); |
|
277 |
||
278 |
/**************************************************************************
|
|
279 |
Insert a record to the dense page directory. */
|
|
280 |
UNIV_INTERN
|
|
281 |
void
|
|
282 |
page_zip_dir_insert( |
|
283 |
/*================*/
|
|
284 |
page_zip_des_t* page_zip,/* in/out: compressed page */ |
|
285 |
const byte* prev_rec,/* in: record after which to insert */ |
|
286 |
const byte* free_rec,/* in: record from which rec was |
|
287 |
allocated, or NULL */
|
|
288 |
byte* rec); /* in: record to insert */ |
|
289 |
||
290 |
/***************************************************************
|
|
291 |
Parses a log record of writing to the header of a page. */
|
|
292 |
UNIV_INTERN
|
|
293 |
byte* |
|
294 |
page_zip_parse_write_header( |
|
295 |
/*========================*/
|
|
296 |
/* out: end of log record or NULL */
|
|
297 |
byte* ptr, /* in: redo log buffer */ |
|
298 |
byte* end_ptr,/* in: redo log buffer end */ |
|
299 |
page_t* page, /* in/out: uncompressed page */ |
|
300 |
page_zip_des_t* page_zip);/* in/out: compressed page */ |
|
301 |
||
302 |
/**************************************************************************
|
|
303 |
Write data to the uncompressed header portion of a page. The data must
|
|
304 |
already have been written to the uncompressed page.
|
|
305 |
However, the data portion of the uncompressed page may differ from
|
|
306 |
the compressed page when a record is being inserted in
|
|
307 |
page_cur_insert_rec_low(). */
|
|
308 |
UNIV_INLINE
|
|
309 |
void
|
|
310 |
page_zip_write_header( |
|
311 |
/*==================*/
|
|
312 |
page_zip_des_t* page_zip,/* in/out: compressed page */ |
|
313 |
const byte* str, /* in: address on the uncompressed page */ |
|
314 |
ulint length, /* in: length of the data */ |
|
315 |
mtr_t* mtr) /* in: mini-transaction, or NULL */ |
|
316 |
__attribute__((nonnull(1,2))); |
|
317 |
||
318 |
/**************************************************************************
|
|
319 |
Reorganize and compress a page. This is a low-level operation for
|
|
320 |
compressed pages, to be used when page_zip_compress() fails.
|
|
321 |
On success, a redo log entry MLOG_ZIP_PAGE_COMPRESS will be written.
|
|
322 |
The function btr_page_reorganize() should be preferred whenever possible.
|
|
323 |
IMPORTANT: if page_zip_reorganize() is invoked on a leaf page of a
|
|
324 |
non-clustered index, the caller must update the insert buffer free
|
|
325 |
bits in the same mini-transaction in such a way that the modification
|
|
326 |
will be redo-logged. */
|
|
327 |
UNIV_INTERN
|
|
328 |
ibool
|
|
329 |
page_zip_reorganize( |
|
330 |
/*================*/
|
|
331 |
/* out: TRUE on success, FALSE on failure;
|
|
332 |
page and page_zip will be left intact
|
|
333 |
on failure. */
|
|
334 |
buf_block_t* block, /* in/out: page with compressed page; |
|
335 |
on the compressed page, in: size;
|
|
336 |
out: data, n_blobs,
|
|
337 |
m_start, m_end, m_nonempty */
|
|
338 |
dict_index_t* index, /* in: index of the B-tree node */ |
|
339 |
mtr_t* mtr) /* in: mini-transaction */ |
|
340 |
__attribute__((nonnull)); |
|
341 |
/**************************************************************************
|
|
641.2.1
by Monty Taylor
InnoDB Plugin 1.0.2 |
342 |
Copy the records of a page byte for byte. Do not copy the page header
|
343 |
or trailer, except those B-tree header fields that are directly
|
|
344 |
related to the storage of records. Also copy PAGE_MAX_TRX_ID.
|
|
345 |
NOTE: The caller must update the lock table and the adaptive hash index. */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
346 |
UNIV_INTERN
|
347 |
void
|
|
641.2.1
by Monty Taylor
InnoDB Plugin 1.0.2 |
348 |
page_zip_copy_recs( |
349 |
/*===============*/
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
350 |
page_zip_des_t* page_zip, /* out: copy of src_zip |
351 |
(n_blobs, m_start, m_end,
|
|
352 |
m_nonempty, data[0..size-1]) */
|
|
353 |
page_t* page, /* out: copy of src */ |
|
354 |
const page_zip_des_t* src_zip, /* in: compressed page */ |
|
355 |
const page_t* src, /* in: page */ |
|
356 |
dict_index_t* index, /* in: index of the B-tree */ |
|
357 |
mtr_t* mtr) /* in: mini-transaction */ |
|
358 |
__attribute__((nonnull(1,2,3,4))); |
|
359 |
||
360 |
/**************************************************************************
|
|
361 |
Parses a log record of compressing an index page. */
|
|
362 |
UNIV_INTERN
|
|
363 |
byte* |
|
364 |
page_zip_parse_compress( |
|
365 |
/*====================*/
|
|
366 |
/* out: end of log record or NULL */
|
|
367 |
byte* ptr, /* in: buffer */ |
|
368 |
byte* end_ptr,/* in: buffer end */ |
|
369 |
page_t* page, /* out: uncompressed page */ |
|
370 |
page_zip_des_t* page_zip)/* out: compressed page */ |
|
371 |
__attribute__((nonnull(1,2))); |
|
372 |
||
373 |
/**************************************************************************
|
|
374 |
Calculate the compressed page checksum. */
|
|
375 |
UNIV_INTERN
|
|
376 |
ulint
|
|
377 |
page_zip_calc_checksum( |
|
378 |
/*===================*/
|
|
379 |
/* out: page checksum */
|
|
380 |
const void* data, /* in: compressed page */ |
|
381 |
ulint size) /* in: size of compressed page */ |
|
382 |
__attribute__((nonnull)); |
|
383 |
||
384 |
#ifdef UNIV_MATERIALIZE
|
|
385 |
# undef UNIV_INLINE
|
|
386 |
# define UNIV_INLINE UNIV_INLINE_ORIGINAL
|
|
387 |
#endif
|
|
388 |
||
389 |
#ifndef UNIV_NONINL
|
|
390 |
# include "page0zip.ic"
|
|
391 |
#endif
|
|
392 |
||
393 |
#endif /* page0zip_h */ |