~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/page0cur.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 page cursor
 
3
 
 
4
(c) 1994-1996 Innobase Oy
 
5
 
 
6
Created 10/4/1994 Heikki Tuuri
 
7
*************************************************************************/
 
8
 
 
9
#include "page0page.h"
 
10
#include "buf0types.h"
 
11
 
 
12
#ifdef UNIV_DEBUG
 
13
/*************************************************************
 
14
Gets pointer to the page frame where the cursor is positioned. */
 
15
UNIV_INLINE
 
16
page_t*
 
17
page_cur_get_page(
 
18
/*==============*/
 
19
                                /* out: page */
 
20
        page_cur_t*     cur)    /* in: page cursor */
 
21
{
 
22
        ut_ad(cur);
 
23
        ut_ad(page_align(cur->rec) == cur->block->frame);
 
24
 
 
25
        return(page_align(cur->rec));
 
26
}
 
27
 
 
28
/*************************************************************
 
29
Gets pointer to the buffer block where the cursor is positioned. */
 
30
UNIV_INLINE
 
31
buf_block_t*
 
32
page_cur_get_block(
 
33
/*===============*/
 
34
                                /* out: page */
 
35
        page_cur_t*     cur)    /* in: page cursor */
 
36
{
 
37
        ut_ad(cur);
 
38
        ut_ad(page_align(cur->rec) == cur->block->frame);
 
39
        return(cur->block);
 
40
}
 
41
 
 
42
/*************************************************************
 
43
Gets pointer to the page frame where the cursor is positioned. */
 
44
UNIV_INLINE
 
45
page_zip_des_t*
 
46
page_cur_get_page_zip(
 
47
/*==================*/
 
48
                                /* out: page */
 
49
        page_cur_t*     cur)    /* in: page cursor */
 
50
{
 
51
        return(buf_block_get_page_zip(page_cur_get_block(cur)));
 
52
}
 
53
 
 
54
/*************************************************************
 
55
Gets the record where the cursor is positioned. */
 
56
UNIV_INLINE
 
57
rec_t*
 
58
page_cur_get_rec(
 
59
/*=============*/
 
60
                                /* out: record */
 
61
        page_cur_t*     cur)    /* in: page cursor */
 
62
{
 
63
        ut_ad(cur);
 
64
        ut_ad(page_align(cur->rec) == cur->block->frame);
 
65
 
 
66
        return(cur->rec);
 
67
}
 
68
#endif /* UNIV_DEBUG */
 
69
 
 
70
/*************************************************************
 
71
Sets the cursor object to point before the first user record
 
72
on the page. */
 
73
UNIV_INLINE
 
74
void
 
75
page_cur_set_before_first(
 
76
/*======================*/
 
77
        const buf_block_t*      block,  /* in: index page */
 
78
        page_cur_t*             cur)    /* in: cursor */
 
79
{
 
80
        cur->block = (buf_block_t*) block;
 
81
        cur->rec = page_get_infimum_rec(buf_block_get_frame(cur->block));
 
82
}
 
83
 
 
84
/*************************************************************
 
85
Sets the cursor object to point after the last user record on
 
86
the page. */
 
87
UNIV_INLINE
 
88
void
 
89
page_cur_set_after_last(
 
90
/*====================*/
 
91
        const buf_block_t*      block,  /* in: index page */
 
92
        page_cur_t*             cur)    /* in: cursor */
 
93
{
 
94
        cur->block = (buf_block_t*) block;
 
95
        cur->rec = page_get_supremum_rec(buf_block_get_frame(cur->block));
 
96
}
 
97
 
 
98
/*************************************************************
 
99
Returns TRUE if the cursor is before first user record on page. */
 
100
UNIV_INLINE
 
101
ibool
 
102
page_cur_is_before_first(
 
103
/*=====================*/
 
104
                                        /* out: TRUE if at start */
 
105
        const page_cur_t*       cur)    /* in: cursor */
 
