~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: kalebral at gmail
  • Date: 2010-12-04 04:58:08 UTC
  • mto: (1971.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1972.
  • Revision ID: kalebral@gmail.com-20101204045808-acto22oxfg43m02e
a few more updates of files that did not have license or had incorrect license structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
189
189
                const char* err_msg;
190
190
 
191
191
                err_msg = dict_process_sys_tables_rec(
192
 
                        heap, rec, &table,
193
 
                        static_cast<dict_table_info>(DICT_TABLE_LOAD_FROM_CACHE
194
 
                        | DICT_TABLE_UPDATE_STATS));
 
192
                        heap, rec, &table, DICT_TABLE_LOAD_FROM_CACHE
 
193
                        | DICT_TABLE_UPDATE_STATS);
195
194
 
196
195
                mtr_commit(&mtr);
197
196
 
352
351
 
353
352
                /* Update statistics if DICT_TABLE_UPDATE_STATS
354
353
                is set */
355
 
                dict_update_statistics(*table,
356
 
                                       FALSE /* update even if
357
 
                                                initialized */);
 
354
                dict_update_statistics_low(*table, TRUE);
358
355
        }
359
356
 
360
357
        return(NULL);
377
374
        const char*     err_msg;
378
375
        byte*           buf;
379
376
 
380
 
        buf = static_cast<unsigned char *>(mem_heap_alloc(heap, 8));
 
377
        buf = mem_heap_alloc(heap, 8);
381
378
 
382
379
        /* Parse the record, and get "dict_index_t" struct filled */
