1 /* Copyright (c) 2006, 2021, 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 /**
24   @file
25   File containing constants that can be used throughout the server.
26 
27   @note This file shall not contain any includes of any kinds.
28 */
29 
30 #ifndef SQL_CONST_INCLUDED
31 #define SQL_CONST_INCLUDED
32 
33 #define LIBLEN FN_REFLEN-FN_LEN			/* Max l{ngd p} dev */
34 /* extra 4+4 bytes for slave tmp tables */
35 #define MAX_DBKEY_LENGTH (NAME_LEN*2+1+1+4+4)
36 #define MAX_ALIAS_NAME 256
37 #define MAX_FIELD_NAME 34			/* Max colum name length +2 */
38 #define MAX_SYS_VAR_LENGTH 32
39 #define MAX_KEY MAX_INDEXES                     /* Max used keys */
40 #define MAX_REF_PARTS 16U			/* Max parts used as ref */
41 #define MAX_KEY_LENGTH 3072U			/* max possible key */
42 #if SIZEOF_OFF_T > 4
43 #define MAX_REFLENGTH 8				/* Max length for record ref */
44 #else
45 #define MAX_REFLENGTH 4				/* Max length for record ref */
46 #endif
47 #define MAX_HOSTNAME  61			/* len+1 in mysql.user */
48 
49 #define MAX_MBWIDTH		3		/* Max multibyte sequence */
50 #define MAX_FIELD_CHARLENGTH	255
51 #define MAX_FIELD_VARCHARLENGTH	65535
52 #define MAX_FIELD_BLOBLENGTH UINT_MAX32     /* cf field_blob::get_length() */
53 /**
54   CHAR and VARCHAR fields longer than this number of characters are converted
55   to BLOB.
56   Non-character fields longer than this number of bytes are converted to BLOB.
57   Comparisons should be '>' or '<='.
58 */
59 #define CONVERT_IF_BIGGER_TO_BLOB 512		/* Used for CREATE ... SELECT */
60 
61 /* Max column width +1 */
62 #define MAX_FIELD_WIDTH		(MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1)
63 
64 #define MAX_BIT_FIELD_LENGTH    64      /* Max length in bits for bit fields */
65 
66 #define MAX_DATE_WIDTH		10	/* YYYY-MM-DD */
67 #define MAX_TIME_WIDTH          10      /* -838:59:59 */
68 #define MAX_TIME_FULL_WIDTH     23      /* -DDDDDD HH:MM:SS.###### */
69 #define MAX_DATETIME_FULL_WIDTH 29	/* YYYY-MM-DD HH:MM:SS.###### AM */
70 #define MAX_DATETIME_WIDTH	19	/* YYYY-MM-DD HH:MM:SS */
71 #define MAX_DATETIME_COMPRESSED_WIDTH 14  /* YYYYMMDDHHMMSS */
72 
73 #define DATE_INT_DIGITS       8         /* YYYYMMDD       */
74 #define TIME_INT_DIGITS       7         /* hhhmmss        */
75 #define DATETIME_INT_DIGITS  14         /* YYYYMMDDhhmmss */
76 
77 #define MAX_TABLES	(sizeof(table_map)*8-3)	/* Max tables in join */
78 #define PARAM_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-3))
79 #define OUTER_REF_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-2))
80 #define RAND_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-1))
81 #define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \
82                            RAND_TABLE_BIT)
83 #define MAX_FIELDS	4096			/* Limit in the .frm file */
84 #define MAX_PARTITIONS  8192
85 
86 #define MAX_SELECT_NESTING (sizeof(nesting_map)*8-1)
87 
88 #define DEFAULT_SORT_MEMORY (256UL* 1024UL)
89 #define MIN_SORT_MEMORY     (32UL * 1024UL)
90 
91 /* Some portable defines */
92 
93 #define STRING_BUFFER_USUAL_SIZE 80
94 
95 /* Memory allocated when parsing a statement / saving a statement */
96 #define MEM_ROOT_BLOCK_SIZE       8192
97 #define MEM_ROOT_PREALLOC         8192
98 #define TRANS_MEM_ROOT_BLOCK_SIZE 4096
99 #define TRANS_MEM_ROOT_PREALLOC   4096
100 
101 #define DEFAULT_ERROR_COUNT	64
102 #define EXTRA_RECORDS	10			/* Extra records in sort */
103 #define SCROLL_EXTRA	5			/* Extra scroll-rows. */
104 #define FIELD_NAME_USED ((uint) 32768)		/* Bit set if fieldname used */
105 #define FORM_NAME_USED	((uint) 16384)		/* Bit set if formname used */
106 #define FIELD_NR_MASK	16383			/* To get fieldnumber */
107 #define FERR		-1			/* Error from my_functions */
108 #define CREATE_MODE	0			/* Default mode on new files */
109 #define NAMES_SEP_CHAR	'\377'			/* Char to sep. names */
110 
111 #define READ_RECORD_BUFFER	(uint) (IO_SIZE*8) /* Pointer_buffer_size */
112 #define DISK_BUFFER_SIZE	(uint) (IO_SIZE*16) /* Size of diskbuffer */
113 
114 /***************************************************************************
115   Configuration parameters
116 ****************************************************************************/
117 
118 #define ACL_CACHE_SIZE		256
119 #define MAX_PASSWORD_LENGTH	32
120 #define HOST_CACHE_SIZE		128
121 #define MAX_ACCEPT_RETRY	10	// Test accept this many times
122 #define MAX_FIELDS_BEFORE_HASH	32
123 #define USER_VARS_HASH_SIZE     16
124 #define TABLE_OPEN_CACHE_MIN    400
125 #define TABLE_OPEN_CACHE_DEFAULT 2000
126 #define TABLE_DEF_CACHE_DEFAULT 400
127 /**
128   Maximum number of connections default value.
129   151 is larger than Apache's default max children,
130   to avoid "too many connections" error in a common setup.
131 */
132 #define MAX_CONNECTIONS_DEFAULT 151
133 /**
134   We must have room for at least 400 table definitions in the table
135   cache, since otherwise there is no chance prepared
136   statements that use these many tables can work.
137   Prepared statements use table definition cache ids (table_map_id)
138   as table version identifiers. If the table definition
139   cache size is less than the number of tables used in a statement,
140   the contents of the table definition cache is guaranteed to rotate
141   between a prepare and execute. This leads to stable validation
142   errors. In future we shall use more stable version identifiers,
143   for now the only solution is to ensure that the table definition
144   cache can contain at least all tables of a given statement.
145 */
146 #define TABLE_DEF_CACHE_MIN     400
147 
148 /*
149   Stack reservation.
150   Feel free to raise this by the smallest amount you can to get the
151   "execution_constants" test to pass.
152 */
153 #define STACK_MIN_SIZE          16000   // Abort if less stack during eval.
154 
155 #define STACK_MIN_SIZE_FOR_OPEN 1024*80
156 
157 #if defined( __SUNPRO_CC)
158 #define STACK_BUFF_ALLOC        352*2   ///< For stack overrun checks
159 #else
160 #define STACK_BUFF_ALLOC        352     ///< For stack overrun checks
161 #endif
162 
163 #ifndef MYSQLD_NET_RETRY_COUNT
164 #define MYSQLD_NET_RETRY_COUNT  10	///< Abort read after this many int.
165 #endif
166 
167 #define QUERY_ALLOC_BLOCK_SIZE		8192
168 #define QUERY_ALLOC_PREALLOC_SIZE   	8192
169 #define TRANS_ALLOC_BLOCK_SIZE		4096
170 #define TRANS_ALLOC_PREALLOC_SIZE	4096
171 #define RANGE_ALLOC_BLOCK_SIZE		4096
172 #define ACL_ALLOC_BLOCK_SIZE		1024
173 #define UDF_ALLOC_BLOCK_SIZE		1024
174 #define TABLE_ALLOC_BLOCK_SIZE		1024
175 #define WARN_ALLOC_BLOCK_SIZE		2048
176 
177 /*
178   The following parameters is to decide when to use an extra cache to
179   optimise seeks when reading a big table in sorted order
180 */
181 #define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
182 #define MIN_ROWS_TO_USE_TABLE_CACHE	 100
183 #define MIN_ROWS_TO_USE_BULK_INSERT	 100
184 
185 /*
186   For sequential disk seeks the cost formula is:
187     DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
188 
189   The cost of average seek
190     DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
191 */
192 #define DISK_SEEK_BASE_COST (0.9)
193 
194 #define BLOCKS_IN_AVG_SEEK  128
195 
196 #define DISK_SEEK_PROP_COST (0.1/BLOCKS_IN_AVG_SEEK)
197 
198 
199 /**
200   Number of rows in a reference table when refereed through a not unique key.
201   This value is only used when we don't know anything about the key
202   distribution.
203 */
204 #define MATCHING_ROWS_IN_OTHER_TABLE 10
205 
206 #define MY_CHARSET_BIN_MB_MAXLEN 1
207 
208 /** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
209 #define KEY_DEFAULT_PACK_LENGTH 8
210 
211 /** Characters shown for the command in 'show processlist'. */
212 #define PROCESS_LIST_WIDTH 100
213 /* Characters shown for the command in 'information_schema.processlist' */
214 #define PROCESS_LIST_INFO_WIDTH 65535
215 
216 #define PRECISION_FOR_DOUBLE 53
217 #define PRECISION_FOR_FLOAT  24
218 
219 /* -[digits].E+## */
220 #define MAX_FLOAT_STR_LENGTH (FLT_DIG + 6)
221 /* -[digits].E+### */
222 #define MAX_DOUBLE_STR_LENGTH (DBL_DIG + 7)
223 
224 /*
225   Default time to wait before aborting a new client connection
226   that does not respond to "initial server greeting" timely
227 */
228 #define CONNECT_TIMEOUT		10
229 
230 /* The following can also be changed from the command line */
231 #define DEFAULT_CONCURRENCY	10
232 #define DELAYED_LIMIT		100		/**< pause after xxx inserts */
233 #define DELAYED_QUEUE_SIZE	1000
234 #define DELAYED_WAIT_TIMEOUT	5*60		/**< Wait for delayed insert */
235 
236 #define LONG_TIMEOUT ((ulong) 3600L*24L*365L)
237 
238 /**
239   Maximum length of time zone name that we support (Time zone name is
240   char(64) in db). mysqlbinlog needs it.
241 */
242 #define MAX_TIME_ZONE_NAME_LENGTH       (NAME_LEN + 1)
243 
244 #if defined(_WIN32)
245 #define INTERRUPT_PRIOR -2
246 #define CONNECT_PRIOR	-1
247 #define WAIT_PRIOR	0
248 #define QUERY_PRIOR	2
249 #else
250 #define INTERRUPT_PRIOR 10
251 #define CONNECT_PRIOR	9
252 #define WAIT_PRIOR	8
253 #define QUERY_PRIOR	6
254 #endif /* _WIN32 */
255 
256 /*
257   Flags below are set when we perform
258   context analysis of the statement and make
259   subqueries non-const. It prevents subquery
260   evaluation at context analysis stage.
261 */
262 
263 /*
264   Don't evaluate this subquery during statement prepare even if
265   it's a constant one. The flag is switched off in the end of
266   mysqld_stmt_prepare.
267 */
268 #define CONTEXT_ANALYSIS_ONLY_PREPARE 1
269 /*
270   Special SELECT_LEX::prepare mode: changing of query is prohibited.
271   When creating a view, we need to just check its syntax omitting
272   any optimizations: afterwards definition of the view will be
273   reconstructed by means of ::print() methods and written to
274   to an .frm file. We need this definition to stay untouched.
275 */
276 #define CONTEXT_ANALYSIS_ONLY_VIEW    2
277 /*
278   Don't evaluate this subquery during derived table prepare even if
279   it's a constant one.
280 */
281 #define CONTEXT_ANALYSIS_ONLY_DERIVED 4
282 
283 
284 /* @@optimizer_switch flags. These must be in sync with optimizer_switch_typelib */
285 #define OPTIMIZER_SWITCH_INDEX_MERGE               (1ULL << 0)
286 #define OPTIMIZER_SWITCH_INDEX_MERGE_UNION         (1ULL << 1)
287 #define OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION    (1ULL << 2)
288 #define OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT     (1ULL << 3)
289 #define OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN (1ULL << 4)
290 #define OPTIMIZER_SWITCH_INDEX_CONDITION_PUSHDOWN  (1ULL << 5)
291 /** If this is off, MRR is never used. */
292 #define OPTIMIZER_SWITCH_MRR                       (1ULL << 6)
293 /**
294    If OPTIMIZER_SWITCH_MRR is on and this is on, MRR is used depending on a
295    cost-based choice ("automatic"). If OPTIMIZER_SWITCH_MRR is on and this is
296    off, MRR is "forced" (i.e. used as long as the storage engine is capable of
297    doing it).
298 */
299 #define OPTIMIZER_SWITCH_MRR_COST_BASED            (1ULL << 7)
300 #define OPTIMIZER_SWITCH_BNL                       (1ULL << 8)
301 #define OPTIMIZER_SWITCH_BKA                       (1ULL << 9)
302 #define OPTIMIZER_SWITCH_MATERIALIZATION           (1ULL << 10)
303 #define OPTIMIZER_SWITCH_SEMIJOIN                  (1ULL << 11)
304 #define OPTIMIZER_SWITCH_LOOSE_SCAN                (1ULL << 12)
305 #define OPTIMIZER_SWITCH_FIRSTMATCH                (1ULL << 13)
306 #define OPTIMIZER_SWITCH_DUPSWEEDOUT               (1ULL << 14)
307 #define OPTIMIZER_SWITCH_SUBQ_MAT_COST_BASED       (1ULL << 15)
308 #define OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS      (1ULL << 16)
309 #define OPTIMIZER_SWITCH_COND_FANOUT_FILTER        (1ULL << 17)
310 #define OPTIMIZER_SWITCH_DERIVED_MERGE             (1ULL << 18)
311 #define OPTIMIZER_SWITCH_PREFER_ORDERING_INDEX     (1ULL << 19)
312 #define OPTIMIZER_SWITCH_LAST                      (1ULL << 20)
313 
314 #define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
315                                   OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
316                                   OPTIMIZER_SWITCH_INDEX_MERGE_SORT_UNION | \
317                                   OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT | \
318                                   OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN |\
319                                   OPTIMIZER_SWITCH_INDEX_CONDITION_PUSHDOWN | \
320                                   OPTIMIZER_SWITCH_MRR | \
321                                   OPTIMIZER_SWITCH_MRR_COST_BASED | \
322                                   OPTIMIZER_SWITCH_BNL | \
323                                   OPTIMIZER_SWITCH_MATERIALIZATION | \
324                                   OPTIMIZER_SWITCH_SEMIJOIN | \
325                                   OPTIMIZER_SWITCH_LOOSE_SCAN | \
326                                   OPTIMIZER_SWITCH_FIRSTMATCH | \
327                                   OPTIMIZER_SWITCH_DUPSWEEDOUT | \
328                                   OPTIMIZER_SWITCH_SUBQ_MAT_COST_BASED | \
329                                   OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS | \
330                                   OPTIMIZER_SWITCH_COND_FANOUT_FILTER | \
331                                   OPTIMIZER_SWITCH_DERIVED_MERGE | \
332                                   OPTIMIZER_SWITCH_PREFER_ORDERING_INDEX)
333 
334 enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
335 
336 enum enum_mark_columns
337 { MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE, MARK_COLUMNS_TEMP};
338 
339 /*
340   Exit code used by mysqld_exit, exit and _exit function
341   to indicate successful termination of mysqld.
342 */
343 #define MYSQLD_SUCCESS_EXIT 0
344 /*
345   Exit code used by mysqld_exit, exit and _exit function to
346   signify unsuccessful termination of mysqld. The exit
347   code signifies the server should NOT BE RESTARTED AUTOMATICALLY
348   by init systems like systemd.
349 */
350 #define MYSQLD_ABORT_EXIT 1
351 /*
352   Exit code used by mysqld_exit, exit and _exit function to
353   signify unsuccessful termination of mysqld. The exit code
354   signifies the server should be RESTARTED AUTOMATICALLY by
355   init systems like systemd.
356 */
357 #define MYSQLD_FAILURE_EXIT 2
358 
359 #endif /* SQL_CONST_INCLUDED */
360