106
{
 
107
        ut_ad(cur);
 
108
        ut_ad(page_align(cur->rec) == cur->block->frame);
 
109
        return(page_rec_is_infimum(cur->rec));
 
110
}
 
111
 
 
112
/*************************************************************
 
113
Returns TRUE if the cursor is after last user record. */
 
114
UNIV_INLINE
 
115
ibool
 
116
page_cur_is_after_last(
 
117
/*===================*/
 
118
                                        /* out: TRUE if at end */
 
119
        const page_cur_t*       cur)    /* in: cursor */
 
120
{
 
121
        ut_ad(cur);
 
122
        ut_ad(page_align(cur->rec) == cur->block->frame);
 
123
        return(page_rec_is_supremum(cur->rec));
 
124
}
 
125
 
 
126
/**************************************************************
 
127
Positions the cursor on the given record. */
 
128
UNIV_INLINE
 
129
void
 
130
page_cur_position(
 
131
/*==============*/
 
132
        const rec_t*            rec,    /* in: record on a page */
 
133
        const buf_block_t*      block,  /* in: buffer block containing
 
134
                                        the record */
 
135
        page_cur_t*             cur)    /* out: page cursor */
 
136
{
 
137
        ut_ad(rec && block && cur);
 
138
        ut_ad(page_align(rec) == block->frame);
 
139
 
 
140
        cur->rec = (rec_t*) rec;
 
141
        cur->block = (buf_block_t*) block;
 
142
}
 
143
 
 
144
/**************************************************************
 
145
Invalidates a page cursor by setting the record pointer NULL. */
 
146
UNIV_INLINE
 
147
void
 
148
page_cur_invalidate(
 
149
/*================*/
 
150
        page_cur_t*     cur)    /* out: page cursor */
 
151
{
 
152
        ut_ad(cur);
 
153
 
 
154
        cur->rec = NULL;
 
155
        cur->block = NULL;
 
156
}
 
157
 
 
158
/**************************************************************
 
159
Moves the cursor to the next record on page. */
 
160
UNIV_INLINE
 
161
void
 
162
page_cur_move_to_next(
 
163
/*==================*/
 
164
        page_cur_t*     cur)    /* in/out: cursor; must not be after last */
 
165
{
 
166
        ut_ad(!page_cur_is_after_last(cur));
 
167
 
 
168
        cur->rec = page_rec_get_next(cur->rec);
 
169
}
 
170
 
 
171
/**************************************************************
 
172
Moves the cursor to the previous record on page. */
 
173
UNIV_INLINE
 
174
void
 
175
page_cur_move_to_prev(
 
176
/*==================*/
 
177
        page_cur_t*     cur)    /* in/out: page cursor, not before first */
 
178
{
 
179
        ut_ad(!page_cur_is_before_first(cur));
 
180
 
 
181
        cur->rec = page_rec_get_prev(cur->rec);
 
182
}
 
183
 
 
184
/********************************************************************
 
185
Searches the right position for a page cursor. */
 
186
UNIV_INLINE
 
187
ulint
 
188
page_cur_search(
 
189
/*============*/
 
190
                                        /* out: number of matched
 
191
                                        fields on the left */
 
192
        const buf_block_t*      block,  /* in: buffer block */
 
193
        const dict_index_t*     index,  /* in: record descriptor */
 
194
        const dtuple_t*         tuple,  /* in: data tuple */
 
195
        ulint                   mode,   /* in: PAGE_CUR_L,
 
196
                                        PAGE_CUR_LE, PAGE_CUR_G, or
 
197
                                        PAGE_CUR_GE */
 
198
        page_cur_t*             cursor) /* out: page cursor */
 
