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