1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 2010, 2014, Oracle and/or its affiliates. All Rights Reserved. |
4 | |
5 | This program is free software; you can redistribute it and/or modify it under |
6 | the terms of the GNU General Public License as published by the Free Software |
7 | Foundation; version 2 of the License. |
8 | |
9 | This program is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License along with |
14 | this program; if not, write to the Free Software Foundation, Inc., |
15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
16 | |
17 | *****************************************************************************/ |
18 | |
19 | /******************************************************************//** |
20 | @file include/dict0priv.ic |
21 | Data dictionary system private include file |
22 | |
23 | Created Wed 13 Oct 2010 16:10:14 EST Sunny Bains |
24 | ***********************************************************************/ |
25 | |
26 | #include "dict0dict.h" |
27 | #include "dict0load.h" |
28 | #include "dict0priv.h" |
29 | |
30 | /**********************************************************************//** |
31 | Gets a table; loads it to the dictionary cache if necessary. A low-level |
32 | function. |
33 | @return table, NULL if not found */ |
34 | UNIV_INLINE |
35 | dict_table_t* |
36 | dict_table_get_low( |
37 | /*===============*/ |
38 | const char* table_name) /*!< in: table name */ |
39 | { |
40 | dict_table_t* table; |
41 | |
42 | ut_ad(table_name); |
43 | ut_ad(mutex_own(&dict_sys->mutex)); |
44 | |
45 | table = dict_table_check_if_in_cache_low(table_name); |
46 | |
47 | if (table && table->corrupted) { |
48 | ib::error error; |
49 | error << "Table " << table->name << "is corrupted" ; |
50 | if (srv_load_corrupted) { |
51 | error << ", but innodb_force_load_corrupted is set" ; |
52 | } else { |
53 | return(NULL); |
54 | } |
55 | } |
56 | |
57 | if (table == NULL) { |
58 | table = dict_load_table(table_name, true, DICT_ERR_IGNORE_NONE); |
59 | } |
60 | |
61 | ut_ad(!table || table->cached); |
62 | |
63 | return(table); |
64 | } |
65 | |
66 | /**********************************************************************//** |
67 | Returns a table object based on table id. |
68 | @return table, NULL if does not exist */ |
69 | UNIV_INLINE |
70 | dict_table_t* |
71 | dict_table_open_on_id_low( |
72 | /*======================*/ |
73 | table_id_t table_id, /*!< in: table id */ |
74 | dict_err_ignore_t ignore_err, /*!< in: errors to ignore |
75 | when loading the table */ |
76 | ibool open_only_if_in_cache) |
77 | { |
78 | dict_table_t* table; |
79 | ulint fold; |
80 | |
81 | ut_ad(mutex_own(&dict_sys->mutex)); |
82 | |
83 | /* Look for the table name in the hash table */ |
84 | fold = ut_fold_ull(table_id); |
85 | |
86 | HASH_SEARCH(id_hash, dict_sys->table_id_hash, fold, |
87 | dict_table_t*, table, ut_ad(table->cached), |
88 | table->id == table_id); |
89 | if (table == NULL && !open_only_if_in_cache) { |
90 | table = dict_load_table_on_id(table_id, ignore_err); |
91 | } |
92 | |
93 | ut_ad(!table || table->cached); |
94 | |
95 | /* TODO: should get the type information from MySQL */ |
96 | |
97 | return(table); |
98 | } |
99 | |
100 | /**********************************************************************//** |
101 | Checks if a table is in the dictionary cache. |
102 | @return table, NULL if not found */ |
103 | UNIV_INLINE |
104 | dict_table_t* |
105 | dict_table_check_if_in_cache_low( |
106 | /*=============================*/ |
107 | const char* table_name) /*!< in: table name */ |
108 | { |
109 | dict_table_t* table; |
110 | ulint table_fold; |
111 | |
112 | DBUG_ENTER("dict_table_check_if_in_cache_low" ); |
113 | DBUG_PRINT("dict_table_check_if_in_cache_low" , |
114 | ("table: '%s'" , table_name)); |
115 | |
116 | ut_ad(table_name); |
117 | ut_ad(mutex_own(&dict_sys->mutex)); |
118 | |
119 | /* Look for the table name in the hash table */ |
120 | table_fold = ut_fold_string(table_name); |
121 | |
122 | HASH_SEARCH(name_hash, dict_sys->table_hash, table_fold, |
123 | dict_table_t*, table, ut_ad(table->cached), |
124 | !strcmp(table->name.m_name, table_name)); |
125 | DBUG_RETURN(table); |
126 | } |
127 | |