1
/************************************************************************
4
(c) 1994-1996 Innobase Oy
6
Created 10/4/1994 Heikki Tuuri
7
*************************************************************************/
10
#include "buf0types.h"
13
/*************************************************************
14
Gets pointer to the page frame where the cursor is positioned. */
20
page_cur_t* cur) /* in: page cursor */
23
ut_ad(page_align(cur->rec) == cur->block->frame);
25
return(page_align(cur->rec));
28
/*************************************************************
29
Gets pointer to the buffer block where the cursor is positioned. */
35
page_cur_t* cur) /* in: page cursor */
38
ut_ad(page_align(cur->rec) == cur->block->frame);
42
/*************************************************************
43
Gets pointer to the page frame where the cursor is positioned. */
46
page_cur_get_page_zip(
47
/*==================*/
49
page_cur_t* cur) /* in: page cursor */
51
return(buf_block_get_page_zip(page_cur_get_block(cur)));
54
/*************************************************************
55
Gets the record where the cursor is positioned. */
61
page_cur_t* cur) /* in: page cursor */
64
ut_ad(page_align(cur->rec) == cur->block->frame);
68
#endif /* UNIV_DEBUG */
70
/*************************************************************
71
Sets the cursor object to point before the first user record
75
page_cur_set_before_first(
76
/*======================*/
77
const buf_block_t* block, /* in: index page */
78
page_cur_t* cur) /* in: cursor */
80
cur->block = (buf_block_t*) block;
81
cur->rec = page_get_infimum_rec(buf_block_get_frame(cur->block));
84
/*************************************************************
85
Sets the cursor object to point after the last user record on
89
page_cur_set_after_last(
90
/*====================*/
91
const buf_block_t* block, /* in: index page */
92
page_cur_t* cur) /* in: cursor */
94
cur->block = (buf_block_t*) block;
95
cur->rec = page_get_supremum_rec(buf_block_get_frame(cur->block));
98
/*************************************************************
99
Returns TRUE if the cursor is before first user record on page. */
102
page_cur_is_before_first(
103
/*=====================*/
104
/* out: TRUE if at start */
105
const page_cur_t* cur) /* in: cursor */
108
ut_ad(page_align(cur->rec) == cur->block->frame);
109
return(page_rec_is_infimum(cur->rec));
112
/*************************************************************
113
Returns TRUE if the cursor is after last user record. */
116
page_cur_is_after_last(
117
/*===================*/
118
/* out: TRUE if at end */
119
const page_cur_t* cur) /* in: cursor */
122
ut_ad(page_align(cur->rec) == cur->block->frame);
123
return(page_rec_is_supremum(cur->rec));
126
/**************************************************************
127
Positions the cursor on the given record. */
132
const rec_t* rec, /* in: record on a page */
133
const buf_block_t* block, /* in: buffer block containing
135
page_cur_t* cur) /* out: page cursor */
137
ut_ad(rec && block && cur);
138
ut_ad(page_align(rec) == block->frame);
140
cur->rec = (rec_t*) rec;
141
cur->block = (buf_block_t*) block;
144
/**************************************************************
145
Invalidates a page cursor by setting the record pointer NULL. */
150
page_cur_t* cur) /* out: page cursor */
158
/**************************************************************
159
Moves the cursor to the next record on page. */
162
page_cur_move_to_next(
163
/*==================*/
164
page_cur_t* cur) /* in/out: cursor; must not be after last */
166
ut_ad(!page_cur_is_after_last(cur));
168
cur->rec = page_rec_get_next(cur->rec);
171
/**************************************************************
172
Moves the cursor to the previous record on page. */
175
page_cur_move_to_prev(
176
/*==================*/
177
page_cur_t* cur) /* in/out: page cursor, not before first */
179
ut_ad(!page_cur_is_before_first(cur));
181
cur->rec = page_rec_get_prev(cur->rec);
184
/********************************************************************
185
Searches the right position for a page cursor. */
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
198
page_cur_t* cursor) /* out: page cursor */
200
ulint low_matched_fields = 0;
201
ulint low_matched_bytes = 0;
202
ulint up_matched_fields = 0;
203
ulint up_matched_bytes = 0;
205
ut_ad(dtuple_check_typed(tuple));
207
page_cur_search_with_match(block, index, tuple, mode,
213
return(low_matched_fields);
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. */
223
page_cur_tuple_insert(
224
/*==================*/
225
/* out: pointer to record if succeed, NULL
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 */
236
= rec_get_converted_size(index, tuple, n_ext);
239
heap = mem_heap_create(size
240
+ (4 + REC_OFFS_HEADER_SIZE
241
+ dtuple_get_n_fields(tuple))
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);
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);
251
rec = page_cur_insert_rec_low(cursor->rec,
252
index, rec, offsets, mtr);
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. */
268
/* out: pointer to record if succeed, NULL
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 */
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));
280
return(page_cur_insert_rec_low(cursor->rec,
281
index, rec, offsets, mtr));