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