1 #ifndef DD_TABLE_SHARE_INCLUDED
2 #define DD_TABLE_SHARE_INCLUDED
3 /* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License, version 2.0,
7    as published by the Free Software Foundation.
8 
9    This program is also distributed with certain software (including
10    but not limited to OpenSSL) that is licensed under separate terms,
11    as designated in a particular file or component or in included license
12    documentation.  The authors of MySQL hereby grant you an additional
13    permission to link the program and your derivative works with the
14    separately licensed software that they have included with MySQL.
15 
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License, version 2.0, for more details.
20 
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
24 
25 #include <sys/types.h>
26 
27 #include "m_ctype.h"
28 #include "my_inttypes.h"
29 #include "my_sys.h"            // get_charset
30 #include "sql/dd/object_id.h"  // dd::Object_id
31 
32 class Field;
33 class KEY_PART_INFO;
34 class THD;
35 struct TABLE_SHARE;
36 enum enum_field_types : int;
37 
38 namespace dd {
39 class Table;
40 
41 enum class enum_column_types;
42 }  // namespace dd
43 
44 /**
45   Read the table definition from the data-dictionary.
46 
47   @param thd        Thread handler
48   @param share      Fill this with table definition
49   @param table_def  A data-dictionary Table-object describing
50                     table to be used for opening, instead of reading
51                     information from DD.
52 
53   @note
54     This function is called when the table definition is not cached in
55     table_def_cache.
56     The data is returned in 'share', which is alloced by
57     alloc_table_share().. The code assumes that share is initialized.
58 
59   @returns
60    false   OK
61    true    Error
62 */
63 bool open_table_def(THD *thd, TABLE_SHARE *share, const dd::Table &table_def);
64 
65 /**
66   Read the table definition from the data-dictionary.
67 
68   @param thd        Thread handler
69   @param share      Fill this with table definition
70   @param table_def  A data-dictionary Table-object describing
71                     table to be used for opening.
72 
73   @note
74     This function is called from InnoDB, and will suppress errors
75     due to:
76       Invalid collations.
77       Missing FTS parser.
78 
79   @returns
80    false   OK
81    true    Error
82 */
83 bool open_table_def_suppress_invalid_meta_data(THD *thd, TABLE_SHARE *share,
84                                                const dd::Table &table_def);
85 
86 /* Map from new to old field type. */
87 enum_field_types dd_get_old_field_type(dd::enum_column_types type);
88 
dd_get_mysql_charset(dd::Object_id dd_cs_id)89 static inline CHARSET_INFO *dd_get_mysql_charset(dd::Object_id dd_cs_id) {
90   return get_charset(static_cast<uint>(dd_cs_id), MYF(0));
91 }
92 
93 /**
94   Check if the given key_part is suitable to be promoted as part of
95   primary key.
96 
97   @param key_part    - pointer to KEY_PART_INTO which we are checking.
98   @param table_field - Pointer to Field of column used by key_part.
99 
100   @returns
101    true  - Is suitable for primary key.
102    false - if not.
103 */
104 bool is_suitable_for_primary_key(KEY_PART_INFO *key_part, Field *table_field);
105 
106 #endif  // DD_TABLE_SHARE_INCLUDED
107