1 /*****************************************************************************
2 
3 Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation.  The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 *****************************************************************************/
26 
27 /**************************************************//**
28 @file include/row0vers.h
29 Row versions
30 
31 Created 2/6/1997 Heikki Tuuri
32 *******************************************************/
33 
34 #ifndef row0vers_h
35 #define row0vers_h
36 
37 #include "univ.i"
38 #include "data0data.h"
39 #include "dict0types.h"
40 #include "trx0types.h"
41 #include "que0types.h"
42 #include "rem0types.h"
43 #include "mtr0mtr.h"
44 #include "read0types.h"
45 
46 /*****************************************************************//**
47 Finds out if an active transaction has inserted or modified a secondary
48 index record.
49 @return 0 if committed, else the active transaction id;
50 NOTE that this function can return false positives but never false
51 negatives. The caller must confirm all positive results by calling
52 trx_is_active() while holding lock_sys->mutex. */
53 UNIV_INTERN
54 trx_id_t
55 row_vers_impl_x_locked(
56 /*===================*/
57 	const rec_t*	rec,	/*!< in: record in a secondary index */
58 	dict_index_t*	index,	/*!< in: the secondary index */
59 	const ulint*	offsets);/*!< in: rec_get_offsets(rec, index) */
60 /*****************************************************************//**
61 Finds out if we must preserve a delete marked earlier version of a clustered
62 index record, because it is >= the purge view.
63 @return	TRUE if earlier version should be preserved */
64 UNIV_INTERN
65 ibool
66 row_vers_must_preserve_del_marked(
67 /*==============================*/
68 	trx_id_t	trx_id,	/*!< in: transaction id in the version */
69 	mtr_t*		mtr);	/*!< in: mtr holding the latch on the
70 				clustered index record; it will also
71 				hold the latch on purge_view */
72 /*****************************************************************//**
73 Finds out if a version of the record, where the version >= the current
74 purge view, should have ientry as its secondary index entry. We check
75 if there is any not delete marked version of the record where the trx
76 id >= purge view, and the secondary index entry == ientry; exactly in
77 this case we return TRUE.
78 @return	TRUE if earlier version should have */
79 UNIV_INTERN
80 ibool
81 row_vers_old_has_index_entry(
82 /*=========================*/
83 	ibool		also_curr,/*!< in: TRUE if also rec is included in the
84 				versions to search; otherwise only versions
85 				prior to it are searched */
86 	const rec_t*	rec,	/*!< in: record in the clustered index; the
87 				caller must have a latch on the page */
88 	mtr_t*		mtr,	/*!< in: mtr holding the latch on rec; it will
89 				also hold the latch on purge_view */
90 	dict_index_t*	index,	/*!< in: the secondary index */
91 	const dtuple_t*	ientry);/*!< in: the secondary index entry */
92 /*****************************************************************//**
93 Constructs the version of a clustered index record which a consistent
94 read should see. We assume that the trx id stored in rec is such that
95 the consistent read should not see rec in its present version.
96 @return	DB_SUCCESS or DB_MISSING_HISTORY */
97 UNIV_INTERN
98 dberr_t
99 row_vers_build_for_consistent_read(
100 /*===============================*/
101 	const rec_t*	rec,	/*!< in: record in a clustered index; the
102 				caller must have a latch on the page; this
103 				latch locks the top of the stack of versions
104 				of this records */
105 	mtr_t*		mtr,	/*!< in: mtr holding the latch on rec; it will
106 				also hold the latch on purge_view */
107 	dict_index_t*	index,	/*!< in: the clustered index */
108 	ulint**		offsets,/*!< in/out: offsets returned by
109 				rec_get_offsets(rec, index) */
110 	read_view_t*	view,	/*!< in: the consistent read view */
111 	mem_heap_t**	offset_heap,/*!< in/out: memory heap from which
112 				the offsets are allocated */
113 	mem_heap_t*	in_heap,/*!< in: memory heap from which the memory for
114 				*old_vers is allocated; memory for possible
115 				intermediate versions is allocated and freed
116 				locally within the function */
117 	rec_t**		old_vers)/*!< out, own: old version, or NULL
118 				if the history is missing or the record
119 				does not exist in the view, that is,
120 				it was freshly inserted afterwards */
121 	MY_ATTRIBUTE((nonnull(1,2,3,4,5,6,7)));
122 
123 /*****************************************************************//**
124 Constructs the last committed version of a clustered index record,
125 which should be seen by a semi-consistent read. */
126 UNIV_INTERN
127 void
128 row_vers_build_for_semi_consistent_read(
129 /*====================================*/
130 	const rec_t*	rec,	/*!< in: record in a clustered index; the
131 				caller must have a latch on the page; this
132 				latch locks the top of the stack of versions
133 				of this records */
134 	mtr_t*		mtr,	/*!< in: mtr holding the latch on rec */
135 	dict_index_t*	index,	/*!< in: the clustered index */
136 	ulint**		offsets,/*!< in/out: offsets returned by
137 				rec_get_offsets(rec, index) */
138 	mem_heap_t**	offset_heap,/*!< in/out: memory heap from which
139 				the offsets are allocated */
140 	mem_heap_t*	in_heap,/*!< in: memory heap from which the memory for
141 				*old_vers is allocated; memory for possible
142 				intermediate versions is allocated and freed
143 				locally within the function */
144 	const rec_t**	old_vers)/*!< out: rec, old version, or NULL if the
145 				record does not exist in the view, that is,
146 				it was freshly inserted afterwards */
147 	MY_ATTRIBUTE((nonnull(1,2,3,4,5)));
148 
149 
150 #ifndef UNIV_NONINL
151 #include "row0vers.ic"
152 #endif
153 
154 #endif
155