MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_priv.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2011, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
26 #ifndef SQL_PRIV_INCLUDED
27 #define SQL_PRIV_INCLUDED
28 
29 #ifndef MYSQL_CLIENT
30 
31 /*
32  Generates a warning that a feature is deprecated.
33 
34  Using it as
35 
36  WARN_DEPRECATED(thd, "BAD", "'GOOD'");
37 
38  Will result in a warning
39 
40  "The syntax 'BAD' is deprecated and will be removed in a
41  future release. Please use 'GOOD' instead"
42 
43  Note that in macro arguments BAD is not quoted, while 'GOOD' is.
44 */
45 #define WARN_DEPRECATED(Thd,Old,New) \
46  do { \
47  if (((THD *) Thd) != NULL) \
48  push_warning_printf(((THD *) Thd), Sql_condition::WARN_LEVEL_WARN, \
49  ER_WARN_DEPRECATED_SYNTAX, \
50  ER(ER_WARN_DEPRECATED_SYNTAX), \
51  (Old), (New)); \
52  else \
53  sql_print_warning("The syntax '%s' is deprecated and will be removed " \
54  "in a future release. Please use %s instead.", \
55  (Old), (New)); \
56  } while(0)
57 
58 /*************************************************************************/
59 
60 #endif
61 
62 /*
63  This is included in the server and in the client.
64  Options for select set by the yacc parser (stored in lex->options).
65 
66  NOTE
67  log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
68  options list are written into binlog. These options can NOT change their
69  values, or it will break replication between version.
70 
71  context is encoded as following:
72  SELECT - SELECT_LEX_NODE::options
73  THD - THD::options
74  intern - neither. used only as
75  func(..., select_node->options | thd->options | OPTION_XXX, ...)
76 
77  TODO: separate three contexts above, move them to separate bitfields.
78 */
79 
80 #define SELECT_DISTINCT (1ULL << 0) // SELECT, user
81 #define SELECT_STRAIGHT_JOIN (1ULL << 1) // SELECT, user
82 #define SELECT_DESCRIBE (1ULL << 2) // SELECT, user
83 #define SELECT_SMALL_RESULT (1ULL << 3) // SELECT, user
84 #define SELECT_BIG_RESULT (1ULL << 4) // SELECT, user
85 #define OPTION_FOUND_ROWS (1ULL << 5) // SELECT, user
86 #define OPTION_TO_QUERY_CACHE (1ULL << 6) // SELECT, user
87 #define SELECT_NO_JOIN_CACHE (1ULL << 7) // intern
88 
89 #define OPTION_AUTOCOMMIT (1ULL << 8) // THD, user
90 #define OPTION_BIG_SELECTS (1ULL << 9) // THD, user
91 #define OPTION_LOG_OFF (1ULL << 10) // THD, user
92 #define OPTION_QUOTE_SHOW_CREATE (1ULL << 11) // THD, user, unused
93 #define TMP_TABLE_ALL_COLUMNS (1ULL << 12) // SELECT, intern
94 #define OPTION_WARNINGS (1ULL << 13) // THD, user
95 #define OPTION_AUTO_IS_NULL (1ULL << 14) // THD, user, binlog
96 #define OPTION_FOUND_COMMENT (1ULL << 15) // SELECT, intern, parser
97 #define OPTION_SAFE_UPDATES (1ULL << 16) // THD, user
98 #define OPTION_BUFFER_RESULT (1ULL << 17) // SELECT, user
99 #define OPTION_BIN_LOG (1ULL << 18) // THD, user
100 #define OPTION_NOT_AUTOCOMMIT (1ULL << 19) // THD, user
101 #define OPTION_BEGIN (1ULL << 20) // THD, intern
102 #define OPTION_TABLE_LOCK (1ULL << 21) // THD, intern
103 #define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE)
104 /* 23rd bit is unused. It was occupied by OPTION_KEEP_LOG. */
105 
106 /* The following is used to detect a conflict with DISTINCT */
107 #define SELECT_ALL (1ULL << 24) // SELECT, user, parser
108 
110 #define OPTION_NO_FOREIGN_KEY_CHECKS (1ULL << 26) // THD, user, binlog
111 
113 #define OPTION_RELAXED_UNIQUE_CHECKS (1ULL << 27) // THD, user, binlog
114 #define SELECT_NO_UNLOCK (1ULL << 28) // SELECT, intern
115 #define OPTION_SCHEMA_TABLE (1ULL << 29) // SELECT, intern
116 
117 #define OPTION_SETUP_TABLES_DONE (1ULL << 30) // intern
118 
119 #define OPTION_SQL_NOTES (1ULL << 31) // THD, user
120 
124 #define TMP_TABLE_FORCE_MYISAM (1ULL << 32)
125 #define OPTION_PROFILING (1ULL << 33)
126 
131 #define SELECT_HIGH_PRIORITY (1ULL << 34) // SELECT, user
132 
141 #define OPTION_MASTER_SQL_ERROR (1ULL << 35)
142 
143 /*
144  Dont report errors for individual rows,
145  But just report error on commit (or read ofcourse)
146  Note! Reserved for use in MySQL Cluster
147 */
148 #define OPTION_ALLOW_BATCH (ULL(1) << 36) // THD, intern (slave)
149 
150 /*
151  Check how many bytes are available on buffer.
152 
153  @param buf_start Pointer to buffer start.
154  @param buf_current Pointer to the current position on buffer.
155  @param buf_len Buffer length.
156 
157  @return Number of bytes available on event buffer.
158 */
159 template <class T> T available_buffer(const char* buf_start,
160  const char* buf_current,
161  T buf_len)
162 {
163  return buf_len - (buf_current - buf_start);
164 }
165 
166 /*
167  Check if jump value is within buffer limits.
168 
169  @param jump Number of positions we want to advance.
170  @param buf_start Pointer to buffer start
171  @param buf_current Pointer to the current position on buffer.
172  @param buf_len Buffer length.
173 
174  @return True If jump value is within buffer limits.
175  False Otherwise.
176 */
177 template <class T> bool valid_buffer_range(T jump,
178  const char* buf_start,
179  const char* buf_current,
180  T buf_len)
181 {
182  return (jump <= available_buffer(buf_start, buf_current, buf_len));
183 }
184 
185 /* The rest of the file is included in the server only */
186 #ifndef MYSQL_CLIENT
187 
188 /* @@optimizer_switch flags. These must be in sync with optimizer_switch_typelib */
189 #define OPTIMIZER_SWITCH_INDEX_MERGE (1ULL << 0)
190 #define OPTIMIZER_SWITCH_INDEX_MERGE_UNION (1ULL << 1)
191 #define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION (1ULL << 2)
192 #define OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT (1ULL << 3)
193 #define OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN (1ULL << 4)
194 #define OPTIMIZER_SWITCH_INDEX_CONDITION_PUSHDOWN (1ULL << 5)
195 
196 #define OPTIMIZER_SWITCH_MRR (1ULL << 6)
197 
203 #define OPTIMIZER_SWITCH_MRR_COST_BASED (1ULL << 7)
204 #define OPTIMIZER_SWITCH_BNL (1ULL << 8)
205 #define OPTIMIZER_SWITCH_BKA (1ULL << 9)
206 #define OPTIMIZER_SWITCH_MATERIALIZATION (1ULL << 10)
207 #define OPTIMIZER_SWITCH_SEMIJOIN (1ULL << 11)
208 #define OPTIMIZER_SWITCH_LOOSE_SCAN (1ULL << 12)
209 #define OPTIMIZER_SWITCH_FIRSTMATCH (1ULL << 13)
210 #define OPTIMIZER_SWITCH_SUBQ_MAT_COST_BASED (1ULL << 14)
211 #define OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS (1ULL << 15)
212 #define OPTIMIZER_SWITCH_LAST (1ULL << 16)
213 
218 #define OPTIMIZER_SWITCH_ALL 1
219 
220 /*
221  The following must be kept in sync with optimizer_switch string in
222  sys_vars.cc.
223 */
224 #ifdef OPTIMIZER_SWITCH_ALL
225 #define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
226  OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
227  OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION | \
228  OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT | \
229  OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN |\
230  OPTIMIZER_SWITCH_INDEX_CONDITION_PUSHDOWN | \
231  OPTIMIZER_SWITCH_MRR | \
232  OPTIMIZER_SWITCH_MRR_COST_BASED | \
233  OPTIMIZER_SWITCH_BNL | \
234  OPTIMIZER_SWITCH_MATERIALIZATION | \
235  OPTIMIZER_SWITCH_SEMIJOIN | \
236  OPTIMIZER_SWITCH_LOOSE_SCAN | \
237  OPTIMIZER_SWITCH_FIRSTMATCH | \
238  OPTIMIZER_SWITCH_SUBQ_MAT_COST_BASED | \
239  OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS)
240 #else
241 #define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
242  OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
243  OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION | \
244  OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT | \
245  OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN |\
246  OPTIMIZER_SWITCH_INDEX_CONDITION_PUSHDOWN | \
247  OPTIMIZER_SWITCH_MRR | \
248  OPTIMIZER_SWITCH_MRR_COST_BASED | \
249  OPTIMIZER_SWITCH_BNL | \
250  OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS)
251 #endif
252 /*
253  Replication uses 8 bytes to store SQL_MODE in the binary log. The day you
254  use strictly more than 64 bits by adding one more define above, you should
255  contact the replication team because the replication code should then be
256  updated (to store more bytes on disk).
257 
258  NOTE: When adding new SQL_MODE types, make sure to also add them to
259  the scripts used for creating the MySQL system tables
260  in scripts/mysql_system_tables.sql and scripts/mysql_system_tables_fix.sql
261 
262 */
263 
264 /*
265  Flags below are set when we perform
266  context analysis of the statement and make
267  subqueries non-const. It prevents subquery
268  evaluation at context analysis stage.
269 */
270 
271 /*
272  Don't evaluate this subquery during statement prepare even if
273  it's a constant one. The flag is switched off in the end of
274  mysqld_stmt_prepare.
275 */
276 #define CONTEXT_ANALYSIS_ONLY_PREPARE 1
277 /*
278  Special JOIN::prepare mode: changing of query is prohibited.
279  When creating a view, we need to just check its syntax omitting
280  any optimizations: afterwards definition of the view will be
281  reconstructed by means of ::print() methods and written to
282  to an .frm file. We need this definition to stay untouched.
283 */
284 #define CONTEXT_ANALYSIS_ONLY_VIEW 2
285 /*
286  Don't evaluate this subquery during derived table prepare even if
287  it's a constant one.
288 */
289 #define CONTEXT_ANALYSIS_ONLY_DERIVED 4
290 
291 // uncachable cause
292 #define UNCACHEABLE_DEPENDENT 1
293 #define UNCACHEABLE_RAND 2
294 #define UNCACHEABLE_SIDEEFFECT 4
295 
296 #define UNCACHEABLE_EXPLAIN 8
297 /* For uncorrelated SELECT in an UNION with some correlated SELECTs */
298 #define UNCACHEABLE_UNITED 16
299 #define UNCACHEABLE_CHECKOPTION 32
300 
301 /*
302  Some defines for exit codes for ::is_equal class functions.
303 */
304 #define IS_EQUAL_NO 0
305 #define IS_EQUAL_YES 1
306 #define IS_EQUAL_PACK_LENGTH 2
307 
308 enum enum_parsing_place
309 {
310  NO_MATTER,
311  IN_HAVING,
312  SELECT_LIST,
313  IN_WHERE,
314  IN_ON
315 };
316 
317 
318 enum enum_var_type
319 {
320  OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
321 };
322 
323 class sys_var;
324 
325 enum enum_yes_no_unknown
326 {
327  TVL_YES, TVL_NO, TVL_UNKNOWN
328 };
329 
330 #ifdef MYSQL_SERVER
331 
332 #endif /* MYSQL_SERVER */
333 
334 #ifdef MYSQL_SERVER
335 /*
336  External variables
337 */
338 
339 /* sql_yacc.cc */
340 #ifndef DBUG_OFF
341 extern void turn_parser_debug_on();
342 
343 #endif
344 
349 inline int hexchar_to_int(char c)
350 {
351  if (c <= '9' && c >= '0')
352  return c-'0';
353  c|=32;
354  if (c <= 'f' && c >= 'a')
355  return c-'a'+10;
356  return -1;
357 }
358 
359 /* This must match the path length limit in the ER_NOT_RW_DIR error msg. */
360 #define ER_NOT_RW_DIR_PATHSIZE 200
361 
362 #define IS_TABLESPACES_TABLESPACE_NAME 0
363 #define IS_TABLESPACES_ENGINE 1
364 #define IS_TABLESPACES_TABLESPACE_TYPE 2
365 #define IS_TABLESPACES_LOGFILE_GROUP_NAME 3
366 #define IS_TABLESPACES_EXTENT_SIZE 4
367 #define IS_TABLESPACES_AUTOEXTEND_SIZE 5
368 #define IS_TABLESPACES_MAXIMUM_SIZE 6
369 #define IS_TABLESPACES_NODEGROUP_ID 7
370 #define IS_TABLESPACES_TABLESPACE_COMMENT 8
371 
372 #endif /* MYSQL_SERVER */
373 
374 #endif /* MYSQL_CLIENT */
375 
376 #endif /* SQL_PRIV_INCLUDED */