~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-02-10 00:14:40 UTC
  • Revision ID: brian@tangent.org-20090210001440-qjg8eofh3h93064b
Adding Multi-threaded Scheduler into the system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1996, 2010, 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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/btr0pcur.h
 
1
/******************************************************
21
2
The index tree persistent cursor
22
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
23
6
Created 2/23/1996 Heikki Tuuri
24
7
*******************************************************/
25
8
 
46
29
#define BTR_PCUR_BEFORE_FIRST_IN_TREE   4       /* in an empty tree */
47
30
#define BTR_PCUR_AFTER_LAST_IN_TREE     5       /* in an empty tree */
48
31
 
49
 
/**************************************************************//**
50
 
Allocates memory for a persistent cursor object and initializes the cursor.
51
 
@return own: persistent cursor */
 
32
/******************************************************************
 
33
Allocates memory for a persistent cursor object and initializes the cursor. */
52
34
UNIV_INTERN
53
35
btr_pcur_t*
54
36
btr_pcur_create_for_mysql(void);
55
37
/*============================*/
56
 
/**************************************************************//**
 
38
                                /* out, own: persistent cursor */
 
39
/******************************************************************
57
40
Frees the memory for a persistent cursor object. */
58
41
UNIV_INTERN
59
42
void
60
43
btr_pcur_free_for_mysql(
61
44
/*====================*/
62
 
        btr_pcur_t*     cursor);        /*!< in, own: persistent cursor */
63
 
/**************************************************************//**
 
45
        btr_pcur_t*     cursor);        /* in, own: persistent cursor */
 
46
/******************************************************************
64
47
Copies the stored position of a pcur to another pcur. */
65
48
UNIV_INTERN
66
49
void
67
50
btr_pcur_copy_stored_position(
68
51
/*==========================*/
69
 
        btr_pcur_t*     pcur_receive,   /*!< in: pcur which will receive the
 
52
        btr_pcur_t*     pcur_receive,   /* in: pcur which will receive the
70
53
                                        position info */
71
 
        btr_pcur_t*     pcur_donate);   /*!< in: pcur from which the info is
 
54
        btr_pcur_t*     pcur_donate);   /* in: pcur from which the info is
72
55
                                        copied */
73
 
/**************************************************************//**
 
56
/******************************************************************
74
57
Sets the old_rec_buf field to NULL. */
75
58
UNIV_INLINE
76
59
void
77
60
btr_pcur_init(
78
61
/*==========*/
79
 
        btr_pcur_t*     pcur);  /*!< in: persistent cursor */
80
 
/**************************************************************//**
 
62
        btr_pcur_t*     pcur);  /* in: persistent cursor */
 
63
/******************************************************************
81
64
Initializes and opens a persistent cursor to an index tree. It should be
82
65
closed with btr_pcur_close. */
83
66
UNIV_INLINE
84
67
void
85
 
btr_pcur_open_func(
86
 
/*===============*/
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, ...;
 
68
btr_pcur_open(
 
69
/*==========*/
 
70
        dict_index_t*   index,  /* in: index */
 
71
        const dtuple_t* tuple,  /* in: tuple on which search done */
 
72
        ulint           mode,   /* in: PAGE_CUR_L, ...;
90
73
                                NOTE that if the search is made using a unique
91
74
                                prefix of a record, mode should be
92
75
                                PAGE_CUR_LE, not PAGE_CUR_GE, as the latter
93
76
                                may end up on the previous page from the
94
77
                                record! */
95
 
        ulint           latch_mode,/*!< in: BTR_SEARCH_LEAF, ... */
96
 
        btr_pcur_t*     cursor, /*!< in: memory buffer for persistent cursor */
97
 
        const char*     file,   /*!< in: file name */
98
 
        ulint           line,   /*!< in: line where called */
99
 
        mtr_t*          mtr);   /*!< in: mtr */
100
 
#define btr_pcur_open(i,t,md,l,c,m)                             \
101
 
        btr_pcur_open_func(i,t,md,l,c,__FILE__,__LINE__,m)
102
 
/**************************************************************//**
 
78
        ulint           latch_mode,/* in: BTR_SEARCH_LEAF, ... */
 
79
        btr_pcur_t*     cursor, /* in: memory buffer for persistent cursor */
 
80
        mtr_t*          mtr);   /* in: mtr */
 
