1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved.
4 Copyright (c) 2013, 2019, MariaDB Corporation.
5 
6 This program is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free Software
8 Foundation; version 2 of the License.
9 
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
17 
18 *****************************************************************************/
19 
20 /**************************************************//**
21 @file include/dict0types.h
22 Data dictionary global types
23 
24 Created 1/8/1996 Heikki Tuuri
25 *******************************************************/
26 
27 #ifndef dict0types_h
28 #define dict0types_h
29 
30 #include <ut0mutex.h>
31 #include <rem0types.h>
32 
33 struct dict_col_t;
34 struct dict_field_t;
35 struct dict_index_t;
36 struct dict_table_t;
37 struct dict_foreign_t;
38 struct dict_v_col_t;
39 
40 struct ind_node_t;
41 struct tab_node_t;
42 struct dict_add_v_col_t;
43 
44 /* Space id and page no where the dictionary header resides */
45 #define	DICT_HDR_SPACE		0	/* the SYSTEM tablespace */
46 #define	DICT_HDR_PAGE_NO	FSP_DICT_HDR_PAGE_NO
47 
48 /* The ibuf table and indexes's ID are assigned as the number
49 DICT_IBUF_ID_MIN plus the space id */
50 #define DICT_IBUF_ID_MIN	0xFFFFFFFF00000000ULL
51 
52 typedef ib_id_t		table_id_t;
53 typedef ib_id_t		index_id_t;
54 
55 /** Maximum transaction identifier */
56 #define TRX_ID_MAX	IB_ID_MAX
57 
58 /** The bit pattern corresponding to TRX_ID_MAX */
59 extern const byte trx_id_max_bytes[8];
60 extern const byte timestamp_max_bytes[7];
61 
62 /** Error to ignore when we load table dictionary into memory. However,
63 the table and index will be marked as "corrupted", and caller will
64 be responsible to deal with corrupted table or index.
65 Note: please define the IGNORE_ERR_* as bits, so their value can
66 be or-ed together */
67 enum dict_err_ignore_t {
68 	DICT_ERR_IGNORE_NONE = 0,	/*!< no error to ignore */
69 	DICT_ERR_IGNORE_FK_NOKEY = 1,	/*!< ignore error if any foreign
70 					key is missing */
71 	DICT_ERR_IGNORE_INDEX_ROOT = 2,	/*!< ignore error if index root
72 					page is FIL_NULL or incorrect value */
73 	DICT_ERR_IGNORE_CORRUPT = 4,	/*!< skip corrupted indexes */
74 	DICT_ERR_IGNORE_RECOVER_LOCK = 8,
75 					/*!< Used when recovering table locks
76 					for resurrected transactions.
77 					Silently load a missing
78 					tablespace, and do not load
79 					incomplete index definitions. */
80 	/** ignore all errors above */
81 	DICT_ERR_IGNORE_ALL = 15,
82 	/** prepare to drop the table; do not attempt to load tablespace */
83 	DICT_ERR_IGNORE_DROP = 31
84 };
85 
86 /** Quiescing states for flushing tables to disk. */
87 enum ib_quiesce_t {
88 	QUIESCE_NONE,
89 	QUIESCE_START,			/*!< Initialise, prepare to start */
90 	QUIESCE_COMPLETE		/*!< All done */
91 };
92 
93 #ifndef UNIV_INNOCHECKSUM
94 typedef ib_mutex_t DictSysMutex;
95 #endif /* !UNIV_INNOCHECKSUM */
96 
97 /** Prefix for tmp tables, adopted from sql/table.h */
98 #define TEMP_FILE_PREFIX		"#sql"
99 #define TEMP_FILE_PREFIX_LENGTH		4
100 #define TEMP_FILE_PREFIX_INNODB		"#sql-ib"
101 
102 #define TEMP_TABLE_PREFIX                "#sql"
103 #define TEMP_TABLE_PATH_PREFIX           "/" TEMP_TABLE_PREFIX
104 
105 /** Table name wrapper for pretty-printing */
106 struct table_name_t
107 {
108 	/** The name in internal representation */
109 	char*	m_name;
110 
111 	/** Default constructor */
table_name_ttable_name_t112 	table_name_t() {}
113 	/** Constructor */
table_name_ttable_name_t114 	table_name_t(char* name) : m_name(name) {}
115 
116 	/** @return the end of the schema name */
dbendtable_name_t117 	const char* dbend() const
118 	{
119 		const char* sep = strchr(m_name, '/');
120 		ut_ad(sep);
121 		return sep;
122 	}
123 
124 	/** @return the length of the schema name, in bytes */
dblentable_name_t125 	size_t dblen() const { return size_t(dbend() - m_name); }
126 
127 	/** Determine the filename-safe encoded table name.
128 	@return	the filename-safe encoded table name */
basenametable_name_t129 	const char* basename() const { return dbend() + 1; }
130 
131 	/** The start of the table basename suffix for partitioned tables */
132 	static const char part_suffix[4];
133 
134 	/** Determine the partition or subpartition name suffix.
135 	@return the partition name
136 	@retval	NULL	if the table is not partitioned */
parttable_name_t137 	const char* part() const { return strstr(basename(), part_suffix); }
138 
139 	/** @return whether this is a temporary or intermediate table name */
140 	inline bool is_temporary() const;
141 };
142 
143 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
144 /** Dump the change buffer at startup */
145 extern my_bool		ibuf_dump;
146 /** Flag to control insert buffer debugging. */
147 extern uint		ibuf_debug;
148 #endif /* UNIV_DEBUG || UNIV_IBUF_DEBUG */
149 
150 /** Shift for spatial status */
151 #define SPATIAL_STATUS_SHIFT	12
152 
153 /** Mask to encode/decode spatial status. */
154 #define SPATIAL_STATUS_MASK	(3U << SPATIAL_STATUS_SHIFT)
155 
156 #if SPATIAL_STATUS_MASK < REC_VERSION_56_MAX_INDEX_COL_LEN
157 # error SPATIAL_STATUS_MASK < REC_VERSION_56_MAX_INDEX_COL_LEN
158 #endif
159 
160 /** whether a col is used in spatial index or regular index
161 Note: the spatial status is part of persistent undo log,
162 so we should not modify the values in MySQL 5.7 */
163 enum spatial_status_t {
164 	/* Unkown status (undo format in 5.7.9) */
165 	SPATIAL_UNKNOWN = 0,
166 
167 	/** Not used in gis index. */
168 	SPATIAL_NONE	= 1,
169 
170 	/** Used in both spatial index and regular index. */
171 	SPATIAL_MIXED	= 2,
172 
173 	/** Only used in spatial index. */
174 	SPATIAL_ONLY	= 3
175 };
176 
177 #endif
178