~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/btr0sea.h

  • Committer: Brian Aker
  • Date: 2009-05-11 17:50:22 UTC
  • Revision ID: brian@gaz-20090511175022-y35q9ky6uh9ldcjt
Replacing Sun employee copyright headers (aka... anything done by a Sun
employee is copyright by Sun).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/********************************************************************//**
20
 
@file include/btr0sea.h
21
 
The index tree adaptive search
22
 
 
23
 
Created 2/17/1996 Heikki Tuuri
24
 
*************************************************************************/
25
 
 
26
 
#ifndef btr0sea_h
27
 
#define btr0sea_h
28
 
 
29
 
#include "univ.i"
30
 
 
31
 
#include "rem0rec.h"
32
 
#include "dict0dict.h"
33
 
#include "btr0types.h"
34
 
#include "mtr0mtr.h"
35
 
#include "ha0ha.h"
36
 
 
37
 
/*****************************************************************//**
38
 
Creates and initializes the adaptive search system at a database start. */
39
 
UNIV_INTERN
40
 
void
41
 
btr_search_sys_create(
42
 
/*==================*/
43
 
        ulint   hash_size);     /*!< in: hash index hash table size */
44
 
/*****************************************************************//**
45
 
Frees the adaptive search system at a database shutdown. */
46
 
UNIV_INTERN
47
 
void
48
 
btr_search_sys_free(void);
49
 
/*=====================*/
50
 
 
51
 
/********************************************************************//**
52
 
Disable the adaptive hash search system and empty the index. */
53
 
UNIV_INTERN
54
 
void
55
 
btr_search_disable(void);
56
 
/*====================*/
57
 
/********************************************************************//**
58
 
Enable the adaptive hash search system. */
59
 
UNIV_INTERN
60
 
void
61
 
btr_search_enable(void);
62
 
/*====================*/
63
 
 
64
 
/********************************************************************//**
65
 
Returns search info for an index.
66
 
@return search info; search mutex reserved */
67
 
UNIV_INLINE
68
 
btr_search_t*
69
 
btr_search_get_info(
70
 
/*================*/
71
 
        dict_index_t*   index); /*!< in: index */
72
 
/*****************************************************************//**
73
 
Creates and initializes a search info struct.
74
 
@return own: search info struct */
75
 
UNIV_INTERN
76
 
btr_search_t*
77
 
btr_search_info_create(
78
 
/*===================*/
79
 
        mem_heap_t*     heap);  /*!< in: heap where created */
80
 
/*****************************************************************//**
81
 
Returns the value of ref_count. The value is protected by
82
 
btr_search_latch.
83
 
@return ref_count value. */
84
 
UNIV_INTERN
85
 
ulint
86
 
btr_search_info_get_ref_count(
87
 
/*==========================*/
88
 
        btr_search_t*   info);  /*!< in: search info. */
89
 
/*********************************************************************//**
90
 
Updates the search info. */
91
 
UNIV_INLINE
92
 
void
93
 
btr_search_info_update(
94
 
/*===================*/
95
 
        dict_index_t*   index,  /*!< in: index of the cursor */
96
 
        btr_cur_t*      cursor);/*!< in: cursor which was just positioned */
97
 
/******************************************************************//**
98
 
Tries to guess the right search position based on the hash search info
99
 
of the index. Note that if mode is PAGE_CUR_LE, which is used in inserts,
100
 
and the function returns TRUE, then cursor->up_match and cursor->low_match
101
 
both have sensible values.
102
 
@return TRUE if succeeded */
103
 
UNIV_INTERN
104
 
ibool
105
 
btr_search_guess_on_hash(
106
 
/*=====================*/
107
 
        dict_index_t*   index,          /*!< in: index */
108
 
        btr_search_t*   info,           /*!< in: index search info */
109
 
        const dtuple_t* tuple,          /*!< in: logical record */
110
 
        ulint           mode,           /*!< in: PAGE_CUR_L, ... */
111
 
        ulint           latch_mode,     /*!< in: BTR_SEARCH_LEAF, ... */
112
 
        btr_cur_t*      cursor,         /*!< out: tree cursor */
113
 
        ulint           has_search_latch,/*!< in: latch mode the caller
114
 
                                        currently has on btr_search_latch:
115
 
                                        RW_S_LATCH, RW_X_LATCH, or 0 */
116
 
        mtr_t*          mtr);           /*!< in: mtr */
117
 
/********************************************************************//**
118
 
Moves or deletes hash entries for moved records. If new_page is already hashed,
119
 
then the hash index for page, if any, is dropped. If new_page is not hashed,
120
 
and page is hashed, then a new hash index is built to new_page with the same
121
 
parameters as page (this often happens when a page is split). */
122
 
