1 /* Copyright (c) 2005, 2010, Oracle and/or its affiliates.
2 Copyright (c) 2012, 2016, MariaDB
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
16
17 #ifndef SQL_SHOW_H
18 #define SQL_SHOW_H
19
20 #include "sql_list.h" /* List */
21 #include "handler.h" /* enum_schema_tables */
22 #include "table.h" /* enum_schema_table_state */
23 #include "my_apc.h"
24
25 /* Forward declarations */
26 class JOIN;
27 class String;
28 class THD;
29 class sp_name;
30 struct TABLE_LIST;
31 typedef class st_select_lex SELECT_LEX;
32 struct LEX;
33 typedef struct st_mysql_show_var SHOW_VAR;
34 typedef struct st_schema_table ST_SCHEMA_TABLE;
35 struct TABLE;
36 typedef struct system_status_var STATUS_VAR;
37
38 /* Used by handlers to store things in schema tables */
39 #define IS_FILES_FILE_ID 0
40 #define IS_FILES_FILE_NAME 1
41 #define IS_FILES_FILE_TYPE 2
42 #define IS_FILES_TABLESPACE_NAME 3
43 #define IS_FILES_TABLE_CATALOG 4
44 #define IS_FILES_TABLE_SCHEMA 5
45 #define IS_FILES_TABLE_NAME 6
46 #define IS_FILES_LOGFILE_GROUP_NAME 7
47 #define IS_FILES_LOGFILE_GROUP_NUMBER 8
48 #define IS_FILES_ENGINE 9
49 #define IS_FILES_FULLTEXT_KEYS 10
50 #define IS_FILES_DELETED_ROWS 11
51 #define IS_FILES_UPDATE_COUNT 12
52 #define IS_FILES_FREE_EXTENTS 13
53 #define IS_FILES_TOTAL_EXTENTS 14
54 #define IS_FILES_EXTENT_SIZE 15
55 #define IS_FILES_INITIAL_SIZE 16
56 #define IS_FILES_MAXIMUM_SIZE 17
57 #define IS_FILES_AUTOEXTEND_SIZE 18
58 #define IS_FILES_CREATION_TIME 19
59 #define IS_FILES_LAST_UPDATE_TIME 20
60 #define IS_FILES_LAST_ACCESS_TIME 21
61 #define IS_FILES_RECOVER_TIME 22
62 #define IS_FILES_TRANSACTION_COUNTER 23
63 #define IS_FILES_VERSION 24
64 #define IS_FILES_ROW_FORMAT 25
65 #define IS_FILES_TABLE_ROWS 26
66 #define IS_FILES_AVG_ROW_LENGTH 27
67 #define IS_FILES_DATA_LENGTH 28
68 #define IS_FILES_MAX_DATA_LENGTH 29
69 #define IS_FILES_INDEX_LENGTH 30
70 #define IS_FILES_DATA_FREE 31
71 #define IS_FILES_CREATE_TIME 32
72 #define IS_FILES_UPDATE_TIME 33
73 #define IS_FILES_CHECK_TIME 34
74 #define IS_FILES_CHECKSUM 35
75 #define IS_FILES_STATUS 36
76 #define IS_FILES_EXTRA 37
77
78 typedef enum { WITHOUT_DB_NAME, WITH_DB_NAME } enum_with_db_name;
79 int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
80 Table_specification_st *create_info_arg,
81 enum_with_db_name with_db_name);
82
83 int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table);
84
85 bool append_identifier(THD *thd, String *packet, const char *name, size_t length);
append_identifier(THD * thd,String * packet,const LEX_CSTRING * name)86 static inline bool append_identifier(THD *thd, String *packet, const LEX_CSTRING *name)
87 {
88 return append_identifier(thd, packet, name->str, name->length);
89 }
90 void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
91 int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
92 bool mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
93 List<Item> *field_list, String *buffer);
94 bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
95 void mysqld_show_create_db_get_fields(THD *thd, List<Item> *field_list);
96 bool mysqld_show_create_db(THD *thd, LEX_CSTRING *db_name,
97 LEX_CSTRING *orig_db_name,
98 const DDL_options_st &options);
99
100 void mysqld_list_processes(THD *thd,const char *user,bool verbose);
101 int mysqld_show_status(THD *thd);
102 int mysqld_show_variables(THD *thd,const char *wild);
103 bool mysqld_show_storage_engines(THD *thd);
104 bool mysqld_show_authors(THD *thd);
105 bool mysqld_show_contributors(THD *thd);
106 bool mysqld_show_privileges(THD *thd);
107 char *make_backup_log_name(char *buff, const char *name, const char* log_ext);
108 uint calc_sum_of_all_status(STATUS_VAR *to);
109 bool append_definer(THD *thd, String *buffer, const LEX_CSTRING *definer_user,
110 const LEX_CSTRING *definer_host);
111 int add_status_vars(SHOW_VAR *list);
112 void remove_status_vars(SHOW_VAR *list);
113 void init_status_vars();
114 void free_status_vars();
115 void reset_status_vars();
116 bool show_create_trigger(THD *thd, const sp_name *trg_name);
117 void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
118
119 void init_fill_schema_files_row(TABLE* table);
120 bool schema_table_store_record(THD *thd, TABLE *table);
121 void initialize_information_schema_acl();
122 COND *make_cond_for_info_schema(THD *thd, COND *cond, TABLE_LIST *table);
123
124 ST_SCHEMA_TABLE *find_schema_table(THD *thd, const LEX_CSTRING *table_name,
125 bool *in_plugin);
find_schema_table(THD * thd,const LEX_CSTRING * table_name)126 static inline ST_SCHEMA_TABLE *find_schema_table(THD *thd, const LEX_CSTRING *table_name)
127 { bool unused; return find_schema_table(thd, table_name, &unused); }
128
129 ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
130 int make_schema_select(THD *thd, SELECT_LEX *sel,
131 ST_SCHEMA_TABLE *schema_table);
132 int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
133 bool get_schema_tables_result(JOIN *join,
134 enum enum_schema_table_state executed_place);
135 enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
136 TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list);
137
138 const char* get_one_variable(THD *thd, const SHOW_VAR *variable,
139 enum_var_type value_type, SHOW_TYPE show_type,
140 system_status_var *status_var,
141 const CHARSET_INFO **charset, char *buff,
142 size_t *length);
143
144 /* These functions were under INNODB_COMPATIBILITY_HOOKS */
145 int get_quote_char_for_identifier(THD *thd, const char *name, size_t length);
146 THD *find_thread_by_id(longlong id, bool query_id= false);
147
148 class select_result_explain_buffer;
149 /*
150 SHOW EXPLAIN request object.
151 */
152
153 class Show_explain_request : public Apc_target::Apc_call
154 {
155 public:
156 THD *target_thd; /* thd that we're running SHOW EXPLAIN for */
157 THD *request_thd; /* thd that run SHOW EXPLAIN command */
158
159 /* If true, there was some error when producing EXPLAIN output. */
160 bool failed_to_produce;
161
162 /* SHOW EXPLAIN will be stored here */
163 select_result_explain_buffer *explain_buf;
164
165 /* Query that we've got SHOW EXPLAIN for */
166 String query_str;
167
168 /* Overloaded virtual function */
169 void call_in_target_thread();
170 };
171
172 /**
173 Condition pushdown used for INFORMATION_SCHEMA / SHOW queries.
174 This structure is to implement an optimization when
175 accessing data dictionary data in the INFORMATION_SCHEMA
176 or SHOW commands.
177 When the query contain a TABLE_SCHEMA or TABLE_NAME clause,
178 narrow the search for data based on the constraints given.
179 */
180 typedef struct st_lookup_field_values
181 {
182 /**
183 Value of a TABLE_SCHEMA clause.
184 Note that this value length may exceed @c NAME_LEN.
185 @sa wild_db_value
186 */
187 LEX_CSTRING db_value;
188 /**
189 Value of a TABLE_NAME clause.
190 Note that this value length may exceed @c NAME_LEN.
191 @sa wild_table_value
192 */
193 LEX_CSTRING table_value;
194 /**
195 True when @c db_value is a LIKE clause,
196 false when @c db_value is an '=' clause.
197 */
198 bool wild_db_value;
199 /**
200 True when @c table_value is a LIKE clause,
201 false when @c table_value is an '=' clause.
202 */
203 bool wild_table_value;
204 } LOOKUP_FIELD_VALUES;
205
206 /*
207 INFORMATION_SCHEMA: Execution plan for get_all_tables() call
208 */
209
210 class IS_table_read_plan : public Sql_alloc
211 {
212 public:
IS_table_read_plan()213 IS_table_read_plan() : no_rows(false), trivial_show_command(FALSE) {}
214
215 bool no_rows;
216 /*
217 For EXPLAIN only: For SHOW KEYS and SHOW COLUMNS, we know which
218 db_name.table_name will be read, however for some reason we don't
219 set the fields in this->lookup_field_vals.
220 In order to not have JOIN::save_explain_data() walking over uninitialized
221 data, we set trivial_show_command=true.
222 */
223 bool trivial_show_command;
224
225 LOOKUP_FIELD_VALUES lookup_field_vals;
226 Item *partial_cond;
227
has_db_lookup_value()228 bool has_db_lookup_value()
229 {
230 return (lookup_field_vals.db_value.length &&
231 !lookup_field_vals.wild_db_value);
232 }
has_table_lookup_value()233 bool has_table_lookup_value()
234 {
235 return (lookup_field_vals.table_value.length &&
236 !lookup_field_vals.wild_table_value);
237 }
238 };
239
240 bool optimize_schema_tables_reads(JOIN *join);
241 bool optimize_schema_tables_memory_usage(List<TABLE_LIST> &tables);
242
243 /* Handle the ignored database directories list for SHOW/I_S. */
244 bool ignore_db_dirs_init();
245 void ignore_db_dirs_free();
246 void ignore_db_dirs_reset();
247 bool ignore_db_dirs_process_additions();
248 bool push_ignored_db_dir(char *path);
249 extern char *opt_ignore_db_dirs;
250
251 #endif /* SQL_SHOW_H */
252