mariadb/dict/dict0mem.c

294 lines
7.1 KiB
C
Raw Normal View History

2005-10-27 09:29:40 +02:00
/**********************************************************************
Data dictionary memory object creation
(c) 1996 Innobase Oy
Created 1/8/1996 Heikki Tuuri
***********************************************************************/
#include "dict0mem.h"
#ifdef UNIV_NONINL
#include "dict0mem.ic"
#endif
#include "rem0rec.h"
#include "data0type.h"
#include "mach0data.h"
#include "dict0dict.h"
#include "que0que.h"
#include "pars0pars.h"
#include "lock0lock.h"
#define DICT_HEAP_SIZE 100 /* initial memory heap size when
creating a table or index object */
/**************************************************************************
Creates a table memory object. */
UNIV_INTERN
2005-10-27 09:29:40 +02:00
dict_table_t*
dict_mem_table_create(
/*==================*/
/* out, own: table object */
const char* name, /* in: table name */
ulint space, /* in: space where the clustered index of
the table is placed; this parameter is
ignored if the table is made a member of
a cluster */
ulint n_cols, /* in: number of columns */
ulint flags) /* in: table flags */
2005-10-27 09:29:40 +02:00
{
dict_table_t* table;
mem_heap_t* heap;
2005-10-27 09:29:40 +02:00
ut_ad(name);
ut_a(!(flags & (~0 << DICT_TF_BITS)));
2005-10-27 09:29:40 +02:00
heap = mem_heap_create(DICT_HEAP_SIZE);
table = mem_heap_zalloc(heap, sizeof(dict_table_t));
2005-10-27 09:29:40 +02:00
table->heap = heap;
table->flags = (unsigned int) flags;
2005-10-27 09:29:40 +02:00
table->name = mem_heap_strdup(heap, name);
table->space = (unsigned int) space;
table->n_cols = (unsigned int) (n_cols + DATA_N_SYS_COLS);
2005-10-27 09:29:40 +02:00
table->cols = mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS)
* sizeof(dict_col_t));
2005-10-27 09:29:40 +02:00
table->auto_inc_lock = mem_heap_alloc(heap, lock_get_size());
mutex_create(&table->autoinc_mutex, SYNC_DICT_AUTOINC_MUTEX);
2005-10-27 09:29:40 +02:00
branches/innodb+: Merge revisions 2835:2862 from branches/zip: ------------------------------------------------------------------------ r2838 | vasil | 2008-10-21 12:49:27 +0300 (Tue, 21 Oct 2008) | 61 lines branches/zip: Merge 2744:2837 from branches/5.1 (skipping r2782 and r2826): ------------------------------------------------------------------------ r2832 | vasil | 2008-10-21 10:08:30 +0300 (Tue, 21 Oct 2008) | 10 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: In ha_innobase::info(): Replace sql_print_warning() which prints to mysqld error log with push_warning_printf() which sends the error message to the client. Suggested by: Marko, Sunny, Michael Objected by: Inaam ------------------------------------------------------------------------ r2837 | vasil | 2008-10-21 12:07:44 +0300 (Tue, 21 Oct 2008) | 32 lines Changed paths: M /branches/5.1/mysql-test/innodb-semi-consistent.result M /branches/5.1/mysql-test/innodb-semi-consistent.test M /branches/5.1/mysql-test/innodb.result M /branches/5.1/mysql-test/innodb.test branches/5.1: Merge a change from MySQL (this fixes the failing innodb and innodb-semi-consistent tests): revno: 2757 committer: Georgi Kodinov <kgeorge@mysql.com> branch nick: B39812-5.1-5.1.29-rc timestamp: Fri 2008-10-03 15:24:19 +0300 message: Bug #39812: Make statement replication default for 5.1 (to match 5.0) Make STMT replication default for 5.1. Add a default of MIXED into the config files Fix the tests that needed MIXED replication mode. modified: mysql-test/include/mix1.inc mysql-test/r/innodb-semi-consistent.result mysql-test/r/innodb.result mysql-test/r/innodb_mysql.result mysql-test/r/tx_isolation_func.result mysql-test/t/innodb-semi-consistent.test mysql-test/t/innodb.test mysql-test/t/tx_isolation_func.test sql/mysqld.cc support-files/my-huge.cnf.sh support-files/my-innodb-heavy-4G.cnf.sh support-files/my-large.cnf.sh support-files/my-medium.cnf.sh support-files/my-small.cnf.sh ------------------------------------------------------------------------ ------------------------------------------------------------------------ r2847 | marko | 2008-10-22 10:07:37 +0300 (Wed, 22 Oct 2008) | 6 lines branches/zip: page_zip_rec_needs_ext(): Fix a bug that was introduced in the fix of Mantis issue #73. With key_block_size=16, we will also have to check the available space on the uncompressed page. Otherwise, the clustered index record can be almost 16 kilobytes in size, and the undo log record will not fit. ------------------------------------------------------------------------ r2850 | marko | 2008-10-22 13:52:12 +0300 (Wed, 22 Oct 2008) | 2 lines branches/zip: ibuf_insert_to_index_page(): Discard the local variable block. page_cur is always positioned on block, the function parameter. ------------------------------------------------------------------------ r2853 | sunny | 2008-10-23 01:52:09 +0300 (Thu, 23 Oct 2008) | 2 lines branches/zip: Add missing UNIV_INTERN. ------------------------------------------------------------------------ r2855 | sunny | 2008-10-23 09:29:46 +0300 (Thu, 23 Oct 2008) | 36 lines branches/zip: Merge revisions 2837:2852 from branches/5.1: ------------------------------------------------------------------------ r2849 | sunny | 2008-10-22 12:01:18 +0300 (Wed, 22 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/row0mysql.h M /branches/5.1/row/row0mysql.c branches/5.1: Return the actual error code encountered when allocating a new autoinc value. The change in behavior (bug) was introduced in 5.1.22 when we introduced the new AUTOINC locking model. rb://31 Bug#40224 New AUTOINC changes mask reporting of deadlock/timeout errors ------------------------------------------------------------------------ r2852 | sunny | 2008-10-23 01:42:24 +0300 (Thu, 23 Oct 2008) | 9 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/handler/ha_innodb.h branches/5.1: Backport r2724 from branches/zip Check column value against the col max value before updating the table's global autoinc counter value. This is part of simplifying the AUTOINC sub-system. We extract the type info from MySQL data structures at runtime. This fixes Bug#37788 InnoDB Plugin: AUTO_INCREMENT wrong for compressed tables ------------------------------------------------------------------------ ------------------------------------------------------------------------ r2856 | sunny | 2008-10-23 10:07:05 +0300 (Thu, 23 Oct 2008) | 1 line Reverting test file changes from r2855 ------------------------------------------------------------------------ r2857 | sunny | 2008-10-23 10:24:33 +0300 (Thu, 23 Oct 2008) | 30 lines branches/zip: Merge revisions 2852:2854 from branches/5.1: ------------------------------------------------------------------------ r2854 | sunny | 2008-10-23 08:30:32 +0300 (Thu, 23 Oct 2008) | 13 lines Changed paths: M /branches/5.1/dict/dict0dict.c M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/handler/ha_innodb.h M /branches/5.1/include/dict0dict.h M /branches/5.1/include/dict0mem.h M /branches/5.1/row/row0mysql.c branches/5.1: Backport changes from branches/zip r2725 Simplify the autoinc initialization code. This removes the non-determinism related to reading the table's autoinc value for the first time. This change has also reduced the sizeof dict_table_t by sizeof(ibool) bytes because we don't need the dict_table_t::autoinc_inited field anymore. Bug#39830 Table autoinc value not updated on first insert. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Bug#36411 Failed to read auto-increment value from storage engine" in 5.1.24 auto-inc rb://16 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r2858 | vasil | 2008-10-23 11:33:43 +0300 (Thu, 23 Oct 2008) | 4 lines branches/zip: Update the ChangeLog ------------------------------------------------------------------------ r2861 | marko | 2008-10-23 12:27:15 +0300 (Thu, 23 Oct 2008) | 24 lines branches/zip: Clean up the file format stamping. trx_sys_file_format_max_upgrade(): Rename from trx_sys_file_format_max_update(). Improve the documentation. Add a const qualifier to the parameter "name". Replace the parameter "flags" with "format_id", because this function should deal with file format identifiers, not with table flags. trx_sys_file_format_max_write(), trx_sys_file_format_max_set(): Add a const qualifier to the parameter "name". ha_innodb.cc: Correct the spelling in some comments: "side effect". Remove redundant prototypes for some static callback functions. innodb_file_format_name_update(), innodb_file_format_check_update(): Correct the function signature. Use appropriate pointer type conversions. MYSQL_SYSVAR_STR(file_format), MYSQL_SYSVAR_STR(file_format_check): Remove the type conversions from the callback function pointers. When the function signatures match, no type conversion is needed. The type conversions would only prevent compilation warnings for any mismatch. Approved by Sunny in rb://25. ------------------------------------------------------------------------ r2862 | marko | 2008-10-23 12:37:42 +0300 (Thu, 23 Oct 2008) | 8 lines branches/zip: Non-functional changes: ibuf_get_volume_buffered(): Declare with static linkage. This function is private to ibuf0ibuf.c. btr_cur_pessimistic_delete(): Use the cached result of btr_cur_get_index(cursor). ------------------------------------------------------------------------
2008-10-23 12:03:20 +02:00
table->autoinc = 0;
/* The number of transactions that are either waiting on the
AUTOINC lock or have been granted the lock. */
table->n_waiting_or_granted_auto_inc_locks = 0;
#ifdef UNIV_DEBUG
2005-10-27 09:29:40 +02:00
table->magic_n = DICT_TABLE_MAGIC_N;
#endif /* UNIV_DEBUG */
2005-10-27 09:29:40 +02:00
return(table);
}
/********************************************************************
Free a table memory object. */
UNIV_INTERN
2005-10-27 09:29:40 +02:00
void
dict_mem_table_free(
/*================*/
dict_table_t* table) /* in: table */
2005-10-27 09:29:40 +02:00
{
ut_ad(table);
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
mutex_free(&(table->autoinc_mutex));
mem_heap_free(table->heap);
2005-10-27 09:29:40 +02:00
}
/********************************************************************
Append 'name' to 'col_names' (@see dict_table_t::col_names). */
static
const char*
dict_add_col_name(
/*==============*/
/* out: new column names array */
const char* col_names, /* in: existing column names, or
NULL */
ulint cols, /* in: number of existing columns */
const char* name, /* in: new column name */
mem_heap_t* heap) /* in: heap */
{
ulint old_len;
ulint new_len;
ulint total_len;
char* res;
ut_ad(!cols == !col_names);
/* Find out length of existing array. */
if (col_names) {
const char* s = col_names;
ulint i;
for (i = 0; i < cols; i++) {
s += strlen(s) + 1;
}
old_len = s - col_names;
} else {
old_len = 0;
}
new_len = strlen(name) + 1;
total_len = old_len + new_len;
res = mem_heap_alloc(heap, total_len);
if (old_len > 0) {
memcpy(res, col_names, old_len);
}
memcpy(res + old_len, name, new_len);
return(res);
}
2005-10-27 09:29:40 +02:00
/**************************************************************************
Adds a column definition to a table. */
UNIV_INTERN
2005-10-27 09:29:40 +02:00
void
dict_mem_table_add_col(
/*===================*/
dict_table_t* table, /* in: table */
mem_heap_t* heap, /* in: temporary memory heap, or NULL */
const char* name, /* in: column name, or NULL */
2005-10-27 09:29:40 +02:00
ulint mtype, /* in: main datatype */
ulint prtype, /* in: precise type */
ulint len) /* in: precision */
2005-10-27 09:29:40 +02:00
{
dict_col_t* col;
ulint mbminlen;
ulint mbmaxlen;
ulint i;
ut_ad(table);
2005-10-27 09:29:40 +02:00
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
ut_ad(!heap == !name);
i = table->n_def++;
2005-10-27 09:29:40 +02:00
if (name) {
if (UNIV_UNLIKELY(table->n_def == table->n_cols)) {
heap = table->heap;
}
if (UNIV_LIKELY(i) && UNIV_UNLIKELY(!table->col_names)) {
/* All preceding column names are empty. */
char* s = mem_heap_zalloc(heap, table->n_def);
table->col_names = s;
}
table->col_names = dict_add_col_name(table->col_names,
i, name, heap);
}
col = dict_table_get_nth_col(table, i);
2005-10-27 09:29:40 +02:00
col->ind = (unsigned int) i;
2005-10-27 09:29:40 +02:00
col->ord_part = 0;
col->mtype = (unsigned int) mtype;
col->prtype = (unsigned int) prtype;
col->len = (unsigned int) len;
dtype_get_mblen(mtype, prtype, &mbminlen, &mbmaxlen);
2005-10-27 09:29:40 +02:00
col->mbminlen = (unsigned int) mbminlen;
col->mbmaxlen = (unsigned int) mbmaxlen;
2005-10-27 09:29:40 +02:00
}
/**************************************************************************
Creates an index memory object. */
UNIV_INTERN
2005-10-27 09:29:40 +02:00
dict_index_t*
dict_mem_index_create(
/*==================*/
/* out, own: index object */
const char* table_name, /* in: table name */
const char* index_name, /* in: index name */
ulint space, /* in: space where the index tree is
placed, ignored if the index is of
the clustered type */
ulint type, /* in: DICT_UNIQUE,
DICT_CLUSTERED, ... ORed */
ulint n_fields) /* in: number of fields */
{
dict_index_t* index;
mem_heap_t* heap;
2005-10-27 09:29:40 +02:00
ut_ad(table_name && index_name);
heap = mem_heap_create(DICT_HEAP_SIZE);
index = mem_heap_zalloc(heap, sizeof(dict_index_t));
2005-10-27 09:29:40 +02:00
index->heap = heap;
2005-10-27 09:29:40 +02:00
index->type = type;
index->space = (unsigned int) space;
2005-10-27 09:29:40 +02:00
index->name = mem_heap_strdup(heap, index_name);
index->table_name = table_name;
index->n_fields = (unsigned int) n_fields;
2005-10-27 09:29:40 +02:00
index->fields = mem_heap_alloc(heap, 1 + n_fields
* sizeof(dict_field_t));
/* The '1 +' above prevents allocation
of an empty mem block */
#ifdef UNIV_DEBUG
2005-10-27 09:29:40 +02:00
index->magic_n = DICT_INDEX_MAGIC_N;
#endif /* UNIV_DEBUG */
2005-10-27 09:29:40 +02:00
return(index);
}
/**************************************************************************
Creates and initializes a foreign constraint memory object. */
UNIV_INTERN
2005-10-27 09:29:40 +02:00
dict_foreign_t*
dict_mem_foreign_create(void)
/*=========================*/
/* out, own: foreign constraint struct */
{
dict_foreign_t* foreign;
mem_heap_t* heap;
heap = mem_heap_create(100);
foreign = mem_heap_zalloc(heap, sizeof(dict_foreign_t));
2005-10-27 09:29:40 +02:00
foreign->heap = heap;
return(foreign);
}
/**************************************************************************
Adds a field definition to an index. NOTE: does not take a copy
of the column name if the field is a column. The memory occupied
by the column name may be released only after publishing the index. */
UNIV_INTERN
2005-10-27 09:29:40 +02:00
void
dict_mem_index_add_field(
/*=====================*/
dict_index_t* index, /* in: index */
const char* name, /* in: column name */
ulint prefix_len) /* in: 0 or the column prefix length
in a MySQL index like
INDEX (textcol(25)) */
{
dict_field_t* field;
ut_ad(index);
2005-10-27 09:29:40 +02:00
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
2005-10-27 09:29:40 +02:00
index->n_def++;
field = dict_index_get_nth_field(index, index->n_def - 1);
2005-10-27 09:29:40 +02:00
field->name = name;
field->prefix_len = (unsigned int) prefix_len;
2005-10-27 09:29:40 +02:00
}
/**************************************************************************
Frees an index memory object. */
UNIV_INTERN
2005-10-27 09:29:40 +02:00
void
dict_mem_index_free(
/*================*/
dict_index_t* index) /* in: index */
{
ut_ad(index);
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
2005-10-27 09:29:40 +02:00
mem_heap_free(index->heap);
}