UNIV_INTERN
123
 
void
124
 
btr_search_move_or_delete_hash_entries(
125
 
/*===================================*/
126
 
        buf_block_t*    new_block,      /*!< in: records are copied
127
 
                                        to this page */
128
 
        buf_block_t*    block,          /*!< in: index page from which
129
 
                                        records were copied, and the
130
 
                                        copied records will be deleted
131
 
                                        from this page */
132
 
        dict_index_t*   index);         /*!< in: record descriptor */
133
 
/********************************************************************//**
134
 
Drops a page hash index. */
135
 
UNIV_INTERN
136
 
void
137
 
btr_search_drop_page_hash_index(
138
 
/*============================*/
139
 
        buf_block_t*    block); /*!< in: block containing index page,
140
 
                                s- or x-latched, or an index page
141
 
                                for which we know that
142
 
                                block->buf_fix_count == 0 */
143
 
/********************************************************************//**
144
 
Drops a page hash index when a page is freed from a fseg to the file system.
145
 
Drops possible hash index if the page happens to be in the buffer pool. */
146
 
UNIV_INTERN
147
 
void
148
 
btr_search_drop_page_hash_when_freed(
149
 
/*=================================*/
150
 
        ulint   space,          /*!< in: space id */
151
 
        ulint   zip_size,       /*!< in: compressed page size in bytes
152
 
                                or 0 for uncompressed pages */
153
 
        ulint   page_no);       /*!< in: page number */
154
 
/********************************************************************//**
155
 
Updates the page hash index when a single record is inserted on a page. */
156
 
UNIV_INTERN
157
 
void
158
 
btr_search_update_hash_node_on_insert(
159
 
/*==================================*/
160
 
        btr_cur_t*      cursor);/*!< in: cursor which was positioned to the
161
 
                                place to insert using btr_cur_search_...,
162
 
                                and the new record has been inserted next
163
 
                                to the cursor */
164
 
/********************************************************************//**
165
 
Updates the page hash index when a single record is inserted on a page. */
166
 
UNIV_INTERN
167
 
void
168
 
btr_search_update_hash_on_insert(
169
 
/*=============================*/
170
 
        btr_cur_t*      cursor);/*!< in: cursor which was positioned to the
171
 
                                place to insert using btr_cur_search_...,
172
 
                                and the new record has been inserted next
173
 
                                to the cursor */
174
 
/********************************************************************//**
175
 
Updates the page hash index when a single record is deleted from a page. */
176
 
UNIV_INTERN
177
 
void
178
 
btr_search_update_hash_on_delete(
179
 
/*=============================*/
180
 
        btr_cur_t*      cursor);/*!< in: cursor which was positioned on the
181
 
                                record to delete using btr_cur_search_...,
182
 
                                the record is not yet deleted */
183
 
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
184
 
/********************************************************************//**
185
 
Validates the search system.
186
 
@return TRUE if ok */
187
 
UNIV_INTERN
188
 
ibool
189
 
btr_search_validate(void);
190
 
/*======================*/
191
 
#else
192
 
# define btr_search_validate()  TRUE
193
 
#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
194
 
 
195
 
/** Flag: has the search system been enabled?
196
 
Protected by btr_search_latch and btr_search_enabled_mutex. */
197
 
extern bool btr_search_enabled;
198
 
 
199
 
/** Flag: whether the search system has completed its disabling process,
200
 
It is set to TRUE right after buf_pool_drop_hash_index() in
201
 
btr_search_disable(), indicating hash index entries are cleaned up.
202
 
Protected by btr_search_latch and btr_search_enabled_mutex. */
203
 
extern ibool    btr_search_fully_disabled;
204
 
 
205
 
/** The search info struct in an index */
206
 
struct btr_search_struct{
207
 
        ulint   ref_count;      /*!< Number of blocks in this index tree
208
 
                                that have search index built
209
 
                                i.e. block->index points to this index.
210
 
                                Protected by btr_search_latch except
211
 
                                when during initialization in
212
 
                                btr_search_info_create(). */
213
 
 
214
 
        /* @{ The following fields are not protected by any latch.
215
 
        Unfortunately, this means that they must be aligned to
216
 
        the machine word, i.e., they cannot be turned into bit-fields. */
217
 
        buf_block_t* root_guess;/*!< the root page frame when it was last time
218
 
                                fetched, or NULL */
219
 
        ulint   hash_analysis;  /*!< when this exceeds
220
 
                                BTR_SEARCH_HASH_ANALYSIS, the hash
221
 
                                analysis starts; this is reset if no
222
 
                                success noticed */
223
 
