~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/btr0btr.h

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
 
58
58
/******************************************************************
59
59
Gets the root node of a tree and x-latches it. */
60
 
UNIV_INTERN
 
60
 
61
61
page_t*
62
62
btr_root_get(
63
63
/*=========*/
67
67
/******************************************************************
68
68
Gets a buffer page and declares its latching order level. */
69
69
UNIV_INLINE
70
 
buf_block_t*
71
 
btr_block_get(
72
 
/*==========*/
73
 
        ulint   space,          /* in: space id */
74
 
        ulint   zip_size,       /* in: compressed page size in bytes
75
 
                                or 0 for uncompressed pages */
76
 
        ulint   page_no,        /* in: page number */
77
 
        ulint   mode,           /* in: latch mode */
78
 
        mtr_t*  mtr);           /* in: mtr */
79
 
/******************************************************************
80
 
Gets a buffer page and declares its latching order level. */
81
 
UNIV_INLINE
82
70
page_t*
83
71
btr_page_get(
84
72
/*=========*/
85
73
        ulint   space,          /* in: space id */
86
 
        ulint   zip_size,       /* in: compressed page size in bytes
87
 
                                or 0 for uncompressed pages */
88
74
        ulint   page_no,        /* in: page number */
89
75
        ulint   mode,           /* in: latch mode */
90
76
        mtr_t*  mtr);           /* in: mtr */
95
81
btr_page_get_index_id(
96
82
/*==================*/
97
83
                                /* out: index id */
98
 
        const page_t*   page);  /* in: index page */
 
84
        page_t*         page);  /* in: index page */
99
85
/************************************************************
100
86
Gets the node level field in an index page. */
101
87
UNIV_INLINE
102
88
ulint
103
89
btr_page_get_level_low(
104
90
/*===================*/
105
 
                                /* out: level, leaf level == 0 */
106
 
        const page_t*   page);  /* in: index page */
 
91
                        /* out: level, leaf level == 0 */
 
92
        page_t* page);  /* in: index page */
107
93
/************************************************************
108
94
Gets the node level field in an index page. */
109
95
UNIV_INLINE
110
96
ulint
111
97
btr_page_get_level(
112
98
/*===============*/
113
 
                                /* out: level, leaf level == 0 */
114
 
        const page_t*   page,   /* in: index page */
115
 
        mtr_t*          mtr);   /* in: mini-transaction handle */
 
99
                        /* out: level, leaf level == 0 */
 
100
        page_t* page,   /* in: index page */
 
101
        mtr_t*  mtr);   /* in: mini-transaction handle */
116
102
/************************************************************
117
103
Gets the next index page number. */
118
104
UNIV_INLINE
119
105
ulint
120
106
btr_page_get_next(
121
107
/*==============*/
122
 
                                /* out: next page number */
123
 
        const page_t*   page,   /* in: index page */
124
 
        mtr_t*          mtr);   /* in: mini-transaction handle */
 
108
                        /* out: next page number */
 
109
        page_t* page,   /* in: index page */
 
110
        mtr_t*  mtr);   /* in: mini-transaction handle */
125
111
/************************************************************
126
112
Gets the previous index page number. */
127
113
UNIV_INLINE
128
114
ulint
129
115
btr_page_get_prev(
130
116
/*==============*/
131
 
                                /* out: prev page number */
132
 
        const page_t*   page,   /* in: index page */
133
 
        mtr_t*          mtr);   /* in: mini-transaction handle */
 
117
                        /* out: prev page number */
 
118
        page_t* page,   /* in: index page */
 
119
        mtr_t*  mtr);   /* in: mini-transaction handle */
134
120
/*****************************************************************
135
121
Gets pointer to the previous user record in the tree. It is assumed
136
122
that the caller has appropriate latches on the page and its neighbor. */
137
 
UNIV_INTERN
 
123
 
