MySQL  8.0.21
Source Code Documentation
show.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
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 
26 class Item;
27 class String;
28 class THD;
29 class SELECT_LEX;
30 class Table_ident;
31 struct YYLTYPE;
32 typedef YYLTYPE POS;
33 
34 namespace dd {
35 namespace 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 - YYLTYPE 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 SELECT_LEX 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 - YYLTYPE 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 SELECT_LEX 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 - YYLTYPE 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 SELECT_LEX on success, NULL otherwise.
123 */
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 - YYLTYPE 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 SELECT_LEX on success, NULL otherwise.
202 */
203 SELECT_LEX *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 - YYLTYPE 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 SELECT_LEX 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 - YYLTYPE 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 SELECT_LEX on success, NULL otherwise.
329 */
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 - YYLTYPE 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 SELECT_LEX on success, NULL otherwise.
385 */
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  Definer,
405  Modified,
406  Created,
407  Security_type,
408  Comment,
409  character_set_client,
410  collation_connection,
411  Database_collation AS `Database Collation`
412  FROM
413  (SELECT
414  ROUTINE_SCHEMA AS `Db`,
415  ROUTINE_NAME AS `Name`,
416  ROUTINE_TYPE AS `Type`,
417  DEFINER AS `Definer`,
418  LAST_ALTERED AS `Modified`,
419  CREATED AS `Created`,
420  SECURITY_TYPE AS `Security_type`,
421  ROUTINE_COMMENT AS `Comment`,
422  CHARACTER_SET_CLIENT AS `character_set_client,
423  COLLATION_CONNECTION AS `collation_connection,
424  DATABASE_COLLATION AS `Database Collation`
425  FROM information_schema.routines) routines
426  WHERE Db == '<value>' <-- Default DB or IN clause
427  AND
428  [ Name LIKE "<value>" | @<where_clause@> ]
429  ORDER BY `Db`, `Name`;
430 
431  @endcode
432 
433  @param pos - YYLTYPE position of parsing context.
434  @param thd - Current thread.
435  @param wild - The value of LIKE clause.
436  @param where_cond - @<where_clause@> clause provided by user.
437 
438  @returns pointer to SELECT_LEX on success, NULL otherwise.
439 */
441  Item *where_cond);
442 
443 /**
444  Build a substitute query for SHOW EVENTS
445 
446  For command like,
447  @code
448  SHOW EVENTS [{FROM | IN} schema_name]
449  [LIKE 'pattern' | WHERE expr]
450  @endcode
451 
452  We build following,
453  @code
454  SELECT
455  Db,
456  Name,
457  Definer,
458  Time zone,
459  Type,
460  Execute at,
461  Interval value,
462  Interval field,
463  Starts,
464  Ends,
465  Status,
466  Originator,
467  character_set_client,
468  collation_connection,
469  Database_collation AS Database Collation
470  FROM
471  (SELECT
472  EVENT_SCHEMA AS `Db`,
473  EVENT_NAME AS `Name`,
474  DEFINER AS `Definer`,
475  TIME_ZONE AS `Time zone`,
476  EVENT_TYPE AS `Type`,
477  EXECUTE_AT AS `Execute at`,
478  INTERVAL_VALUE AS `Interval value`,
479  INTERVAL_FIELD AS `Interval field`,
480  STARTS AS `Starts`,
481  ENDS AS `Ends`,
482  STATUS AS `Status`,
483  ORIGINATOR AS `Originator`,
484  CHARACTER_SET_CLIENT AS `character_set_client`,
485  COLLATION_CONNECTION AS `collation_connection`,
486  DATABASE_COLLATION AS `Database Collation`
487  FROM information_schema.events) as events
488  WHERE Db == '<value>' <-- Default DB or IN clause
489  AND
490  [ Name LIKE "<value>" | @<where_clause@> ]
491  ORDER BY `Db`, `Name`;
492 
493  @endcode
494 
495  @param pos - YYLTYPE position of parsing context.
496  @param thd - Current thread.
497  @param wild - The value of LIKE clause.
498  @param where_cond - @<where_clause@> clause provided by user.
499 
500  @returns pointer to SELECT_LEX on success, NULL otherwise.
501 */
502 SELECT_LEX *build_show_events_query(const POS &pos, THD *thd, String *wild,
503  Item *where_cond);
504 
505 } // namespace info_schema
506 } // namespace dd
507 
508 #endif /* SQL_DD_SHOW_H */
SELECT_LEX * 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
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1001
SELECT_LEX * 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
SELECT_LEX * build_show_databases_query(const POS &pos, THD *thd, String *wild, Item *where_cond)
Build a substitute query for SHOW DATABASES.
Definition: show.cc:308
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:164
SELECT_LEX * 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:619
Definition: sql_lex.h:256
SELECT_LEX * 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:762
SELECT_LEX * build_show_triggers_query(const POS &pos, THD *thd, String *wild, Item *where_cond)
Build a substitute query for SHOW TRIGGERS.
Definition: show.cc:926
char * pos
Definition: do_ctype.cc:76
Bison "location" class.
Definition: parse_location.h:43
Definition: item.h:741
SELECT_LEX * 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:1075
SELECT_LEX * 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:501
YYLTYPE POS
Definition: show.h:31
SELECT_LEX * build_show_events_query(const POS &pos, THD *thd, String *wild, Item *where_cond)
Build a substitute query for SHOW EVENTS.
Definition: show.cc:1189
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:799