~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2011-01-05 16:29:27 UTC
  • mto: (2060.2.1 clean)
  • mto: This revision was merged to the branch mainline in revision 2063.
  • Revision ID: brian@tangent.org-20110105162927-fi2gnmlz35qcagik
Add additional gperf for non-reserved SQL keywords.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
#include <ctype.h>
58
58
 
59
 
#include <drizzled/session.h>
60
 
 
61
59
/** the dictionary system */
62
60
UNIV_INTERN dict_sys_t* dict_sys        = NULL;
63
61
 
690
688
{
691
689
        int     i;
692
690
 
693
 
        dict_sys = static_cast<dict_sys_t *>(mem_alloc(sizeof(dict_sys_t)));
 
691
        dict_sys = mem_alloc(sizeof(dict_sys_t));
694
692
 
695
693
        mutex_create(dict_sys_mutex_key, &dict_sys->mutex, SYNC_DICT);
696
694
 
1013
1011
                memory fragmentation, we assume a repeated calls of
1014
1012
                ut_realloc() with the same size do not cause fragmentation */
1015
1013
                ut_a(strlen(new_name) <= MAX_TABLE_NAME_LEN);
1016
 
                table->name = static_cast<char *>(ut_realloc(table->name, MAX_TABLE_NAME_LEN + 1));
 
1014
                table->name = ut_realloc(table->name, MAX_TABLE_NAME_LEN + 1);
1017
1015
        }
1018
1016
        memcpy(table->name, new_name, strlen(new_name) + 1);
1019
1017
 
1081
1079
                        TODO: store buf len to save memory */
1082
1080
 
1083
1081
                        foreign->foreign_table_name
1084
 
                                = static_cast<char *>(mem_heap_alloc(foreign->heap,
1085
 
                                                 ut_strlen(table->name) + 1));
 
1082
                                = mem_heap_alloc(foreign->heap,
 
1083
                                                 ut_strlen(table->name) + 1);
1086
1084
                }
1087
1085
 
1088
1086
                strcpy(foreign->foreign_table_name, table->name);
1105
1103
                                /* This is a generated >= 4.0.18 format id */
1106
1104
 
1107
1105
                                if (strlen(table->name) > strlen(old_name)) {
1108
 
                                        foreign->id = static_cast<char *>(mem_heap_alloc(
 
1106
                                        foreign->id = mem_heap_alloc(
1109
1107
                                                foreign->heap,
1110
1108
                                                strlen(table->name)
1111
 
                                                + strlen(old_id) + 1));
 
1109
                                                + strlen(old_id) + 1);
1112
1110
                                }
1113
1111
 
1114
1112
                                /* Replace the prefix 'databasename/tablename'
1124
1122
                                if (dict_get_db_name_len(table->name)
1125
1123
                                    > dict_get_db_name_len(foreign->id)) {
1126
1124
 
1127
 
                                        foreign->id = static_cast<char *>(mem_heap_alloc(
 
1125
                                        foreign->id = mem_heap_alloc(
1128
1126
                                                foreign->heap,
1129
 
                                                db_len + strlen(old_id) + 1));
 
1127
                                                db_len + strlen(old_id) + 1);
1130
1128
                                }
1131
1129
 
1132
1130
                                /* Replace the database prefix in id with the
1152
1150
                        /* Allocate a longer name buffer;
1153
1151
                        TODO: store buf len to save memory */
1154
1152
 
1155
 
                        foreign->referenced_table_name = static_cast<char *>(mem_heap_alloc(
1156
 
                                foreign->heap, strlen(table->name) + 1));
 
1153
                        foreign->referenced_table_name = mem_heap_alloc(
 
1154
                                foreign->heap, strlen(table->name) + 1);
1157
1155
                }
1158
1156
 
1159
1157
                strcpy(foreign->referenced_table_name, table->name);
1681
1679
 
1682
1680
        if (!UNIV_UNLIKELY(new_index->type & DICT_UNIVERSAL)) {
1683
1681
 
1684
 
                new_index->stat_n_diff_key_vals = static_cast<ib_int64_t *>(mem_heap_alloc(
 
1682
                new_index->stat_n_diff_key_vals = mem_heap_alloc(
1685
1683
                        new_index->heap,
1686
1684
                        (1 + dict_index_get_n_unique(new_index))
1687
 
                        * sizeof(ib_int64_t)));
 
1685
                        * sizeof(ib_int64_t));
1688
1686
                /* Give some sensible values to stat_n_... in case we do
1689
1687
                not calculate statistics quickly enough */
1690
1688
 
2065
2063
        }
