1/*****************************************************************************
2
3Copyright (c) 2010, 2014, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/******************************************************************//**
20@file include/dict0priv.ic
21Data dictionary system private include file
22
23Created 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/**********************************************************************//**
31Gets a table; loads it to the dictionary cache if necessary. A low-level
32function.
33@return table, NULL if not found */
34UNIV_INLINE
35dict_table_t*
36dict_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/**********************************************************************//**
67Returns a table object based on table id.
68@return table, NULL if does not exist */
69UNIV_INLINE
70dict_table_t*
71dict_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/**********************************************************************//**
101Checks if a table is in the dictionary cache.
102@return table, NULL if not found */
103UNIV_INLINE
104dict_table_t*
105dict_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