1/* Copyright (c) 2000, 2018, Oracle and/or its affiliates.
2 Copyright (c) 2010, 2018, Monty Program Ab.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17/**
18 @file
19
20 @details
21 Mostly this file is used in the server. But a little part of it is used in
22 mysqlbinlog too (definition of SELECT_DISTINCT and others).
23 The consequence is that 90% of the file is wrapped in \#ifndef MYSQL_CLIENT,
24 except the part which must be in the server and in the client.
25*/
26
27#ifndef SQL_PRIV_INCLUDED
28#define SQL_PRIV_INCLUDED
29
30#ifndef MYSQL_CLIENT
31
32/*
33 Generates a warning that a feature is deprecated. After a specified
34 version asserts that the feature is removed.
35
36 Using it as
37
38 WARN_DEPRECATED(thd, 6,2, "BAD", "'GOOD'");
39
40 Will result in a warning
41
42 "The syntax 'BAD' is deprecated and will be removed in MySQL 6.2. Please
43 use 'GOOD' instead"
44
45 Note that in macro arguments BAD is not quoted, while 'GOOD' is.
46 Note that the version is TWO numbers, separated with a comma
47 (two macro arguments, that is)
48*/
49#define WARN_DEPRECATED(Thd,VerHi,VerLo,Old,New) \
50 do { \
51 compile_time_assert(MYSQL_VERSION_ID < VerHi * 10000 + VerLo * 100); \
52 if (((THD *) Thd) != NULL) \
53 push_warning_printf(((THD *) Thd), Sql_condition::WARN_LEVEL_WARN, \
54 ER_WARN_DEPRECATED_SYNTAX, \
55 ER_THD(((THD *) Thd), ER_WARN_DEPRECATED_SYNTAX), \
56 (Old), (New)); \
57 else \
58 sql_print_warning("The syntax '%s' is deprecated and will be removed " \
59 "in a future release. Please use %s instead.", \
60 (Old), (New)); \
61 } while(0)
62
63
64/*
65 Generates a warning that a feature is deprecated and there is no replacement.
66
67 Using it as
68
69 WARN_DEPRECATED_NO_REPLACEMENT(thd, "BAD");
70
71 Will result in a warning
72
73 "'BAD' is deprecated and will be removed in a future release."
74
75 Note that in macro arguments BAD is not quoted.
76*/
77
78#define WARN_DEPRECATED_NO_REPLACEMENT(Thd,Old) \
79 do { \
80 THD *thd_= ((THD*) Thd); \
81 if (thd_ != NULL) \
82 push_warning_printf(thd_, Sql_condition::WARN_LEVEL_WARN, \
83 ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT, \
84 ER_THD(thd_, ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT), \
85 (Old)); \
86 else \
87 sql_print_warning("'%s' is deprecated and will be removed " \
88 "in a future release.", (Old)); \
89 } while(0)
90
91/*************************************************************************/
92
93#endif
94
95/*
96 This is included in the server and in the client.
97 Options for select set by the yacc parser (stored in lex->options).
98
99 NOTE
100 log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
101 options list are written into binlog. These options can NOT change their
102 values, or it will break replication between version.
103
104 context is encoded as following:
105 SELECT - SELECT_LEX_NODE::options
106 THD - THD::options
107 intern - neither. used only as
108 func(..., select_node->options | thd->options | OPTION_XXX, ...)
109
110 TODO: separate three contexts above, move them to separate bitfields.
111*/
112
113#define SELECT_DISTINCT (1ULL << 0) // SELECT, user
114#define SELECT_STRAIGHT_JOIN (1ULL << 1) // SELECT, user
115#define SELECT_DESCRIBE (1ULL << 2) // SELECT, user
116#define SELECT_SMALL_RESULT (1ULL << 3) // SELECT, user
117#define SELECT_BIG_RESULT (1ULL << 4) // SELECT, user
118#define OPTION_FOUND_ROWS (1ULL << 5) // SELECT, user
119#define OPTION_TO_QUERY_CACHE (1ULL << 6) // SELECT, user
120#define SELECT_NO_JOIN_CACHE (1ULL << 7) // intern
121/** always the opposite of OPTION_NOT_AUTOCOMMIT except when in fix_autocommit() */
122#define OPTION_AUTOCOMMIT (1ULL << 8) // THD, user
123#define OPTION_BIG_SELECTS (1ULL << 9) // THD, user
124#define OPTION_LOG_OFF (1ULL << 10) // THD, user
125#define OPTION_QUOTE_SHOW_CREATE (1ULL << 11) // THD, user
126#define TMP_TABLE_ALL_COLUMNS (1ULL << 12) // SELECT, intern
127#define OPTION_WARNINGS (1ULL << 13) // THD, user
128#define OPTION_AUTO_IS_NULL (1ULL << 14) // THD, user, binlog
129#define OPTION_NO_CHECK_CONSTRAINT_CHECKS (1ULL << 14)
130#define OPTION_SAFE_UPDATES (1ULL << 16) // THD, user
131#define OPTION_BUFFER_RESULT (1ULL << 17) // SELECT, user
132#define OPTION_BIN_LOG (1ULL << 18) // THD, user
133#define OPTION_NOT_AUTOCOMMIT (1ULL << 19) // THD, user
134#define OPTION_BEGIN (1ULL << 20) // THD, intern
135#define OPTION_TABLE_LOCK (1ULL << 21) // THD, intern
136#define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE)
137#define OPTION_KEEP_LOG (1ULL << 23) // THD, user
138
139/* The following is used to detect a conflict with DISTINCT */
140#define SELECT_ALL (1ULL << 24) // SELECT, user, parser
141#define OPTION_GTID_BEGIN (1ULL << 25) // GTID BEGIN found in log
142
143/** The following can be set when importing tables in a 'wrong order'
144 to suppress foreign key checks */
145#define OPTION_NO_FOREIGN_KEY_CHECKS (1ULL << 26) // THD, user, binlog
146/** The following speeds up inserts to InnoDB tables by suppressing unique
147 key checks in some cases */
148#define OPTION_RELAXED_UNIQUE_CHECKS (1ULL << 27) // THD, user, binlog
149#define SELECT_NO_UNLOCK (1ULL << 28) // SELECT, intern
150#define OPTION_SCHEMA_TABLE (1ULL << 29) // SELECT, intern
151/** Flag set if setup_tables already done */
152#define OPTION_SETUP_TABLES_DONE (1ULL << 30) // intern
153/** If not set then the thread will ignore all warnings with level notes. */
154#define OPTION_SQL_NOTES (1ULL << 31) // THD, user
155/**
156 Force the used temporary table to be a MyISAM table (because we will use
157 fulltext functions when reading from it.
158*/
159#define TMP_TABLE_FORCE_MYISAM (1ULL << 32)
160#define OPTION_PROFILING (1ULL << 33)
161/**
162 Indicates that this is a HIGH_PRIORITY SELECT.
163 Currently used only for printing of such selects.
164 Type of locks to be acquired is specified directly.
165*/
166#define SELECT_HIGH_PRIORITY (1ULL << 34) // SELECT, user
167/**
168 Is set in slave SQL thread when there was an
169 error on master, which, when is not reproducible
170 on slave (i.e. the query succeeds on slave),
171 is not terminal to the state of repliation,
172 and should be ignored. The slave SQL thread,
173 however, needs to rollback the effects of the
174 succeeded statement to keep replication consistent.
175*/
176#define OPTION_MASTER_SQL_ERROR (1ULL << 35)
177
178/*
179 Dont report errors for individual rows,
180 But just report error on commit (or read ofcourse)
181 Note! Reserved for use in MySQL Cluster
182*/
183#define OPTION_ALLOW_BATCH (1ULL << 36) // THD, intern (slave)
184#define OPTION_SKIP_REPLICATION (1ULL << 37) // THD, user
185#define OPTION_RPL_SKIP_PARALLEL (1ULL << 38)
186#define OPTION_FOUND_COMMENT (1ULL << 39) // SELECT, intern, parser
187
188/* The rest of the file is included in the server only */
189#ifndef MYSQL_CLIENT
190
191/* @@optimizer_switch flags. These must be in sync with optimizer_switch_typelib */
192#define OPTIMIZER_SWITCH_INDEX_MERGE (1ULL << 0)
193#define OPTIMIZER_SWITCH_INDEX_MERGE_UNION (1ULL << 1)
194#define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION (1ULL << 2)
195#define OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT (1ULL << 3)
196#define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_INTERSECT (1ULL << 4)
197#define deprecated_ENGINE_CONDITION_PUSHDOWN (1ULL << 5)
198#define OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN (1ULL << 6)
199#define OPTIMIZER_SWITCH_DERIVED_MERGE (1ULL << 7)
200#define OPTIMIZER_SWITCH_DERIVED_WITH_KEYS (1ULL << 8)
201#define OPTIMIZER_SWITCH_FIRSTMATCH (1ULL << 9)
202#define OPTIMIZER_SWITCH_LOOSE_SCAN (1ULL << 10)
203#define OPTIMIZER_SWITCH_MATERIALIZATION (1ULL << 11)
204#define OPTIMIZER_SWITCH_IN_TO_EXISTS (1ULL << 12)
205#define OPTIMIZER_SWITCH_SEMIJOIN (1ULL << 13)
206#define OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE (1ULL << 14)
207#define OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN (1ULL << 15)
208#define OPTIMIZER_SWITCH_SUBQUERY_CACHE (1ULL << 16)
209/** If this is off, MRR is never used. */
210#define OPTIMIZER_SWITCH_MRR (1ULL << 17)
211/**
212 If OPTIMIZER_SWITCH_MRR is on and this is on, MRR is used depending on a
213 cost-based choice ("automatic"). If OPTIMIZER_SWITCH_MRR is on and this is
214 off, MRR is "forced" (i.e. used as long as the storage engine is capable of
215 doing it).
216*/
217#define OPTIMIZER_SWITCH_MRR_COST_BASED (1ULL << 18)
218#define OPTIMIZER_SWITCH_MRR_SORT_KEYS (1ULL << 19)
219#define OPTIMIZER_SWITCH_OUTER_JOIN_WITH_CACHE (1ULL << 20)
220#define OPTIMIZER_SWITCH_SEMIJOIN_WITH_CACHE (1ULL << 21)
221#define OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL (1ULL << 22)
222#define OPTIMIZER_SWITCH_JOIN_CACHE_HASHED (1ULL << 23)
223#define OPTIMIZER_SWITCH_JOIN_CACHE_BKA (1ULL << 24)
224#define OPTIMIZER_SWITCH_OPTIMIZE_JOIN_BUFFER_SIZE (1ULL << 25)
225#define OPTIMIZER_SWITCH_TABLE_ELIMINATION (1ULL << 26)
226#define OPTIMIZER_SWITCH_EXTENDED_KEYS (1ULL << 27)
227#define OPTIMIZER_SWITCH_EXISTS_TO_IN (1ULL << 28)
228#define OPTIMIZER_SWITCH_ORDERBY_EQ_PROP (1ULL << 29)
229#define OPTIMIZER_SWITCH_COND_PUSHDOWN_FOR_DERIVED (1ULL << 30)
230#define OPTIMIZER_SWITCH_SPLIT_MATERIALIZED (1ULL << 31)
231
232#define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
233 OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
234 OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION | \
235 OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT | \
236 OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN | \
237 OPTIMIZER_SWITCH_DERIVED_MERGE | \
238 OPTIMIZER_SWITCH_DERIVED_WITH_KEYS | \
239 OPTIMIZER_SWITCH_TABLE_ELIMINATION | \
240 OPTIMIZER_SWITCH_EXTENDED_KEYS | \
241 OPTIMIZER_SWITCH_IN_TO_EXISTS | \
242 OPTIMIZER_SWITCH_MATERIALIZATION | \
243 OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE|\
244 OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN|\
245 OPTIMIZER_SWITCH_OUTER_JOIN_WITH_CACHE | \
246 OPTIMIZER_SWITCH_SEMIJOIN_WITH_CACHE | \
247 OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL | \
248 OPTIMIZER_SWITCH_JOIN_CACHE_HASHED | \
249 OPTIMIZER_SWITCH_JOIN_CACHE_BKA | \
250 OPTIMIZER_SWITCH_SUBQUERY_CACHE | \
251 OPTIMIZER_SWITCH_SEMIJOIN | \
252 OPTIMIZER_SWITCH_FIRSTMATCH | \
253 OPTIMIZER_SWITCH_LOOSE_SCAN | \
254 OPTIMIZER_SWITCH_EXISTS_TO_IN | \
255 OPTIMIZER_SWITCH_ORDERBY_EQ_PROP | \
256 OPTIMIZER_SWITCH_COND_PUSHDOWN_FOR_DERIVED | \
257 OPTIMIZER_SWITCH_SPLIT_MATERIALIZED)
258
259/*
260 Replication uses 8 bytes to store SQL_MODE in the binary log. The day you
261 use strictly more than 64 bits by adding one more define above, you should
262 contact the replication team because the replication code should then be
263 updated (to store more bytes on disk).
264
265 NOTE: When adding new SQL_MODE types, make sure to also add them to
266 the scripts used for creating the MySQL system tables
267 in scripts/mysql_system_tables.sql and scripts/mysql_system_tables_fix.sql
268
269*/
270
271/*
272 Flags below are set when we perform
273 context analysis of the statement and make
274 subqueries non-const. It prevents subquery
275 evaluation at context analysis stage.
276*/
277
278/*
279 Don't evaluate this subquery during statement prepare even if
280 it's a constant one. The flag is switched off in the end of
281 mysqld_stmt_prepare.
282*/
283#define CONTEXT_ANALYSIS_ONLY_PREPARE 1
284/*
285 Special JOIN::prepare mode: changing of query is prohibited.
286 When creating a view, we need to just check its syntax omitting
287 any optimizations: afterwards definition of the view will be
288 reconstructed by means of ::print() methods and written to
289 to an .frm file. We need this definition to stay untouched.
290*/
291#define CONTEXT_ANALYSIS_ONLY_VIEW 2
292/*
293 Don't evaluate this subquery during derived table prepare even if
294 it's a constant one.
295*/
296#define CONTEXT_ANALYSIS_ONLY_DERIVED 4
297/*
298 Don't evaluate constant sub-expressions of virtual column
299 expressions when opening tables
300*/
301#define CONTEXT_ANALYSIS_ONLY_VCOL_EXPR 8
302
303
304/*
305 Uncachable causes:
306*/
307/* This subquery has fields from outer query (put by user) */
308#define UNCACHEABLE_DEPENDENT_GENERATED 1
309/* This subquery contains functions with random result */
310#define UNCACHEABLE_RAND 2
311/* This subquery contains functions with side effect */
312#define UNCACHEABLE_SIDEEFFECT 4
313/* Forcing to save JOIN tables for explain */
314#define UNCACHEABLE_EXPLAIN 8
315/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
316#define UNCACHEABLE_UNITED 16
317#define UNCACHEABLE_CHECKOPTION 32
318/*
319 This subquery has fields from outer query injected during
320 transformation process
321*/
322#define UNCACHEABLE_DEPENDENT_INJECTED 64
323/* This subquery has fields from outer query (any nature) */
324#define UNCACHEABLE_DEPENDENT (UNCACHEABLE_DEPENDENT_GENERATED | \
325 UNCACHEABLE_DEPENDENT_INJECTED)
326
327/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
328#define UNDEF_POS (-1)
329
330#define IN_SUBQUERY_CONVERSION_THRESHOLD 1000
331
332#endif /* !MYSQL_CLIENT */
333
334/* BINLOG_DUMP options */
335
336#define BINLOG_DUMP_NON_BLOCK 1
337#define BINLOG_SEND_ANNOTATE_ROWS_EVENT 2
338
339#ifndef MYSQL_CLIENT
340
341/*
342 Some defines for exit codes for ::is_equal class functions.
343*/
344#define IS_EQUAL_NO 0
345#define IS_EQUAL_YES 1
346#define IS_EQUAL_PACK_LENGTH 2
347
348enum enum_parsing_place
349{
350 NO_MATTER,
351 IN_HAVING,
352 SELECT_LIST,
353 IN_WHERE,
354 IN_ON,
355 IN_GROUP_BY,
356 IN_ORDER_BY,
357 IN_UPDATE_ON_DUP_KEY,
358 IN_PART_FUNC,
359 PARSING_PLACE_SIZE /* always should be the last */
360};
361
362
363class sys_var;
364
365enum enum_yes_no_unknown
366{
367 TVL_YES, TVL_NO, TVL_UNKNOWN
368};
369
370#ifdef MYSQL_SERVER
371
372/*
373 External variables
374*/
375
376
377/* sql_yacc.cc */
378#ifndef DBUG_OFF
379extern void turn_parser_debug_on();
380
381#endif
382
383/**
384 convert a hex digit into number.
385*/
386
387inline int hexchar_to_int(char c)
388{
389 if (c <= '9' && c >= '0')
390 return c-'0';
391 c|=32;
392 if (c <= 'f' && c >= 'a')
393 return c-'a'+10;
394 return -1;
395}
396
397/* This must match the path length limit in the ER_NOT_RW_DIR error msg. */
398#define ER_NOT_RW_DIR_PATHSIZE 200
399
400#define IS_TABLESPACES_TABLESPACE_NAME 0
401#define IS_TABLESPACES_ENGINE 1
402#define IS_TABLESPACES_TABLESPACE_TYPE 2
403#define IS_TABLESPACES_LOGFILE_GROUP_NAME 3
404#define IS_TABLESPACES_EXTENT_SIZE 4
405#define IS_TABLESPACES_AUTOEXTEND_SIZE 5
406#define IS_TABLESPACES_MAXIMUM_SIZE 6
407#define IS_TABLESPACES_NODEGROUP_ID 7
408#define IS_TABLESPACES_TABLESPACE_COMMENT 8
409
410bool db_name_is_in_ignore_db_dirs_list(const char *dbase);
411
412#endif /* MYSQL_SERVER */
413
414#endif /* MYSQL_CLIENT */
415
416#endif /* SQL_PRIV_INCLUDED */
417