1 /* Copyright (c) 2011, 2012, 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 Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 
24 #ifndef OPT_EXPLAIN_INCLUDED
25 #define OPT_EXPLAIN_INCLUDED
26 
27 /** @file "EXPLAIN <command>"
28 
29 Single table UPDATE/DELETE commands are explained by the
30 explain_single_table_modification() function.
31 
32 A query expression (complete SELECT query possibly including
33 subqueries and unions), INSERT...SELECT and multitable UPDATE/DELETE
34 commands are explained like this:
35 
36 (1) explain_query_expression()
37 
38 Is the entry point. Forwards the job to explain_unit().
39 
40 (2) explain_unit()
41 
42 Is for a SELECT_LEX_UNIT, prepares, optimizes, explains one JOIN for
43 each "top-level" SELECT_LEXs of the unit (like: all SELECTs of a
44 UNION; but not subqueries), and one JOIN for the fake SELECT_LEX of
45 UNION); each JOIN explain (JOIN::exec()) calls explain_query_specification()
46 
47 (3) explain_query_specification()
48 
49 Is for a single SELECT_LEX (fake or not). It needs a prepared and
50 optimized JOIN, for which it builds the EXPLAIN rows. But it also
51 launches the EXPLAIN process for "inner units" (==subqueries of this
52 SELECT_LEX), by calling explain_unit() for each of them.
53 */
54 
55 #include <my_base.h>
56 
57 class JOIN;
58 class select_result;
59 class select_result_interceptor;
60 class SQL_SELECT;
61 struct TABLE;
62 class THD;
63 
64 
65 extern const char *join_type_str[];
66 
67 bool explain_no_table(THD *thd, JOIN *join, const char *message);
68 bool explain_no_table(THD *thd, const char *message,
69                       ha_rows rows= HA_POS_ERROR);
70 bool explain_single_table_modification(THD *thd,
71                                        TABLE *table,
72                                        const SQL_SELECT *select,
73                                        uint key,
74                                        ha_rows limit,
75                                        bool need_tmp_table,
76                                        bool need_sort,
77                                        bool is_update,
78                                        bool used_key_is_modified= false);
79 bool explain_query_specification(THD *thd, JOIN *join);
80 bool explain_multi_table_modification(THD *thd,
81                                       select_result_interceptor *result);
82 bool explain_query_expression(THD *thd, select_result *result);
83 
84 #endif /* OPT_EXPLAIN_INCLUDED */
85