1 /*****************************************************************************
2 
3 Copyright (c) 1996, 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/btr0types.h
29 The index tree general types
30 
31 Created 2/17/1996 Heikki Tuuri
32 *************************************************************************/
33 
34 #ifndef btr0types_h
35 #define btr0types_h
36 
37 #include "univ.i"
38 
39 #include "rem0types.h"
40 #include "page0types.h"
41 #include "sync0rw.h"
42 
43 /** Persistent cursor */
44 struct btr_pcur_t;
45 /** B-tree cursor */
46 struct btr_cur_t;
47 /** B-tree search information for the adaptive hash index */
48 struct btr_search_t;
49 
50 #ifndef UNIV_HOTBACKUP
51 
52 /** @brief The latch protecting the adaptive search system
53 
54 This latch protects the
55 (1) hash index;
56 (2) columns of a record to which we have a pointer in the hash index;
57 
58 but does NOT protect:
59 
60 (3) next record offset field in a record;
61 (4) next or previous records on the same page.
62 
63 Bear in mind (3) and (4) when using the hash index.
64 */
65 extern rw_lock_t*	btr_search_latch_temp;
66 
67 #endif /* UNIV_HOTBACKUP */
68 
69 /** The latch protecting the adaptive search system */
70 #define btr_search_latch	(*btr_search_latch_temp)
71 
72 /** Flag: has the search system been enabled?
73 Protected by btr_search_latch. */
74 extern char	btr_search_enabled;
75 
76 #ifdef UNIV_BLOB_DEBUG
77 # include "buf0types.h"
78 /** An index->blobs entry for keeping track of off-page column references */
79 struct btr_blob_dbg_t;
80 
81 /** Insert to index->blobs a reference to an off-page column.
82 @param index	the index tree
83 @param b	the reference
84 @param ctx	context (for logging) */
85 UNIV_INTERN
86 void
87 btr_blob_dbg_rbt_insert(
88 /*====================*/
89 	dict_index_t*		index,	/*!< in/out: index tree */
90 	const btr_blob_dbg_t*	b,	/*!< in: the reference */
91 	const char*		ctx)	/*!< in: context (for logging) */
92 	MY_ATTRIBUTE((nonnull));
93 
94 /** Remove from index->blobs a reference to an off-page column.
95 @param index	the index tree
96 @param b	the reference
97 @param ctx	context (for logging) */
98 UNIV_INTERN
99 void
100 btr_blob_dbg_rbt_delete(
101 /*====================*/
102 	dict_index_t*		index,	/*!< in/out: index tree */
103 	const btr_blob_dbg_t*	b,	/*!< in: the reference */
104 	const char*		ctx)	/*!< in: context (for logging) */
105 	MY_ATTRIBUTE((nonnull));
106 
107 /**************************************************************//**
108 Add to index->blobs any references to off-page columns from a record.
109 @return number of references added */
110 UNIV_INTERN
111 ulint
112 btr_blob_dbg_add_rec(
113 /*=================*/
114 	const rec_t*	rec,	/*!< in: record */
115 	dict_index_t*	index,	/*!< in/out: index */
116 	const ulint*	offsets,/*!< in: offsets */
117 	const char*	ctx)	/*!< in: context (for logging) */
118 	MY_ATTRIBUTE((nonnull));
119 /**************************************************************//**
120 Remove from index->blobs any references to off-page columns from a record.
121 @return number of references removed */
122 UNIV_INTERN
123 ulint
124 btr_blob_dbg_remove_rec(
125 /*====================*/
126 	const rec_t*	rec,	/*!< in: record */
127 	dict_index_t*	index,	/*!< in/out: index */
128 	const ulint*	offsets,/*!< in: offsets */
129 	const char*	ctx)	/*!< in: context (for logging) */
130 	MY_ATTRIBUTE((nonnull));
131 /**************************************************************//**
132 Count and add to index->blobs any references to off-page columns
133 from records on a page.
134 @return number of references added */
135 UNIV_INTERN
136 ulint
137 btr_blob_dbg_add(
138 /*=============*/
139 	const page_t*	page,	/*!< in: rewritten page */
140 	dict_index_t*	index,	/*!< in/out: index */
141 	const char*	ctx)	/*!< in: context (for logging) */
142 	MY_ATTRIBUTE((nonnull));
143 /**************************************************************//**
144 Count and remove from index->blobs any references to off-page columns
145 from records on a page.
146 Used when reorganizing a page, before copying the records.
147 @return number of references removed */
148 UNIV_INTERN
149 ulint
150 btr_blob_dbg_remove(
151 /*================*/
152 	const page_t*	page,	/*!< in: b-tree page */
153 	dict_index_t*	index,	/*!< in/out: index */
154 	const char*	ctx)	/*!< in: context (for logging) */
155 	MY_ATTRIBUTE((nonnull));
156 /**************************************************************//**
157 Restore in index->blobs any references to off-page columns
158 Used when page reorganize fails due to compressed page overflow. */
159 UNIV_INTERN
160 void
161 btr_blob_dbg_restore(
162 /*=================*/
163 	const page_t*	npage,	/*!< in: page that failed to compress */
164 	const page_t*	page,	/*!< in: copy of original page */
165 	dict_index_t*	index,	/*!< in/out: index */
166 	const char*	ctx)	/*!< in: context (for logging) */
167 	MY_ATTRIBUTE((nonnull));
168 
169 /** Operation that processes the BLOB references of an index record
170 @param[in]	rec	record on index page
171 @param[in/out]	index	the index tree of the record
172 @param[in]	offsets	rec_get_offsets(rec,index)
173 @param[in]	ctx	context (for logging)
174 @return			number of BLOB references processed */
175 typedef ulint (*btr_blob_dbg_op_f)
176 (const rec_t* rec,dict_index_t* index,const ulint* offsets,const char* ctx);
177 
178 /**************************************************************//**
179 Count and process all references to off-page columns on a page.
180 @return number of references processed */
181 UNIV_INTERN
182 ulint
183 btr_blob_dbg_op(
184 /*============*/
185 	const page_t*		page,	/*!< in: B-tree leaf page */
186 	const rec_t*		rec,	/*!< in: record to start from
187 					(NULL to process the whole page) */
188 	dict_index_t*		index,	/*!< in/out: index */
189 	const char*		ctx,	/*!< in: context (for logging) */
190 	const btr_blob_dbg_op_f	op)	/*!< in: operation on records */
191 	MY_ATTRIBUTE((nonnull(1,3,4,5)));
192 #else /* UNIV_BLOB_DEBUG */
193 # define btr_blob_dbg_add_rec(rec, index, offsets, ctx)		((void) 0)
194 # define btr_blob_dbg_add(page, index, ctx)			((void) 0)
195 # define btr_blob_dbg_remove_rec(rec, index, offsets, ctx)	((void) 0)
196 # define btr_blob_dbg_remove(page, index, ctx)			((void) 0)
197 # define btr_blob_dbg_restore(npage, page, index, ctx)		((void) 0)
198 # define btr_blob_dbg_op(page, rec, index, ctx, op)		((void) 0)
199 #endif /* UNIV_BLOB_DEBUG */
200 
201 /** The size of a reference to data stored on a different page.
202 The reference is stored at the end of the prefix of the field
203 in the index record. */
204 #define BTR_EXTERN_FIELD_REF_SIZE	20
205 
206 /** A BLOB field reference full of zero, for use in assertions and tests.
207 Initially, BLOB field references are set to zero, in
208 dtuple_convert_big_rec(). */
209 extern const byte field_ref_zero[BTR_EXTERN_FIELD_REF_SIZE];
210 
211 #endif
212