81
/******************************************************************
103
82
Opens an persistent cursor to an index tree without initializing the
104
83
cursor. */
105
84
UNIV_INLINE
106
85
void
107
 
btr_pcur_open_with_no_init_func(
108
 
/*============================*/
109
 
        dict_index_t*   index,  /*!< in: index */
110
 
        const dtuple_t* tuple,  /*!< in: tuple on which search done */
111
 
        ulint           mode,   /*!< in: PAGE_CUR_L, ...;
 
86
btr_pcur_open_with_no_init(
 
87
/*=======================*/
 
88
        dict_index_t*   index,  /* in: index */
 
89
        const dtuple_t* tuple,  /* in: tuple on which search done */
 
90
        ulint           mode,   /* in: PAGE_CUR_L, ...;
112
91
                                NOTE that if the search is made using a unique
113
92
                                prefix of a record, mode should be
114
93
                                PAGE_CUR_LE, not PAGE_CUR_GE, as the latter
115
94
                                may end up on the previous page of the
116
95
                                record! */
117
 
        ulint           latch_mode,/*!< in: BTR_SEARCH_LEAF, ...;
 
96
        ulint           latch_mode,/* in: BTR_SEARCH_LEAF, ...;
118
97
                                NOTE that if has_search_latch != 0 then
119
98
                                we maybe do not acquire a latch on the cursor
120
99
                                page, but assume that the caller uses his
121
100
                                btr search latch to protect the record! */
122
 
        btr_pcur_t*     cursor, /*!< in: memory buffer for persistent cursor */
123
 
        ulint           has_search_latch,/*!< in: latch mode the caller
 
101
        btr_pcur_t*     cursor, /* in: memory buffer for persistent cursor */
 
102
        ulint           has_search_latch,/* in: latch mode the caller
124
103
                                currently has on btr_search_latch:
125
104
                                RW_S_LATCH, or 0 */
126
 
        const char*     file,   /*!< in: file name */
127
 
        ulint           line,   /*!< in: line where called */
128
 
        mtr_t*          mtr);   /*!< in: mtr */
129
 
#define btr_pcur_open_with_no_init(ix,t,md,l,cur,has,m)                 \
130
 
        btr_pcur_open_with_no_init_func(ix,t,md,l,cur,has,__FILE__,__LINE__,m)
131
 
 
132
 
/*****************************************************************//**
 
105
        mtr_t*          mtr);   /* in: mtr */
 
106
/*********************************************************************
133
107
Opens a persistent cursor at either end of an index. */
134
108
UNIV_INLINE
135
109
void
136
110
btr_pcur_open_at_index_side(
137
111
/*========================*/
138
 
        ibool           from_left,      /*!< in: TRUE if open to the low end,
 
112
        ibool           from_left,      /* in: TRUE if open to the low end,
139
113
                                        FALSE if to the high end */
140
 
        dict_index_t*   index,          /*!< in: index */
141
 
        ulint           latch_mode,     /*!< in: latch mode */
142
 
        btr_pcur_t*     pcur,           /*!< in: cursor */
143
 
        ibool           do_init,        /*!< in: TRUE if should be initialized */
144
 
        mtr_t*          mtr);           /*!< in: mtr */
145
 
/**************************************************************//**
146
 
Gets the up_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_GE, otherwise undefined */
 
114
        dict_index_t*   index,          /* in: index */
 
115
        ulint           latch_mode,     /* in: latch mode */
 
116
        btr_pcur_t*     pcur,           /* in: cursor */
 
117
        ibool           do_init,        /* in: TRUE if should be initialized */
 
118
        mtr_t*          mtr);           /* in: mtr */
 
119
/******************************************************************
 
120
Gets the up_match value for a pcur after a search. */
149
121
UNIV_INLINE
150
122
ulint
151
123
btr_pcur_get_up_match(
152
124
/*==================*/
153
 
        btr_pcur_t*     cursor); /*!< in: memory buffer for persistent cursor */
154
 
/**************************************************************//**
155
 
Gets the low_match value for a pcur after a search.
156
 
@return number of matched fields at the cursor or to the right if
157
 
search mode was PAGE_CUR_LE, otherwise undefined */
 
125
                                /* out: number of matched fields at the cursor
 
126
                                or to the right if search mode was PAGE_CUR_GE,
 
127
                                otherwise undefined */
 
