~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1994, 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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/********************************************************************//**
20
@file ha/ha0ha.c
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
The hash table with external chains
22
23
Created 8/22/1994 Heikki Tuuri
24
*************************************************************************/
25
26
#include "ha0ha.h"
27
#ifdef UNIV_NONINL
28
#include "ha0ha.ic"
29
#endif
30
31
#ifdef UNIV_DEBUG
32
# include "buf0buf.h"
33
#endif /* UNIV_DEBUG */
1819.7.68 by Stewart Smith
Merge initial InnoDB+ import.
34
#ifdef UNIV_SYNC_DEBUG
35
# include "btr0sea.h"
36
#endif /* UNIV_SYNC_DEBUG */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
37
#include "page0page.h"
38
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
39
/*************************************************************//**
40
Creates a hash table with at least n array cells.  The actual number
41
of cells is chosen to be a prime number slightly bigger than n.
42
@return	own: created table */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
43
UNIV_INTERN
44
hash_table_t*
45
ha_create_func(
46
/*===========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
47
	ulint	n,		/*!< in: number of array cells */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
48
#ifdef UNIV_SYNC_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
49
	ulint	mutex_level,	/*!< in: level of the mutexes in the latching
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
50
				order: this is used in the debug version */
51
#endif /* UNIV_SYNC_DEBUG */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
52
	ulint	n_mutexes)	/*!< in: number of mutexes to protect the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
53
				hash table: must be a power of 2, or 0 */
