MySQL 9.1.0
Source Code Documentation
show.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_DD_SHOW_H
25#define SQL_DD_SHOW_H
26
27class Item;
28class String;
29class THD;
30class Query_block;
31class Table_ident;
32
33#include "sql/parse_location.h"
34
35namespace dd {
36namespace info_schema {
37
38/**
39 Build a substitute query for SHOW CHARSETS.
40
41 For command like,
42 @code
43 SHOW CHARACTER SET [ LIKE 'pattern' | WHERE expr ]
44 @endcode
45
46 We build following,
47 @code
48 SELECT * FROM
49 (SELECT CHARACTER_SET_NAME as `Charset`,
50 DESCRIPTION as `Description`,
51 DEFAULT_COLLATE_NAME as `Default collation`,
52 MAXLEN as `Maxlen`
53 FROM information_schema.character_sets) character_sets
54 [ WHERE Charset LIKE "<value>" | WHERE @<where_clause@> ]
55 ORDER BY `Charset`;
56 @endcode
57
58 @param pos - POS position of parsing context.
59 @param thd - Current thread.
60 @param wild - The value of LIKE clause.
61 @param where_cond - @<where_clause@> clause provided by user.
62
63 @returns pointer to Query_block on success, NULL otherwise.
64*/
66 const String *wild,
67 Item *where_cond);
68
69/**
70 Build a substitute query for SHOW COLLATION.
71
72 For command like,
73 @code
74 SHOW COLLATION [ LIKE 'pattern' | WHERE expr ]
75 @endcode
76
77 We build following,
78 @code
79 SELECT * FROM
80 (SELECT COLLATION_NAME as `Collation`,
81 CHARACTER_SET_NAME as `Charset`,
82 ID as `Id`,
83 IS_COMPILED as `Compiled`,
84 SORTLEN as `Sortlen`,
85 PAD_ATTRIBUTE as `Pad_attribute`,
86 FROM information_schema.collations) collations
87 [ WHERE Collation LIKE "<value>" | WHERE @<where_clause@> ]
88 ORDER BY `Collation`;
89 @endcode
90
91 @param pos - POS position of parsing context.
92 @param thd - Current thread.
93 @param wild - The value of LIKE clause.
94 @param where_cond - @<where_clause@> clause provided by user.
95
96 @returns pointer to Query_block on success, NULL otherwise.
97*/
99 const String *wild, Item *where_cond);
100
101/**
102 Build a substitute query for SHOW DATABASES.
103
104 For command like,
105 @code
106 SHOW DATABASES [ LIKE 'pattern' | WHERE expr ]
107 @endcode
108
109 We build following,
110 @code
111 SELECT Database FROM
112 (SELECT SCHEMA_NAME as `Database`,
113 FROM information_schema.schemata) schemata
114 [ WHERE Database LIKE "<value>" | WHERE @<where_clause@> ]
115 ORDER BY `Database`;
116 @endcode
117
118 @param pos - POS position of parsing context.
119 @param thd - Current thread.
120 @param wild - The value of LIKE clause.
121 @param where_cond - @<where_clause@> clause provided by user.
122
123 @returns pointer to Query_block on success, NULL otherwise.
124*/
125Query_block *build_show_databases_query(const POS &pos, THD *thd, String *wild,
126 Item *where_cond);
127
128/**
129 Build a substitute query for SHOW TABLES / TABLE STATUS.
130
131 For command like,
132 @code
133 SHOW [FULL] TABLES [{FROM | IN} db_name]
134 [LIKE 'pattern' | WHERE expr]
135 OR
136 SHOW TABLE STATUS [{FROM | IN} db_name]
137 [LIKE 'pattern' | WHERE expr]
138 @endcode
139
140 We build following,
141 @code
142 SELECT `Table`,
143 `Table_type`, <-- only with 'FULL'
144
145 // For SHOW TABLE STATUS
146 `Engine`,
147 `Version`,
148 `Row_format`,
149 `Rows`,
150 `Avg_row_length`,
151 `Data_length`,
152 `Max_data_length`,
153 `Index_length`,
154 `Data_free`,
155 `Auto_increment`,
156 `Create_time`,
157 `Update_time`,
158 `Check_time`,
159 `Collation`,
160 `Checksum`,
161 `Create_options`,
162 `Comment`
163 FROM
164 (SELECT TABLE_SCHEMA AS `Database`,
165 TABLE_NAME as `Table`,
166 TABLE_TYPE AS `Table_type`, <-- only with 'FULL'
167
168 // For SHOW TABLE STATUS
169 ENGINE AS `Engine`,
170 VERSION AS `Version`,
171 ROW_FORMAT AS `Row_format`,
172 TABLE_ROWS AS `Rows`,
173 AVG_ROW_LENGTH AS `Avg_row_length`,
174 DATA_LENGTH AS `Data_length`,
175 MAX_DATA_LENGTH AS `Max_data_length`,
176 INDEX_LENGTH AS `Index_length`,
177 DATA_FREE AS `Data_free`,
178 AUTO_INCREMENT AS `Auto_increment`,
179 CREATE_TIME AS `Create_time`,
180 UPDATE_TIME AS `Update_time`,
181 CHECK_TIME AS `Check_time`,
182 TABLE_COLLATION AS `Collation`,
183 CHECKSUM AS `Checksum`,
184 CREATE_OPTIONS AS `Create_options`,
185 TABLE_COMMENT AS `Comment`
186 FROM information_schema.tables) tables
187 WHERE Database == '<value>' <-- Default DB or IN clause
188 AND
189 [ Table LIKE "<value>" | @<where_clause@> ]
190 ORDER BY `Table`;
191 @endcode
192
193 Note that the thd->lex->verbose == true would mean user has
194 provide keyword 'FULL'.
195
196 @param pos - POS position of parsing context.
197 @param thd - Current thread.
198 @param wild - The value of LIKE clause.
199 @param where_cond - @<where_clause@> clause provided by user.
200 @param include_status_fields - If we are handling SHOW TABLE STATUS
201
202 @returns pointer to Query_block on success, NULL otherwise.
203*/
204Query_block *build_show_tables_query(const POS &pos, THD *thd, String *wild,
205 Item *where_cond,
206 bool include_status_fields);
207
208/**
209 Build a substitute query for SHOW COLUMNS/FIELDS OR DESCRIBE.
210
211 For command like,
212 @code
213 SHOW [FULL] COLUMNS
214 {FROM | IN} tbl_name
215 [{FROM | IN} db_name]
216 [LIKE 'pattern' | WHERE expr]
217 OR
218 DESCRIBE tbl_name
219 @endcode
220
221 We build following,
222 @code
223 SELECT Field,
224 Type,
225 Collation, <-- only with 'FULL'
226 Null,
227 Key,
228 Default,
229 Extra,
230 Privileges, <-- only with 'FULL'
231 Comment <-- only with 'FULL'
232 FROM
233 (SELECT TABLE_SCHEMA AS Database,
234 TABLE_NAME AS Table,
235 COLUMN_NAME AS Field,
236 COLUMN_TYPE AS Type,
237 COLLATION_NAME AS Collation, <-- only with 'FULL'
238 IS_NULLABLE AS Null,
239 COLUMN_KEY AS Key,
240 COLUMN_DEFAULT AS Default,
241 EXTRA AS Extra,
242 PRIVILEGES AS Privileges, <-- only with 'FULL'
243 COLUMN_COMMENT AS Comment, <-- only with 'FULL'
244 ORDINAL_POSITION AS Oridinal_position
245 FROM information_schema.columns) columns
246 WHERE Database == '<value>' <-- Default DB or db_name
247 AND
248 Table == 'value' <-- tbl_name
249 AND
250 [ Field LIKE "<value>" | @<where_clause@> ]
251 ORDER BY `Ordinal_position`;
252 @endcode
253
254 Note that the thd->lex->verbose == true would mean user has
255 provide keyword 'FULL'.
256
257 @param pos - POS position of parsing context.
258 @param thd - Current thread.
259 @param table_ident - Database and Table name of table being used.
260 @param wild - The value of LIKE clause.
261 @param where_cond - @<where_clause@> clause provided by user.
262
263 @returns pointer to Query_block on success, NULL otherwise.
264*/
266 Table_ident *table_ident,
267 const String *wild, Item *where_cond);
268
269/**
270 Build a substitute query for SHOW INDEX|KEYS|INDEXES
271
272 For command like,
273 @code
274 SHOW {INDEX | INDEXES | KEYS}
275 {FROM | IN} tbl_name
276 [{FROM | IN} db_name]
277 [WHERE expr]
278 @endcode
279
280 We build following,
281 @code
282 SELECT Table,
283 Non_unique,
284 Key_name,
285 Seq_in_index,
286 Column_name,
287 Collation,
288 Cardinality,
289 Sub_part,
290 Packed,
291 Null,
292 Index_type,
293 Comment,
294 Index_comment,
295 Visible
296 FROM
297 (SELECT Database,
298 Table,
299 Non_unique,
300 Key_name,
301 Seq_in_index,
302 Column_name,
303 Collation,
304 Cardinality,
305 Sub_part,
306 Packed,
307 Null,
308 Index_type,
309 Comment,
310 Index_comment,
311 Visible,
312 INDEX_ORDINAL_POSITION,
313 COLUMN_ORDINAL_POSITION
314 FROM information_schema.show_statistics) statistics
315 WHERE Database == '<value>' <-- Default DB or db_name
316 AND
317 Table == 'value' <-- tbl_name
318 AND
319 [ @<where_clause@> ]
320 ORDER BY INDEX_ORDINAL_POSITION, COLUMN_ORDINAL_POSITION
321 @endcode
322
323
324 @param pos - POS position of parsing context.
325 @param thd - Current thread.
326 @param table_ident - Database and Table name of table being used.
327 @param where_cond - @<where_clause@> clause provided by user.
328
329 @returns pointer to Query_block on success, NULL otherwise.
330*/
331Query_block *build_show_keys_query(const POS &pos, THD *thd,
332 Table_ident *table_ident, Item *where_cond);
333
334/**
335 Build a substitute query for SHOW TRIGGERS
336
337 For command like,
338 @code
339 SHOW TRIGGERS [{FROM | IN} db_name]
340 [LIKE 'pattern' | WHERE expr]
341 @endcode
342
343 We build following,
344 @code
345 SELECT
346 Trigger,
347 Event,
348 Table,
349 Statement,
350 Timing,
351 Created,
352 sql_mode,
353 Definer,
354 character_set_client,
355 collation_connection,
356 Database_collation AS `Database Collation`
357 FROM
358 (SELECT
359 EVENT_OBJECT_SCHEMA AS `Database`
360 TRIGGER_NAME AS `Trigger`,
361 EVENT_MANIPULATION AS `Event`,
362 EVENT_OBJECT_TABLE AS `Table`,
363 ACTION_STATEMENT AS `Statement`,
364 ACTION_TIMING AS `Timing`,
365 CREATED AS `Created`,
366 SQL_MODE AS `sql_mode`,
367 DEFINER AS `Definer`,
368 CHARACTER_SET_CLIENT AS `character_set_client`,
369 COLLATION_CONNECTION AS `collation_connection`,
370 DATABASE_COLLATION AS `Database_collation`,
371 ACTION_ORDER AS `action_order`
372 FROM information_schema.triggers) triggers
373 WHERE Database == '<value>' <-- Default DB or IN clause
374 AND
375 [ Table LIKE "<value>" | @<where_clause@> ]
376 ORDER BY `Table`, `Event`, `Timing`, `action_order`;
377
378 @endcode
379
380 @param pos - POS position of parsing context.
381 @param thd - Current thread.
382 @param wild - The value of LIKE clause.
383 @param where_cond - @<where_clause@> clause provided by user.
384
385 @returns pointer to Query_block on success, NULL otherwise.
386*/
387Query_block *build_show_triggers_query(const POS &pos, THD *thd, String *wild,
388 Item *where_cond);
389
390/**
391 Build a substitute query for SHOW PROCEDURE/FUNCTION STATUS
392
393 For command like,
394 @code
395 SHOW [PROCEDURE|FUNCTION] STATUS
396 [LIKE 'pattern' | WHERE expr]
397 @endcode
398
399 We build following,
400 @code
401 SELECT
402 Db,
403 Name,
404 Type,
405 Language,
406 Definer,
407 Modified,
408 Created,
409 Security_type,
410 Comment,
411 character_set_client,
412 collation_connection,
413 Database_collation AS `Database Collation`
414 FROM
415 (SELECT
416 ROUTINE_SCHEMA AS `Db`,
417 ROUTINE_NAME AS `Name`,
418 ROUTINE_TYPE AS `Type`,
419 EXTERNAL_LANGUAGE AS `Language`,
420 DEFINER AS `Definer`,
421 LAST_ALTERED AS `Modified`,
422 CREATED AS `Created`,
423 SECURITY_TYPE AS `Security_type`,
424 ROUTINE_COMMENT AS `Comment`,
425 CHARACTER_SET_CLIENT AS `character_set_client,
426 COLLATION_CONNECTION AS `collation_connection,
427 DATABASE_COLLATION AS `Database Collation`
428 FROM information_schema.routines) routines
429 WHERE Db == '<value>' <-- Default DB or IN clause
430 AND
431 [ Name LIKE "<value>" | @<where_clause@> ]
432 ORDER BY `Db`, `Name`;
433
434 @endcode
435
436 @param pos - POS position of parsing context.
437 @param thd - Current thread.
438 @param wild - The value of LIKE clause.
439 @param where_cond - @<where_clause@> clause provided by user.
440
441 @returns pointer to Query_block on success, NULL otherwise.
442*/
443Query_block *build_show_procedures_query(const POS &pos, THD *thd, String *wild,
444 Item *where_cond);
445
446/**
447 Build a substitute query for SHOW EVENTS
448
449 For command like,
450 @code
451 SHOW EVENTS [{FROM | IN} schema_name]
452 [LIKE 'pattern' | WHERE expr]
453 @endcode
454
455 We build following,
456 @code
457 SELECT
458 Db,
459 Name,
460 Definer,
461 Time zone,
462 Type,
463 Execute at,
464 Interval value,
465 Interval field,
466 Starts,
467 Ends,
468 Status,
469 Originator,
470 character_set_client,
471 collation_connection,
472 Database_collation AS Database Collation
473 FROM
474 (SELECT
475 EVENT_SCHEMA AS `Db`,
476 EVENT_NAME AS `Name`,
477 DEFINER AS `Definer`,
478 TIME_ZONE AS `Time zone`,
479 EVENT_TYPE AS `Type`,
480 EXECUTE_AT AS `Execute at`,
481 INTERVAL_VALUE AS `Interval value`,
482 INTERVAL_FIELD AS `Interval field`,
483 STARTS AS `Starts`,
484 ENDS AS `Ends`,
485 STATUS AS `Status`,
486 ORIGINATOR AS `Originator`,
487 CHARACTER_SET_CLIENT AS `character_set_client`,
488 COLLATION_CONNECTION AS `collation_connection`,
489 DATABASE_COLLATION AS `Database Collation`
490 FROM information_schema.events) as events
491 WHERE Db == '<value>' <-- Default DB or IN clause
492 AND
493 [ Name LIKE "<value>" | @<where_clause@> ]
494 ORDER BY `Db`, `Name`;
495
496 @endcode
497
498 @param pos - POS position of parsing context.
499 @param thd - Current thread.
500 @param wild - The value of LIKE clause.
501 @param where_cond - @<where_clause@> clause provided by user.
502
503 @returns pointer to Query_block on success, NULL otherwise.
504*/
505Query_block *build_show_events_query(const POS &pos, THD *thd, String *wild,
506 Item *where_cond);
507
508} // namespace info_schema
509} // namespace dd
510
511#endif /* SQL_DD_SHOW_H */
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1159
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: sql_lex.h:297
Query_block * build_show_character_set_query(const POS &pos, THD *thd, const String *wild, Item *where_cond)
Build a substitute query for SHOW CHARSETS.
Definition: show.cc:47
Query_block * build_show_events_query(const POS &pos, THD *thd, String *wild, Item *where_cond)
Build a substitute query for SHOW EVENTS.
Definition: show.cc:1191
Query_block * build_show_keys_query(const POS &pos, THD *thd, Table_ident *table_ident, Item *where_cond)
Build a substitute query for SHOW INDEX|KEYS|INDEXES.
Definition: show.cc:759
Query_block * build_show_triggers_query(const POS &pos, THD *thd, String *wild, Item *where_cond)
Build a substitute query for SHOW TRIGGERS.
Definition: show.cc:923
Query_block * build_show_procedures_query(const POS &pos, THD *thd, String *wild, Item *where_cond)
Build a substitute query for SHOW PROCEDURE/FUNCTION STATUS.
Definition: show.cc:1072
Query_block * build_show_columns_query(const POS &pos, THD *thd, Table_ident *table_ident, const String *wild, Item *where_cond)
Build a substitute query for SHOW COLUMNS/FIELDS OR DESCRIBE.
Definition: show.cc:616
Query_block * build_show_tables_query(const POS &pos, THD *thd, String *wild, Item *where_cond, bool include_status_fields)
Build a substitute query for SHOW TABLES / TABLE STATUS.
Definition: show.cc:498
Query_block * build_show_collation_query(const POS &pos, THD *thd, const String *wild, Item *where_cond)
Build a substitute query for SHOW COLLATION.
Definition: show.cc:162
Query_block * build_show_databases_query(const POS &pos, THD *thd, String *wild, Item *where_cond)
Build a substitute query for SHOW DATABASES.
Definition: show.cc:305
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Bison "location" class.
Definition: parse_location.h:43