~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/btr0pcur.ic

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
The index tree persistent cursor
 
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
 
6
Created 2/23/1996 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
 
 
10
/*************************************************************
 
11
Gets the rel_pos field for a cursor whose position has been stored. */
 
12
UNIV_INLINE
 
13
ulint
 
14
btr_pcur_get_rel_pos(
 
15
/*=================*/
 
16
                                        /* out: BTR_PCUR_ON, ... */
 
17
        const btr_pcur_t*       cursor) /* in: persistent cursor */
 
18
{
 
19
        ut_ad(cursor);
 
20
        ut_ad(cursor->old_rec);
 
21
        ut_ad(cursor->old_stored == BTR_PCUR_OLD_STORED);
 
22
        ut_ad(cursor->pos_state == BTR_PCUR_WAS_POSITIONED
 
23
              || cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
24
 
 
25
        return(cursor->rel_pos);
 
26
}
 
27
 
 
28
/*************************************************************
 
29
Sets the mtr field for a pcur. */
 
30
UNIV_INLINE
 
31
void
 
32
btr_pcur_set_mtr(
 
33
/*=============*/
 
34
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
35
        mtr_t*          mtr)    /* in, own: mtr */
 
36
{
 
37
        ut_ad(cursor);
 
38
 
 
39
        cursor->mtr = mtr;
 
40
}
 
41
 
 
42
/*************************************************************
 
43
Gets the mtr field for a pcur. */
 
44
UNIV_INLINE
 
45
mtr_t*
 
46
btr_pcur_get_mtr(
 
47
/*=============*/
 
48
                                /* out: mtr */
 
49
        btr_pcur_t*     cursor) /* in: persistent cursor */
 
50
{
 
51
        ut_ad(cursor);
 
52
 
 
53
        return(cursor->mtr);
 
54
}
 
55
 
 
56
#ifdef UNIV_DEBUG
 
57
/*************************************************************
 
58
Returns the btr cursor component of a persistent cursor. */
 
59
UNIV_INLINE
 
60
btr_cur_t*
 
61
btr_pcur_get_btr_cur(
 
62
/*=================*/
 
63
                                        /* out: pointer to
 
64
                                        btr cursor component */
 
65
        const btr_pcur_t*       cursor) /* in: persistent cursor */
 
66
{
 
67
        const btr_cur_t*        btr_cur = &cursor->btr_cur;
 
68
        return((btr_cur_t*) btr_cur);
 
69
}
 
70
 
 
71
/*************************************************************
 
72
Returns the page cursor component of a persistent cursor. */
 
73
UNIV_INLINE
 
74
page_cur_t*
 
75
btr_pcur_get_page_cur(
 
76
/*==================*/
 
77
                                        /* out: pointer to page cursor
 
78
                                        component */
 
79
        const btr_pcur_t*       cursor) /* in: persistent cursor */
 
80
{
 
81
        return(btr_cur_get_page_cur(btr_pcur_get_btr_cur(cursor)));
 
82
}
 
83
#endif /* UNIV_DEBUG */
 
84
/*************************************************************
 
85
Returns the page of a persistent cursor. */
 
86
UNIV_INLINE
 
87
page_t*
 
88
btr_pcur_get_page(
 
89
/*==============*/
 
90
                                /* out: pointer to the page */
 
91
        btr_pcur_t*     cursor) /* in: persistent cursor */
 
92
{
 
93
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
94
 
 
95
        return(btr_cur_get_page(btr_pcur_get_btr_cur(cursor)));
 
96
}
 
97
 
 
98
/*************************************************************
 
99
Returns the buffer block of a persistent cursor. */
 
100
UNIV_INLINE
 
101
buf_block_t*
 
102
btr_pcur_get_block(
 
103
/*===============*/
 
104
                                /* out: pointer to the block */
 
105
        btr_pcur_t*     cursor) /* in: persistent cursor */
 
106
{
 
107
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
108
 
 
109
        return(btr_cur_get_block(btr_pcur_get_btr_cur(cursor)));
 
110
}
 
111
 
 
112
/*************************************************************
 
113
Returns the record of a persistent cursor. */
 
114
UNIV_INLINE
 
115
rec_t*
 
116
btr_pcur_get_rec(
 
117
/*=============*/
 
118
                                /* out: pointer to the record */
 
119
        btr_pcur_t*     cursor) /* in: persistent cursor */
 
120
{
 
121
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
122
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
123
 
 
124
        return(btr_cur_get_rec(btr_pcur_get_btr_cur(cursor)));
 
125
}
 
126
 
 
127
/******************************************************************
 
128
Gets the up_match value for a pcur after a search. */
 
129
UNIV_INLINE
 
130
ulint
 
131
btr_pcur_get_up_match(
 
132
/*==================*/
 
133
                                /* out: number of matched fields at the cursor
 
134
                                or to the right if search mode was PAGE_CUR_GE,
 
135
                                otherwise undefined */
 
136
        btr_pcur_t*     cursor) /* in: memory buffer for persistent cursor */
 
137
{
 
138
        btr_cur_t*      btr_cursor;
 
139
 
 
140
        ut_ad((cursor->pos_state == BTR_PCUR_WAS_POSITIONED)
 
141
              || (cursor->pos_state == BTR_PCUR_IS_POSITIONED));
 
142
 
 
143
        btr_cursor = btr_pcur_get_btr_cur(cursor);
 
144
 
 
145
        ut_ad(btr_cursor->up_match != ULINT_UNDEFINED);
 
146
 
 
147
        return(btr_cursor->up_match);
 
148
}
 
149
 
 
150
/******************************************************************
 
151
Gets the low_match value for a pcur after a search. */
 
152
UNIV_INLINE
 
153
ulint
 
154
btr_pcur_get_low_match(
 
155
/*===================*/
 
156
                                /* out: number of matched fields at the cursor
 
157
                                or to the right if search mode was PAGE_CUR_LE,
 
158
                                otherwise undefined */
 
159
        btr_pcur_t*     cursor) /* in: memory buffer for persistent cursor */
 
160
{
 
161
        btr_cur_t*      btr_cursor;
 
162
 
 
163
        ut_ad((cursor->pos_state == BTR_PCUR_WAS_POSITIONED)
 
164
              || (cursor->pos_state == BTR_PCUR_IS_POSITIONED));
 
165
 
 
166
        btr_cursor = btr_pcur_get_btr_cur(cursor);
 
167
        ut_ad(btr_cursor->low_match != ULINT_UNDEFINED);
 
168
 
 
169
        return(btr_cursor->low_match);
 
170
}
 
171
 
 
172
/*************************************************************
 
173
Checks if the persistent cursor is after the last user record on
 
174
a page. */
 
175
UNIV_INLINE
 
176
ibool
 
177
btr_pcur_is_after_last_on_page(
 
178
/*===========================*/
 
179
        const btr_pcur_t*       cursor) /* in: persistent cursor */
 
180
{
 
181
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
182
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
183
 
 
184
        return(page_cur_is_after_last(btr_pcur_get_page_cur(cursor)));
 
185
}
 
186
 
 
187
/*************************************************************
 
188
Checks if the persistent cursor is before the first user record on
 
189
a page. */
 
190
UNIV_INLINE
 
191
ibool
 
192
btr_pcur_is_before_first_on_page(
 
193
/*=============================*/
 
194
        const btr_pcur_t*       cursor) /* in: persistent cursor */
 
195
{
 
196
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
197
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
198
 
 
199
        return(page_cur_is_before_first(btr_pcur_get_page_cur(cursor)));
 
200
}
 
201
 
 
202
/*************************************************************
 
203
Checks if the persistent cursor is on a user record. */
 
204
UNIV_INLINE
 
205
ibool
 
206
btr_pcur_is_on_user_rec(
 
207
/*====================*/
 
208
        const btr_pcur_t*       cursor) /* in: persistent cursor */
 
209
{
 
210
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
211
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
212
 
 
213
        if (btr_pcur_is_before_first_on_page(cursor)
 
214
            || btr_pcur_is_after_last_on_page(cursor)) {
 
215
 
 
216
                return(FALSE);
 
217
        }
 
218
 
 
219
        return(TRUE);
 
220
}
 
221
 
 
222
/*************************************************************
 
223
Checks if the persistent cursor is before the first user record in
 
224
the index tree. */
 
225
UNIV_INLINE
 
226
ibool
 
227
btr_pcur_is_before_first_in_tree(
 
228
/*=============================*/
 
229
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
230
        mtr_t*          mtr)    /* in: mtr */
 
231
{
 
232
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
233
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
234
 
 
235
        if (btr_page_get_prev(btr_pcur_get_page(cursor), mtr) != FIL_NULL) {
 
236
 
 
237
                return(FALSE);
 
238
        }
 
239
 
 
240
        return(page_cur_is_before_first(btr_pcur_get_page_cur(cursor)));
 
241
}
 
242
 
 
243
/*************************************************************
 
244
Checks if the persistent cursor is after the last user record in
 
245
the index tree. */
 
246
UNIV_INLINE
 
247
ibool
 
248
btr_pcur_is_after_last_in_tree(
 
249
/*===========================*/
 
250
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
251
        mtr_t*          mtr)    /* in: mtr */
 
252
{
 
253
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
254
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
255
 
 
256
        if (btr_page_get_next(btr_pcur_get_page(cursor), mtr) != FIL_NULL) {
 
257
 
 
258
                return(FALSE);
 
259
        }
 
260
 
 
261
        return(page_cur_is_after_last(btr_pcur_get_page_cur(cursor)));
 
262
}
 
263
 
 
264
/*************************************************************
 
265
Moves the persistent cursor to the next record on the same page. */
 
266
UNIV_INLINE
 
267
void
 
268
btr_pcur_move_to_next_on_page(
 
269
/*==========================*/
 
270
        btr_pcur_t*     cursor) /* in/out: persistent cursor */
 
271
{
 
272
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
273
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
274
 
 
275
        page_cur_move_to_next(btr_pcur_get_page_cur(cursor));
 
276
 
 
277
        cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
278
}
 
279
 
 
280
/*************************************************************
 
281
Moves the persistent cursor to the previous record on the same page. */
 
282
UNIV_INLINE
 
283
void
 
284
btr_pcur_move_to_prev_on_page(
 
285
/*==========================*/
 
286
        btr_pcur_t*     cursor) /* in/out: persistent cursor */
 
287
{
 
288
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
289
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
290
 
 
291
        page_cur_move_to_prev(btr_pcur_get_page_cur(cursor));
 
292
 
 
293
        cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
294
}
 
295
 
 
296
/*************************************************************
 
297
Moves the persistent cursor to the last record on the same page. */
 
298
UNIV_INLINE
 
299
void
 
300
btr_pcur_move_to_last_on_page(
 
301
/*==========================*/
 
302
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
303
        mtr_t*          mtr)    /* in: mtr */
 
304
{
 
305
        UT_NOT_USED(mtr);
 
306
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
307
 
 
308
        page_cur_set_after_last(btr_pcur_get_block(cursor),
 
309
                                btr_pcur_get_page_cur(cursor));
 
310
 
 
311
        cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
312
}
 
313
 
 
314
/*************************************************************
 
315
Moves the persistent cursor to the next user record in the tree. If no user
 
316
records are left, the cursor ends up 'after last in tree'. */
 
317
UNIV_INLINE
 
318
ibool
 
319
btr_pcur_move_to_next_user_rec(
 
320
/*===========================*/
 
321
                                /* out: TRUE if the cursor moved forward,
 
322
                                ending on a user record */
 
323
        btr_pcur_t*     cursor, /* in: persistent cursor; NOTE that the
 
324
                                function may release the page latch */
 
325
        mtr_t*          mtr)    /* in: mtr */
 
326
{
 
327
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
328
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
329
        cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
330
loop:
 
331
        if (btr_pcur_is_after_last_on_page(cursor)) {
 
332
 
 
333
                if (btr_pcur_is_after_last_in_tree(cursor, mtr)) {
 
334
 
 
335
                        return(FALSE);
 
336
                }
 
337
 
 
338
                btr_pcur_move_to_next_page(cursor, mtr);
 
339
        } else {
 
340
                btr_pcur_move_to_next_on_page(cursor);
 
341
        }
 
342
 
 
343
        if (btr_pcur_is_on_user_rec(cursor)) {
 
344
 
 
345
                return(TRUE);
 
346
        }
 
347
 
 
348
        goto loop;
 
349
}
 
350
 
 
351
/*************************************************************
 
352
Moves the persistent cursor to the next record in the tree. If no records are
 
353
left, the cursor stays 'after last in tree'. */
 
354
UNIV_INLINE
 
355
ibool
 
356
btr_pcur_move_to_next(
 
357
/*==================*/
 
358
                                /* out: TRUE if the cursor was not after last
 
359
                                in tree */
 
360
        btr_pcur_t*     cursor, /* in: persistent cursor; NOTE that the
 
361
                                function may release the page latch */
 
362
        mtr_t*          mtr)    /* in: mtr */
 
363
{
 
364
        ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
 
365
        ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
 
366
 
 
367
        cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
368
 
 
369
        if (btr_pcur_is_after_last_on_page(cursor)) {
 
370
 
 
371
                if (btr_pcur_is_after_last_in_tree(cursor, mtr)) {
 
372
 
 
373
                        return(FALSE);
 
374
                }
 
375
 
 
376
                btr_pcur_move_to_next_page(cursor, mtr);
 
377
 
 
378
                return(TRUE);
 
379
        }
 
380
 
 
381
        btr_pcur_move_to_next_on_page(cursor);
 
382
 
 
383
        return(TRUE);
 
384
}
 
385
 
 
386
/******************************************************************
 
387
Commits the pcur mtr and sets the pcur latch mode to BTR_NO_LATCHES,
 
388
that is, the cursor becomes detached. If there have been modifications
 
389
to the page where pcur is positioned, this can be used instead of
 
390
btr_pcur_release_leaf. Function btr_pcur_store_position should be used
 
391
before calling this, if restoration of cursor is wanted later. */
 
392
UNIV_INLINE
 
393
void
 
394
btr_pcur_commit(
 
395
/*============*/
 
396
        btr_pcur_t*     pcur)   /* in: persistent cursor */
 
397
{
 
398
        ut_a(pcur->pos_state == BTR_PCUR_IS_POSITIONED);
 
399
 
 
400
        pcur->latch_mode = BTR_NO_LATCHES;
 
401
 
 
402
        mtr_commit(pcur->mtr);
 
403
 
 
404
        pcur->pos_state = BTR_PCUR_WAS_POSITIONED;
 
405
}
 
406
 
 
407
/******************************************************************
 
408
Differs from btr_pcur_commit in that we can specify the mtr to commit. */
 
409
UNIV_INLINE
 
410
void
 
411
btr_pcur_commit_specify_mtr(
 
412
/*========================*/
 
413
        btr_pcur_t*     pcur,   /* in: persistent cursor */
 
414
        mtr_t*          mtr)    /* in: mtr to commit */
 
415
{
 
416
        ut_a(pcur->pos_state == BTR_PCUR_IS_POSITIONED);
 
417
 
 
418
        pcur->latch_mode = BTR_NO_LATCHES;
 
419
 
 
420
        mtr_commit(mtr);
 
421
 
 
422
        pcur->pos_state = BTR_PCUR_WAS_POSITIONED;
 
423
}
 
424
 
 
425
/******************************************************************
 
426
Sets the pcur latch mode to BTR_NO_LATCHES. */
 
427
UNIV_INLINE
 
428
void
 
429
btr_pcur_detach(
 
430
/*============*/
 
431
        btr_pcur_t*     pcur)   /* in: persistent cursor */
 
432
{
 
433
        ut_a(pcur->pos_state == BTR_PCUR_IS_POSITIONED);
 
434
 
 
435
        pcur->latch_mode = BTR_NO_LATCHES;
 
436
 
 
437
        pcur->pos_state = BTR_PCUR_WAS_POSITIONED;
 
438
}
 
439
 
 
440
/******************************************************************
 
441
Tests if a cursor is detached: that is the latch mode is BTR_NO_LATCHES. */
 
442
UNIV_INLINE
 
443
ibool
 
444
btr_pcur_is_detached(
 
445
/*=================*/
 
446
                                /* out: TRUE if detached */
 
447
        btr_pcur_t*     pcur)   /* in: persistent cursor */
 
448
{
 
449
        if (pcur->latch_mode == BTR_NO_LATCHES) {
 
450
 
 
451
                return(TRUE);
 
452
        }
 
453
 
 
454
        return(FALSE);
 
455
}
 
456
 
 
457
/******************************************************************
 
458
Sets the old_rec_buf field to NULL. */
 
459
UNIV_INLINE
 
460
void
 
461
btr_pcur_init(
 
462
/*==========*/
 
463
        btr_pcur_t*     pcur)   /* in: persistent cursor */
 
464
{
 
465
        pcur->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
466
        pcur->old_rec_buf = NULL;
 
467
        pcur->old_rec = NULL;
 
468
}
 
469
 
 
470
/******************************************************************
 
471
Initializes and opens a persistent cursor to an index tree. It should be
 
472
closed with btr_pcur_close. */
 
473
UNIV_INLINE
 
474
void
 
475
btr_pcur_open(
 
476
/*==========*/
 
477
        dict_index_t*   index,  /* in: index */
 
478
        const dtuple_t* tuple,  /* in: tuple on which search done */
 
479
        ulint           mode,   /* in: PAGE_CUR_L, ...;
 
480
                                NOTE that if the search is made using a unique
 
481
                                prefix of a record, mode should be
 
482
                                PAGE_CUR_LE, not PAGE_CUR_GE, as the latter
 
483
                                may end up on the previous page from the
 
484
                                record! */
 
485
        ulint           latch_mode,/* in: BTR_SEARCH_LEAF, ... */
 
486
        btr_pcur_t*     cursor, /* in: memory buffer for persistent cursor */
 
487
        mtr_t*          mtr)    /* in: mtr */
 
488
{
 
489
        btr_cur_t*      btr_cursor;
 
490
 
 
491
        /* Initialize the cursor */
 
492
 
 
493
        btr_pcur_init(cursor);
 
494
 
 
495
        cursor->latch_mode = latch_mode;
 
496
        cursor->search_mode = mode;
 
497
 
 
498
        /* Search with the tree cursor */
 
499
 
 
500
        btr_cursor = btr_pcur_get_btr_cur(cursor);
 
501
 
 
502
        btr_cur_search_to_nth_level(index, 0, tuple, mode, latch_mode,
 
503
                                    btr_cursor, 0, mtr);
 
504
        cursor->pos_state = BTR_PCUR_IS_POSITIONED;
 
505
 
 
506
        cursor->trx_if_known = NULL;
 
507
}
 
508
 
 
509
/******************************************************************
 
510
Opens an persistent cursor to an index tree without initializing the
 
511
cursor. */
 
512
UNIV_INLINE
 
513
void
 
514
btr_pcur_open_with_no_init(
 
515
/*=======================*/
 
516
        dict_index_t*   index,  /* in: index */
 
517
        const dtuple_t* tuple,  /* in: tuple on which search done */
 
518
        ulint           mode,   /* in: PAGE_CUR_L, ...;
 
519
                                NOTE that if the search is made using a unique
 
520
                                prefix of a record, mode should be
 
521
                                PAGE_CUR_LE, not PAGE_CUR_GE, as the latter
 
522
                                may end up on the previous page of the
 
523
                                record! */
 
524
        ulint           latch_mode,/* in: BTR_SEARCH_LEAF, ...;
 
525
                                NOTE that if has_search_latch != 0 then
 
526
                                we maybe do not acquire a latch on the cursor
 
527
                                page, but assume that the caller uses his
 
528
                                btr search latch to protect the record! */
 
529
        btr_pcur_t*     cursor, /* in: memory buffer for persistent cursor */
 
530
        ulint           has_search_latch,/* in: latch mode the caller
 
531
                                currently has on btr_search_latch:
 
532
                                RW_S_LATCH, or 0 */
 
533
        mtr_t*          mtr)    /* in: mtr */
 
534
{
 
535
        btr_cur_t*      btr_cursor;
 
536
 
 
537
        cursor->latch_mode = latch_mode;
 
538
        cursor->search_mode = mode;
 
539
 
 
540
        /* Search with the tree cursor */
 
541
 
 
542
        btr_cursor = btr_pcur_get_btr_cur(cursor);
 
543
 
 
544
        btr_cur_search_to_nth_level(index, 0, tuple, mode, latch_mode,
 
545
                                    btr_cursor, has_search_latch, mtr);
 
546
        cursor->pos_state = BTR_PCUR_IS_POSITIONED;
 
547
 
 
548
        cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
549
 
 
550
        cursor->trx_if_known = NULL;
 
551
}
 
552
 
 
553
/*********************************************************************
 
554
Opens a persistent cursor at either end of an index. */
 
555
UNIV_INLINE
 
556
void
 
557
btr_pcur_open_at_index_side(
 
558
/*========================*/
 
559
        ibool           from_left,      /* in: TRUE if open to the low end,
 
560
                                        FALSE if to the high end */
 
561
        dict_index_t*   index,          /* in: index */
 
562
        ulint           latch_mode,     /* in: latch mode */
 
563
        btr_pcur_t*     pcur,           /* in: cursor */
 
564
        ibool           do_init,        /* in: TRUE if should be initialized */
 
565
        mtr_t*          mtr)            /* in: mtr */
 
566
{
 
567
        pcur->latch_mode = latch_mode;
 
568
 
 
569
        if (from_left) {
 
570
                pcur->search_mode = PAGE_CUR_G;
 
571
        } else {
 
572
                pcur->search_mode = PAGE_CUR_L;
 
573
        }
 
574
 
 
575
        if (do_init) {
 
576
                btr_pcur_init(pcur);
 
577
        }
 
578
 
 
579
        btr_cur_open_at_index_side(from_left, index, latch_mode,
 
580
                                   btr_pcur_get_btr_cur(pcur), mtr);
 
581
        pcur->pos_state = BTR_PCUR_IS_POSITIONED;
 
582
 
 
583
        pcur->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
584
 
 
585
        pcur->trx_if_known = NULL;
 
586
}
 
587
 
 
588
/**************************************************************************
 
589
Positions a cursor at a randomly chosen position within a B-tree. */
 
590
UNIV_INLINE
 
591
void
 
592
btr_pcur_open_at_rnd_pos(
 
593
/*=====================*/
 
594
        dict_index_t*   index,          /* in: index */
 
595
        ulint           latch_mode,     /* in: BTR_SEARCH_LEAF, ... */
 
596
        btr_pcur_t*     cursor,         /* in/out: B-tree pcur */
 
597
        mtr_t*          mtr)            /* in: mtr */
 
598
{
 
599
        /* Initialize the cursor */
 
600
 
 
601
        cursor->latch_mode = latch_mode;
 
602
        cursor->search_mode = PAGE_CUR_G;
 
603
 
 
604
        btr_pcur_init(cursor);
 
605
 
 
606
        btr_cur_open_at_rnd_pos(index, latch_mode,
 
607
                                btr_pcur_get_btr_cur(cursor), mtr);
 
608
        cursor->pos_state = BTR_PCUR_IS_POSITIONED;
 
609
        cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
610
 
 
611
        cursor->trx_if_known = NULL;
 
612
}
 
613
 
 
614
/******************************************************************
 
615
Frees the possible memory heap of a persistent cursor and sets the latch
 
616
mode of the persistent cursor to BTR_NO_LATCHES. */
 
617
UNIV_INLINE
 
618
void
 
619
btr_pcur_close(
 
620
/*===========*/
 
621
        btr_pcur_t*     cursor) /* in: persistent cursor */
 
622
{
 
623
        if (cursor->old_rec_buf != NULL) {
 
624
 
 
625
                mem_free(cursor->old_rec_buf);
 
626
 
 
627
                cursor->old_rec = NULL;
 
628
                cursor->old_rec_buf = NULL;
 
629
        }
 
630
 
 
631
        cursor->btr_cur.page_cur.rec = NULL;
 
632
        cursor->btr_cur.page_cur.block = NULL;
 
633
        cursor->old_rec = NULL;
 
634
        cursor->old_stored = BTR_PCUR_OLD_NOT_STORED;
 
635
 
 
636
        cursor->latch_mode = BTR_NO_LATCHES;
 
637
        cursor->pos_state = BTR_PCUR_NOT_POSITIONED;
 
638
 
 
639
        cursor->trx_if_known = NULL;
 
640
}