128
        btr_pcur_t*     cursor); /* in: memory buffer for persistent cursor */
 
129
/******************************************************************
 
130
Gets the low_match value for a pcur after a search. */
158
131
UNIV_INLINE
159
132
ulint
160
133
btr_pcur_get_low_match(
161
134
/*===================*/
162
 
        btr_pcur_t*     cursor); /*!< in: memory buffer for persistent cursor */
163
 
/**************************************************************//**
 
135
                                /* out: number of matched fields at the cursor
 
136
                                or to the right if search mode was PAGE_CUR_LE,
 
137
                                otherwise undefined */
 
138
        btr_pcur_t*     cursor); /* in: memory buffer for persistent cursor */
 
139
/******************************************************************
164
140
If mode is PAGE_CUR_G or PAGE_CUR_GE, opens a persistent cursor on the first
165
141
user record satisfying the search condition, in the case PAGE_CUR_L or
166
142
PAGE_CUR_LE, on the last user record. If no such user record exists, then
169
145
BTR_MODIFY_LEAF. */
170
146
UNIV_INTERN
171
147
void
172
 
btr_pcur_open_on_user_rec_func(
173
 
/*===========================*/
174
 
        dict_index_t*   index,          /*!< in: index */
175
 
        const dtuple_t* tuple,          /*!< in: tuple on which search done */
176
 
        ulint           mode,           /*!< in: PAGE_CUR_L, ... */
177
 
        ulint           latch_mode,     /*!< in: BTR_SEARCH_LEAF or
 
148
btr_pcur_open_on_user_rec(
 
149
/*======================*/
 
150
        dict_index_t*   index,          /* in: index */
 
151
        const dtuple_t* tuple,          /* in: tuple on which search done */
 
152
        ulint           mode,           /* in: PAGE_CUR_L, ... */
 
153
        ulint           latch_mode,     /* in: BTR_SEARCH_LEAF or
178
154
                                        BTR_MODIFY_LEAF */
179
 
        btr_pcur_t*     cursor,         /*!< in: memory buffer for persistent
 
155
        btr_pcur_t*     cursor,         /* in: memory buffer for persistent
180
156
                                        cursor */
181
 
        const char*     file,           /*!< in: file name */
182
 
        ulint           line,           /*!< in: line where called */
183
 
        mtr_t*          mtr);           /*!< in: mtr */
184
 
#define btr_pcur_open_on_user_rec(i,t,md,l,c,m)                         \
185
 
        btr_pcur_open_on_user_rec_func(i,t,md,l,c,__FILE__,__LINE__,m)
186
 
/**********************************************************************//**
 
157
        mtr_t*          mtr);           /* in: mtr */
 
158
/**************************************************************************
187
159
Positions a cursor at a randomly chosen position within a B-tree. */
188
160
UNIV_INLINE
189
161
void
190
 
btr_pcur_open_at_rnd_pos_func(
191
 
/*==========================*/
192
 
        dict_index_t*   index,          /*!< in: index */
193
 
        ulint           latch_mode,     /*!< in: BTR_SEARCH_LEAF, ... */
194
 
        btr_pcur_t*     cursor,         /*!< in/out: B-tree pcur */
195
 
        const char*     file,           /*!< in: file name */
196
 
        ulint           line,           /*!< in: line where called */
197
 
        mtr_t*          mtr);           /*!< in: mtr */
198
 
#define btr_pcur_open_at_rnd_pos(i,l,c,m)                               \
199
 
        btr_pcur_open_at_rnd_pos_func(i,l,c,__FILE__,__LINE__,m)
200
 
/**************************************************************//**
 
162
btr_pcur_open_at_rnd_pos(
 
163
/*=====================*/
 
164
        dict_index_t*   index,          /* in: index */
 
165
        ulint           latch_mode,     /* in: BTR_SEARCH_LEAF, ... */
 
166
        btr_pcur_t*     cursor,         /* in/out: B-tree pcur */
 
167
        mtr_t*          mtr);           /* in: mtr */
 
168
/******************************************************************
201
169
Frees the possible old_rec_buf buffer of a persistent cursor and sets the
202
170
latch mode of the persistent cursor to BTR_NO_LATCHES. */
203
171
UNIV_INLINE
204
172
void
205
173
btr_pcur_close(
206
174
/*===========*/
207
 
        btr_pcur_t*     cursor);        /*!< in: persistent cursor */