138
124
rec_t*
139
125
btr_get_prev_user_rec(
140
126
/*==================*/
145
131
/*****************************************************************
146
132
Gets pointer to the next user record in the tree. It is assumed
147
133
that the caller has appropriate latches on the page and its neighbor. */
148
 
UNIV_INTERN
 
134
 
149
135
rec_t*
150
136
btr_get_next_user_rec(
151
137
/*==================*/
159
145
void
160
146
btr_leaf_page_release(
161
147
/*==================*/
162
 
        buf_block_t*    block,          /* in: buffer block */
163
 
        ulint           latch_mode,     /* in: BTR_SEARCH_LEAF or
164
 
                                        BTR_MODIFY_LEAF */
165
 
        mtr_t*          mtr);           /* in: mtr */
 
148
        page_t* page,           /* in: page */
 
149
        ulint   latch_mode,     /* in: BTR_SEARCH_LEAF or BTR_MODIFY_LEAF */
 
150
        mtr_t*  mtr);           /* in: mtr */
166
151
/******************************************************************
167
152
Gets the child node file address in a node pointer. */
168
153
UNIV_INLINE
170
155
btr_node_ptr_get_child_page_no(
171
156
/*===========================*/
172
157
                                /* out: child node address */
173
 
        const rec_t*    rec,    /* in: node pointer record */
 
158
        rec_t*          rec,    /* in: node pointer record */
174
159
        const ulint*    offsets);/* in: array returned by rec_get_offsets() */
175
160
/****************************************************************
176
161
Creates the root node for a new index tree. */
177
 
UNIV_INTERN
 
162
 
178
163
ulint
179
164
btr_create(
180
165
/*=======*/
181
 
                                /* out: page number of the created root,
182
 
                                FIL_NULL if did not succeed */
183
 
        ulint           type,   /* in: type of the index */
184
 
        ulint           space,  /* in: space where created */
185
 
        ulint           zip_size,/* in: compressed page size in bytes
186
 
                                or 0 for uncompressed pages */
187
 
        dulint          index_id,/* in: index id */
188
 
        dict_index_t*   index,  /* in: index */
189
 
        mtr_t*          mtr);   /* in: mini-transaction handle */
 
166
                        /* out: page number of the created root, FIL_NULL if
 
167
                        did not succeed */
 
168
        ulint   type,   /* in: type of the index */
 
169
        ulint   space,  /* in: space where created */
 
170
        dulint  index_id,/* in: index id */
 
171
        ulint   comp,   /* in: nonzero=compact page format */
 
172
        mtr_t*  mtr);   /* in: mini-transaction handle */
190
173
/****************************************************************
191
174
Frees a B-tree except the root page, which MUST be freed after this
192
175
by calling btr_free_root. */
193
 
UNIV_INTERN
 
176
 
194
177
void
195
178
btr_free_but_not_root(
196
179
/*==================*/
197
180
        ulint   space,          /* in: space where created */
198
 
        ulint   zip_size,       /* in: compressed page size in bytes
199
 
                                or 0 for uncompressed pages */
200
181
        ulint   root_page_no);  /* in: root page number */
201
182
/****************************************************************
202
183
Frees the B-tree root page. Other tree MUST already have been freed. */
203
 
UNIV_INTERN
 
184
 
204
185
void
205
186
btr_free_root(
206
187
/*==========*/
207
188
        ulint   space,          /* in: space where created */
208
 
        ulint   zip_size,       /* in: compressed page size in bytes
209
 
                                or 0 for uncompressed pages */
210
189
        ulint   root_page_no,   /* in: root page number */
211
190
        mtr_t*  mtr);           /* in: a mini-transaction which has already
212
191
                                been started */
216
195
NOTE that the operation of this function must always succeed,
217
196
we cannot reverse it: therefore enough free disk space must be
218
197
guaranteed to be available before this function is called. */
219
 
UNIV_INTERN
 
198
 
220
199
rec_t*
221
200
btr_root_raise_and_insert(
222
201
/*======================*/
225
204
                                on the root page; when the function returns,
226
205
                                the cursor is positioned on the predecessor
227
206
                                of the inserted record */
228
 
        const dtuple_t* tuple,  /* in: tuple to insert */
229
 
        ulint           n_ext,  /* in: number of externally stored columns */
 
207
        dtuple_t*       tuple,  /* in: tuple to insert */
230
208
        mtr_t*          mtr);   /* in: mtr */
231
209
/*****************************************************************
232
 
Reorganizes an index page.
233
 
IMPORTANT: if btr_page_reorganize() is invoked on a compressed leaf
234
 
page of a non-clustered index, the caller must update the insert
235
 
buffer free bits in the same mini-transaction in such a way that the
236
 
modification will be redo-logged. */
237
 
UNIV_INTERN
238
 
ibool
 
210
Reorganizes an index page. */
 
211
 
 
212
void
239
213
btr_page_reorganize(
240
214
/*================*/
241
 
                                /* out: TRUE on success, FALSE on failure */
242
 
        buf_block_t*    block,  /* in: page to be reorganized */
 
215
        page_t*         page,   /* in: page to be reorganized */
243
216
        dict_index_t*   index,  /* in: record descriptor */
244
217
        mtr_t*          mtr);   /* in: mtr */
