mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
2b9a8afa50
BitKeeper/etc/logging_ok: auto-union Build-tools/mysql-copyright-2: Auto merged include/violite.h: Auto merged innobase/btr/btr0btr.c: Auto merged innobase/buf/buf0buf.c: Auto merged innobase/buf/buf0flu.c: Auto merged innobase/buf/buf0lru.c: Auto merged innobase/dict/dict0dict.c: Auto merged innobase/dict/dict0mem.c: Auto merged innobase/fsp/fsp0fsp.c: Auto merged innobase/fut/fut0lst.c: Auto merged innobase/ha/hash0hash.c: Auto merged innobase/include/buf0buf.ic: Auto merged innobase/include/buf0lru.h: Auto merged innobase/include/data0data.h: Auto merged innobase/include/dict0dict.h: Auto merged innobase/include/dict0mem.h: Auto merged innobase/include/fsp0fsp.h: Auto merged innobase/include/hash0hash.h: Auto merged innobase/include/lock0lock.h: Auto merged innobase/include/log0log.h: Auto merged innobase/include/log0log.ic: Auto merged innobase/include/mem0dbg.ic: Auto merged innobase/include/mem0pool.h: Auto merged innobase/include/mtr0mtr.h: Auto merged innobase/include/sync0rw.h: Auto merged innobase/include/sync0sync.h: Auto merged innobase/include/trx0roll.h: Auto merged innobase/include/trx0trx.h: Auto merged innobase/include/ut0mem.h: Auto merged innobase/lock/lock0lock.c: Auto merged innobase/log/log0log.c: Auto merged innobase/mem/mem0dbg.c: Auto merged innobase/mem/mem0pool.c: Auto merged innobase/mtr/mtr0mtr.c: Auto merged innobase/pars/lexyy.c: Auto merged innobase/pars/pars0opt.c: Auto merged innobase/que/que0que.c: Auto merged innobase/rem/rem0cmp.c: Auto merged innobase/row/row0ins.c: Auto merged innobase/row/row0mysql.c: Auto merged innobase/row/row0upd.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/srv/srv0start.c: Auto merged innobase/sync/sync0rw.c: Auto merged innobase/sync/sync0sync.c: Auto merged innobase/thr/thr0loc.c: Auto merged innobase/trx/trx0purge.c: Auto merged innobase/trx/trx0roll.c: Auto merged innobase/trx/trx0sys.c: Auto merged innobase/trx/trx0trx.c: Auto merged innobase/usr/usr0sess.c: Auto merged innobase/ut/ut0mem.c: Auto merged mysql-test/r/func_if.result: Auto merged mysql-test/r/type_date.result: Auto merged mysql-test/t/type_date.test: Auto merged mysql-test/t/type_decimal.test: Auto merged mysys/mf_tempfile.c: Auto merged netware/BUILD/nwbootstrap: Auto merged netware/Makefile.am: Auto merged scripts/mysqld_safe.sh: Auto merged sql/item_cmpfunc.cc: Auto merged mysql-test/t/func_if.test: Auto merged sql/mysqld.cc: Auto merged sql/opt_range.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_parse.cc: Auto merged support-files/my-innodb-heavy-4G.cnf.sh: Auto merged Build-tools/Do-compile: Merge with 4.0 Build-tools/mysql-copyright: Merge with 4.0 client/mysqltest.c: Merge with 4.0 include/my_global.h: Merge with 4.0 innobase/buf/buf0rea.c: Merge with 4.0 innobase/data/data0type.c: Merge with 4.0 innobase/ibuf/ibuf0ibuf.c: Merge with 4.0 innobase/include/buf0buf.h: Merge with 4.0 innobase/include/data0type.h: Merge with 4.0 innobase/include/mem0mem.h: Merge with 4.0 innobase/include/mem0mem.ic: Merge with 4.0 innobase/log/log0recv.c: Merge with 4.0 libmysql/libmysql.c: Merge with 4.0 libmysqld/Makefile.am: Merge with 4.0 mysql-test/r/range.result: Merge with 4.0 mysql-test/r/type_decimal.result: Merge with 4.0 mysql-test/t/range.test: Merge with 4.0 netware/BUILD/mwenv: Merge with 4.0 netware/mysql_test_run.c: Merge with 4.0 scripts/mysql_install_db.sh: Merge with 4.0 sql/field.cc: Merge with 4.0 sql/field.h: Merge with 4.0 sql/item_cmpfunc.h: Merge with 4.0 support-files/my-huge.cnf.sh: Merge with 4.0 support-files/my-large.cnf.sh: Merge with 4.0 support-files/my-medium.cnf.sh: Merge with 4.0 support-files/my-small.cnf.sh: Merge with 4.0 support-files/mysql.spec.sh: Merge with 4.0
289 lines
7.1 KiB
C
289 lines
7.1 KiB
C
/**********************************************************************
|
|
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. */
|
|
|
|
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 */
|
|
{
|
|
dict_table_t* table;
|
|
mem_heap_t* heap;
|
|
|
|
ut_ad(name);
|
|
|
|
heap = mem_heap_create(DICT_HEAP_SIZE);
|
|
|
|
table = mem_heap_alloc(heap, sizeof(dict_table_t));
|
|
|
|
table->heap = heap;
|
|
|
|
table->type = DICT_TABLE_ORDINARY;
|
|
table->name = mem_heap_strdup(heap, name);
|
|
table->space = space;
|
|
table->ibd_file_missing = FALSE;
|
|
table->tablespace_discarded = FALSE;
|
|
table->n_def = 0;
|
|
table->n_cols = n_cols + DATA_N_SYS_COLS;
|
|
table->mem_fix = 0;
|
|
|
|
table->n_mysql_handles_opened = 0;
|
|
table->n_foreign_key_checks_running = 0;
|
|
|
|
table->cached = FALSE;
|
|
|
|
table->mix_id = ut_dulint_zero;
|
|
table->mix_len = 0;
|
|
|
|
table->cols = mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS)
|
|
* sizeof(dict_col_t));
|
|
UT_LIST_INIT(table->indexes);
|
|
|
|
table->auto_inc_lock = mem_heap_alloc(heap, lock_get_size());
|
|
|
|
table->query_cache_inv_trx_id = ut_dulint_zero;
|
|
|
|
UT_LIST_INIT(table->locks);
|
|
UT_LIST_INIT(table->foreign_list);
|
|
UT_LIST_INIT(table->referenced_list);
|
|
|
|
table->does_not_fit_in_memory = FALSE;
|
|
|
|
table->stat_initialized = FALSE;
|
|
|
|
table->stat_modified_counter = 0;
|
|
|
|
mutex_create(&(table->autoinc_mutex));
|
|
mutex_set_level(&(table->autoinc_mutex), SYNC_DICT_AUTOINC_MUTEX);
|
|
|
|
table->autoinc_inited = FALSE;
|
|
|
|
table->magic_n = DICT_TABLE_MAGIC_N;
|
|
|
|
return(table);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Creates a cluster memory object. */
|
|
|
|
dict_table_t*
|
|
dict_mem_cluster_create(
|
|
/*====================*/
|
|
/* out, own: cluster object */
|
|
const char* name, /* in: cluster name */
|
|
ulint space, /* in: space where the clustered indexes
|
|
of the member tables are placed */
|
|
ulint n_cols, /* in: number of columns */
|
|
ulint mix_len)/* in: length of the common key prefix in the
|
|
cluster */
|
|
{
|
|
dict_table_t* cluster;
|
|
|
|
cluster = dict_mem_table_create(name, space, n_cols);
|
|
|
|
cluster->type = DICT_TABLE_CLUSTER;
|
|
cluster->mix_len = mix_len;
|
|
|
|
return(cluster);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Declares a non-published table as a member in a cluster. */
|
|
|
|
void
|
|
dict_mem_table_make_cluster_member(
|
|
/*===============================*/
|
|
dict_table_t* table, /* in: non-published table */
|
|
const char* cluster_name) /* in: cluster name */
|
|
{
|
|
table->type = DICT_TABLE_CLUSTER_MEMBER;
|
|
table->cluster_name = cluster_name;
|
|
}
|
|
|
|
/**************************************************************************
|
|
Adds a column definition to a table. */
|
|
|
|
void
|
|
dict_mem_table_add_col(
|
|
/*===================*/
|
|
dict_table_t* table, /* in: table */
|
|
const char* name, /* in: column name */
|
|
ulint mtype, /* in: main datatype */
|
|
ulint prtype, /* in: precise type */
|
|
ulint len, /* in: length */
|
|
ulint prec) /* in: precision */
|
|
{
|
|
dict_col_t* col;
|
|
dtype_t* type;
|
|
|
|
ut_ad(table && name);
|
|
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
|
|
|
|
table->n_def++;
|
|
|
|
col = dict_table_get_nth_col(table, table->n_def - 1);
|
|
|
|
col->ind = table->n_def - 1;
|
|
col->name = mem_heap_strdup(table->heap, name);
|
|
col->table = table;
|
|
col->ord_part = 0;
|
|
|
|
col->clust_pos = ULINT_UNDEFINED;
|
|
|
|
type = dict_col_get_type(col);
|
|
|
|
dtype_set(type, mtype, prtype, len, prec);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Creates an index memory object. */
|
|
|
|
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;
|
|
|
|
ut_ad(table_name && index_name);
|
|
|
|
heap = mem_heap_create(DICT_HEAP_SIZE);
|
|
index = mem_heap_alloc(heap, sizeof(dict_index_t));
|
|
|
|
index->heap = heap;
|
|
|
|
index->type = type;
|
|
index->space = space;
|
|
index->name = mem_heap_strdup(heap, index_name);
|
|
index->table_name = table_name;
|
|
index->table = NULL;
|
|
index->n_def = 0;
|
|
index->n_fields = n_fields;
|
|
index->fields = mem_heap_alloc(heap, 1 + n_fields
|
|
* sizeof(dict_field_t));
|
|
/* The '1 +' above prevents allocation
|
|
of an empty mem block */
|
|
index->stat_n_diff_key_vals = NULL;
|
|
|
|
index->cached = FALSE;
|
|
index->magic_n = DICT_INDEX_MAGIC_N;
|
|
|
|
return(index);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Creates and initializes a foreign constraint memory object. */
|
|
|
|
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_alloc(heap, sizeof(dict_foreign_t));
|
|
|
|
foreign->heap = heap;
|
|
|
|
foreign->id = NULL;
|
|
|
|
foreign->type = 0;
|
|
foreign->foreign_table_name = NULL;
|
|
foreign->foreign_table = NULL;
|
|
foreign->foreign_col_names = NULL;
|
|
|
|
foreign->referenced_table_name = NULL;
|
|
foreign->referenced_table = NULL;
|
|
foreign->referenced_col_names = NULL;
|
|
|
|
foreign->n_fields = 0;
|
|
|
|
foreign->foreign_index = NULL;
|
|
foreign->referenced_index = NULL;
|
|
|
|
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. */
|
|
|
|
void
|
|
dict_mem_index_add_field(
|
|
/*=====================*/
|
|
dict_index_t* index, /* in: index */
|
|
const char* name, /* in: column name */
|
|
ulint order, /* in: order criterion; 0 means an
|
|
ascending order */
|
|
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 && name);
|
|
ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
|
|
|
|
index->n_def++;
|
|
|
|
field = dict_index_get_nth_field(index, index->n_def - 1);
|
|
|
|
field->name = name;
|
|
field->order = order;
|
|
|
|
field->prefix_len = prefix_len;
|
|
}
|
|
|
|
/**************************************************************************
|
|
Frees an index memory object. */
|
|
|
|
void
|
|
dict_mem_index_free(
|
|
/*================*/
|
|
dict_index_t* index) /* in: index */
|
|
{
|
|
mem_heap_free(index->heap);
|
|
}
|