208
 
/**************************************************************//**
 
175
        btr_pcur_t*     cursor);        /* in: persistent cursor */
 
176
/******************************************************************
209
177
The position of the cursor is stored by taking an initial segment of the
210
178
record the cursor is positioned on, before, or after, and copying it to the
211
179
cursor data structure, or just setting a flag if the cursor id before the
216
184
void
217
185
btr_pcur_store_position(
218
186
/*====================*/
219
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor */
220
 
        mtr_t*          mtr);   /*!< in: mtr */
221
 
/**************************************************************//**
 
187
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
188
        mtr_t*          mtr);   /* in: mtr */
 
189
/******************************************************************
222
190
Restores the stored position of a persistent cursor bufferfixing the page and
223
191
obtaining the specified latches. If the cursor position was saved when the
224
192
(1) cursor was positioned on a user record: this function restores the position
229
197
(3) cursor was positioned on the page supremum: restores to the first record
230
198
GREATER than the user record which was the predecessor of the supremum.
231
199
(4) cursor was positioned before the first or after the last in an empty tree:
232
 
restores to before first or after the last in the tree.
233
 
@return TRUE if the cursor position was stored when it was on a user
234
 
record and it can be restored on a user record whose ordering fields
235
 
are identical to the ones of the original user record */
 
200
restores to before first or after the last in the tree. */
236
201
UNIV_INTERN
237
202
ibool
238
 
btr_pcur_restore_position_func(
239
 
/*===========================*/
240
 
        ulint           latch_mode,     /*!< in: BTR_SEARCH_LEAF, ... */
241
 
        btr_pcur_t*     cursor,         /*!< in: detached persistent cursor */
242
 
        const char*     file,           /*!< in: file name */
243
 
        ulint           line,           /*!< in: line where called */
244
 
        mtr_t*          mtr);           /*!< in: mtr */
245
 
#define btr_pcur_restore_position(l,cur,mtr)                            \
246
 
        btr_pcur_restore_position_func(l,cur,__FILE__,__LINE__,mtr)
247
 
/**************************************************************//**
 
203
btr_pcur_restore_position(
 
204
/*======================*/
 
205
                                        /* out: TRUE if the cursor position
 
206
                                        was stored when it was on a user record
 
207
                                        and it can be restored on a user record
 
208
                                        whose ordering fields are identical to
 
209
                                        the ones of the original user record */
 
210
        ulint           latch_mode,     /* in: BTR_SEARCH_LEAF, ... */
 
211
        btr_pcur_t*     cursor,         /* in: detached persistent cursor */
 
212
        mtr_t*          mtr);           /* in: mtr */
 
213
/******************************************************************
248
214
If the latch mode of the cursor is BTR_LEAF_SEARCH or BTR_LEAF_MODIFY,
249
215
releases the page latch and bufferfix reserved by the cursor.
250
216
NOTE! In the case of BTR_LEAF_MODIFY, there should not exist changes
254
220
void
255
221
btr_pcur_release_leaf(
256
222
/*==================*/
257
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor */
258
 
        mtr_t*          mtr);   /*!< in: mtr */
259
 
/*********************************************************//**
260
 
Gets the rel_pos field for a cursor whose position has been stored.
261
 
@return BTR_PCUR_ON, ... */
 
223
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
224
        mtr_t*          mtr);   /* in: mtr */
 
225
/*************************************************************
 
226
Gets the rel_pos field for a cursor whose position has been stored. */
262
227
UNIV_INLINE
263
228
ulint
264
229
btr_pcur_get_rel_pos(
265
230
/*=================*/
266
 
        const btr_pcur_t*       cursor);/*!< in: persistent cursor */
267
 
/*********************************************************//**
 
231
                                        /* out: BTR_PCUR_ON, ... */
 
232
        const btr_pcur_t*       cursor);/* in: persistent cursor */
 
233
/*************************************************************
268
234
Sets the mtr field for a pcur. */
269
235
UNIV_INLINE
270
236
void
271
237
btr_pcur_set_mtr(
272
238
/*=============*/
273
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor */
274
 
        mtr_t*          mtr);   /*!< in, own: mtr */
