46
45
#define BTR_PCUR_BEFORE_FIRST_IN_TREE 4 /* in an empty tree */
47
46
#define BTR_PCUR_AFTER_LAST_IN_TREE 5 /* in an empty tree */
49
/**************************************************************//**
50
Allocates memory for a persistent cursor object and initializes the cursor.
51
@return own: persistent cursor */
48
/******************************************************************
49
Allocates memory for a persistent cursor object and initializes the cursor. */
54
52
btr_pcur_create_for_mysql(void);
55
53
/*============================*/
56
/**************************************************************//**
54
/* out, own: persistent cursor */
55
/******************************************************************
57
56
Frees the memory for a persistent cursor object. */
60
59
btr_pcur_free_for_mysql(
61
60
/*====================*/
62
btr_pcur_t* cursor); /*!< in, own: persistent cursor */
63
/**************************************************************//**
61
btr_pcur_t* cursor); /* in, own: persistent cursor */
62
/******************************************************************
64
63
Copies the stored position of a pcur to another pcur. */
67
66
btr_pcur_copy_stored_position(
68
67
/*==========================*/
69
btr_pcur_t* pcur_receive, /*!< in: pcur which will receive the
68
btr_pcur_t* pcur_receive, /* in: pcur which will receive the
71
btr_pcur_t* pcur_donate); /*!< in: pcur from which the info is
70
btr_pcur_t* pcur_donate); /* in: pcur from which the info is
73
/**************************************************************//**
72
/******************************************************************
74
73
Sets the old_rec_buf field to NULL. */
79
btr_pcur_t* pcur); /*!< in: persistent cursor */
80
/**************************************************************//**
78
btr_pcur_t* pcur); /* in: persistent cursor */
79
/******************************************************************
81
80
Initializes and opens a persistent cursor to an index tree. It should be
82
81
closed with btr_pcur_close. */
87
dict_index_t* index, /*!< in: index */
88
const dtuple_t* tuple, /*!< in: tuple on which search done */
89
ulint mode, /*!< in: PAGE_CUR_L, ...;
86
dict_index_t* index, /* in: index */
87
const dtuple_t* tuple, /* in: tuple on which search done */
88
ulint mode, /* in: PAGE_CUR_L, ...;
90
89
NOTE that if the search is made using a unique
91
90
prefix of a record, mode should be
92
91
PAGE_CUR_LE, not PAGE_CUR_GE, as the latter
93
92
may end up on the previous page from the
95
ulint latch_mode,/*!< in: BTR_SEARCH_LEAF, ... */
96
btr_pcur_t* cursor, /*!< in: memory buffer for persistent cursor */
97
mtr_t* mtr); /*!< in: mtr */
98
/**************************************************************//**
94
ulint latch_mode,/* in: BTR_SEARCH_LEAF, ... */
95
btr_pcur_t* cursor, /* in: memory buffer for persistent cursor */
96
mtr_t* mtr); /* in: mtr */
97
/******************************************************************
99
98
Opens an persistent cursor to an index tree without initializing the
103
102
btr_pcur_open_with_no_init(
104
103
/*=======================*/
105
dict_index_t* index, /*!< in: index */
106
const dtuple_t* tuple, /*!< in: tuple on which search done */
107
ulint mode, /*!< in: PAGE_CUR_L, ...;
104
dict_index_t* index, /* in: index */
105
const dtuple_t* tuple, /* in: tuple on which search done */
106
ulint mode, /* in: PAGE_CUR_L, ...;
108
107
NOTE that if the search is made using a unique
109
108
prefix of a record, mode should be
110
109
PAGE_CUR_LE, not PAGE_CUR_GE, as the latter
111
110
may end up on the previous page of the
113
ulint latch_mode,/*!< in: BTR_SEARCH_LEAF, ...;
112
ulint latch_mode,/* in: BTR_SEARCH_LEAF, ...;
114
113
NOTE that if has_search_latch != 0 then
115
114
we maybe do not acquire a latch on the cursor
116
115
page, but assume that the caller uses his
117
116
btr search latch to protect the record! */
118
btr_pcur_t* cursor, /*!< in: memory buffer for persistent cursor */
119
ulint has_search_latch,/*!< in: latch mode the caller
117
btr_pcur_t* cursor, /* in: memory buffer for persistent cursor */
118
ulint has_search_latch,/* in: latch mode the caller
120
119
currently has on btr_search_latch:
121
120
RW_S_LATCH, or 0 */
122
mtr_t* mtr); /*!< in: mtr */
123
/*****************************************************************//**
121
mtr_t* mtr); /* in: mtr */
122
/*********************************************************************
124
123
Opens a persistent cursor at either end of an index. */
127
126
btr_pcur_open_at_index_side(
128
127
/*========================*/
129
ibool from_left, /*!< in: TRUE if open to the low end,
128
ibool from_left, /* in: TRUE if open to the low end,
130
129
FALSE if to the high end */
131
dict_index_t* index, /*!< in: index */
132
ulint latch_mode, /*!< in: latch mode */
133
btr_pcur_t* pcur, /*!< in: cursor */
134
ibool do_init, /*!< in: TRUE if should be initialized */
135
mtr_t* mtr); /*!< in: mtr */
136
/**************************************************************//**
137
Gets the up_match value for a pcur after a search.
138
@return number of matched fields at the cursor or to the right if
139
search mode was PAGE_CUR_GE, otherwise undefined */
130
dict_index_t* index, /* in: index */
131
ulint latch_mode, /* in: latch mode */
132
btr_pcur_t* pcur, /* in: cursor */
133
ibool do_init, /* in: TRUE if should be initialized */
134
mtr_t* mtr); /* in: mtr */
135
/******************************************************************
136
Gets the up_match value for a pcur after a search. */
142
139
btr_pcur_get_up_match(
143
140
/*==================*/
144
btr_pcur_t* cursor); /*!< in: memory buffer for persistent cursor */
145
/**************************************************************//**
146
Gets the low_match value for a pcur after a search.
147
@return number of matched fields at the cursor or to the right if
148
search mode was PAGE_CUR_LE, otherwise undefined */
141
/* out: number of matched fields at the cursor
142
or to the right if search mode was PAGE_CUR_GE,
143
otherwise undefined */
144
btr_pcur_t* cursor); /* in: memory buffer for persistent cursor */
145
/******************************************************************
146
Gets the low_match value for a pcur after a search. */
151
149
btr_pcur_get_low_match(
152
150
/*===================*/
153
btr_pcur_t* cursor); /*!< in: memory buffer for persistent cursor */
154
/**************************************************************//**
151
/* out: number of matched fields at the cursor
152
or to the right if search mode was PAGE_CUR_LE,
153
otherwise undefined */
154
btr_pcur_t* cursor); /* in: memory buffer for persistent cursor */
155
/******************************************************************
155
156
If mode is PAGE_CUR_G or PAGE_CUR_GE, opens a persistent cursor on the first
156
157
user record satisfying the search condition, in the case PAGE_CUR_L or
157
158
PAGE_CUR_LE, on the last user record. If no such user record exists, then
163
164
btr_pcur_open_on_user_rec(
164
165
/*======================*/
165
dict_index_t* index, /*!< in: index */
166
const dtuple_t* tuple, /*!< in: tuple on which search done */
167
ulint mode, /*!< in: PAGE_CUR_L, ... */
168
ulint latch_mode, /*!< in: BTR_SEARCH_LEAF or
166
dict_index_t* index, /* in: index */
167
const dtuple_t* tuple, /* in: tuple on which search done */
168
ulint mode, /* in: PAGE_CUR_L, ... */
169
ulint latch_mode, /* in: BTR_SEARCH_LEAF or
169
170
BTR_MODIFY_LEAF */
170
btr_pcur_t* cursor, /*!< in: memory buffer for persistent
171
btr_pcur_t* cursor, /* in: memory buffer for persistent
172
mtr_t* mtr); /*!< in: mtr */
173
/**********************************************************************//**
173
mtr_t* mtr); /* in: mtr */
174
/**************************************************************************
174
175
Positions a cursor at a randomly chosen position within a B-tree. */
177
178
btr_pcur_open_at_rnd_pos(
178
179
/*=====================*/
179
dict_index_t* index, /*!< in: index */
180
ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */
181
btr_pcur_t* cursor, /*!< in/out: B-tree pcur */
182
mtr_t* mtr); /*!< in: mtr */
183
/**************************************************************//**
180
dict_index_t* index, /* in: index */
181
ulint latch_mode, /* in: BTR_SEARCH_LEAF, ... */
182
btr_pcur_t* cursor, /* in/out: B-tree pcur */
183
mtr_t* mtr); /* in: mtr */
184
/******************************************************************
184
185
Frees the possible old_rec_buf buffer of a persistent cursor and sets the
185
186
latch mode of the persistent cursor to BTR_NO_LATCHES. */
190
btr_pcur_t* cursor); /*!< in: persistent cursor */
191
/**************************************************************//**
191
btr_pcur_t* cursor); /* in: persistent cursor */
192
/******************************************************************
192
193
The position of the cursor is stored by taking an initial segment of the
193
194
record the cursor is positioned on, before, or after, and copying it to the
194
195
cursor data structure, or just setting a flag if the cursor id before the
212
213
(3) cursor was positioned on the page supremum: restores to the first record
213
214
GREATER than the user record which was the predecessor of the supremum.
214
215
(4) cursor was positioned before the first or after the last in an empty tree:
215
restores to before first or after the last in the tree.
216
@return TRUE if the cursor position was stored when it was on a user
217
record and it can be restored on a user record whose ordering fields
218
are identical to the ones of the original user record */
216
restores to before first or after the last in the tree. */
221
219
btr_pcur_restore_position(
222
220
/*======================*/
223
ulint latch_mode, /*!< in: BTR_SEARCH_LEAF, ... */
224
btr_pcur_t* cursor, /*!< in: detached persistent cursor */
225
mtr_t* mtr); /*!< in: mtr */
226
/**************************************************************//**
221
/* out: TRUE if the cursor position
222
was stored when it was on a user record
223
and it can be restored on a user record
224
whose ordering fields are identical to
225
the ones of the original user record */
226
ulint latch_mode, /* in: BTR_SEARCH_LEAF, ... */
227
btr_pcur_t* cursor, /* in: detached persistent cursor */
228
mtr_t* mtr); /* in: mtr */
229
/******************************************************************
227
230
If the latch mode of the cursor is BTR_LEAF_SEARCH or BTR_LEAF_MODIFY,
228
231
releases the page latch and bufferfix reserved by the cursor.
229
232
NOTE! In the case of BTR_LEAF_MODIFY, there should not exist changes
234
237
btr_pcur_release_leaf(
235
238
/*==================*/
236
btr_pcur_t* cursor, /*!< in: persistent cursor */
237
mtr_t* mtr); /*!< in: mtr */
238
/*********************************************************//**
239
Gets the rel_pos field for a cursor whose position has been stored.
240
@return BTR_PCUR_ON, ... */
239
btr_pcur_t* cursor, /* in: persistent cursor */
240
mtr_t* mtr); /* in: mtr */
241
/*************************************************************
242
Gets the rel_pos field for a cursor whose position has been stored. */
243
245
btr_pcur_get_rel_pos(
244
246
/*=================*/
245
const btr_pcur_t* cursor);/*!< in: persistent cursor */
246
/*********************************************************//**
247
/* out: BTR_PCUR_ON, ... */
248
const btr_pcur_t* cursor);/* in: persistent cursor */
249
/*************************************************************
247
250
Sets the mtr field for a pcur. */
250
253
btr_pcur_set_mtr(
251
254
/*=============*/
252
btr_pcur_t* cursor, /*!< in: persistent cursor */
253
mtr_t* mtr); /*!< in, own: mtr */
254
/*********************************************************//**
255
Gets the mtr field for a pcur.
255
btr_pcur_t* cursor, /* in: persistent cursor */
256
mtr_t* mtr); /* in, own: mtr */
257
/*************************************************************
258
Gets the mtr field for a pcur. */
259
261
btr_pcur_get_mtr(
260
262
/*=============*/
261
btr_pcur_t* cursor); /*!< in: persistent cursor */
262
/**************************************************************//**
264
btr_pcur_t* cursor); /* in: persistent cursor */
265
/******************************************************************
263
266
Commits the pcur mtr and sets the pcur latch mode to BTR_NO_LATCHES,
264
267
that is, the cursor becomes detached. If there have been modifications
265
268
to the page where pcur is positioned, this can be used instead of
272
btr_pcur_t* pcur); /*!< in: persistent cursor */
273
/**************************************************************//**
275
btr_pcur_t* pcur); /* in: persistent cursor */
276
/******************************************************************
274
277
Differs from btr_pcur_commit in that we can specify the mtr to commit. */
277
280
btr_pcur_commit_specify_mtr(
278
281
/*========================*/
279
btr_pcur_t* pcur, /*!< in: persistent cursor */
280
mtr_t* mtr); /*!< in: mtr to commit */
281
/**************************************************************//**
282
Tests if a cursor is detached: that is the latch mode is BTR_NO_LATCHES.
283
@return TRUE if detached */
282
btr_pcur_t* pcur, /* in: persistent cursor */
283
mtr_t* mtr); /* in: mtr to commit */
284
/******************************************************************
285
Tests if a cursor is detached: that is the latch mode is BTR_NO_LATCHES. */
286
288
btr_pcur_is_detached(
287
289
/*=================*/
288
btr_pcur_t* pcur); /*!< in: persistent cursor */
289
/*********************************************************//**
290
/* out: TRUE if detached */
291
btr_pcur_t* pcur); /* in: persistent cursor */
292
/*************************************************************
290
293
Moves the persistent cursor to the next record in the tree. If no records are
291
left, the cursor stays 'after last in tree'.
292
@return TRUE if the cursor was not after last in tree */
294
left, the cursor stays 'after last in tree'. */
295
297
btr_pcur_move_to_next(
296
298
/*==================*/
297
btr_pcur_t* cursor, /*!< in: persistent cursor; NOTE that the
299
/* out: TRUE if the cursor was not after last
301
btr_pcur_t* cursor, /* in: persistent cursor; NOTE that the
298
302
function may release the page latch */
299
mtr_t* mtr); /*!< in: mtr */
300
/*********************************************************//**
303
mtr_t* mtr); /* in: mtr */
304
/*************************************************************
301
305
Moves the persistent cursor to the previous record in the tree. If no records
302
are left, the cursor stays 'before first in tree'.
303
@return TRUE if the cursor was not before first in tree */
306
are left, the cursor stays 'before first in tree'. */
306
309
btr_pcur_move_to_prev(
307
310
/*==================*/
308
btr_pcur_t* cursor, /*!< in: persistent cursor; NOTE that the
311
/* out: TRUE if the cursor was not before first
313
btr_pcur_t* cursor, /* in: persistent cursor; NOTE that the
309
314
function may release the page latch */
310
mtr_t* mtr); /*!< in: mtr */
311
/*********************************************************//**
315
mtr_t* mtr); /* in: mtr */
316
/*************************************************************
312
317
Moves the persistent cursor to the last record on the same page. */
315
320
btr_pcur_move_to_last_on_page(
316
321
/*==========================*/
317
btr_pcur_t* cursor, /*!< in: persistent cursor */
318
mtr_t* mtr); /*!< in: mtr */
319
/*********************************************************//**
322
btr_pcur_t* cursor, /* in: persistent cursor */
323
mtr_t* mtr); /* in: mtr */
324
/*************************************************************
320
325
Moves the persistent cursor to the next user record in the tree. If no user
321
records are left, the cursor ends up 'after last in tree'.
322
@return TRUE if the cursor moved forward, ending on a user record */
326
records are left, the cursor ends up 'after last in tree'. */
325
329
btr_pcur_move_to_next_user_rec(
326
330
/*===========================*/
327
btr_pcur_t* cursor, /*!< in: persistent cursor; NOTE that the
331
/* out: TRUE if the cursor moved forward,
332
ending on a user record */
333
btr_pcur_t* cursor, /* in: persistent cursor; NOTE that the
328
334
function may release the page latch */
329
mtr_t* mtr); /*!< in: mtr */
330
/*********************************************************//**
335
mtr_t* mtr); /* in: mtr */
336
/*************************************************************
331
337
Moves the persistent cursor to the first record on the next page.
332
338
Releases the latch on the current page, and bufferunfixes it.
333
339
Note that there must not be modifications on the current page,
354
360
btr_pcur_move_backward_from_page(
355
361
/*=============================*/
356
btr_pcur_t* cursor, /*!< in: persistent cursor, must be on the
362
btr_pcur_t* cursor, /* in: persistent cursor, must be on the
357
363
first record of the current page */
358
mtr_t* mtr); /*!< in: mtr */
364
mtr_t* mtr); /* in: mtr */
359
365
#ifdef UNIV_DEBUG
360
/*********************************************************//**
361
Returns the btr cursor component of a persistent cursor.
362
@return pointer to btr cursor component */
366
/*************************************************************
367
Returns the btr cursor component of a persistent cursor. */
365
370
btr_pcur_get_btr_cur(
366
371
/*=================*/
367
const btr_pcur_t* cursor); /*!< in: persistent cursor */
368
/*********************************************************//**
369
Returns the page cursor component of a persistent cursor.
370
@return pointer to page cursor component */
373
btr cursor component */
374
const btr_pcur_t* cursor); /* in: persistent cursor */
375
/*************************************************************
376
Returns the page cursor component of a persistent cursor. */
373
379
btr_pcur_get_page_cur(
374
380
/*==================*/
375
const btr_pcur_t* cursor); /*!< in: persistent cursor */
382
page cursor component */
383
const btr_pcur_t* cursor); /* in: persistent cursor */
376
384
#else /* UNIV_DEBUG */
377
385
# define btr_pcur_get_btr_cur(cursor) (&(cursor)->btr_cur)
378
386
# define btr_pcur_get_page_cur(cursor) (&(cursor)->btr_cur.page_cur)
379
387
#endif /* UNIV_DEBUG */
380
/*********************************************************//**
381
Returns the page of a persistent cursor.
382
@return pointer to the page */
388
/*************************************************************
389
Returns the page of a persistent cursor. */
385
392
btr_pcur_get_page(
386
393
/*==============*/
387
btr_pcur_t* cursor);/*!< in: persistent cursor */
388
/*********************************************************//**
389
Returns the buffer block of a persistent cursor.
390
@return pointer to the block */
394
/* out: pointer to the page */
395
btr_pcur_t* cursor);/* in: persistent cursor */
396
/*************************************************************
397
Returns the buffer block of a persistent cursor. */
393
400
btr_pcur_get_block(
394
401
/*===============*/
395
btr_pcur_t* cursor);/*!< in: persistent cursor */
396
/*********************************************************//**
397
Returns the record of a persistent cursor.
398
@return pointer to the record */
402
/* out: pointer to the block */
403
btr_pcur_t* cursor);/* in: persistent cursor */
404
/*************************************************************
405
Returns the record of a persistent cursor. */
401
408
btr_pcur_get_rec(
402
409
/*=============*/
403
btr_pcur_t* cursor);/*!< in: persistent cursor */
404
/*********************************************************//**
410
/* out: pointer to the record */
411
btr_pcur_t* cursor);/* in: persistent cursor */
412
/*************************************************************
405
413
Checks if the persistent cursor is on a user record. */
408
416
btr_pcur_is_on_user_rec(
409
417
/*====================*/
410
const btr_pcur_t* cursor);/*!< in: persistent cursor */
411
/*********************************************************//**
418
const btr_pcur_t* cursor);/* in: persistent cursor */
419
/*************************************************************
412
420
Checks if the persistent cursor is after the last user record on
416
424
btr_pcur_is_after_last_on_page(
417
425
/*===========================*/
418
const btr_pcur_t* cursor);/*!< in: persistent cursor */
419
/*********************************************************//**
426
const btr_pcur_t* cursor);/* in: persistent cursor */
427
/*************************************************************
420
428
Checks if the persistent cursor is before the first user record on
424
432
btr_pcur_is_before_first_on_page(
425
433
/*=============================*/
426
const btr_pcur_t* cursor);/*!< in: persistent cursor */
427
/*********************************************************//**
434
const btr_pcur_t* cursor);/* in: persistent cursor */
435
/*************************************************************
428
436
Checks if the persistent cursor is before the first user record in
429
437
the index tree. */
432
440
btr_pcur_is_before_first_in_tree(
433
441
/*=============================*/
434
btr_pcur_t* cursor, /*!< in: persistent cursor */
435
mtr_t* mtr); /*!< in: mtr */
436
/*********************************************************//**
442
btr_pcur_t* cursor, /* in: persistent cursor */
443
mtr_t* mtr); /* in: mtr */
444
/*************************************************************
437
445
Checks if the persistent cursor is after the last user record in
438
446
the index tree. */
441
449
btr_pcur_is_after_last_in_tree(
442
450
/*===========================*/
443
btr_pcur_t* cursor, /*!< in: persistent cursor */
444
mtr_t* mtr); /*!< in: mtr */
445
/*********************************************************//**
451
btr_pcur_t* cursor, /* in: persistent cursor */
452
mtr_t* mtr); /* in: mtr */
453
/*************************************************************
446
454
Moves the persistent cursor to the next record on the same page. */
449
457
btr_pcur_move_to_next_on_page(
450
458
/*==========================*/
451
btr_pcur_t* cursor);/*!< in/out: persistent cursor */
452
/*********************************************************//**
459
btr_pcur_t* cursor);/* in/out: persistent cursor */
460
/*************************************************************
453
461
Moves the persistent cursor to the previous record on the same page. */
456
464
btr_pcur_move_to_prev_on_page(
457
465
/*==========================*/
458
btr_pcur_t* cursor);/*!< in/out: persistent cursor */
466
btr_pcur_t* cursor);/* in/out: persistent cursor */
461
469
/* The persistent B-tree cursor structure. This is used mainly for SQL
462
470
selects, updates, and deletes. */
464
472
struct btr_pcur_struct{
465
btr_cur_t btr_cur; /*!< a B-tree cursor */
466
ulint latch_mode; /*!< see TODO note below!
473
btr_cur_t btr_cur; /* a B-tree cursor */
474
ulint latch_mode; /* see TODO note below!
467
475
BTR_SEARCH_LEAF, BTR_MODIFY_LEAF,
468
476
BTR_MODIFY_TREE, or BTR_NO_LATCHES,
469
477
depending on the latching state of
474
482
detached; it can be restored to
475
483
attached if the old position was
476
484
stored in old_rec */
477
ulint old_stored; /*!< BTR_PCUR_OLD_STORED
485
ulint old_stored; /* BTR_PCUR_OLD_STORED
478
486
or BTR_PCUR_OLD_NOT_STORED */
479
rec_t* old_rec; /*!< if cursor position is stored,
487
rec_t* old_rec; /* if cursor position is stored,
480
488
contains an initial segment of the
481
489
latest record cursor was positioned
482
490
either on, before, or after */
483
ulint old_n_fields; /*!< number of fields in old_rec */
484
ulint rel_pos; /*!< BTR_PCUR_ON, BTR_PCUR_BEFORE, or
491
ulint old_n_fields; /* number of fields in old_rec */
492
ulint rel_pos; /* BTR_PCUR_ON, BTR_PCUR_BEFORE, or
485
493
BTR_PCUR_AFTER, depending on whether
486
494
cursor was on, before, or after the
487
495
old_rec record */
488
496
buf_block_t* block_when_stored;/* buffer block when the position was
490
ib_uint64_t modify_clock; /*!< the modify clock value of the
498
ib_uint64_t modify_clock; /* the modify clock value of the
491
499
buffer block when the cursor position
493
ulint pos_state; /*!< see TODO note below!
501
ulint pos_state; /* see TODO note below!
494
502
BTR_PCUR_IS_POSITIONED,
495
503
BTR_PCUR_WAS_POSITIONED,
496
504
BTR_PCUR_NOT_POSITIONED */
497
ulint search_mode; /*!< PAGE_CUR_G, ... */
498
trx_t* trx_if_known; /*!< the transaction, if we know it;
505
ulint search_mode; /* PAGE_CUR_G, ... */
506
trx_t* trx_if_known; /* the transaction, if we know it;
499
507
otherwise this field is not defined;
500
508
can ONLY BE USED in error prints in
501
509
fatal assertion failures! */