54
{
55
	hash_table_t*	table;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
56
#ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
57
	ulint		i;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
58
#endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
59
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
60
	ut_ad(ut_is_2pow(n_mutexes));
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
61
	table = hash_create(n);
62
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
63
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
64
# ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
65
	table->adaptive = TRUE;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
66
# endif /* !UNIV_HOTBACKUP */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
67
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
68
	/* Creating MEM_HEAP_BTR_SEARCH type heaps can potentially fail,
69
	but in practise it never should in this case, hence the asserts. */
70
71
	if (n_mutexes == 0) {
72
		table->heap = mem_heap_create_in_btr_search(
73
			ut_min(4096, MEM_MAX_ALLOC_IN_BUF));
74
		ut_a(table->heap);
75
76
		return(table);
77
	}
78
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
79
#ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
80
	hash_create_mutexes(table, n_mutexes, mutex_level);
81
82
	table->heaps = mem_alloc(n_mutexes * sizeof(void*));
83
84
	for (i = 0; i < n_mutexes; i++) {
85
		table->heaps[i] = mem_heap_create_in_btr_search(4096);
86
		ut_a(table->heaps[i]);
87
	}
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
88
#endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
89
90
	return(table);
91
}
92
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
93
/*************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
94
Empties a hash table and frees the memory heaps. */
95
UNIV_INTERN
96
void
97
ha_clear(
98
/*=====*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
99
	hash_table_t*	table)	/*!< in, own: hash table */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
100
{
101
	ulint	i;
102
	ulint	n;
103
1819.5.262 by mmakela
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6900 from MySQL InnoDB
104
	ut_ad(table);
105
	ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
106
#ifdef UNIV_SYNC_DEBUG
107
	ut_ad(rw_lock_own(&btr_search_latch, RW_LOCK_EXCLUSIVE));
108
#endif /* UNIV_SYNC_DEBUG */
109
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
110
#ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
111
	/* Free the memory heaps. */
112
	n = table->n_mutexes;
113
114
	for (i = 0; i < n; i++) {
115
		mem_heap_free(table->heaps[i]);
116
	}
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
117
#endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
118
119
	/* Clear the hash table. */
120
	n = hash_get_n_cells(table);
121
122
	for (i = 0; i < n; i++) {
123
		hash_get_nth_cell(table, i)->node = NULL;
124
	}
125
}
126
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
127
/*************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
128
Inserts an entry into a hash table. If an entry with the same fold number
129
is found, its node is updated to point to the new data, and no new node
1819.7.68 by Stewart Smith
Merge initial InnoDB+ import.
130
is inserted.
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
131
@return	TRUE if succeed, FALSE if no more memory could be allocated */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
132
UNIV_INTERN
133
ibool
134
ha_insert_for_fold_func(
135
/*====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
136
	hash_table_t*	table,	/*!< in: hash table */
137
	ulint		fold,	/*!< in: folded value of data; if a node with
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
138
				the same fold value already exists, it is
139
				updated to point to the same data, and no new
140
				node is created! */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
141
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
142
	buf_block_t*	block,	/*!< in: buffer block containing the data */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
143
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
144
	void*		data)	/*!< in: data, must not be NULL */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
145
{
146
	hash_cell_t*	cell;
147
	ha_node_t*	node;
148
	ha_node_t*	prev_node;
149
	ulint		hash;
150
1819.5.262 by mmakela
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6900 from MySQL InnoDB
151
	ut_ad(data);
152
	ut_ad(table);
153
	ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
154
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
155
	ut_a(block->frame == page_align(data));
156
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
157
	ASSERT_HASH_MUTEX_OWN(table, fold);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
158
159
	hash = hash_calc_hash(fold, table);
160
161
	cell = hash_get_nth_cell(table, hash);
162
163
	prev_node = cell->node;
164
165
	while (prev_node != NULL) {
166
		if (prev_node->fold == fold) {
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
167
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
168
# ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
169
			if (table->adaptive) {
170
				buf_block_t* prev_block = prev_node->block;
171
				ut_a(prev_block->frame
172
				     == page_align(prev_node->data));
173
				ut_a(prev_block->n_pointers > 0);
174
				prev_block->n_pointers--;
175
				block->n_pointers++;
176
			}
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
177
# endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
178
179
			prev_node->block = block;
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
180
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
181
			prev_node->data = data;
182
183
			return(TRUE);
184
		}
185
186
		prev_node = prev_node->next;
187
	}
188
189
	/* We have to allocate a new chain node */
190
191
	node = mem_heap_alloc(hash_get_heap(table, fold), sizeof(ha_node_t));
192
193
	if (node == NULL) {
194
		/* It was a btr search type memory heap and at the moment
195
		no more memory could be allocated: return */
196
197
		ut_ad(hash_get_heap(table, fold)->type & MEM_HEAP_BTR_SEARCH);
198
199
		return(FALSE);
200
	}
201
202
	ha_node_set_data(node, block, data);
203
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
204
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
205
# ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
206
	if (table->adaptive) {
207
		block->n_pointers++;
208
	}
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
209
# endif /* !UNIV_HOTBACKUP */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
210
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
211
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
212
	node->fold = fold;
213
214
	node->next = NULL;
215
216
	prev_node = cell->node;
217
218
	if (prev_node == NULL) {
219
220
		cell->node = node;
221
222
		return(TRUE);
223
	}
224
225
	while (prev_node->next != NULL) {
226
227
		prev_node = prev_node->next;
228
	}
229
230
	prev_node->next = node;
231
232
	return(TRUE);
233
}
234
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
235
/***********************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
236
Deletes a hash node. */
237
UNIV_INTERN
238
void
239
ha_delete_hash_node(
240
/*================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
241
	hash_table_t*	table,		/*!< in: hash table */
242
	ha_node_t*	del_node)	/*!< in: node to be deleted */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
243
{
1819.5.262 by mmakela
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6900 from MySQL InnoDB
244
	ut_ad(table);
245
	ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
246
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
247
# ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
248
	if (table->adaptive) {
249
		ut_a(del_node->block->frame = page_align(del_node->data));
250
		ut_a(del_node->block->n_pointers > 0);
251
		del_node->block->n_pointers--;
252
	}
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
253
# endif /* !UNIV_HOTBACKUP */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
254
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
255
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
256
	HASH_DELETE_AND_COMPACT(ha_node_t, next, table, del_node);
257
}
258
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
259
/*********************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
260
Looks for an element when we know the pointer to the data, and updates
261
the pointer to data, if found. */
262
UNIV_INTERN
263
void
264
ha_search_and_update_if_found_func(
265
/*===============================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
266
	hash_table_t*	table,	/*!< in/out: hash table */
267
	ulint		fold,	/*!< in: folded value of the searched data */
268
	void*		data,	/*!< in: pointer to the data */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
269
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
270
	buf_block_t*	new_block,/*!< in: block containing new_data */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
271
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
272
	void*		new_data)/*!< in: new pointer to the data */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
273
{
274
	ha_node_t*	node;
275
1819.5.262 by mmakela
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6900 from MySQL InnoDB
276
	ut_ad(table);
277
	ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
278
	ASSERT_HASH_MUTEX_OWN(table, fold);
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
279
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
280
	ut_a(new_block->frame == page_align(new_data));
281
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
282
283
	node = ha_search_with_data(table, fold, data);
284
285
	if (node) {
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
286
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
287
# ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
288
		if (table->adaptive) {
289
			ut_a(node->block->n_pointers > 0);
290
			node->block->n_pointers--;
291
			new_block->n_pointers++;
292
		}
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
293
# endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
294
295
		node->block = new_block;
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
296
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
297
		node->data = new_data;
298
	}
299
}
300
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
301
#ifndef UNIV_HOTBACKUP
302
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
303
Removes from the chain determined by fold all nodes whose data pointer
304
points to the page given. */
305
UNIV_INTERN
306
void
307
ha_remove_all_nodes_to_page(
308
/*========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
309
	hash_table_t*	table,	/*!< in: hash table */
310
	ulint		fold,	/*!< in: fold value */
311
	const page_t*	page)	/*!< in: buffer page */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
312
{
313
	ha_node_t*	node;
314
1819.5.262 by mmakela
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6900 from MySQL InnoDB
315
	ut_ad(table);
316
	ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
317
	ASSERT_HASH_MUTEX_OWN(table, fold);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
318
319
	node = ha_chain_get_first(table, fold);
320
321
	while (node) {
322
		if (page_align(ha_node_get_data(node)) == page) {
323
324
			/* Remove the hash node */
325
326
			ha_delete_hash_node(table, node);
327
328
			/* Start again from the first node in the chain
329
			because the deletion may compact the heap of
330
			nodes and move other nodes! */
331
332
			node = ha_chain_get_first(table, fold);
333
		} else {
334
			node = ha_chain_get_next(node);
335
		}
336
	}
337
#ifdef UNIV_DEBUG
338
	/* Check that all nodes really got deleted */
339
340
	node = ha_chain_get_first(table, fold);
341
342
	while (node) {
343
		ut_a(page_align(ha_node_get_data(node)) != page);
344
345
		node = ha_chain_get_next(node);
346
	}
347
#endif
348
}
349
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
350
/*************************************************************//**
351
Validates a given range of the cells in hash table.
352
@return	TRUE if ok */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
353
UNIV_INTERN
354
ibool
355
ha_validate(
356
/*========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
357
	hash_table_t*	table,		/*!< in: hash table */
358
	ulint		start_index,	/*!< in: start index */
359
	ulint		end_index)	/*!< in: end index */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
360
{
361
	hash_cell_t*	cell;
362
	ha_node_t*	node;
363
	ibool		ok	= TRUE;
364
	ulint		i;
365
1819.5.262 by mmakela
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6900 from MySQL InnoDB
366
	ut_ad(table);
367
	ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
368
	ut_a(start_index <= end_index);
369
	ut_a(start_index < hash_get_n_cells(table));
370
	ut_a(end_index < hash_get_n_cells(table));
371
372
	for (i = start_index; i <= end_index; i++) {
373
374
		cell = hash_get_nth_cell(table, i);
375
376
		node = cell->node;
377
378
		while (node) {
379
			if (hash_calc_hash(node->fold, table) != i) {
380
				ut_print_timestamp(stderr);
381
				fprintf(stderr,
382
					"InnoDB: Error: hash table node"
383
					" fold value %lu does not\n"
384
					"InnoDB: match the cell number %lu.\n",
385
					(ulong) node->fold, (ulong) i);
386
387
				ok = FALSE;
388
			}
389
390
			node = node->next;
391
		}
392
	}
393
394
	return(ok);
395
}
396
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
397
/*************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
398
Prints info of a hash table. */
399
UNIV_INTERN
400
void
401
ha_print_info(
402
/*==========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
403
	FILE*		file,	/*!< in: file where to print */
404
	hash_table_t*	table)	/*!< in: hash table */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
405
{
1819.5.262 by mmakela
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6900 from MySQL InnoDB
406
	ut_ad(table);
407
	ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
408
#ifdef UNIV_DEBUG
409
/* Some of the code here is disabled for performance reasons in production
410
builds, see http://bugs.mysql.com/36941 */
411
#define PRINT_USED_CELLS
412
#endif /* UNIV_DEBUG */
413
414
#ifdef PRINT_USED_CELLS
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
415
	hash_cell_t*	cell;
416
	ulint		cells	= 0;
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
417
	ulint		i;
418
#endif /* PRINT_USED_CELLS */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
419
	ulint		n_bufs;
420
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
421
#ifdef PRINT_USED_CELLS
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
422
	for (i = 0; i < hash_get_n_cells(table); i++) {
423
424
		cell = hash_get_nth_cell(table, i);
425
426
		if (cell->node) {
427
428
			cells++;
429
		}
430
	}
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
431
#endif /* PRINT_USED_CELLS */
432
433
	fprintf(file, "Hash table size %lu",
434
		(ulong) hash_get_n_cells(table));
435
436
#ifdef PRINT_USED_CELLS
437
	fprintf(file, ", used cells %lu", (ulong) cells);
438
#endif /* PRINT_USED_CELLS */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
439
440
	if (table->heaps == NULL && table->heap != NULL) {
441
442
		/* This calculation is intended for the adaptive hash
443
		index: how many buffer frames we have reserved? */
444
445
		n_bufs = UT_LIST_GET_LEN(table->heap->base) - 1;
446
447
		if (table->heap->free_block) {
448
			n_bufs++;
449
		}
450
451
		fprintf(file, ", node heap has %lu buffer(s)\n",
452
			(ulong) n_bufs);
453
	}
454
}
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
455
#endif /* !UNIV_HOTBACKUP */