275
 
/*********************************************************//**
276
 
Gets the mtr field for a pcur.
277
 
@return mtr */
 
239
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
240
        mtr_t*          mtr);   /* in, own: mtr */
 
241
/*************************************************************
 
242
Gets the mtr field for a pcur. */
278
243
UNIV_INLINE
279
244
mtr_t*
280
245
btr_pcur_get_mtr(
281
246
/*=============*/
282
 
        btr_pcur_t*     cursor);        /*!< in: persistent cursor */
283
 
/**************************************************************//**
284
 
Commits the mtr and sets the pcur latch mode to BTR_NO_LATCHES,
 
247
                                /* out: mtr */
 
248
        btr_pcur_t*     cursor);        /* in: persistent cursor */
 
249
/******************************************************************
 
250
Commits the pcur mtr and sets the pcur latch mode to BTR_NO_LATCHES,
285
251
that is, the cursor becomes detached. If there have been modifications
286
252
to the page where pcur is positioned, this can be used instead of
287
253
btr_pcur_release_leaf. Function btr_pcur_store_position should be used
288
254
before calling this, if restoration of cursor is wanted later. */
289
255
UNIV_INLINE
290
256
void
 
257
btr_pcur_commit(
 
258
/*============*/
 
259
        btr_pcur_t*     pcur);  /* in: persistent cursor */
 
260
/******************************************************************
 
261
Differs from btr_pcur_commit in that we can specify the mtr to commit. */
 
262
UNIV_INLINE
 
263
void
291
264
btr_pcur_commit_specify_mtr(
292
265
/*========================*/
293
 
        btr_pcur_t*     pcur,   /*!< in: persistent cursor */
294
 
        mtr_t*          mtr);   /*!< in: mtr to commit */
295
 
/**************************************************************//**
296
 
Tests if a cursor is detached: that is the latch mode is BTR_NO_LATCHES.
297
 
@return TRUE if detached */
 
266
        btr_pcur_t*     pcur,   /* in: persistent cursor */
 
267
        mtr_t*          mtr);   /* in: mtr to commit */
 
268
/******************************************************************
 
269
Tests if a cursor is detached: that is the latch mode is BTR_NO_LATCHES. */
298
270
UNIV_INLINE
299
271
ibool
300
272
btr_pcur_is_detached(
301
273
/*=================*/
302
 
        btr_pcur_t*     pcur);  /*!< in: persistent cursor */
303
 
/*********************************************************//**
 
274
                                /* out: TRUE if detached */
 
275
        btr_pcur_t*     pcur);  /* in: persistent cursor */
 
276
/*************************************************************
304
277
Moves the persistent cursor to the next record in the tree. If no records are
305
 
left, the cursor stays 'after last in tree'.
306
 
@return TRUE if the cursor was not after last in tree */
 
278
left, the cursor stays 'after last in tree'. */
307
279
UNIV_INLINE
308
280
ibool
309
281
btr_pcur_move_to_next(
310
282
/*==================*/
311
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor; NOTE that the
 
283
                                /* out: TRUE if the cursor was not after last
 
284
                                in tree */
 
285
        btr_pcur_t*     cursor, /* in: persistent cursor; NOTE that the
312
286
                                function may release the page latch */
313
 
        mtr_t*          mtr);   /*!< in: mtr */
314
 
/*********************************************************//**
 
287
        mtr_t*          mtr);   /* in: mtr */
 
288
/*************************************************************
315
289
Moves the persistent cursor to the previous record in the tree. If no records
316
 
are left, the cursor stays 'before first in tree'.
317
 
@return TRUE if the cursor was not before first in tree */
 
290
are left, the cursor stays 'before first in tree'. */
318
291
UNIV_INTERN
319
292
ibool
320
293
btr_pcur_move_to_prev(
321
294
/*==================*/
322
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor; NOTE that the
 
295
                                /* out: TRUE if the cursor was not before first
 
296
                                in tree */
 
297
        btr_pcur_t*     cursor, /* in: persistent cursor; NOTE that the
323
298
                                function may release the page latch */
324
 
        mtr_t*          mtr);   /*!< in: mtr */
325
 
/*********************************************************//**
 
299
        mtr_t*          mtr);   /* in: mtr */
 
