~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: jay
  • Date: 2008-12-23 00:18:10 UTC
  • Revision ID: jay@piggy.tangent.org-20081223001810-026ibij22q2842k1
Had a --regex-replace by accident. Should have been --replace_column call.  Only showed up in make test, not running single test, because InnoDB key numbers were different with multiple test running.

Show diffs side-by-side

added added

removed removed

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