30
13
#include "data0data.h"
31
#include "row0types.h"
32
14
#include "btr0types.h"
33
16
#include "dict0types.h"
34
17
#include "trx0types.h"
36
#ifndef UNIV_HOTBACKUP
37
# include "btr0pcur.h"
38
# include "que0types.h"
39
# include "pars0types.h"
40
#endif /* !UNIV_HOTBACKUP */
42
/*********************************************************************//**
43
Creates an update vector object.
44
@return own: update vector object */
18
#include "que0types.h"
19
#include "row0types.h"
20
#include "pars0types.h"
22
/*************************************************************************
23
Creates an update vector object. */
49
ulint n, /*!< in: number of fields */
50
mem_heap_t* heap); /*!< in: heap from which memory allocated */
51
/*********************************************************************//**
28
/* out, own: update vector object */
29
ulint n, /* in: number of fields */
30
mem_heap_t* heap); /* in: heap from which memory allocated */
31
/*************************************************************************
52
32
Returns the number of fields in the update vector == number of columns
53
to be updated by an update vector.
54
@return number of fields */
33
to be updated by an update vector. */
59
const upd_t* update); /*!< in: update vector */
38
/* out: number of fields */
39
const upd_t* update); /* in: update vector */
61
/*********************************************************************//**
62
Returns the nth field of an update vector.
63
@return update vector field */
41
/*************************************************************************
42
Returns the nth field of an update vector. */
68
const upd_t* update, /*!< in: update vector */
69
ulint n); /*!< in: field position in update vector */
47
/* out: update vector field */
48
const upd_t* update, /* in: update vector */
49
ulint n); /* in: field position in update vector */
71
51
# define upd_get_nth_field(update, n) ((update)->fields + (n))
73
#ifndef UNIV_HOTBACKUP
74
/*********************************************************************//**
53
/*************************************************************************
75
54
Sets an index field number to be updated by an update vector field. */
78
57
upd_field_set_field_no(
79
58
/*===================*/
80
upd_field_t* upd_field, /*!< in: update vector field */
81
ulint field_no, /*!< in: field number in a clustered
59
upd_field_t* upd_field, /* in: update vector field */
60
ulint field_no, /* in: field number in a clustered
83
dict_index_t* index, /*!< in: index */
84
trx_t* trx); /*!< in: transaction */
85
/*********************************************************************//**
86
Returns a field of an update vector by field_no.
87
@return update vector field, or NULL */
62
dict_index_t* index, /* in: index */
63
trx_t* trx); /* in: transaction */
64
/*************************************************************************
65
Returns a field of an update vector by field_no. */
90
68
upd_get_field_by_field_no(
91
69
/*======================*/
92
const upd_t* update, /*!< in: update vector */
93
ulint no) /*!< in: field_no */
70
/* out: update vector field, or NULL */
71
const upd_t* update, /* in: update vector */
72
ulint no) /* in: field_no */
94
73
__attribute__((nonnull, pure));
95
/*********************************************************************//**
74
/*************************************************************************
96
75
Writes into the redo log the values of trx id and roll ptr and enough info
97
to determine their positions within a clustered index record.
98
@return new pointer to mlog */
76
to determine their positions within a clustered index record. */
101
79
row_upd_write_sys_vals_to_log(
102
80
/*==========================*/
103
dict_index_t* index, /*!< in: clustered index */
104
trx_t* trx, /*!< in: transaction */
105
roll_ptr_t roll_ptr,/*!< in: roll ptr of the undo log record */
106
byte* log_ptr,/*!< pointer to a buffer of size > 20 opened
81
/* out: new pointer to mlog */
82
dict_index_t* index, /* in: clustered index */
83
trx_t* trx, /* in: transaction */
84
dulint roll_ptr,/* in: roll ptr of the undo log record */
85
byte* log_ptr,/* pointer to a buffer of size > 20 opened
108
mtr_t* mtr); /*!< in: mtr */
109
/*********************************************************************//**
87
mtr_t* mtr); /* in: mtr */
88
/*************************************************************************
110
89
Updates the trx id and roll ptr field in a clustered index record when
111
90
a row is updated or marked deleted. */
114
93
row_upd_rec_sys_fields(
115
94
/*===================*/
116
rec_t* rec, /*!< in/out: record */
117
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
95
rec_t* rec, /* in/out: record */
96
page_zip_des_t* page_zip,/* in/out: compressed page whose
118
97
uncompressed part will be updated, or NULL */
119
dict_index_t* index, /*!< in: clustered index */
120
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
121
trx_t* trx, /*!< in: transaction */
122
roll_ptr_t roll_ptr);/*!< in: roll ptr of the undo log record */
123
/*********************************************************************//**
98
dict_index_t* index, /* in: clustered index */
99
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
100
trx_t* trx, /* in: transaction */
101
dulint roll_ptr);/* in: roll ptr of the undo log record */
102
/*************************************************************************
124
103
Sets the trx id or roll ptr field of a clustered index entry. */
127
106
row_upd_index_entry_sys_field(
128
107
/*==========================*/
129
const dtuple_t* entry, /*!< in: index entry, where the memory buffers
108
const dtuple_t* entry, /* in: index entry, where the memory buffers
130
109
for sys fields are already allocated:
131
110
the function just copies the new values to
133
dict_index_t* index, /*!< in: clustered index */
134
ulint type, /*!< in: DATA_TRX_ID or DATA_ROLL_PTR */
135
dulint val); /*!< in: value to write */
136
/*********************************************************************//**
137
Creates an update node for a query graph.
138
@return own: update node */
112
dict_index_t* index, /* in: clustered index */
113
ulint type, /* in: DATA_TRX_ID or DATA_ROLL_PTR */
114
dulint val); /* in: value to write */
115
/*************************************************************************
116
Creates an update node for a query graph. */
143
mem_heap_t* heap); /*!< in: mem heap where created */
144
/***********************************************************//**
121
/* out, own: update node */
122
mem_heap_t* heap); /* in: mem heap where created */
123
/***************************************************************
145
124
Writes to the redo log the new values of the fields occurring in the index. */
148
127
row_upd_index_write_log(
149
128
/*====================*/
150
const upd_t* update, /*!< in: update vector */
151
byte* log_ptr,/*!< in: pointer to mlog buffer: must
129
const upd_t* update, /* in: update vector */
130
byte* log_ptr,/* in: pointer to mlog buffer: must
152
131
contain at least MLOG_BUF_MARGIN bytes
153
132
of free space; the buffer is closed
154
133
within this function */
155
mtr_t* mtr); /*!< in: mtr into whose log to write */
156
/***********************************************************//**
134
mtr_t* mtr); /* in: mtr into whose log to write */
135
/***************************************************************
157
136
Returns TRUE if row update changes size of some field in index or if some
158
field to be updated is stored externally in rec or update.
159
@return TRUE if the update changes the size of some field in index or
160
the field is external in rec or update */
137
field to be updated is stored externally in rec or update. */
163
140
row_upd_changes_field_size_or_external(
164
141
/*===================================*/
165
dict_index_t* index, /*!< in: index */
166
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
167
const upd_t* update);/*!< in: update vector */
168
#endif /* !UNIV_HOTBACKUP */
169
/***********************************************************//**
142
/* out: TRUE if the update changes the size of
143
some field in index or the field is external
145
dict_index_t* index, /* in: index */
146
const ulint* offsets,/* in: rec_get_offsets(rec, index) */
147
const upd_t* update);/* in: update vector */
148
/***************************************************************
170
149
Replaces the new column values stored in the update vector to the record
171
150
given. No field size changes are allowed. */
174
153
row_upd_rec_in_place(
175
154
/*=================*/
176
rec_t* rec, /*!< in/out: record where replaced */
177
dict_index_t* index, /*!< in: the index the record belongs to */
178
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
179
const upd_t* update, /*!< in: update vector */
180
page_zip_des_t* page_zip);/*!< in: compressed page with enough space
155
rec_t* rec, /* in/out: record where replaced */
156
dict_index_t* index, /* in: the index the record belongs to */
157
const ulint* offsets,/* in: array returned by rec_get_offsets() */
158
const upd_t* update, /* in: update vector */
159
page_zip_des_t* page_zip);/* in: compressed page with enough space
181
160
available, or NULL */
182
#ifndef UNIV_HOTBACKUP
183
/***************************************************************//**
161
/*******************************************************************
184
162
Builds an update vector from those fields which in a secondary index entry
185
163
differ from a record that has the equal ordering fields. NOTE: we compare
186
the fields as binary strings!
187
@return own: update vector of differing fields */
164
the fields as binary strings! */
190
167
row_upd_build_sec_rec_difference_binary(
191
168
/*====================================*/
192
dict_index_t* index, /*!< in: index */
193
const dtuple_t* entry, /*!< in: entry to insert */
194
const rec_t* rec, /*!< in: secondary index record */
195
trx_t* trx, /*!< in: transaction */
196
mem_heap_t* heap); /*!< in: memory heap from which allocated */
197
/***************************************************************//**
169
/* out, own: update vector of differing
171
dict_index_t* index, /* in: index */
172
const dtuple_t* entry, /* in: entry to insert */
173
const rec_t* rec, /* in: secondary index record */
174
trx_t* trx, /* in: transaction */
175
mem_heap_t* heap); /* in: memory heap from which allocated */
176
/*******************************************************************
198
177
Builds an update vector from those fields, excluding the roll ptr and
199
178
trx id fields, which in an index entry differ from a record that has
200
the equal ordering fields. NOTE: we compare the fields as binary strings!
201
@return own: update vector of differing fields, excluding roll ptr and
179
the equal ordering fields. NOTE: we compare the fields as binary strings! */
205
182
row_upd_build_difference_binary(
206
183
/*============================*/
207
dict_index_t* index, /*!< in: clustered index */
208
const dtuple_t* entry, /*!< in: entry to insert */
209
const rec_t* rec, /*!< in: clustered index record */
210
trx_t* trx, /*!< in: transaction */
211
mem_heap_t* heap); /*!< in: memory heap from which allocated */
212
/***********************************************************//**
184
/* out, own: update vector of differing
185
fields, excluding roll ptr and trx id */
186
dict_index_t* index, /* in: clustered index */
187
const dtuple_t* entry, /* in: entry to insert */
188
const rec_t* rec, /* in: clustered index record */
189
trx_t* trx, /* in: transaction */
190
mem_heap_t* heap); /* in: memory heap from which allocated */
191
/***************************************************************
213
192
Replaces the new column values stored in the update vector to the index entry
217
196
row_upd_index_replace_new_col_vals_index_pos(
218
197
/*=========================================*/
219
dtuple_t* entry, /*!< in/out: index entry where replaced;
198
dtuple_t* entry, /* in/out: index entry where replaced;
220
199
the clustered index record must be
221
200
covered by a lock or a page latch to
222
201
prevent deletion (rollback or purge) */
223
dict_index_t* index, /*!< in: index; NOTE that this may also be a
202
dict_index_t* index, /* in: index; NOTE that this may also be a
224
203
non-clustered index */
225
const upd_t* update, /*!< in: an update vector built for the index so
204
const upd_t* update, /* in: an update vector built for the index so
226
205
that the field number in an upd_field is the
227
206
index position */
228
207
ibool order_only,
229
/*!< in: if TRUE, limit the replacement to
208
/* in: if TRUE, limit the replacement to
230
209
ordering fields of index; note that this
231
210
does not work for non-clustered indexes. */
232
mem_heap_t* heap) /*!< in: memory heap for allocating and
211
mem_heap_t* heap) /* in: memory heap for allocating and
233
212
copying the new values */
234
213
__attribute__((nonnull));
235
/***********************************************************//**
214
/***************************************************************
236
215
Replaces the new column values stored in the update vector to the index entry
240
219
row_upd_index_replace_new_col_vals(
241
220
/*===============================*/
242
dtuple_t* entry, /*!< in/out: index entry where replaced;
221
dtuple_t* entry, /* in/out: index entry where replaced;
243
222
the clustered index record must be
244
223
covered by a lock or a page latch to
245
224
prevent deletion (rollback or purge) */
246
dict_index_t* index, /*!< in: index; NOTE that this may also be a
225
dict_index_t* index, /* in: index; NOTE that this may also be a
247
226
non-clustered index */
248
const upd_t* update, /*!< in: an update vector built for the
227
const upd_t* update, /* in: an update vector built for the
249
228
CLUSTERED index so that the field number in
250
229
an upd_field is the clustered index position */
251
mem_heap_t* heap) /*!< in: memory heap for allocating and
230
mem_heap_t* heap) /* in: memory heap for allocating and
252
231
copying the new values */
253
232
__attribute__((nonnull));
254
/***********************************************************//**
233
/***************************************************************
255
234
Replaces the new column values stored in the update vector. */
260
dtuple_t* row, /*!< in/out: row where replaced,
239
dtuple_t* row, /* in/out: row where replaced,
261
240
indexed by col_no;
262
241
the clustered index record must be
263
242
covered by a lock or a page latch to
264
243
prevent deletion (rollback or purge) */
265
row_ext_t** ext, /*!< out, own: NULL, or externally
244
row_ext_t** ext, /* out, own: NULL, or externally
266
245
stored column prefixes */
267
const dict_index_t* index, /*!< in: clustered index */
268
const upd_t* update, /*!< in: an update vector built for the
246
const dict_index_t* index, /* in: clustered index */
247
const upd_t* update, /* in: an update vector built for the
269
248
clustered index */
270
mem_heap_t* heap); /*!< in: memory heap */
271
/***********************************************************//**
249
mem_heap_t* heap); /* in: memory heap */
250
/***************************************************************
272
251
Checks if an update vector changes an ordering field of an index record.
274
252
This function is fast if the update vector is short or the number of ordering
275
253
fields in the index is small. Otherwise, this can be quadratic.
276
NOTE: we compare the fields as binary strings!
277
@return TRUE if update vector changes an ordering field in the index record */
254
NOTE: we compare the fields as binary strings! */
280
257
row_upd_changes_ord_field_binary(
281
258
/*=============================*/
282
const dtuple_t* row, /*!< in: old value of row, or NULL if the
259
/* out: TRUE if update vector changes
260
an ordering field in the index record;
261
NOTE: the fields are compared as binary
263
const dtuple_t* row, /* in: old value of row, or NULL if the
283
264
row and the data values in update are not
284
265
known when this function is called, e.g., at
286
dict_index_t* index, /*!< in: index of the record */
287
const upd_t* update);/*!< in: update vector for the row; NOTE: the
267
dict_index_t* index, /* in: index of the record */
268
const upd_t* update);/* in: update vector for the row; NOTE: the
288
269
field numbers in this MUST be clustered index
290
/***********************************************************//**
271
/***************************************************************
291
272
Checks if an update vector changes an ordering field of an index record.
292
273
This function is fast if the update vector is short or the number of ordering
293
274
fields in the index is small. Otherwise, this can be quadratic.
294
NOTE: we compare the fields as binary strings!
295
@return TRUE if update vector may change an ordering field in an index
275
NOTE: we compare the fields as binary strings! */
299
278
row_upd_changes_some_index_ord_field_binary(
300
279
/*========================================*/
301
const dict_table_t* table, /*!< in: table */
302
const upd_t* update);/*!< in: update vector for the row */
303
/***********************************************************//**
280
/* out: TRUE if update vector
281
may change an ordering field
282
in an index record */
283
const dict_table_t* table, /* in: table */
284
const upd_t* update);/* in: update vector for the row */
285
/***************************************************************
304
286
Updates a row in a table. This is a high-level function used
305
in SQL execution graphs.
306
@return query thread to run next or NULL */
287
in SQL execution graphs. */
311
que_thr_t* thr); /*!< in: query thread */
312
#endif /* !UNIV_HOTBACKUP */
313
/*********************************************************************//**
314
Parses the log data of system field values.
315
@return log data end or NULL */
292
/* out: query thread to run next or NULL */
293
que_thr_t* thr); /* in: query thread */
294
/*************************************************************************
295
Performs an in-place update for the current clustered index record in
299
row_upd_in_place_in_select(
300
/*=======================*/
301
sel_node_t* sel_node, /* in: select node */
302
que_thr_t* thr, /* in: query thread */
303
mtr_t* mtr); /* in: mtr */
304
/*************************************************************************
305
Parses the log data of system field values. */
318
308
row_upd_parse_sys_vals(
319
309
/*===================*/
320
byte* ptr, /*!< in: buffer */
321
byte* end_ptr,/*!< in: buffer end */
322
ulint* pos, /*!< out: TRX_ID position in record */
323
trx_id_t* trx_id, /*!< out: trx id */
324
roll_ptr_t* roll_ptr);/*!< out: roll ptr */
325
/*********************************************************************//**
310
/* out: log data end or NULL */
311
byte* ptr, /* in: buffer */
312
byte* end_ptr,/* in: buffer end */
313
ulint* pos, /* out: TRX_ID position in record */
314
dulint* trx_id, /* out: trx id */
315
dulint* roll_ptr);/* out: roll ptr */
316
/*************************************************************************
326
317
Updates the trx id and roll ptr field in a clustered index record in database
330
321
row_upd_rec_sys_fields_in_recovery(
331
322
/*===============================*/
332
rec_t* rec, /*!< in/out: record */
333
page_zip_des_t* page_zip,/*!< in/out: compressed page, or NULL */
334
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
335
ulint pos, /*!< in: TRX_ID position in rec */
336
trx_id_t trx_id, /*!< in: transaction id */
337
roll_ptr_t roll_ptr);/*!< in: roll ptr of the undo log record */
338
/*********************************************************************//**
339
Parses the log data written by row_upd_index_write_log.
340
@return log data end or NULL */
323
rec_t* rec, /* in/out: record */
324
page_zip_des_t* page_zip,/* in/out: compressed page, or NULL */
325
const ulint* offsets,/* in: array returned by rec_get_offsets() */
326
ulint pos, /* in: TRX_ID position in rec */
327
dulint trx_id, /* in: transaction id */
328
dulint roll_ptr);/* in: roll ptr of the undo log record */
329
/*************************************************************************
330
Parses the log data written by row_upd_index_write_log. */
343
333
row_upd_index_parse(
344
334
/*================*/
345
byte* ptr, /*!< in: buffer */
346
byte* end_ptr,/*!< in: buffer end */
347
mem_heap_t* heap, /*!< in: memory heap where update vector is
335
/* out: log data end or NULL */
336
byte* ptr, /* in: buffer */
337
byte* end_ptr,/* in: buffer end */
338
mem_heap_t* heap, /* in: memory heap where update vector is
349
upd_t** update_out);/*!< out: update vector */
340
upd_t** update_out);/* out: update vector */
352
343
/* Update vector field */
353
344
struct upd_field_struct{
354
unsigned field_no:16; /*!< field number in an index, usually
345
unsigned field_no:16; /* field number in an index, usually
355
346
the clustered index, but in updating
356
347
a secondary index record in btr0cur.c
357
348
this is the position in the secondary
359
#ifndef UNIV_HOTBACKUP
360
unsigned orig_len:16; /*!< original length of the locally
350
unsigned orig_len:16; /* original length of the locally
361
351
stored part of an externally stored
363
que_node_t* exp; /*!< expression for calculating a new
353
que_node_t* exp; /* expression for calculating a new
364
354
value: it refers to column values and
365
355
constants in the symbol table of the
367
#endif /* !UNIV_HOTBACKUP */
368
dfield_t new_val; /*!< new value for the column */
357
dfield_t new_val; /* new value for the column */
371
360
/* Update vector structure */
372
361
struct upd_struct{
373
ulint info_bits; /*!< new value of info bits to record;
362
ulint info_bits; /* new value of info bits to record;
375
ulint n_fields; /*!< number of update fields */
376
upd_field_t* fields; /*!< array of update fields */
364
ulint n_fields; /* number of update fields */
365
upd_field_t* fields; /* array of update fields */
379
#ifndef UNIV_HOTBACKUP
380
368
/* Update node structure which also implements the delete operation
383
371
struct upd_node_struct{
384
que_common_t common; /*!< node type: QUE_NODE_UPDATE */
372
que_common_t common; /* node type: QUE_NODE_UPDATE */
385
373
ibool is_delete;/* TRUE if delete, FALSE if update */
386
374
ibool searched_update;
387
375
/* TRUE if searched update, FALSE if
377
ibool select_will_do_update;
378
/* TRUE if a searched update where ordering
379
fields will not be updated, and the size of
380
the fields will not change: in this case the
381
select node will take care of the update */
389
382
ibool in_mysql_interface;
390
383
/* TRUE if the update node was created
391
384
for the MySQL interface */