256
256
/** Get the mutex that protects index->stat_n_diff_key_vals[] */
257
257
#define GET_INDEX_STAT_MUTEX(index) \
258
(&dict_index_stat_mutex[ut_fold_dulint(index->id) \
259
% DICT_INDEX_STAT_MUTEX_SIZE])
258
(&dict_index_stat_mutex[ut_fold_ull(index->id) \
259
% DICT_INDEX_STAT_MUTEX_SIZE])
261
261
/**********************************************************************//**
262
262
Lock the appropriate mutex to protect index->stat_n_diff_key_vals[].
424
424
dict_index_get_on_id_low(
425
425
/*=====================*/
426
426
dict_table_t* table, /*!< in: table */
427
dulint id) /*!< in: index id */
427
index_id_t id) /*!< in: index id */
429
429
dict_index_t* index;
431
431
index = dict_table_get_first_index(table);
434
if (0 == ut_dulint_cmp(id, index->id)) {
434
if (id == index->id) {
574
574
dict_table_get_on_id(
575
575
/*=================*/
576
dulint table_id, /*!< in: table id */
577
trx_t* trx) /*!< in: transaction handle */
576
table_id_t table_id, /*!< in: table id */
577
trx_t* trx) /*!< in: transaction handle */
579
579
dict_table_t* table;
581
if (ut_dulint_cmp(table_id, DICT_FIELDS_ID) <= 0
582
|| trx->dict_operation_lock_mode == RW_X_LATCH) {
583
/* It is a system table which will always exist in the table
584
cache: we avoid acquiring the dictionary mutex, because
585
if we are doing a rollback to handle an error in TABLE
586
CREATE, for example, we already have the mutex! */
588
ut_ad(mutex_own(&(dict_sys->mutex))
589
|| trx->dict_operation_lock_mode == RW_X_LATCH);
581
if (trx->dict_operation_lock_mode == RW_X_LATCH) {
583
/* Note: An X latch implies that the transaction
584
already owns the dictionary mutex. */
586
ut_ad(mutex_own(&dict_sys->mutex));
591
588
return(dict_table_get_on_id_low(table_id));
841
838
dict_table_t* table2;
842
839
HASH_SEARCH(id_hash, dict_sys->table_id_hash, id_fold,
843
840
dict_table_t*, table2, ut_ad(table2->cached),
844
ut_dulint_cmp(table2->id, table->id) == 0);
841
table2->id == table->id);
845
842
ut_a(table2 == NULL);
847
844
#ifdef UNIV_DEBUG
863
860
/* Add table to LRU list of tables */
864
861
UT_LIST_ADD_FIRST(table_LRU, dict_sys->table_LRU, table);
866
dict_sys->size += mem_heap_get_size(table->heap);
863
dict_sys->size += mem_heap_get_size(table->heap)
864
+ strlen(table->name) + 1;
869
867
/**********************************************************************//**
917
915
dict_foreign_t* foreign;
918
916
dict_index_t* index;
921
const char* old_name;
918
char old_name[MAX_TABLE_NAME_LEN + 1];
924
921
ut_ad(mutex_own(&(dict_sys->mutex)));
926
old_size = mem_heap_get_size(table->heap);
927
old_name = table->name;
923
/* store the old/current name to an automatic variable */
924
if (strlen(table->name) + 1 <= sizeof(old_name)) {
925
memcpy(old_name, table->name, strlen(table->name) + 1);
927
ut_print_timestamp(stderr);
928
fprintf(stderr, "InnoDB: too long table name: '%s', "
929
"max length is %d\n", table->name,
929
934
fold = ut_fold_string(new_name);
970
975
/* Remove table from the hash tables of tables */
971
976
HASH_DELETE(dict_table_t, name_hash, dict_sys->table_hash,
972
977
ut_fold_string(old_name), table);
973
table->name = mem_heap_strdup(table->heap, new_name);
979
if (strlen(new_name) > strlen(table->name)) {
980
/* We allocate MAX_TABLE_NAME_LEN+1 bytes here to avoid
981
memory fragmentation, we assume a repeated calls of
982
ut_realloc() with the same size do not cause fragmentation */
983
ut_a(strlen(new_name) <= MAX_TABLE_NAME_LEN);
984
table->name = ut_realloc(table->name, MAX_TABLE_NAME_LEN + 1);
986
memcpy(table->name, new_name, strlen(new_name) + 1);
975
988
/* Add table to hash table of tables */
976
989
HASH_INSERT(dict_table_t, name_hash, dict_sys->table_hash, fold,
978
dict_sys->size += (mem_heap_get_size(table->heap) - old_size);
992
dict_sys->size += strlen(new_name) - strlen(old_name);
993
ut_a(dict_sys->size > 0);
980
995
/* Update the table_name field in indexes */
981
996
index = dict_table_get_first_index(table);
1125
1140
dict_table_change_id_in_cache(
1126
1141
/*==========================*/
1127
1142
dict_table_t* table, /*!< in/out: table object already in cache */
1128
dulint new_id) /*!< in: new id to set */
1143
table_id_t new_id) /*!< in: new id to set */
1131
1146
ut_ad(mutex_own(&(dict_sys->mutex)));
1134
1149
/* Remove the table from the hash table of id's */
1136
1151
HASH_DELETE(dict_table_t, id_hash, dict_sys->table_id_hash,
1137
ut_fold_dulint(table->id), table);
1152
ut_fold_ull(table->id), table);
1138
1153
table->id = new_id;
1140
1155
/* Add the table back to the hash table */
1141
1156
HASH_INSERT(dict_table_t, id_hash, dict_sys->table_id_hash,
1142
ut_fold_dulint(table->id), table);
1157
ut_fold_ull(table->id), table);
1145
1160
/**********************************************************************//**
1195
1210
HASH_DELETE(dict_table_t, name_hash, dict_sys->table_hash,
1196
1211
ut_fold_string(table->name), table);
1197
1212
HASH_DELETE(dict_table_t, id_hash, dict_sys->table_id_hash,
1198
ut_fold_dulint(table->id), table);
1213
ut_fold_ull(table->id), table);
1200
1215
/* Remove table from LRU list of tables */
1201
1216
UT_LIST_REMOVE(table_LRU, dict_sys->table_LRU, table);
1203
size = mem_heap_get_size(table->heap);
1218
size = mem_heap_get_size(table->heap) + strlen(table->name) + 1;
1205
1220
ut_ad(dict_sys->size >= size);
2457
2472
/* We found a matching index, select
2458
2473
the index with the higher id*/
2461
|| ut_dulint_cmp(index->id, found->id) > 0) {
2475
if (!found || index->id > found->id) {
3947
3961
dict_index_get_if_in_cache_low(
3948
3962
/*===========================*/
3949
dulint index_id) /*!< in: index id */
3963
index_id_t index_id) /*!< in: index id */
3951
3965
ut_ad(mutex_own(&(dict_sys->mutex)));
4208
/* If we have set a high innodb_force_recovery level, do not calculate
4209
statistics, as a badly corrupted index can cause a crash in it. */
4211
if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
4216
4221
/* Find out the sizes of the indexes and how many different values
4217
4222
for the key they approximately have */
4228
size = btr_get_size(index, BTR_TOTAL_SIZE);
4230
index->stat_index_size = size;
4232
sum_of_index_sizes += size;
4234
size = btr_get_size(index, BTR_N_LEAF_PAGES);
4237
/* The root node of the tree is a leaf */
4235
(srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE
4236
|| (srv_force_recovery < SRV_FORCE_NO_LOG_REDO
4237
&& dict_index_is_clust(index)))) {
4239
size = btr_get_size(index, BTR_TOTAL_SIZE);
4241
index->stat_index_size = size;
4243
sum_of_index_sizes += size;
4245
size = btr_get_size(index, BTR_N_LEAF_PAGES);
4248
/* The root node of the tree is a leaf */
4252
index->stat_n_leaf_pages = size;
4254
btr_estimate_number_of_different_key_vals(index);
4256
/* If we have set a high innodb_force_recovery
4257
level, do not calculate statistics, as a badly
4258
corrupted index can cause a crash in it.
4259
Initialize some bogus index cardinality
4260
statistics, so that the data can be queried in
4261
various means, also via secondary indexes. */
4264
sum_of_index_sizes++;
4265
index->stat_index_size = index->stat_n_leaf_pages = 1;
4267
for (i = dict_index_get_n_unique(index); i; ) {
4268
index->stat_n_diff_key_vals[i--] = 1;
4241
index->stat_n_leaf_pages = size;
4243
btr_estimate_number_of_different_key_vals(index);
4245
4272
index = dict_table_get_next_index(index);
4248
4275
index = dict_table_get_first_index(table);
4358
4385
fprintf(stderr,
4359
4386
"--------------------------------------\n"
4360
"TABLE: name %s, id %lu %lu, flags %lx, columns %lu,"
4387
"TABLE: name %s, id %llu, flags %lx, columns %lu,"
4361
4388
" indexes %lu, appr.rows %lu\n"
4364
(ulong) ut_dulint_get_high(table->id),
4365
(ulong) ut_dulint_get_low(table->id),
4366
4392
(ulong) table->flags,
4367
4393
(ulong) table->n_cols,
4368
4394
(ulong) UT_LIST_GET_LEN(table->indexes),
4443
4468
dict_index_stat_mutex_exit(index);
4445
if (dict_index_is_clust(index)) {
4446
type_string = "clustered index";
4447
} else if (dict_index_is_unique(index)) {
4448
type_string = "unique index";
4450
type_string = "secondary index";
4453
4470
fprintf(stderr,
4454
" INDEX: name %s, id %lu %lu, fields %lu/%lu,"
4471
" INDEX: name %s, id %llu, fields %lu/%lu,"
4455
4472
" uniq %lu, type %lu\n"
4456
4473
" root page %lu, appr.key vals %lu,"
4457
4474
" leaf pages %lu, size pages %lu\n"
4460
(ulong) ut_dulint_get_high(index->id),
4461
(ulong) ut_dulint_get_low(index->id),
4462
4478
(ulong) index->n_user_defined_cols,
4463
4479
(ulong) index->n_fields,
4464
4480
(ulong) index->n_uniq,