summaryrefslogtreecommitdiff
path: root/storage/xtradb/include/btr0sea.ic
blob: e5a8e1190e337d4701f0e52c3954f2a46e63a539 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*****************************************************************************

Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

*****************************************************************************/

/********************************************************************//**
@file include/btr0sea.ic
The index tree adaptive search

Created 2/17/1996 Heikki Tuuri
*************************************************************************/

#include "dict0mem.h"
#include "btr0cur.h"
#include "buf0buf.h"

/*********************************************************************//**
Updates the search info. */
UNIV_INTERN
void
btr_search_info_update_slow(
/*========================*/
	btr_search_t*	info,	/*!< in/out: search info */
	btr_cur_t*	cursor);/*!< in: cursor which was just positioned */

/********************************************************************//**
Returns search info for an index.
@return	search info; search mutex reserved */
UNIV_INLINE
btr_search_t*
btr_search_get_info(
/*================*/
	dict_index_t*	index)	/*!< in: index */
{
	ut_ad(index);

	return(index->search_info);
}

/*********************************************************************//**
Updates the search info. */
UNIV_INLINE
void
btr_search_info_update(
/*===================*/
	dict_index_t*	index,	/*!< in: index of the cursor */
	btr_cur_t*	cursor)	/*!< in: cursor which was just positioned */
{
	btr_search_t*	info;

#ifdef UNIV_SYNC_DEBUG
	ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_SHARED));
	ut_ad(!rw_lock_own(btr_search_get_latch(index->id), RW_LOCK_EX));
#endif /* UNIV_SYNC_DEBUG */

	info = btr_search_get_info(index);

	info->hash_analysis++;

	if (info->hash_analysis < BTR_SEARCH_HASH_ANALYSIS) {

		/* Do nothing */

		return;

	}

	ut_ad(cursor->flag != BTR_CUR_HASH);

	btr_search_info_update_slow(info, cursor);
}

/*********************************************************************//**
New functions to control split btr_search_index */
UNIV_INLINE
hash_table_t*
btr_search_get_hash_index(
/*======================*/
	index_id_t	key)
{
	return(btr_search_sys->hash_index[key % btr_search_index_num]);
}

UNIV_INLINE
rw_lock_t*
btr_search_get_latch(
/*=================*/
	index_id_t	key)
{
	return(btr_search_latch_part[key % btr_search_index_num]);
}

UNIV_INLINE
void
btr_search_x_lock_all(void)
/*=======================*/
{
	ulint	i;

	for (i = 0; i < btr_search_index_num; i++) {
		rw_lock_x_lock(btr_search_latch_part[i]);
	}
}

UNIV_INLINE
void
btr_search_x_unlock_all(void)
/*==========================*/
{
	ulint	i;

	for (i = 0; i < btr_search_index_num; i++) {
		rw_lock_x_unlock(btr_search_latch_part[i]);
	}
}

UNIV_INLINE
void
btr_search_s_lock_all(void)
/*=======================*/
{
	ulint	i;

	for (i = 0; i < btr_search_index_num; i++) {
		rw_lock_s_lock(btr_search_latch_part[i]);
	}
}

UNIV_INLINE
void
btr_search_s_unlock_all(void)
/*=========================*/
{
	ulint	i;

	for (i = 0; i < btr_search_index_num; i++) {
		rw_lock_s_unlock(btr_search_latch_part[i]);
	}
}