300
/*************************************************************
326
301
Moves the persistent cursor to the last record on the same page. */
327
302
UNIV_INLINE
328
303
void
329
304
btr_pcur_move_to_last_on_page(
330
305
/*==========================*/
331
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor */
332
 
        mtr_t*          mtr);   /*!< in: mtr */
333
 
/*********************************************************//**
 
306
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
307
        mtr_t*          mtr);   /* in: mtr */
 
308
/*************************************************************
334
309
Moves the persistent cursor to the next user record in the tree. If no user
335
 
records are left, the cursor ends up 'after last in tree'.
336
 
@return TRUE if the cursor moved forward, ending on a user record */
 
310
records are left, the cursor ends up 'after last in tree'. */
337
311
UNIV_INLINE
338
312
ibool
339
313
btr_pcur_move_to_next_user_rec(
340
314
/*===========================*/
341
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor; NOTE that the
 
315
                                /* out: TRUE if the cursor moved forward,
 
316
                                ending on a user record */
 
317
        btr_pcur_t*     cursor, /* in: persistent cursor; NOTE that the
342
318
                                function may release the page latch */
343
 
        mtr_t*          mtr);   /*!< in: mtr */
344
 
/*********************************************************//**
 
319
        mtr_t*          mtr);   /* in: mtr */
 
320
/*************************************************************
345
321
Moves the persistent cursor to the first record on the next page.
346
322
Releases the latch on the current page, and bufferunfixes it.
347
323
Note that there must not be modifications on the current page,
350
326
void
351
327
btr_pcur_move_to_next_page(
352
328
/*=======================*/
353
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor; must be on the
 
329
        btr_pcur_t*     cursor, /* in: persistent cursor; must be on the
354
330
                                last record of the current page */
355
 
        mtr_t*          mtr);   /*!< in: mtr */
356
 
/*********************************************************//**
 
331
        mtr_t*          mtr);   /* in: mtr */
 
332
/*************************************************************
357
333
Moves the persistent cursor backward if it is on the first record
358
334
of the page. Releases the latch on the current page, and bufferunfixes
359
335
it. Note that to prevent a possible deadlock, the operation first
367
343
void
368
344
btr_pcur_move_backward_from_page(
369
345
/*=============================*/
370
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor, must be on the
 
346
        btr_pcur_t*     cursor, /* in: persistent cursor, must be on the
371
347
                                first record of the current page */
372
 
        mtr_t*          mtr);   /*!< in: mtr */
 
348
        mtr_t*          mtr);   /* in: mtr */
373
349
#ifdef UNIV_DEBUG
374
 
/*********************************************************//**
375
 
Returns the btr cursor component of a persistent cursor.
376
 
@return pointer to btr cursor component */
 
350
/*************************************************************
 
351
Returns the btr cursor component of a persistent cursor. */
377
352
UNIV_INLINE
378
353
btr_cur_t*
379
354
btr_pcur_get_btr_cur(
380
355
/*=================*/
381
 
        const btr_pcur_t*       cursor);        /*!< in: persistent cursor */
382
 
/*********************************************************//**
383
 
Returns the page cursor component of a persistent cursor.
384
 
@return pointer to page cursor component */
 
356
                                                /* out: pointer to
 
357
                                                btr cursor component */
 
358
        const btr_pcur_t*       cursor);        /* in: persistent cursor */
 
359
/*************************************************************
 
360
Returns the page cursor component of a persistent cursor. */
385
361
UNIV_INLINE
386
362
page_cur_t*
387
363
btr_pcur_get_page_cur(
388
364
/*==================*/
389
 
        const btr_pcur_t*       cursor);        /*!< in: persistent cursor */
 
365
                                                /* out: pointer to
 
366
                                                page cursor component */
 
367
        const btr_pcur_t*       cursor);        /* in: persistent cursor */
390
368
#else /* UNIV_DEBUG */
391
369
# define btr_pcur_get_btr_cur(cursor) (&(cursor)->btr_cur)
392
370
# define btr_pcur_get_page_cur(cursor) (&(cursor)->btr_cur.page_cur)
393
371
#endif /* UNIV_DEBUG */
394
 
/*********************************************************//**
395
 
Returns the page of a persistent cursor.
396
 
@return pointer to the page */
 
