diff options
author | unknown <monty@donna.mysql.com> | 2001-02-17 14:19:19 +0200 |
---|---|---|
committer | unknown <monty@donna.mysql.com> | 2001-02-17 14:19:19 +0200 |
commit | 2662b59306ef0cd495fa6e2edf7129e58a11393a (patch) | |
tree | bfe39951a73e906579ab819bf5198ad8f3a64a36 /innobase/ha | |
parent | 66de55a56bdcf2f7a9c0c4f8e19b3e761475e202 (diff) | |
download | mariadb-git-2662b59306ef0cd495fa6e2edf7129e58a11393a.tar.gz |
Added Innobase to source distribution
Docs/manual.texi:
Added Innobase documentation
configure.in:
Incremented version
include/my_base.h:
Added option for Innobase
myisam/mi_check.c:
cleanup
mysql-test/t/bdb.test:
cleanup
mysql-test/t/innobase.test:
Extended with new tests from bdb.test
mysql-test/t/merge.test:
Added test of SHOW create
mysys/my_init.c:
Fix for UNIXWARE 7
scripts/mysql_install_db.sh:
Always write how to start mysqld
scripts/safe_mysqld.sh:
Fixed type
sql/ha_innobase.cc:
Update to new version
sql/ha_innobase.h:
Update to new version
sql/handler.h:
Added 'update_table_comment()' and 'append_create_info()'
sql/sql_delete.cc:
Fixes for Innobase
sql/sql_select.cc:
Fixes for Innobase
sql/sql_show.cc:
Append create information (for MERGE tables)
sql/sql_update.cc:
Fixes for Innobase
Diffstat (limited to 'innobase/ha')
-rw-r--r-- | innobase/ha/Makefile.am | 24 | ||||
-rw-r--r-- | innobase/ha/ha0ha.c | 317 | ||||
-rw-r--r-- | innobase/ha/hash0hash.c | 152 | ||||
-rw-r--r-- | innobase/ha/makefilewin | 10 | ||||
-rw-r--r-- | innobase/ha/ts/makefile | 12 | ||||
-rw-r--r-- | innobase/ha/ts/tsha.c | 120 |
6 files changed, 635 insertions, 0 deletions
diff --git a/innobase/ha/Makefile.am b/innobase/ha/Makefile.am new file mode 100644 index 00000000000..ce846d37622 --- /dev/null +++ b/innobase/ha/Makefile.am @@ -0,0 +1,24 @@ +# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +# & Innobase Oy +# +# 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; either version 2 of the License, or +# (at your option) any later version. +# +# 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 + +include ../include/Makefile.i + +libs_LIBRARIES = libha.a + +libha_a_SOURCES = ha0ha.c hash0hash.c + +EXTRA_PROGRAMS = diff --git a/innobase/ha/ha0ha.c b/innobase/ha/ha0ha.c new file mode 100644 index 00000000000..3e4473126cf --- /dev/null +++ b/innobase/ha/ha0ha.c @@ -0,0 +1,317 @@ +/************************************************************************ +The hash table with external chains + +(c) 1994-1997 Innobase Oy + +Created 8/22/1994 Heikki Tuuri +*************************************************************************/ + +#include "ha0ha.h" +#ifdef UNIV_NONINL +#include "ha0ha.ic" +#endif + +#include "buf0buf.h" + +/***************************************************************** +Creates a hash table with >= n array cells. The actual number of cells is +chosen to be a prime number slightly bigger than n. */ + +hash_table_t* +ha_create( +/*======*/ + /* out, own: created table */ + ibool in_btr_search, /* in: TRUE if the hash table is used in + the btr_search module */ + ulint n, /* in: number of array cells */ + ulint n_mutexes, /* in: number of mutexes to protect the + hash table: must be a power of 2, or 0 */ + ulint mutex_level) /* in: level of the mutexes in the latching + order: this is used in the debug version */ +{ + hash_table_t* table; + ulint i; + + table = hash_create(n); + + if (n_mutexes == 0) { + if (in_btr_search) { + table->heap = mem_heap_create_in_btr_search(4096); + } else { + table->heap = mem_heap_create_in_buffer(4096); + } + + return(table); + } + + hash_create_mutexes(table, n_mutexes, mutex_level); + + table->heaps = mem_alloc(n_mutexes * sizeof(void*)); + + for (i = 0; i < n_mutexes; i++) { + if (in_btr_search) { + table->heaps[i] = mem_heap_create_in_btr_search(4096); + } else { + table->heaps[i] = mem_heap_create_in_buffer(4096); + } + } + + return(table); +} + +/***************************************************************** +Checks that a hash table node is in the chain. */ + +ibool +ha_node_in_chain( +/*=============*/ + /* out: TRUE if in chain */ + hash_cell_t* cell, /* in: hash table cell */ + ha_node_t* node) /* in: external chain node */ +{ + ha_node_t* node2; + + node2 = cell->node; + + while (node2 != NULL) { + + if (node2 == node) { + + return(TRUE); + } + + node2 = node2->next; + } + + return(FALSE); +} + +/***************************************************************** +Inserts an entry into a hash table. If an entry with the same fold number +is found, its node is updated to point to the new data, and no new node +is inserted. */ + +ibool +ha_insert_for_fold( +/*===============*/ + /* out: TRUE if succeed, FALSE if no more + memory could be allocated */ + hash_table_t* table, /* in: hash table */ + ulint fold, /* in: folded value of data; if a node with + the same fold value already exists, it is + updated to point to the same data, and no new + node is created! */ + void* data) /* in: data, must not be NULL */ +{ + hash_cell_t* cell; + ha_node_t* node; + ha_node_t* prev_node; + ulint hash; + + ut_ad(table && data); + ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold))); + + hash = hash_calc_hash(fold, table); + + cell = hash_get_nth_cell(table, hash); + + prev_node = cell->node; + + while (prev_node != NULL) { + if (prev_node->fold == fold) { + + prev_node->data = data; + + return(TRUE); + } + + prev_node = prev_node->next; + } + + /* We have to allocate a new chain node */ + + node = mem_heap_alloc(hash_get_heap(table, fold), sizeof(ha_node_t)); + + if (node == NULL) { + /* It was a btr search type memory heap and at the moment + no more memory could be allocated: return */ + + ut_ad(hash_get_heap(table, fold)->type & MEM_HEAP_BTR_SEARCH); + + return(FALSE); + } + + ha_node_set_data(node, data); + node->fold = fold; + + node->next = NULL; + + prev_node = cell->node; + + if (prev_node == NULL) { + + cell->node = node; + + return(TRUE); + } + + while (prev_node->next != NULL) { + + prev_node = prev_node->next; + } + + prev_node->next = node; + + return(TRUE); +} + +/*************************************************************** +Deletes a hash node. */ + +void +ha_delete_hash_node( +/*================*/ + hash_table_t* table, /* in: hash table */ + ha_node_t* del_node) /* in: node to be deleted */ +{ + HASH_DELETE_AND_COMPACT(ha_node_t, next, table, del_node); +} + +/***************************************************************** +Deletes an entry from a hash table. */ + +void +ha_delete( +/*======*/ + hash_table_t* table, /* in: hash table */ + ulint fold, /* in: folded value of data */ + void* data) /* in: data, must not be NULL and must exist + in the hash table */ +{ + ha_node_t* node; + + ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold))); + + node = ha_search_with_data(table, fold, data); + + ut_ad(node); + + ha_delete_hash_node(table, node); +} + +/********************************************************************* +Removes from the chain determined by fold all nodes whose data pointer +points to the page given. */ + +void +ha_remove_all_nodes_to_page( +/*========================*/ + hash_table_t* table, /* in: hash table */ + ulint fold, /* in: fold value */ + page_t* page) /* in: buffer page */ +{ + ha_node_t* node; + + ut_ad(!table->mutexes || mutex_own(hash_get_mutex(table, fold))); + + node = ha_chain_get_first(table, fold); + + while (node) { + if (buf_frame_align(ha_node_get_data(node)) == page) { + + /* Remove the hash node */ + + ha_delete_hash_node(table, node); + + /* Start again from the first node in the chain + because the deletion may compact the heap of + nodes and move other nodes! */ + + node = ha_chain_get_first(table, fold); + } else { + node = ha_chain_get_next(table, node); + } + } +} + +/***************************************************************** +Validates a hash table. */ + +ibool +ha_validate( +/*========*/ + /* out: TRUE if ok */ + hash_table_t* table) /* in: hash table */ +{ + hash_cell_t* cell; + ha_node_t* node; + ulint i; + + for (i = 0; i < hash_get_n_cells(table); i++) { + + cell = hash_get_nth_cell(table, i); + + node = cell->node; + + while (node) { + ut_a(hash_calc_hash(node->fold, table) == i); + + node = node->next; + } + } + + return(TRUE); +} + +/***************************************************************** +Prints info of a hash table. */ + +void +ha_print_info( +/*==========*/ + hash_table_t* table) /* in: hash table */ +{ + hash_cell_t* cell; + ha_node_t* node; + ulint nodes = 0; + ulint cells = 0; + ulint len = 0; + ulint max_len = 0; + ulint i; + + for (i = 0; i < hash_get_n_cells(table); i++) { + + cell = hash_get_nth_cell(table, i); + + if (cell->node) { + + cells++; + + len = 0; + + node = cell->node; + + for (;;) { + len++; + nodes++; + + if (ha_chain_get_next(table, node) == NULL) { + + break; + } + + node = node->next; + } + + if (len > max_len) { + max_len = len; + } + } + } + + printf("Hash table size %lu, used cells %lu, nodes %lu\n", + hash_get_n_cells(table), cells, nodes); + printf("max chain length %lu\n", max_len); + + ut_a(ha_validate(table)); +} diff --git a/innobase/ha/hash0hash.c b/innobase/ha/hash0hash.c new file mode 100644 index 00000000000..1f7edf9d7d2 --- /dev/null +++ b/innobase/ha/hash0hash.c @@ -0,0 +1,152 @@ +/****************************************************** +The simple hash table utility + +(c) 1997 Innobase Oy + +Created 5/20/1997 Heikki Tuuri +*******************************************************/ + +#include "hash0hash.h" +#ifdef UNIV_NONINL +#include "hash0hash.ic" +#endif + +#include "mem0mem.h" + +/**************************************************************** +Reserves the mutex for a fold value in a hash table. */ + +void +hash_mutex_enter( +/*=============*/ + hash_table_t* table, /* in: hash table */ + ulint fold) /* in: fold */ +{ + mutex_enter(hash_get_mutex(table, fold)); +} + +/**************************************************************** +Releases the mutex for a fold value in a hash table. */ + +void +hash_mutex_exit( +/*============*/ + hash_table_t* table, /* in: hash table */ + ulint fold) /* in: fold */ +{ + mutex_exit(hash_get_mutex(table, fold)); +} + +/**************************************************************** +Reserves all the mutexes of a hash table, in an ascending order. */ + +void +hash_mutex_enter_all( +/*=================*/ + hash_table_t* table) /* in: hash table */ +{ + ulint i; + + for (i = 0; i < table->n_mutexes; i++) { + + mutex_enter(table->mutexes + i); + } +} + +/**************************************************************** +Releases all the mutexes of a hash table. */ + +void +hash_mutex_exit_all( +/*================*/ + hash_table_t* table) /* in: hash table */ +{ + ulint i; + + for (i = 0; i < table->n_mutexes; i++) { + + mutex_exit(table->mutexes + i); + } +} + +/***************************************************************** +Creates a hash table with >= n array cells. The actual number of cells is +chosen to be a prime number slightly bigger than n. */ + +hash_table_t* +hash_create( +/*========*/ + /* out, own: created table */ + ulint n) /* in: number of array cells */ +{ + hash_cell_t* array; + ulint prime; + hash_table_t* table; + ulint i; + hash_cell_t* cell; + + prime = ut_find_prime(n); + + table = mem_alloc(sizeof(hash_table_t)); + + array = ut_malloc(sizeof(hash_cell_t) * prime); + + table->array = array; + table->n_cells = prime; + table->n_mutexes = 0; + table->mutexes = NULL; + table->heaps = NULL; + table->heap = NULL; + table->magic_n = HASH_TABLE_MAGIC_N; + + /* Initialize the cell array */ + + for (i = 0; i < prime; i++) { + + cell = hash_get_nth_cell(table, i); + cell->node = NULL; + } + + return(table); +} + +/***************************************************************** +Frees a hash table. */ + +void +hash_table_free( +/*============*/ + hash_table_t* table) /* in, own: hash table */ +{ + ut_a(table->mutexes == NULL); + + ut_free(table->array); + mem_free(table); +} + +/***************************************************************** +Creates a mutex array to protect a hash table. */ + +void +hash_create_mutexes( +/*================*/ + hash_table_t* table, /* in: hash table */ + ulint n_mutexes, /* in: number of mutexes, must be a + power of 2 */ + ulint sync_level) /* in: latching order level of the + mutexes: used in the debug version */ +{ + ulint i; + + ut_a(n_mutexes == ut_2_power_up(n_mutexes)); + + table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t)); + + for (i = 0; i < n_mutexes; i++) { + mutex_create(table->mutexes + i); + + mutex_set_level(table->mutexes + i, sync_level); + } + + table->n_mutexes = n_mutexes; +} diff --git a/innobase/ha/makefilewin b/innobase/ha/makefilewin new file mode 100644 index 00000000000..c7cd130ceea --- /dev/null +++ b/innobase/ha/makefilewin @@ -0,0 +1,10 @@ +include ..\include\makefile.i + +ha.lib: ha0ha.obj hash0hash.obj + lib -out:..\libs\ha.lib ha0ha.obj hash0hash.obj + +ha0ha.obj: ha0ha.c + $(CCOM) $(CFL) -c ha0ha.c + +hash0hash.obj: hash0hash.c + $(CCOM) $(CFL) -c hash0hash.c diff --git a/innobase/ha/ts/makefile b/innobase/ha/ts/makefile new file mode 100644 index 00000000000..aea21f11141 --- /dev/null +++ b/innobase/ha/ts/makefile @@ -0,0 +1,12 @@ + +include ..\..\makefile.i + +tsha: ..\ha.lib tsha.c makefile + $(CCOM) $(CFL) -I.. -I..\.. ..\..\btr.lib ..\..\trx.lib ..\..\pars.lib ..\..\que.lib ..\..\lock.lib ..\..\row.lib ..\..\read.lib ..\..\srv.lib ..\..\com.lib ..\..\usr.lib ..\..\thr.lib ..\..\fut.lib ..\..\fsp.lib ..\..\page.lib ..\..\dyn.lib ..\..\mtr.lib ..\..\log.lib ..\..\rem.lib ..\..\fil.lib ..\..\buf.lib ..\..\dict.lib ..\..\data.lib ..\..\mach.lib ..\ha.lib ..\..\ut.lib ..\..\sync.lib ..\..\mem.lib ..\..\os.lib tsha.c $(LFL) + + + + + + + diff --git a/innobase/ha/ts/tsha.c b/innobase/ha/ts/tsha.c new file mode 100644 index 00000000000..fd9a2e12f6e --- /dev/null +++ b/innobase/ha/ts/tsha.c @@ -0,0 +1,120 @@ +/************************************************************************ +The test module for hash table + +(c) 1994, 1995 Innobase Oy + +Created 1/25/1994 Heikki Tuuri +*************************************************************************/ + +#include "ut0ut.h" +#include "ha0ha.h" +#include "mem0mem.h" +#include "sync0sync.h" + +ulint ulint_array[200000]; + +void +test1(void) +{ + hash_table_t* table1; + ulint i; + ulint n313 = 313; + ulint n414 = 414; + + printf("------------------------------------------------\n"); + printf("TEST 1. BASIC TEST\n"); + + table1 = ha_create(50000); + + ha_insert_for_fold(table1, 313, &n313); + + ha_insert_for_fold(table1, 313, &n414); + + ut_a(ha_validate(table1)); + + ha_delete(table1, 313, &n313); + ha_delete(table1, 313, &n414); + + ut_a(ha_validate(table1)); + + printf("------------------------------------------------\n"); + printf("TEST 2. TEST OF MASSIVE INSERTS AND DELETES\n"); + + table1 = ha_create(10000); + + for (i = 0; i < 200000; i++) { + ulint_array[i] = i; + } + + for (i = 0; i < 50000; i++) { + ha_insert_for_fold(table1, i * 7, ulint_array + i); + } + + ut_a(ha_validate(table1)); + + for (i = 0; i < 50000; i++) { + ha_delete(table1, i * 7, ulint_array + i); + } + + ut_a(ha_validate(table1)); +} + +void +test2(void) +{ + hash_table_t* table1; + ulint i; + ulint oldtm, tm; + ha_node_t* node; + + printf("------------------------------------------------\n"); + printf("TEST 3. SPEED TEST\n"); + + table1 = ha_create(300000); + + oldtm = ut_clock(); + + for (i = 0; i < 200000; i++) { + ha_insert_for_fold(table1, i * 27877, ulint_array + i); + } + + tm = ut_clock(); + + printf("Wall clock time for %lu inserts %lu millisecs\n", + i, tm - oldtm); + + oldtm = ut_clock(); + + for (i = 0; i < 200000; i++) { + node = ha_search(table1, i * 27877); + } + + tm = ut_clock(); + + printf("Wall clock time for %lu searches %lu millisecs\n", + i, tm - oldtm); + + oldtm = ut_clock(); + + for (i = 0; i < 200000; i++) { + ha_delete(table1, i * 27877, ulint_array + i); + } + + tm = ut_clock(); + + printf("Wall clock time for %lu deletes %lu millisecs\n", + i, tm - oldtm); +} + +void +main(void) +{ + sync_init(); + mem_init(1000000); + + test1(); + + test2(); + + printf("TESTS COMPLETED SUCCESSFULLY!\n"); +} |