199
{
 
200
        ulint           low_matched_fields = 0;
 
201
        ulint           low_matched_bytes = 0;
 
202
        ulint           up_matched_fields = 0;
 
203
        ulint           up_matched_bytes = 0;
 
204
 
 
205
        ut_ad(dtuple_check_typed(tuple));
 
206
 
 
207
        page_cur_search_with_match(block, index, tuple, mode,
 
208
                                   &up_matched_fields,
 
209
                                   &up_matched_bytes,
 
210
                                   &low_matched_fields,
 
211
                                   &low_matched_bytes,
 
212
                                   cursor);
 
213
        return(low_matched_fields);
 
214
}
 
215
 
 
216
/***************************************************************
 
217
Inserts a record next to page cursor. Returns pointer to inserted record if
 
218
succeed, i.e., enough space available, NULL otherwise. The cursor stays at
 
219
the same logical position, but the physical position may change if it is
 
220
pointing to a compressed page that was reorganized. */
 
221
UNIV_INLINE
 
222
rec_t*
 
223
page_cur_tuple_insert(
 
224
/*==================*/
 
225
                                /* out: pointer to record if succeed, NULL
 
226
                                otherwise */
 
227
        page_cur_t*     cursor, /* in/out: a page cursor */
 
228
        const dtuple_t* tuple,  /* in: pointer to a data tuple */
 
229
        dict_index_t*   index,  /* in: record descriptor */
 
230
        ulint           n_ext,  /* in: number of externally stored columns */
 
231
        mtr_t*          mtr)    /* in: mini-transaction handle, or NULL */
 
232
{
 
233
        mem_heap_t*     heap;
 
234
        ulint*          offsets;
 
235
        ulint           size
 
236
                = rec_get_converted_size(index, tuple, n_ext);
 
237
        rec_t*          rec;
 
238
 
 
239
        heap = mem_heap_create(size
 
240
                               + (4 + REC_OFFS_HEADER_SIZE
 
241
                                  + dtuple_get_n_fields(tuple))
 
242
                               * sizeof *offsets);
 
243
        rec = rec_convert_dtuple_to_rec((byte*) mem_heap_alloc(heap, size),
 
244
                                        index, tuple, n_ext);
 
245
        offsets = rec_get_offsets(rec, index, NULL, ULINT_UNDEFINED, &heap);
 
246
 
 
247
        if (buf_block_get_page_zip(cursor->block)) {
 
248
                rec = page_cur_insert_rec_zip(&cursor->rec, cursor->block,
 
249
                                              index, rec, offsets, mtr);
 
250
        } else {
 
251
                rec = page_cur_insert_rec_low(cursor->rec,
 
252
                                              index, rec, offsets, mtr);
 
253
        }
 
254
 
 
255
        mem_heap_free(heap);
 
256
        return(rec);
 
257
}
 
258
 
 
259
/***************************************************************
 
260
Inserts a record next to page cursor. Returns pointer to inserted record if
 
261
succeed, i.e., enough space available, NULL otherwise. The cursor stays at
 
262
the same logical position, but the physical position may change if it is
 
263
pointing to a compressed page that was reorganized. */
 
264
UNIV_INLINE
 
265
rec_t*
 
266
page_cur_rec_insert(
 
267
/*================*/
 
268
                                /* out: pointer to record if succeed, NULL
 
269
                                otherwise */
 
270
        page_cur_t*     cursor, /* in/out: a page cursor */
 
271
        const rec_t*    rec,    /* in: record to insert */
 
272
        dict_index_t*   index,  /* in: record descriptor */
 
273
        ulint*          offsets,/* in/out: rec_get_offsets(rec, index) */
 
274
        mtr_t*          mtr)    /* in: mini-transaction handle, or NULL */
 
275
{
 
276
        if (buf_block_get_page_zip(cursor->block)) {
 
277
                return(page_cur_insert_rec_zip(&cursor->rec, cursor->block,
 
278
                                               index, rec, offsets, mtr));
 
279
        } else {
 
280
                return(page_cur_insert_rec_low(cursor->rec,
 
281
                                               index, rec, offsets, mtr));
 
282
        }
 
283
}
 
284