372
/*************************************************************
 
373
Returns the page of a persistent cursor. */
397
374
UNIV_INLINE
398
375
page_t*
399
376
btr_pcur_get_page(
400
377
/*==============*/
401
 
        btr_pcur_t*     cursor);/*!< in: persistent cursor */
402
 
/*********************************************************//**
403
 
Returns the buffer block of a persistent cursor.
404
 
@return pointer to the block */
 
378
                                /* out: pointer to the page */
 
379
        btr_pcur_t*     cursor);/* in: persistent cursor */
 
380
/*************************************************************
 
381
Returns the buffer block of a persistent cursor. */
405
382
UNIV_INLINE
406
383
buf_block_t*
407
384
btr_pcur_get_block(
408
385
/*===============*/
409
 
        btr_pcur_t*     cursor);/*!< in: persistent cursor */
410
 
/*********************************************************//**
411
 
Returns the record of a persistent cursor.
412
 
@return pointer to the record */
 
386
                                /* out: pointer to the block */
 
387
        btr_pcur_t*     cursor);/* in: persistent cursor */
 
388
/*************************************************************
 
389
Returns the record of a persistent cursor. */
413
390
UNIV_INLINE
414
391
rec_t*
415
392
btr_pcur_get_rec(
416
393
/*=============*/
417
 
        btr_pcur_t*     cursor);/*!< in: persistent cursor */
418
 
/*********************************************************//**
 
394
                                /* out: pointer to the record */
 
395
        btr_pcur_t*     cursor);/* in: persistent cursor */
 
396
/*************************************************************
419
397
Checks if the persistent cursor is on a user record. */
420
398
UNIV_INLINE
421
399
ibool
422
400
btr_pcur_is_on_user_rec(
423
401
/*====================*/
424
 
        const btr_pcur_t*       cursor);/*!< in: persistent cursor */
425
 
/*********************************************************//**
 
402
        const btr_pcur_t*       cursor);/* in: persistent cursor */
 
403
/*************************************************************
426
404
Checks if the persistent cursor is after the last user record on
427
405
a page. */
428
406
UNIV_INLINE
429
407
ibool
430
408
btr_pcur_is_after_last_on_page(
431
409
/*===========================*/
432
 
        const btr_pcur_t*       cursor);/*!< in: persistent cursor */
433
 
/*********************************************************//**
 
410
        const btr_pcur_t*       cursor);/* in: persistent cursor */
 
411
/*************************************************************
434
412
Checks if the persistent cursor is before the first user record on
435
413
a page. */
436
414
UNIV_INLINE
437
415
ibool
438
416
btr_pcur_is_before_first_on_page(
439
417
/*=============================*/
440
 
        const btr_pcur_t*       cursor);/*!< in: persistent cursor */
441
 
/*********************************************************//**
 
418
        const btr_pcur_t*       cursor);/* in: persistent cursor */
 
419
/*************************************************************
442
420
Checks if the persistent cursor is before the first user record in
443
421
the index tree. */
444
422
UNIV_INLINE
445
423
ibool
446
424
btr_pcur_is_before_first_in_tree(
447
425
/*=============================*/
448
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor */
449
 
        mtr_t*          mtr);   /*!< in: mtr */
450
 
/*********************************************************//**
 
426
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
427
        mtr_t*          mtr);   /* in: mtr */
 
428
/*************************************************************
451
429
Checks if the persistent cursor is after the last user record in
452
430
the index tree. */
453
431
UNIV_INLINE
454
432
ibool
455
433
btr_pcur_is_after_last_in_tree(
456
434
/*===========================*/
457
 
        btr_pcur_t*     cursor, /*!< in: persistent cursor */
458
 
        mtr_t*          mtr);   /*!< in: mtr */
459
 
/*********************************************************//**
 
435
        btr_pcur_t*     cursor, /* in: persistent cursor */
 
436
        mtr_t*          mtr);   /* in: mtr */
 
437
/*************************************************************
460
438
Moves the persistent cursor to the next record on the same page. */
461
439
UNIV_INLINE
462
440
void
463
441
btr_pcur_move_to_next_on_page(
464
442
/*==========================*/
465
 
        btr_pcur_t*     cursor);/*!< in/out: persistent cursor */
466
 
/*********************************************************//**
 
443
        btr_pcur_t*     cursor);/* in/out: persistent cursor */
 
