~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/dict/dict0dict.c

  • Committer: Lee Bieber
  • Date: 2010-12-03 01:16:19 UTC
  • mfrom: (1819.9.81 update-innobase)
  • Revision ID: kalebral@gmail.com-20101203011619-n6v584rijwdet05b
Merge Stewart - update Innobase plugin based on InnoDB 1.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
255
255
 
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])
260
260
 
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 */
428
428
{
429
429
        dict_index_t*   index;
430
430
 
431
431
        index = dict_table_get_first_index(table);
432
432
 
433
433
        while (index) {
434
 
                if (0 == ut_dulint_cmp(id, index->id)) {
 
434
                if (id == index->id) {
435
435
                        /* Found */
436
436
 
437
437
                        return(index);
573
573
dict_table_t*
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 */
578
578
{
579
579
        dict_table_t*   table;
580
580
 
581
 
        if (ut_dulint_cmp(table_id, DICT_FIELDS_ID) <= 0
 
581
        if (table_id <= DICT_FIELDS_ID
582
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! */
587
 
 
588
 
                ut_ad(mutex_own(&(dict_sys->mutex))
589
 
                      || trx->dict_operation_lock_mode == RW_X_LATCH);
 
583
 
 
584
                /* Note: An X latch implies that the transaction
 
585
                already owns the dictionary mutex. */
 
586
 
 
587
                ut_ad(mutex_own(&dict_sys->mutex));
590
588
 
591
589
                return(dict_table_get_on_id_low(table_id));
592
590
        }
799
797
        table->cached = TRUE;
800
798
 
801
799
        fold = ut_fold_string(table->name);
802
 
        id_fold = ut_fold_dulint(table->id);
 
800
        id_fold = ut_fold_ull(table->id);
803
801
 
804
802
        row_len = 0;
805
803
        for (i = 0; i < table->n_def; i++) {
841
839
                dict_table_t*   table2;
842
840
                HASH_SEARCH(id_hash, dict_sys->table_id_hash, id_fold,
843
841
                            dict_table_t*, table2, ut_ad(table2->cached),
844
 
                            ut_dulint_cmp(table2->id, table->id) == 0);
 
842
                            table2->id == table->id);
845
843
                ut_a(table2 == NULL);
846
844
 
847
845
#ifdef UNIV_DEBUG
863
861
        /* Add table to LRU list of tables */
864
862
        UT_LIST_ADD_FIRST(table_LRU, dict_sys->table_LRU, table);
865
863
 
866
 
        dict_sys->size += mem_heap_get_size(table->heap);
 
864
        dict_sys->size += mem_heap_get_size(table->heap)
 
865
                + strlen(table->name) + 1;
867
866
}
868
867
 
869
868
/**********************************************************************//**
875
874
dict_index_t*
876
875
dict_index_find_on_id_low(
877
876
/*======================*/
878
 
        dulint  id)     /*!< in: index id */
 
877
        index_id_t      id)     /*!< in: index id */
879
878
{
880
879
        dict_table_t*   table;
881
880
        dict_index_t*   index;
886
885
                index = dict_table_get_first_index(table);
887
886
 
888
887
                while (index) {
889
 
                        if (0 == ut_dulint_cmp(id, index->id)) {
 
888
                        if (id == index->id) {
890
889
                                /* Found */
891
890
 
892
891
                                return(index);
917
916
        dict_foreign_t* foreign;
918
917
        dict_index_t*   index;
919
918
        ulint           fold;
920
 
        ulint           old_size;
921
 
        const char*     old_name;
 
919
        char            old_name[MAX_TABLE_NAME_LEN + 1];
922
920
 
923
921
        ut_ad(table);
924
922
        ut_ad(mutex_own(&(dict_sys->mutex)));
925
923
 
926
 
        old_size = mem_heap_get_size(table->heap);
927
 
        old_name = table->name;
 
924
        /* store the old/current name to an automatic variable */
 
925
        if (strlen(table->name) + 1 <= sizeof(old_name)) {
 
926
                memcpy(old_name, table->name, strlen(table->name) + 1);
 
927
        } else {
 
928
                ut_print_timestamp(stderr);
 
929
                fprintf(stderr, "InnoDB: too long table name: '%s', "
 
930
                        "max length is %d\n", table->name,
 
931
                        MAX_TABLE_NAME_LEN);
 
932
                ut_error;
 
933
        }
928
934
 
929
935
        fold = ut_fold_string(new_name);
930
936
 
970
976
        /* Remove table from the hash tables of tables */
971
977
        HASH_DELETE(dict_table_t, name_hash, dict_sys->table_hash,
972
978
                    ut_fold_string(old_name), table);
973
 
        table->name = mem_heap_strdup(table->heap, new_name);
 
979
 
 
980
        if (strlen(new_name) > strlen(table->name)) {
 
981
                /* We allocate MAX_TABLE_NAME_LEN+1 bytes here to avoid
 
982
                memory fragmentation, we assume a repeated calls of
 
983
                ut_realloc() with the same size do not cause fragmentation */
 
984
                ut_a(strlen(new_name) <= MAX_TABLE_NAME_LEN);
 
985
                table->name = ut_realloc(table->name, MAX_TABLE_NAME_LEN + 1);
 
986
        }
 
987
        memcpy(table->name, new_name, strlen(new_name) + 1);
974
988
 
975
989
        /* Add table to hash table of tables */
976
990
        HASH_INSERT(dict_table_t, name_hash, dict_sys->table_hash, fold,
977
991
                    table);
978
 
        dict_sys->size += (mem_heap_get_size(table->heap) - old_size);
 
992
 
 
993
        dict_sys->size += strlen(new_name) - strlen(old_name);
 
994
        ut_a(dict_sys->size > 0);
979
995
 
980
996
        /* Update the table_name field in indexes */
981
997
        index = dict_table_get_first_index(table);
1125
1141
dict_table_change_id_in_cache(
1126
1142
/*==========================*/
1127
1143
        dict_table_t*   table,  /*!< in/out: table object already in cache */
1128
 
        dulint          new_id) /*!< in: new id to set */
 
1144
        table_id_t      new_id) /*!< in: new id to set */
1129
1145
{
1130
1146
        ut_ad(table);
1131
1147
        ut_ad(mutex_own(&(dict_sys->mutex)));
1134
1150
        /* Remove the table from the hash table of id's */
1135
1151
 
1136
1152
        HASH_DELETE(dict_table_t, id_hash, dict_sys->table_id_hash,
1137
 
                    ut_fold_dulint(table->id), table);
 
1153
                    ut_fold_ull(table->id), table);
1138
1154
        table->id = new_id;
1139
1155
 
1140
1156
        /* Add the table back to the hash table */
1141
1157
        HASH_INSERT(dict_table_t, id_hash, dict_sys->table_id_hash,
1142
 
                    ut_fold_dulint(table->id), table);
 
1158
                    ut_fold_ull(table->id), table);
1143
1159
}
1144
1160
 
1145
1161
/**********************************************************************//**
1195
1211
        HASH_DELETE(dict_table_t, name_hash, dict_sys->table_hash,
1196
1212
                    ut_fold_string(table->name), table);
1197
1213
        HASH_DELETE(dict_table_t, id_hash, dict_sys->table_id_hash,
1198
 
                    ut_fold_dulint(table->id), table);
 
1214
                    ut_fold_ull(table->id), table);
1199
1215
 
1200
1216
        /* Remove table from LRU list of tables */
1201
1217
        UT_LIST_REMOVE(table_LRU, dict_sys->table_LRU, table);
1202
1218
 
1203
 
        size = mem_heap_get_size(table->heap);
 
1219
        size = mem_heap_get_size(table->heap) + strlen(table->name) + 1;
1204
1220
 
1205
1221
        ut_ad(dict_sys->size >= size);
1206
1222
 
2457
2473
                                /* We found a matching index, select
2458
2474
                                the index with the higher id*/
2459
2475
 
2460
 
                                if (!found
2461
 
                                    || ut_dulint_cmp(index->id, found->id) > 0) {
 
2476
                                if (!found || index->id > found->id) {
2462
2477
 
2463
2478
                                        found = index;
2464
2479
                                }
3946
3961
dict_index_t*
3947
3962
dict_index_get_if_in_cache_low(
3948
3963
/*===========================*/
3949
 
        dulint  index_id)       /*!< in: index id */
 
3964
        index_id_t      index_id)       /*!< in: index id */
3950
3965
{
3951
3966
        ut_ad(mutex_own(&(dict_sys->mutex)));
3952
3967
 
3961
3976
dict_index_t*
3962
3977
dict_index_get_if_in_cache(
3963
3978
/*=======================*/
3964
 
        dulint  index_id)       /*!< in: index id */
 
3979
        index_id_t      index_id)       /*!< in: index id */
3965
3980
{
3966
3981
        dict_index_t*   index;
3967
3982
 
4357
4372
 
4358
4373
        fprintf(stderr,
4359
4374
                "--------------------------------------\n"
4360
 
                "TABLE: name %s, id %lu %lu, flags %lx, columns %lu,"
 
4375
                "TABLE: name %s, id %llu, flags %lx, columns %lu,"
4361
4376
                " indexes %lu, appr.rows %lu\n"
4362
4377
                "  COLUMNS: ",
4363
4378
                table->name,
4364
 
                (ulong) ut_dulint_get_high(table->id),
4365
 
                (ulong) ut_dulint_get_low(table->id),
 
4379
                (ullint) table->id,
4366
4380
                (ulong) table->flags,
4367
4381
                (ulong) table->n_cols,
4368
4382
                (ulong) UT_LIST_GET_LEN(table->indexes),
4451
4465
        }
4452
4466
 
4453
4467
        fprintf(stderr,
4454
 
                "  INDEX: name %s, id %lu %lu, fields %lu/%lu,"
 
4468
                "  INDEX: name %s, id %llu, fields %lu/%lu,"
4455
4469
                " uniq %lu, type %lu\n"
4456
4470
                "   root page %lu, appr.key vals %lu,"
4457
4471
                " leaf pages %lu, size pages %lu\n"
4458
4472
                "   FIELDS: ",
4459
4473
                index->name,
4460
 
                (ulong) ut_dulint_get_high(index->id),
4461
 
                (ulong) ut_dulint_get_low(index->id),
 
4474
                (ullint) index->id,
4462
4475
                (ulong) index->n_user_defined_cols,
4463
4476
                (ulong) index->n_fields,
4464
4477
                (ulong) index->n_uniq,
4830
4843
 
4831
4844
        while (index != NULL) {
4832
4845
                if (ut_strcmp(index->name, name) == 0) {
4833
 
                        if (!min_index
4834
 
                            || ut_dulint_cmp(index->id, min_index->id) < 0) {
 
4846
                        if (!min_index || index->id < min_index->id) {
4835
4847
 
4836
4848
                                min_index = index;
4837
4849
                        }