1
/******************************************************
2
Compressed page interface
6
Created June 2005 by Marko Makela
7
*******************************************************/
12
#ifdef UNIV_MATERIALIZE
17
#include "mtr0types.h"
18
#include "page0types.h"
19
#include "buf0types.h"
20
#include "dict0types.h"
23
/**************************************************************************
24
Determine the size of a compressed page in bytes. */
29
/* out: size in bytes */
30
const page_zip_des_t* page_zip) /* in: compressed page */
31
__attribute__((nonnull, pure));
32
/**************************************************************************
33
Set the size of a compressed page in bytes. */
38
page_zip_des_t* page_zip, /* in/out: compressed page */
39
ulint size); /* in: size in bytes */
41
/**************************************************************************
42
Determine if a record is so big that it needs to be stored externally. */
45
page_zip_rec_needs_ext(
46
/*===================*/
47
/* out: FALSE if the entire record
48
can be stored locally on the page */
49
ulint rec_size, /* in: length of the record in bytes */
50
ulint comp, /* in: nonzero=compact format */
51
ulint zip_size) /* in: compressed page size in bytes, or 0 */
52
__attribute__((__const__));
54
/**************************************************************************
55
Determine the guaranteed free space on an empty page. */
60
/* out: minimum payload size on the page */
61
ulint n_fields, /* in: number of columns in the index */
62
ulint zip_size) /* in: compressed page size in bytes */
63
__attribute__((const));
65
/**************************************************************************
66
Initialize a compressed page descriptor. */
71
page_zip_des_t* page_zip); /* in/out: compressed page
74
/**************************************************************************
75
Configure the zlib allocator to use the given memory heap. */
80
void* stream, /* in/out: zlib stream */
81
mem_heap_t* heap); /* in: memory heap to use */
83
/**************************************************************************
89
/* out: TRUE on success, FALSE on failure;
90
page_zip will be left intact on failure. */
91
page_zip_des_t* page_zip,/* in: size; out: data, n_blobs,
92
m_start, m_end, m_nonempty */
93
const page_t* page, /* in: uncompressed page */
94
dict_index_t* index, /* in: index of the B-tree node */
95
mtr_t* mtr) /* in: mini-transaction, or NULL */
96
__attribute__((nonnull(1,2,3)));
98
/**************************************************************************
99
Decompress a page. This function should tolerate errors on the compressed
100
page. Instead of letting assertions fail, it will return FALSE if an
101
inconsistency is detected. */
106
/* out: TRUE on success, FALSE on failure */
107
page_zip_des_t* page_zip,/* in: data, ssize;
108
out: m_start, m_end, m_nonempty, n_blobs */
109
page_t* page) /* out: uncompressed page, may be trashed */
110
__attribute__((nonnull));
113
/**************************************************************************
114
Validate a compressed page descriptor. */
117
page_zip_simple_validate(
118
/*=====================*/
119
/* out: TRUE if ok */
120
const page_zip_des_t* page_zip); /* in: compressed page
122
#endif /* UNIV_DEBUG */
124
#ifdef UNIV_ZIP_DEBUG
125
/**************************************************************************
126
Check that the compressed and decompressed pages match. */
131
const page_zip_des_t* page_zip,/* in: compressed page */
132
const page_t* page) /* in: uncompressed page */
133
__attribute__((nonnull));
134
#endif /* UNIV_ZIP_DEBUG */
136
/**************************************************************************
137
Determine how big record can be inserted without recompressing the page. */
140
page_zip_max_ins_size(
141
/*==================*/
142
/* out: a positive number
143
indicating the maximum size of
144
a record whose insertion is
145
guaranteed to succeed, or
147
const page_zip_des_t* page_zip,/* in: compressed page */
148
ibool is_clust)/* in: TRUE if clustered index */
149
__attribute__((nonnull, pure));
151
/**************************************************************************
152
Determine if enough space is available in the modification log. */
157
/* out: TRUE if page_zip_write_rec()
159
const page_zip_des_t* page_zip,/* in: compressed page */
160
ibool is_clust,/* in: TRUE if clustered index */
161
ulint length, /* in: combined size of the record */
162
ulint create) /* in: nonzero=add the record to
164
__attribute__((nonnull, pure));
166
/**************************************************************************
167
Write an entire record on the compressed page. The data must already
168
have been written to the uncompressed page. */
173
page_zip_des_t* page_zip,/* in/out: compressed page */
174
const byte* rec, /* in: record being written */
175
dict_index_t* index, /* in: the index the record belongs to */
176
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
177
ulint create) /* in: nonzero=insert, zero=update */
178
__attribute__((nonnull));
180
/***************************************************************
181
Parses a log record of writing a BLOB pointer of a record. */
184
page_zip_parse_write_blob_ptr(
185
/*==========================*/
186
/* out: end of log record or NULL */
187
byte* ptr, /* in: redo log buffer */
188
byte* end_ptr,/* in: redo log buffer end */
189
page_t* page, /* in/out: uncompressed page */
190
page_zip_des_t* page_zip);/* in/out: compressed page */
192
/**************************************************************************
193
Write a BLOB pointer of a record on the leaf page of a clustered index.
194
The information must already have been updated on the uncompressed page. */
197
page_zip_write_blob_ptr(
198
/*====================*/
199
page_zip_des_t* page_zip,/* in/out: compressed page */
200
const byte* rec, /* in/out: record whose data is being
202
dict_index_t* index, /* in: index of the page */
203
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
204
ulint n, /* in: column index */
205
mtr_t* mtr) /* in: mini-transaction handle,
206
or NULL if no logging is needed */
207
__attribute__((nonnull(1,2,3,4)));
209
/***************************************************************
210
Parses a log record of writing the node pointer of a record. */
213
page_zip_parse_write_node_ptr(
214
/*==========================*/
215
/* out: end of log record or NULL */
216
byte* ptr, /* in: redo log buffer */
217
byte* end_ptr,/* in: redo log buffer end */
218
page_t* page, /* in/out: uncompressed page */
219
page_zip_des_t* page_zip);/* in/out: compressed page */
221
/**************************************************************************
222
Write the node pointer of a record on a non-leaf compressed page. */
225
page_zip_write_node_ptr(
226
/*====================*/
227
page_zip_des_t* page_zip,/* in/out: compressed page */
228
byte* rec, /* in/out: record */
229
ulint size, /* in: data size of rec */
230
ulint ptr, /* in: node pointer */
231
mtr_t* mtr) /* in: mini-transaction, or NULL */
232
__attribute__((nonnull(1,2)));
234
/**************************************************************************
235
Write the trx_id and roll_ptr of a record on a B-tree leaf node page. */
238
page_zip_write_trx_id_and_roll_ptr(
239
/*===============================*/
240
page_zip_des_t* page_zip,/* in/out: compressed page */
241
byte* rec, /* in/out: record */
242
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
243
ulint trx_id_col,/* in: column number of TRX_ID in rec */
244
dulint trx_id, /* in: transaction identifier */
245
dulint roll_ptr)/* in: roll_ptr */
246
__attribute__((nonnull));
248
/**************************************************************************
249
Insert a record to the dense page directory. */
254
page_zip_des_t* page_zip,/* in/out: compressed page */
255
const byte* prev_rec,/* in: record after which to insert */
256
const byte* free_rec,/* in: record from which rec was
257
allocated, or NULL */
258
byte* rec); /* in: record to insert */
260
/***************************************************************
261
Parses a log record of writing to the header of a page. */
264
page_zip_parse_write_header(
265
/*========================*/
266
/* out: end of log record or NULL */
267
byte* ptr, /* in: redo log buffer */
268
byte* end_ptr,/* in: redo log buffer end */
269
page_t* page, /* in/out: uncompressed page */
270
page_zip_des_t* page_zip);/* in/out: compressed page */
272
/**************************************************************************
273
Write data to the uncompressed header portion of a page. The data must
274
already have been written to the uncompressed page.
275
However, the data portion of the uncompressed page may differ from
276
the compressed page when a record is being inserted in
277
page_cur_insert_rec_low(). */
280
page_zip_write_header(
281
/*==================*/
282
page_zip_des_t* page_zip,/* in/out: compressed page */
283
const byte* str, /* in: address on the uncompressed page */
284
ulint length, /* in: length of the data */
285
mtr_t* mtr) /* in: mini-transaction, or NULL */
286
__attribute__((nonnull(1,2)));
288
/**************************************************************************
289
Reorganize and compress a page. This is a low-level operation for
290
compressed pages, to be used when page_zip_compress() fails.
291
On success, a redo log entry MLOG_ZIP_PAGE_COMPRESS will be written.
292
The function btr_page_reorganize() should be preferred whenever possible.
293
IMPORTANT: if page_zip_reorganize() is invoked on a leaf page of a
294
non-clustered index, the caller must update the insert buffer free
295
bits in the same mini-transaction in such a way that the modification
296
will be redo-logged. */
301
/* out: TRUE on success, FALSE on failure;
302
page and page_zip will be left intact
304
buf_block_t* block, /* in/out: page with compressed page;
305
on the compressed page, in: size;
307
m_start, m_end, m_nonempty */
308
dict_index_t* index, /* in: index of the B-tree node */
309
mtr_t* mtr) /* in: mini-transaction */
310
__attribute__((nonnull));
311
/**************************************************************************
312
Copy a page byte for byte, except for the file page header and trailer. */
317
page_zip_des_t* page_zip, /* out: copy of src_zip
318
(n_blobs, m_start, m_end,
319
m_nonempty, data[0..size-1]) */
320
page_t* page, /* out: copy of src */
321
const page_zip_des_t* src_zip, /* in: compressed page */
322
const page_t* src, /* in: page */
323
dict_index_t* index, /* in: index of the B-tree */
324
mtr_t* mtr) /* in: mini-transaction */
325
__attribute__((nonnull(1,2,3,4)));
327
/**************************************************************************
328
Parses a log record of compressing an index page. */
331
page_zip_parse_compress(
332
/*====================*/
333
/* out: end of log record or NULL */
334
byte* ptr, /* in: buffer */
335
byte* end_ptr,/* in: buffer end */
336
page_t* page, /* out: uncompressed page */
337
page_zip_des_t* page_zip)/* out: compressed page */
338
__attribute__((nonnull(1,2)));
340
/**************************************************************************
341
Calculate the compressed page checksum. */
344
page_zip_calc_checksum(
345
/*===================*/
346
/* out: page checksum */
347
const void* data, /* in: compressed page */
348
ulint size) /* in: size of compressed page */
349
__attribute__((nonnull));
351
#ifdef UNIV_MATERIALIZE
353
# define UNIV_INLINE UNIV_INLINE_ORIGINAL
357
# include "page0zip.ic"
360
#endif /* page0zip_h */