        ibool   last_hash_succ; /*!< TRUE if the last search would have
224
 
                                succeeded, or did succeed, using the hash
225
 
                                index; NOTE that the value here is not exact:
226
 
                                it is not calculated for every search, and the
227
 
                                calculation itself is not always accurate! */
228
 
        ulint   n_hash_potential;
229
 
                                /*!< number of consecutive searches
230
 
                                which would have succeeded, or did succeed,
231
 
                                using the hash index;
232
 
                                the range is 0 .. BTR_SEARCH_BUILD_LIMIT + 5 */
233
 
        /* @} */
234
 
        /*---------------------- @{ */
235
 
        ulint   n_fields;       /*!< recommended prefix length for hash search:
236
 
                                number of full fields */
237
 
        ulint   n_bytes;        /*!< recommended prefix: number of bytes in
238
 
                                an incomplete field
239
 
                                @see BTR_PAGE_MAX_REC_SIZE */
240
 
        ibool   left_side;      /*!< TRUE or FALSE, depending on whether
241
 
                                the leftmost record of several records with
242
 
                                the same prefix should be indexed in the
243
 
                                hash index */
244
 
        /*---------------------- @} */
245
 
#ifdef UNIV_SEARCH_PERF_STAT
246
 
        ulint   n_hash_succ;    /*!< number of successful hash searches thus
247
 
                                far */
248
 
        ulint   n_hash_fail;    /*!< number of failed hash searches */
249
 
        ulint   n_patt_succ;    /*!< number of successful pattern searches thus
250
 
                                far */
251
 
        ulint   n_searches;     /*!< number of searches */
252
 
#endif /* UNIV_SEARCH_PERF_STAT */
253
 
#ifdef UNIV_DEBUG
254
 
        ulint   magic_n;        /*!< magic number @see BTR_SEARCH_MAGIC_N */
255
 
/** value of btr_search_struct::magic_n, used in assertions */
256
 
# define BTR_SEARCH_MAGIC_N     1112765
257
 
#endif /* UNIV_DEBUG */
258
 
};
259
 
 
260
 
/** The hash index system */
261
 
typedef struct btr_search_sys_struct    btr_search_sys_t;
262
 
 
263
 
/** The hash index system */
264
 
struct btr_search_sys_struct{
265
 
        hash_table_t*   hash_index;     /*!< the adaptive hash index,
266
 
                                        mapping dtuple_fold values
267
 
                                        to rec_t pointers on index pages */
268
 
};
269
 
 
270
 
/** The adaptive hash index */
271
 
extern btr_search_sys_t*        btr_search_sys;
272
 
 
273
 
/** @brief The latch protecting the adaptive search system
274
 
 
275
 
This latch protects the
276
 
(1) hash index;
277
 
(2) columns of a record to which we have a pointer in the hash index;
278
 
 
279
 
but does NOT protect:
280
 
 
281
 
(3) next record offset field in a record;
282
 
(4) next or previous records on the same page.
283
 
 
284
 
Bear in mind (3) and (4) when using the hash index.
285
 
*/
286
 
extern rw_lock_t*       btr_search_latch_temp;
287
 
 
288
 
/** The latch protecting the adaptive search system */
289
 
#define btr_search_latch        (*btr_search_latch_temp)
290
 
 
291
 
#ifdef UNIV_SEARCH_PERF_STAT
292
 
/** Number of successful adaptive hash index lookups */
293
 
extern ulint    btr_search_n_succ;
294
 
/** Number of failed adaptive hash index lookups */
295
 
extern ulint    btr_search_n_hash_fail;
296
 
#endif /* UNIV_SEARCH_PERF_STAT */
297
 
 
298
 
/** After change in n_fields or n_bytes in info, this many rounds are waited
299
 
before starting the hash analysis again: this is to save CPU time when there
300
 
is no hope in building a hash index. */
301
 
#define BTR_SEARCH_HASH_ANALYSIS        17
302
 
 
303
 
/** Limit of consecutive searches for trying a search shortcut on the search
304
 
pattern */
305
 
#define BTR_SEARCH_ON_PATTERN_LIMIT     3
306
 
 
307
 
/** Limit of consecutive searches for trying a search shortcut using
308
 
the hash index */
309
 
#define BTR_SEARCH_ON_HASH_LIMIT        3
310
 
 
311
 
/** We do this many searches before trying to keep the search latch
312
 
over calls from MySQL. If we notice someone waiting for the latch, we
313
 
again set this much timeout. This is to reduce contention. */
314
 
#define BTR_SEA_TIMEOUT                 10000
315
 
 
316
 
#ifndef UNIV_NONINL
317
 
#include "btr0sea.ic"
318
 
#endif
319
 
 
320
 
#endif