383
380
        err_msg = dict_load_index_low(buf, NULL,
429
426
        byte*           last_index_id;
430
427
        const char*     err_msg;
431
428
 
432
 
        buf = static_cast<unsigned char *>(mem_heap_alloc(heap, 8));
 
429
        buf = mem_heap_alloc(heap, 8);
433
430
 
434
 
        last_index_id = static_cast<unsigned char *>(mem_heap_alloc(heap, 8));
 
431
        last_index_id = mem_heap_alloc(heap, 8);
435
432
        mach_write_to_8(last_index_id, last_id);
436
433
 
437
434
        err_msg = dict_load_field_low(buf, NULL, sys_field,
702
699
                return(ULINT_UNDEFINED);
703
700
        }
704
701
 
705
 
        if (UNIV_UNLIKELY(flags & (SIZE_MAX << DICT_TF_BITS))) {
 
702
        if (UNIV_UNLIKELY(flags & (~0 << DICT_TF_BITS))) {
706
703
                /* Some unused bits are set. */
707
704
                return(ULINT_UNDEFINED);
708
705
        }
1028
1025
        tuple = dtuple_create(heap, 1);
1029
1026
        dfield = dtuple_get_nth_field(tuple, 0);
1030
1027
 
1031
 
        buf = static_cast<unsigned char *>(mem_heap_alloc(heap, 8));
 
1028
        buf = mem_heap_alloc(heap, 8);
1032
1029
        mach_write_to_8(buf, table->id);
1033
1030
 
1034
1031
        dfield_set_data(dfield, buf, 8);
1212
1209
        tuple = dtuple_create(heap, 1);
1213
1210
        dfield = dtuple_get_nth_field(tuple, 0);
1214
1211
 
1215
 
        buf = static_cast<unsigned char *>(mem_heap_alloc(heap, 8));
 
1212
        buf = mem_heap_alloc(heap, 8);
1216
1213
        mach_write_to_8(buf, index->id);
1217
1214
 
1218
1215
        dfield_set_data(dfield, buf, 8);
1415
1412
        tuple = dtuple_create(heap, 1);
1416
1413
        dfield = dtuple_get_nth_field(tuple, 0);
1417
1414
 
1418
 
        buf = static_cast<unsigned char *>(mem_heap_alloc(heap, 8));
 
1415
        buf = mem_heap_alloc(heap, 8);
1419
1416
        mach_write_to_8(buf, table->id);
1420
1417
 
1421
1418
        dfield_set_data(dfield, buf, 8);
1641
1638
 
1642
1639
                flags2 = mach_read_from_4(field);
1643
1640
 
1644
 
                if (flags2 & (SIZE_MAX << (DICT_TF2_BITS - DICT_TF2_SHIFT))) {
 
1641
                if (flags2 & (~0 << (DICT_TF2_BITS - DICT_TF2_SHIFT))) {
1645
1642
                        ut_print_timestamp(stderr);
1646
1643
                        fputs("  InnoDB: Warning: table ", stderr);
1647
1644
                        ut_print_filename(stderr, name);
1802
1799
 
1803
1800
        err = dict_load_indexes(table, heap);
1804
1801
 
1805
 
        /* Initialize table foreign_child value. Its value could be
1806
 
        changed when dict_load_foreigns() is called below */
1807
 
        table->fk_max_recusive_level = 0;
1808
 
 
1809
1802
        /* If the force recovery flag is set, we open the table irrespective
1810
1803
        of the error condition, since the user may want to dump data from the
1811
1804
        clustered index. However we load the foreign key information only if
1812
1805
        all indexes were loaded. */
1813
1806
        if (!cached) {
1814
1807
        } else if (err == DB_SUCCESS) {
1815
 
                err = dict_load_foreigns(table->name, TRUE, TRUE);
1816
 
 
1817
 
                if (err != DB_SUCCESS) {
1818
 
                        dict_table_remove_from_cache(table);
1819
 
                        table = NULL;
1820
 
                } else {
1821
 
                        table->fk_max_recusive_level = 0;
1822
 
                }
 
1808
                err = dict_load_foreigns(table->name, TRUE);
1823
1809
        } else if (!srv_force_recovery) {
1824
1810
                dict_table_remove_from_cache(table);
1825
1811
                table = NULL;
1877
1863
 
1878
1864
        ut_ad(mutex_own(&(dict_sys->mutex)));
1879
1865
 
1880
 
        table = NULL;
1881
 
 
1882
1866
        /* NOTE that the operation of this function is protected by
1883
1867
        the dictionary mutex, and therefore no deadlocks can occur
1884
1868
        with other dictionary operations. */
1905
1889
                                  BTR_SEARCH_LEAF, &pcur, &mtr);
1906
1890
        rec = btr_pcur_get_rec(&pcur);
1907
1891
 
1908
 
        if (!btr_pcur_is_on_user_rec(&pcur)) {
 
1892
        if (!btr_pcur_is_on_user_rec(&pcur)
 
1893
            || rec_get_deleted_flag(rec, 0)) {
1909
1894
                /* Not found */
1910
 
                goto func_exit;
1911
 
        }
1912
 
 
1913
 
        /* Find the first record that is not delete marked */
1914
 
        while (rec_get_deleted_flag(rec, 0)) {
1915
 
                if (!btr_pcur_move_to_next_user_rec(&pcur, &mtr)) {
1916
 
                        goto func_exit;
1917
 
                }
1918
 
                rec = btr_pcur_get_rec(&pcur);
 
1895
 
 
1896
                btr_pcur_close(&pcur);
 
1897
                mtr_commit(&mtr);
 
1898
                mem_heap_free(heap);
 
1899
 
 
1900
                return(NULL);
1919
1901
        }
1920
1902
 
1921
1903
        /*---------------------------------------------------*/
1928
1910
 
1929
1911
        /* Check if the table id in record is the one searched for */
1930
1912
        if (table_id != mach_read_from_8(field)) {
1931
 
                goto func_exit;
 
1913
 
 
1914
                btr_pcur_close(&pcur);
 
1915
                mtr_commit(&mtr);
 
1916
                mem_heap_free(heap);
 
1917
 
 
1918
                return(NULL);
1932
1919
        }
1933
1920
 
1934
1921
        /* Now we get the table name from the record */
1936
1923
        /* Load the table definition to memory */
1937
1924
        table = dict_load_table(mem_heap_strdupl(heap, (char*) field, len),
1938
1925
                                TRUE);
1939
 
func_exit:
 
1926
 
1940
1927
        btr_pcur_close(&pcur);
1941
1928
        mtr_commit(&mtr);
1942
1929
        mem_heap_free(heap);
1988
1975
 
1989
1976
        ut_ad(mutex_own(&(dict_sys->mutex)));
1990
1977
 
1991
 
        foreign->foreign_col_names = static_cast<const char **>(mem_heap_alloc(
1992
 
                foreign->heap, foreign->n_fields * sizeof(void*)));
 
1978
        foreign->foreign_col_names = mem_heap_alloc(
 
1979
                foreign->heap, foreign->n_fields * sizeof(void*));
1993
1980
 
1994
 
        foreign->referenced_col_names = static_cast<const char **>(mem_heap_alloc(
1995
 
                foreign->heap, foreign->n_fields * sizeof(void*)));
 
1981
        foreign->referenced_col_names = mem_heap_alloc(
 
1982
                foreign->heap, foreign->n_fields * sizeof(void*));
1996
1983
        mtr_start(&mtr);
1997
1984
 
1998
1985
        sys_foreign_cols = dict_table_get_low("SYS_FOREIGN_COLS");
2046
2033
/*==============*/
2047
2034
        const char*     id,     /*!< in: foreign constraint id as a
2048
2035
                                null-terminated string */
2049
 
        ibool           check_charsets,
 
2036
        ibool           check_charsets)
2050
2037
                                /*!< in: TRUE=check charset compatibility */
2051
 
        ibool           check_recursive)
2052
 
                                /*!< in: Whether to record the foreign table
2053
 
                                parent count to avoid unlimited recursive
2054
 
                                load of chained foreign tables */
2055
2038
{
2056
2039
        dict_foreign_t* foreign;
2057
2040
        dict_table_t*   sys_foreign;
2065
2048
        ulint           len;
2066
2049
        ulint           n_fields_and_type;
2067
2050
        mtr_t           mtr;
2068
 
        dict_table_t*   for_table;
2069
 
        dict_table_t*   ref_table;
2070
2051
 
2071
2052
        ut_ad(mutex_own(&(dict_sys->mutex)));
2072
2053
 
2151
2132
 
2152
2133
        dict_load_foreign_cols(id, foreign);
2153
2134
 
2154
 
        ref_table = dict_table_check_if_in_cache_low(
2155
 
                        foreign->referenced_table_name);
2156
 
 
2157
 
        /* We could possibly wind up in a deep recursive calls if
2158
 
        we call dict_table_get_low() again here if there
2159
 
        is a chain of tables concatenated together with
2160
 
        foreign constraints. In such case, each table is
2161
 
        both a parent and child of the other tables, and
2162
 
        act as a "link" in such table chains.
2163
 
        To avoid such scenario, we would need to check the
2164
 
        number of ancesters the current table has. If that
2165
 
        exceeds DICT_FK_MAX_CHAIN_LEN, we will stop loading
2166
 
        the child table.
2167
 
        Foreign constraints are loaded in a Breath First fashion,
2168
 
        that is, the index on FOR_NAME is scanned first, and then
2169
 
        index on REF_NAME. So foreign constrains in which
2170
 
        current table is a child (foreign table) are loaded first,
2171
 
        and then those constraints where current table is a
2172
 
        parent (referenced) table.
2173
 
        Thus we could check the parent (ref_table) table's
2174
 
        reference count (fk_max_recusive_level) to know how deep the
2175
 
        recursive call is. If the parent table (ref_table) is already
2176
 
        loaded, and its fk_max_recusive_level is larger than
2177
 
        DICT_FK_MAX_CHAIN_LEN, we will stop the recursive loading
2178
 
        by skipping loading the child table. It will not affect foreign
2179
 
        constraint check for DMLs since child table will be loaded
2180
 
        at that time for the constraint check. */
2181
 
        if (!ref_table
2182
 
            || ref_table->fk_max_recusive_level < DICT_FK_MAX_RECURSIVE_LOAD) {
2183
 
 
2184
 
                /* If the foreign table is not yet in the dictionary cache, we
2185
 
                have to load it so that we are able to make type comparisons
2186
 
                in the next function call. */
2187
 
 
2188
 
                for_table = dict_table_get_low(foreign->foreign_table_name);
2189
 
 
2190
 
                if (for_table && ref_table && check_recursive) {
2191
 
                        /* This is to record the longest chain of ancesters
2192
 
                        this table has, if the parent has more ancesters
2193
 
                        than this table has, record it after add 1 (for this
2194
 
                        parent */
2195
 
                        if (ref_table->fk_max_recusive_level
2196
 
                            >= for_table->fk_max_recusive_level) {
2197
 
                                for_table->fk_max_recusive_level =
2198
 
                                         ref_table->fk_max_recusive_level + 1;
2199
 
                        }
2200
 
                }
2201
 
        }
 
2135
        /* If the foreign table is not yet in the dictionary cache, we
 
2136
        have to load it so that we are able to make type comparisons
 
2137
        in the next function call. */
 
2138
 
 
2139
        dict_table_get_low(foreign->foreign_table_name);
2202
2140
 
2203
2141
        /* Note that there may already be a foreign constraint object in
2204
2142
        the dictionary cache for this constraint: then the following
2223
2161
dict_load_foreigns(
2224
2162
/*===============*/
2225
2163
        const char*     table_name,     /*!< in: table name */
2226
 
        ibool           check_recursive,/*!< in: Whether to check recursive
2227
 
                                        load of tables chained by FK */
2228
2164
        ibool           check_charsets) /*!< in: TRUE=check charset
2229
2165
                                        compatibility */
2230
2166
{
2295
2231
 
2296
2232
        if (0 != cmp_data_data(dfield_get_type(dfield)->mtype,
2297
2233
                               dfield_get_type(dfield)->prtype,
2298
 
                               static_cast<const unsigned char *>(dfield_get_data(dfield)),
2299
 
                               dfield_get_len(dfield),
 
2234
                               dfield_get_data(dfield), dfield_get_len(dfield),
2300
2235
                               field, len)) {
2301
2236
 
2302
2237
                goto load_next_index;
2327
2262
 
2328
2263
        /* Load the foreign constraint definition to the dictionary cache */
2329
2264
 
2330
 
        err = dict_load_foreign(id, check_charsets, check_recursive);
 
2265
        err = dict_load_foreign(id, check_charsets);
2331
2266
 
2332
2267
        if (err != DB_SUCCESS) {
2333
2268
                btr_pcur_close(&pcur);
2355
2290
 
2356
2291
                mtr_start(&mtr);
2357
2292
 
2358
 
                /* Switch to scan index on REF_NAME, fk_max_recusive_level
2359
 
                already been updated when scanning FOR_NAME index, no need to
2360
 
                update again */
2361
 
                check_recursive = FALSE;
2362
 
 
2363
2293
                goto start_load;
2364
2294
        }
2365
2295