245
218
/*****************************************************************
246
219
Decides if the page should be split at the convergence point of
247
220
inserts converging to left. */
248
 
UNIV_INTERN
 
221
 
249
222
ibool
250
223
btr_page_get_split_rec_to_left(
251
224
/*===========================*/
257
230
/*****************************************************************
258
231
Decides if the page should be split at the convergence point of
259
232
inserts converging to right. */
260
 
UNIV_INTERN
 
233
 
261
234
ibool
262
235
btr_page_get_split_rec_to_right(
263
236
/*============================*/
273
246
function must always succeed, we cannot reverse it: therefore
274
247
enough free disk space must be guaranteed to be available before
275
248
this function is called. */
276
 
UNIV_INTERN
 
249
 
277
250
rec_t*
278
251
btr_page_split_and_insert(
279
252
/*======================*/
283
256
        btr_cur_t*      cursor, /* in: cursor at which to insert; when the
284
257
                                function returns, the cursor is positioned
285
258
                                on the predecessor of the inserted record */
286
 
        const dtuple_t* tuple,  /* in: tuple to insert */
287
 
        ulint           n_ext,  /* in: number of externally stored columns */
 
259
        dtuple_t*       tuple,  /* in: tuple to insert */
288
260
        mtr_t*          mtr);   /* in: mtr */
289
261
/***********************************************************
290
262
Inserts a data tuple to a tree on a non-leaf level. It is assumed
291
263
that mtr holds an x-latch on the tree. */
292
 
UNIV_INTERN
 
264
 
293
265
void
294
266
btr_insert_on_non_leaf_level(
295
267
/*=========================*/
299
271
        mtr_t*          mtr);   /* in: mtr */
300
272
/********************************************************************
301
273
Sets a record as the predefined minimum record. */
302
 
UNIV_INTERN
 
274
 
303
275
void
304
276
btr_set_min_rec_mark(
305
277
/*=================*/
306
 
        rec_t*  rec,    /* in/out: record */
 
278
        rec_t*  rec,    /* in: record */
 
279
        ulint   comp,   /* in: nonzero=compact page format */
307
280
        mtr_t*  mtr);   /* in: mtr */
308
281
/*****************************************************************
309
282
Deletes on the upper level the node pointer to a page. */
310
 
UNIV_INTERN
 
283
 
311
284
void
312
285
btr_node_ptr_delete(
313
286
/*================*/
314
287
        dict_index_t*   index,  /* in: index tree */
315
 
        buf_block_t*    block,  /* in: page whose node pointer is deleted */
 
288
        page_t*         page,   /* in: page whose node pointer is deleted */
316
289
        mtr_t*          mtr);   /* in: mtr */
317
290
#ifdef UNIV_DEBUG
318
291
/****************************************************************
319
292
Checks that the node pointer to a page is appropriate. */
320
 
UNIV_INTERN
 
293
 
321
294
ibool
322
295
btr_check_node_ptr(
323
296
/*===============*/
324
297
                                /* out: TRUE */
325
298
        dict_index_t*   index,  /* in: index tree */
326
 
        buf_block_t*    block,  /* in: index page */
 
299
        page_t*         page,   /* in: index page */
327
300
        mtr_t*          mtr);   /* in: mtr */
328
301
#endif /* UNIV_DEBUG */
329
302
/*****************************************************************
334
307
level lifts the records of the page to the father page, thus reducing the
335
308
tree height. It is assumed that mtr holds an x-latch on the tree and on the
336
309
page. If cursor is on the leaf level, mtr must also hold x-latches to
337
 
the brothers, if they exist. */
338
 
UNIV_INTERN
339
 
ibool
 
310
the brothers, if they exist. NOTE: it is assumed that the caller has reserved
 
311
enough free extents so that the compression will always succeed if done! */
 
312
void
340
313
btr_compress(
341
314
/*=========*/
342
 
                                /* out: TRUE on success */
343
315
        btr_cur_t*      cursor, /* in: cursor on the page to merge or lift;
344
316
                                the page must not be empty: in record delete
345
317
                                use btr_discard_page if the page would become
349
321
Discards a page from a B-tree. This is used to remove the last record from
350
322
a B-tree page: the whole page must be removed at the same time. This cannot
351
323
be used for the root page, which is allowed to be empty. */
352
 
UNIV_INTERN
 
324
 
353
325
void
354
326
btr_discard_page(
355
327
/*=============*/
359
331
/********************************************************************
360
332
Parses the redo log record for setting an index record as the predefined
361
333
minimum record. */
362
 
UNIV_INTERN
 
334
 
363
335
byte*
364
336
btr_parse_set_min_rec_mark(
365
337
/*=======================*/
371
343
        mtr_t*  mtr);   /* in: mtr or NULL */
372
344
/***************************************************************
373
345
Parses a redo log record of reorganizing a page. */
374
 
UNIV_INTERN
 
346
 
375
347
byte*
376
348
btr_parse_page_reorganize(
377
349
/*======================*/
379
351
        byte*           ptr,    /* in: buffer */
380
352
        byte*           end_ptr,/* in: buffer end */
381
353
        dict_index_t*   index,  /* in: record descriptor */
382
 
        buf_block_t*    block,  /* in: page to be reorganized, or NULL */
 
354
        page_t*         page,   /* in: page or NULL */
383
355
        mtr_t*          mtr);   /* in: mtr or NULL */
384
356
/******************************************************************
385
357
Gets the number of pages in a B-tree. */
386
 
UNIV_INTERN
 
358
 
387
359
ulint
388
360
btr_get_size(
389
361
/*=========*/
393
365
/******************************************************************
394
366
Allocates a new file page to be used in an index tree. NOTE: we assume
395
367
that the caller has made the reservation for free extents! */
396
 
UNIV_INTERN
397
 
buf_block_t*
 
368
 
 
369
page_t*
398
370
btr_page_alloc(
399
371
/*===========*/
400
 
                                        /* out: new allocated block, x-latched;
 
372
                                        /* out: new allocated page, x-latched;
401
373
                                        NULL if out of space */
402
374
        dict_index_t*   index,          /* in: index tree */
403
375
        ulint           hint_page_no,   /* in: hint of a good page */
409
381
/******************************************************************
410
382
Frees a file page used in an index tree. NOTE: cannot free field external
411
383
storage pages because the page must contain info on its level. */
412
 
UNIV_INTERN
 
384
 
413
385
void
414
386
btr_page_free(
415
387
/*==========*/
416
388
        dict_index_t*   index,  /* in: index tree */
417
 
        buf_block_t*    block,  /* in: block to be freed, x-latched */
 
389
        page_t*         page,   /* in: page to be freed, x-latched */
418
390
        mtr_t*          mtr);   /* in: mtr */
419
391
/******************************************************************
420
392
Frees a file page used in an index tree. Can be used also to BLOB
421
393
external storage pages, because the page level 0 can be given as an
422
394
argument. */
423
 
UNIV_INTERN
 
395
 
424
396
void
425
397
btr_page_free_low(
426
398
/*==============*/
427
399
        dict_index_t*   index,  /* in: index tree */
428
 
        buf_block_t*    block,  /* in: block to be freed, x-latched */
 
400
        page_t*         page,   /* in: page to be freed, x-latched */
429
401
        ulint           level,  /* in: page level */
430
402
        mtr_t*          mtr);   /* in: mtr */
431
403
#ifdef UNIV_BTR_PRINT
432
404
/*****************************************************************
433
405
Prints size info of a B-tree. */
434
 
UNIV_INTERN
 
406
 
435
407
void
436
408
btr_print_size(
437
409
/*===========*/
438
410
        dict_index_t*   index); /* in: index tree */
439
411
/******************************************************************
440
412
Prints directories and other info of all nodes in the index. */
441
 
UNIV_INTERN
 
413
 
442
414
void
443
415
btr_print_index(
444
416
/*============*/
449
421
/****************************************************************
450
422
Checks the size and number of fields in a record based on the definition of
451
423
the index. */
452
 
UNIV_INTERN
 
424
 
453
425
ibool
454
426
btr_index_rec_validate(
455
427
/*===================*/
456
 
                                                /* out: TRUE if ok */
457
 
        const rec_t*            rec,            /* in: index record */
458
 
        const dict_index_t*     index,          /* in: index */
459
 
        ibool                   dump_on_error); /* in: TRUE if the function
460
 
                                                should print hex dump of record
461
 
                                                and page on error */
 
428
                                        /* out: TRUE if ok */
 
429
        rec_t*          rec,            /* in: index record */
 
430
        dict_index_t*   index,          /* in: index */
 
431
        ibool           dump_on_error); /* in: TRUE if the function
 
432
                                        should print hex dump of record
 
433
                                        and page on error */
462
434
/******************************************************************
463
435
Checks the consistency of an index tree. */
464
 
UNIV_INTERN
 
436
 
465
437
ibool
466
438
btr_validate_index(
467
439
/*===============*/