444
/*************************************************************
467
445
Moves the persistent cursor to the previous record on the same page. */
468
446
UNIV_INLINE
469
447
void
470
448
btr_pcur_move_to_prev_on_page(
471
449
/*==========================*/
472
 
        btr_pcur_t*     cursor);/*!< in/out: persistent cursor */
 
450
        btr_pcur_t*     cursor);/* in/out: persistent cursor */
473
451
 
474
452
 
475
453
/* The persistent B-tree cursor structure. This is used mainly for SQL
476
454
selects, updates, and deletes. */
477
455
 
478
456
struct btr_pcur_struct{
479
 
        btr_cur_t       btr_cur;        /*!< a B-tree cursor */
480
 
        ulint           latch_mode;     /*!< see TODO note below!
 
457
        btr_cur_t       btr_cur;        /* a B-tree cursor */
 
458
        ulint           latch_mode;     /* see TODO note below!
481
459
                                        BTR_SEARCH_LEAF, BTR_MODIFY_LEAF,
482
460
                                        BTR_MODIFY_TREE, or BTR_NO_LATCHES,
483
461
                                        depending on the latching state of
488
466
                                        detached; it can be restored to
489
467
                                        attached if the old position was
490
468
                                        stored in old_rec */
491
 
        ulint           old_stored;     /*!< BTR_PCUR_OLD_STORED
 
469
        ulint           old_stored;     /* BTR_PCUR_OLD_STORED
492
470
                                        or BTR_PCUR_OLD_NOT_STORED */
493
 
        rec_t*          old_rec;        /*!< if cursor position is stored,
 
471
        rec_t*          old_rec;        /* if cursor position is stored,
494
472
                                        contains an initial segment of the
495
473
                                        latest record cursor was positioned
496
474
                                        either on, before, or after */
497
 
        ulint           old_n_fields;   /*!< number of fields in old_rec */
498
 
        ulint           rel_pos;        /*!< BTR_PCUR_ON, BTR_PCUR_BEFORE, or
 
475
        ulint           old_n_fields;   /* number of fields in old_rec */
 
476
        ulint           rel_pos;        /* BTR_PCUR_ON, BTR_PCUR_BEFORE, or
499
477
                                        BTR_PCUR_AFTER, depending on whether
500
478
                                        cursor was on, before, or after the
501
479
                                        old_rec record */
502
480
        buf_block_t*    block_when_stored;/* buffer block when the position was
503
481
                                        stored */
504
 
        ib_uint64_t     modify_clock;   /*!< the modify clock value of the
 
482
        ib_uint64_t     modify_clock;   /* the modify clock value of the
505
483
                                        buffer block when the cursor position
506
484
                                        was stored */
507
 
        ulint           pos_state;      /*!< see TODO note below!
 
485
        ulint           pos_state;      /* see TODO note below!
508
486
                                        BTR_PCUR_IS_POSITIONED,
509
487
                                        BTR_PCUR_WAS_POSITIONED,
510
488
                                        BTR_PCUR_NOT_POSITIONED */
511
 
        ulint           search_mode;    /*!< PAGE_CUR_G, ... */
512
 
        trx_t*          trx_if_known;   /*!< the transaction, if we know it;
 
489
        ulint           search_mode;    /* PAGE_CUR_G, ... */
 
490
        trx_t*          trx_if_known;   /* the transaction, if we know it;
513
491
                                        otherwise this field is not defined;
514
492
                                        can ONLY BE USED in error prints in
515
493
                                        fatal assertion failures! */
517
495
        /* NOTE that the following fields may possess dynamically allocated
518
496
        memory which should be freed if not needed anymore! */
519
497
 
520
 
        mtr_t*          mtr;            /*!< NULL, or this field may contain
 
498
        mtr_t*          mtr;            /* NULL, or this field may contain
521
499
                                        a mini-transaction which holds the
522
500
                                        latch on the cursor page */
523
 
        byte*           old_rec_buf;    /*!< NULL, or a dynamically allocated
 
501
        byte*           old_rec_buf;    /* NULL, or a dynamically allocated
524
502
                                        buffer for old_rec */
525
 
        ulint           buf_size;       /*!< old_rec_buf size if old_rec_buf
 
503
        ulint           buf_size;       /* old_rec_buf size if old_rec_buf
526
504
                                        is not NULL */
527
505
};
528
506