summaryrefslogtreecommitdiff
path: root/storage/innobase/include/row0upd.ic
blob: e2d81a39cfa19ef92e5efb47397bfe8b2e866585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/******************************************************
Update of a row

(c) 1996 Innobase Oy

Created 12/27/1996 Heikki Tuuri
*******************************************************/

#include "mtr0log.h"
#include "trx0trx.h"
#include "trx0undo.h"
#include "row0row.h"
#include "btr0sea.h"

/*************************************************************************
Creates an update vector object. */
UNIV_INLINE
upd_t*
upd_create(
/*=======*/
				/* out, own: update vector object */
	ulint		n,	/* in: number of fields */
	mem_heap_t*	heap)	/* in: heap from which memory allocated */
{
	upd_t*	update;
	ulint	i;

	update = mem_heap_alloc(heap, sizeof(upd_t));

	update->info_bits = 0;
	update->n_fields = n;
	update->fields = mem_heap_alloc(heap, sizeof(upd_field_t) * n);

	for (i = 0; i < n; i++) {
		update->fields[i].extern_storage = 0;
	}
	
	return(update);
}

/*************************************************************************
Returns the number of fields in the update vector == number of columns
to be updated by an update vector. */
UNIV_INLINE
ulint
upd_get_n_fields(
/*=============*/
			/* out: number of fields */
	upd_t*	update)	/* in: update vector */
{
	ut_ad(update);

	return(update->n_fields);
}

/*************************************************************************
Returns the nth field of an update vector. */
UNIV_INLINE
upd_field_t*
upd_get_nth_field(
/*==============*/
			/* out: update vector field */
	upd_t*	update,	/* in: update vector */
	ulint	n)	/* in: field position in update vector */
{
	ut_ad(update);
	ut_ad(n < update->n_fields);

	return(update->fields + n);
}

/*************************************************************************
Sets an index field number to be updated by an update vector field. */
UNIV_INLINE
void
upd_field_set_field_no(
/*===================*/
	upd_field_t*	upd_field,	/* in: update vector field */
	ulint		field_no,	/* in: field number in a clustered
					index */
	dict_index_t*	index,		/* in: index */
	trx_t*		trx)		/* in: transaction */
{	
	upd_field->field_no = field_no;

	if (field_no >= dict_index_get_n_fields(index)) {
		fprintf(stderr,
			"InnoDB: Error: trying to access field %lu in ",
			(ulong) field_no);
		dict_index_name_print(stderr, trx, index);
		fprintf(stderr, "\n"
			"InnoDB: but index only has %lu fields\n",
		(ulong) dict_index_get_n_fields(index));
	}

	dtype_copy(dfield_get_type(&(upd_field->new_val)),
				dict_index_get_nth_type(index, field_no));
}

/*************************************************************************
Updates the trx id and roll ptr field in a clustered index record when
a row is updated or marked deleted. */
UNIV_INLINE
void
row_upd_rec_sys_fields(
/*===================*/
	rec_t*		rec,	/* in: record */
	dict_index_t*	index,	/* in: clustered index */
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
	trx_t*		trx,	/* in: transaction */
	dulint		roll_ptr)/* in: roll ptr of the undo log record */
{
	ut_ad(index->type & DICT_CLUSTERED);
	ut_ad(rec_offs_validate(rec, index, offsets));
#ifdef UNIV_SYNC_DEBUG
	ut_ad(!buf_block_align(rec)->is_hashed
			|| rw_lock_own(&btr_search_latch, RW_LOCK_EX));
#endif /* UNIV_SYNC_DEBUG */

	row_set_rec_trx_id(rec, index, offsets, trx->id);
	row_set_rec_roll_ptr(rec, index, offsets, roll_ptr);
}