2066
2064
 
2067
2065
        /* Remember the table columns already contained in new_index */
2068
 
        void *indexed_ptr= mem_zalloc(table->n_cols * sizeof *indexed);
2069
 
        indexed = static_cast<unsigned long *>(indexed_ptr);
 
2066
        indexed = mem_zalloc(table->n_cols * sizeof *indexed);
2070
2067
 
2071
2068
        /* Mark the table columns already contained in new_index */
2072
2069
        for (i = 0; i < new_index->n_def; i++) {
2150
2147
        dict_index_copy(new_index, index, table, 0, index->n_fields);
2151
2148
 
2152
2149
        /* Remember the table columns already contained in new_index */
2153
 
        void *indexed_ptr= mem_zalloc(table->n_cols * sizeof *indexed);
2154
 
        indexed = static_cast<unsigned long *>(indexed_ptr);
 
2150
        indexed = mem_zalloc(table->n_cols * sizeof *indexed);
2155
2151
 
2156
2152
        /* Mark the table columns already contained in new_index */
2157
2153
        for (i = 0; i < new_index->n_def; i++) {
2842
2838
 
2843
2839
        if (quote) {
2844
2840
                char*   d;
2845
 
                str = d = static_cast<char *>(mem_heap_alloc(heap, len + 1));
 
2841
                str = d = mem_heap_alloc(heap, len + 1);
2846
2842
                while (len--) {
2847
2843
                        if ((*d++ = *s++) == quote) {
2848
2844
                                s++;
2861
2857
                /* Convert the identifier from connection character set
2862
2858
                to UTF-8. */
2863
2859
                len = 3 * len + 1;
2864
 
                *id = dst = static_cast<char *>(mem_heap_alloc(heap, len));
 
2860
                *id = dst = mem_heap_alloc(heap, len);
2865
2861
 
2866
2862
                innobase_convert_from_id(cs, dst, str, len);
2867
 
        } else if (!strncmp(str, srv_mysql50_table_name_prefix.c_str(),
2868
 
                            srv_mysql50_table_name_prefix.size())) {
 
2863
        } else if (!strncmp(str, srv_mysql50_table_name_prefix,
 
2864
                            sizeof srv_mysql50_table_name_prefix)) {
2869
2865
                /* This is a pre-5.1 table name
2870
2866
                containing chars other than [A-Za-z0-9].
2871
2867
                Discard the prefix and use raw UTF-8 encoding. */
2872
 
                str += srv_mysql50_table_name_prefix.size();
2873
 
                len -= srv_mysql50_table_name_prefix.size();
 
2868
                str += sizeof srv_mysql50_table_name_prefix;
 
2869
                len -= sizeof srv_mysql50_table_name_prefix;
2874
2870
                goto convert_id;
2875
2871
        } else {
2876
2872
                /* Encode using filename-safe characters. */
2877
2873
                len = 5 * len + 1;
2878
 
                *id = dst = static_cast<char *>(mem_heap_alloc(heap, len));
 
2874
                *id = dst = mem_heap_alloc(heap, len);
2879
2875
 
2880
2876
                innobase_convert_from_table_id(cs, dst, str, len);
2881
2877
        }
3013
3009
        table_name_len = strlen(table_name);
3014
3010
 
3015
3011
        /* Copy database_name, '/', table_name, '\0' */
3016
 
        ref = static_cast<char *>(mem_heap_alloc(heap, database_name_len + table_name_len + 2));
 
3012
        ref = mem_heap_alloc(heap, database_name_len + table_name_len + 2);
3017
3013
        memcpy(ref, database_name, database_name_len);
3018
3014
        ref[database_name_len] = '/';
3019
3015
        memcpy(ref + database_name_len + 1, table_name, table_name_len + 1);
3080
3076
        /* unclosed quote character (0 if none) */
3081
3077
        char            quote   = 0;
3082
3078
 
3083
 
        str = static_cast<char *>(mem_alloc(sql_length + 1));
 
3079
        str = mem_alloc(sql_length + 1);
3084
3080
 
3085
3081
        sptr = sql_string;
3086
3082
        ptr = str;
3509
3505
 
3510
3506
                db_len = dict_get_db_name_len(table->name);
3511
3507
 
3512
 
                foreign->id = static_cast<char*>(mem_heap_alloc(
3513
 
                        foreign->heap, db_len + strlen(constraint_name) + 2));
 
3508
                foreign->id = mem_heap_alloc(
 
3509
                        foreign->heap, db_len + strlen(constraint_name) + 2);
3514
3510
 
3515
3511
                ut_memcpy(foreign->id, table->name, db_len);
3516
3512
                foreign->id[db_len] = '/';
3522
3518
                                                      table->name);
3523
3519
        foreign->foreign_index = index;
3524
3520
        foreign->n_fields = (unsigned int) i;
3525
 
        foreign->foreign_col_names = static_cast<const char **>(mem_heap_alloc(foreign->heap,
3526
 
                                                    i * sizeof(void*)));
 
3521
        foreign->foreign_col_names = mem_heap_alloc(foreign->heap,
 
3522
                                                    i * sizeof(void*));
3527
3523
        for (i = 0; i < foreign->n_fields; i++) {
3528
3524
                foreign->foreign_col_names[i] = mem_heap_strdup(
3529
3525
                        foreign->heap,
3779
3775
        foreign->referenced_table_name
3780
3776
                = mem_heap_strdup(foreign->heap, referenced_table_name);
3781
3777
 
3782
 
        foreign->referenced_col_names = static_cast<const char **>(mem_heap_alloc(foreign->heap,
3783
 
                                                       i * sizeof(void*)));
 
3778
        foreign->referenced_col_names = mem_heap_alloc(foreign->heap,
 
3779
                                                       i * sizeof(void*));
3784
3780
        for (i = 0; i < foreign->n_fields; i++) {
3785
3781
                foreign->referenced_col_names[i]
3786
3782
                        = mem_heap_strdup(foreign->heap, column_names[i]);
3838
3834
        heap = mem_heap_create(10000);
3839
3835
 
3840
3836
        err = dict_create_foreign_constraints_low(
3841
 
                trx, heap, trx->session()->charset(), str, name,
 
3837
                trx, heap, innobase_get_charset(trx->mysql_thd), str, name,
3842
3838
                reject_fks);
3843
3839
 
3844
3840
        mem_heap_free(heap);
3876
3872
        ut_a(trx);
3877
3873
        ut_a(trx->mysql_thd);
3878
3874
 
3879
 
        cs = trx->session()->charset();
 
3875
        cs = innobase_get_charset(trx->mysql_thd);
3880
3876
 
3881
3877
        *n = 0;
3882
3878
 
3883
 
        *constraints_to_drop = static_cast<const char **>(mem_heap_alloc(heap, 1000 * sizeof(char*)));
 
3879
        *constraints_to_drop = mem_heap_alloc(heap, 1000 * sizeof(char*));
3884
3880
 
3885
 
        ptr= trx->session()->getQueryStringCopy(len);
 
3881
        ptr = innobase_get_stmt(trx->mysql_thd, &len);
3886
3882
 
3887
3883
        str = dict_strip_comments(ptr, len);
3888
3884
 
4097
4093
 
4098
4094
        dict_index_copy_types(tuple, index, n_unique);
4099
4095
 
4100
 
        buf = static_cast<unsigned char *>(mem_heap_alloc(heap, 4));
 
4096
        buf = mem_heap_alloc(heap, 4);
4101
4097
 
4102
4098
        mach_write_to_4(buf, page_no);
4103
4099
 
4951
4947
        for (i = 0; i < hash_get_n_cells(dict_sys->table_hash); i++) {
4952
4948
                dict_table_t*   table;
4953
4949
 
4954
 
                table = static_cast<dict_table_t *>(HASH_GET_FIRST(dict_sys->table_hash, i));
 
4950
                table = HASH_GET_FIRST(dict_sys->table_hash, i);
4955
4951
 
4956
4952
                while (table) {
4957
4953
                        dict_table_t*   prev_table = table;
4958
4954
 
4959
 
                        table = static_cast<dict_table_t *>(HASH_GET_NEXT(name_hash, prev_table));
 
4955
                        table = HASH_GET_NEXT(name_hash, prev_table);
4960
4956
#ifdef UNIV_DEBUG
4961
4957
                        ut_a(prev_table->magic_n == DICT_TABLE_MAGIC_N);
4962
4958
#endif