1 /* Copyright (c) 2006, 2010, 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
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1335  USA */
15 
16 /**
17   @file
18   File containing constants that can be used throughout the server.
19 
20   @note This file shall not contain or include any declarations of any kinds.
21 */
22 
23 #ifndef SQL_CONST_INCLUDED
24 #define SQL_CONST_INCLUDED
25 
26 #include <mysql_version.h>
27 
28 #define LIBLEN FN_REFLEN-FN_LEN			/* Max l{ngd p} dev */
29 /* extra 4+4 bytes for slave tmp tables */
30 #define MAX_DBKEY_LENGTH (NAME_LEN*2+1+1+4+4)
31 #define MAX_ALIAS_NAME 256
32 #define MAX_FIELD_NAME 34			/* Max colum name length +2 */
33 #define MAX_SYS_VAR_LENGTH 32
34 #define MAX_KEY MAX_INDEXES                     /* Max used keys */
35 #define MAX_REF_PARTS 32			/* Max parts used as ref */
36 
37 /*
38   Maximum length of the data part of an index lookup key.
39 
40   The "data part" is defined as the value itself, not including the
41   NULL-indicator bytes or varchar length bytes ("the Extras"). We need this
42   value because there was a bug where length of the Extras were not counted.
43 
44   You probably need MAX_KEY_LENGTH, not this constant.
45 */
46 #define MAX_DATA_LENGTH_FOR_KEY 3072
47 #if SIZEOF_OFF_T > 4
48 #define MAX_REFLENGTH 8				/* Max length for record ref */
49 #else
50 #define MAX_REFLENGTH 4				/* Max length for record ref */
51 #endif
52 #define MAX_HOSTNAME  61			/* len+1 in mysql.user */
53 #define MAX_CONNECTION_NAME NAME_LEN
54 
55 #define MAX_MBWIDTH		3		/* Max multibyte sequence */
56 #define MAX_FILENAME_MBWIDTH    5
57 #define MAX_FIELD_CHARLENGTH	255
58 /*
59   In MAX_FIELD_VARCHARLENGTH we reserve extra bytes for the overhead:
60   - 2 bytes for the length
61   - 1 byte for NULL bits
62   to avoid the "Row size too large" error for these three corner definitions:
63     CREATE TABLE t1 (c VARBINARY(65533));
64     CREATE TABLE t1 (c VARBINARY(65534));
65     CREATE TABLE t1 (c VARBINARY(65535));
66   Like VARCHAR(65536), they will be converted to BLOB automatically
67   in non-strict mode.
68 */
69 #define MAX_FIELD_VARCHARLENGTH	(65535-2-1)
70 #define MAX_FIELD_BLOBLENGTH UINT_MAX32         /* cf field_blob::get_length() */
71 #define CONVERT_IF_BIGGER_TO_BLOB 512           /* Threshold *in characters*   */
72 
73 /* Max column width +1 */
74 #define MAX_FIELD_WIDTH		(MAX_FIELD_CHARLENGTH*MAX_MBWIDTH+1)
75 
76 #define MAX_BIT_FIELD_LENGTH    64      /* Max length in bits for bit fields */
77 
78 #define MAX_DATE_WIDTH		10	/* YYYY-MM-DD */
79 #define MIN_TIME_WIDTH          10      /* -HHH:MM:SS */
80 #define MAX_TIME_WIDTH          16      /* -DDDDDD HH:MM:SS */
81 #define MAX_TIME_FULL_WIDTH     23      /* -DDDDDD HH:MM:SS.###### */
82 #define MAX_DATETIME_FULL_WIDTH 26	/* YYYY-MM-DD HH:MM:SS.###### */
83 #define MAX_DATETIME_WIDTH	19	/* YYYY-MM-DD HH:MM:SS */
84 #define MAX_DATETIME_COMPRESSED_WIDTH 14  /* YYYYMMDDHHMMSS */
85 #define MAX_DATETIME_PRECISION  6
86 
87 #define MAX_TABLES	(sizeof(table_map)*8-3)	/* Max tables in join */
88 #define PARAM_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-3))
89 #define OUTER_REF_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-2))
90 #define RAND_TABLE_BIT	(((table_map) 1) << (sizeof(table_map)*8-1))
91 #define PSEUDO_TABLE_BITS (PARAM_TABLE_BIT | OUTER_REF_TABLE_BIT | \
92                            RAND_TABLE_BIT)
93 #define CONNECT_STRING_MAXLEN   65535           /* stored in 2 bytes in .frm */
94 #define MAX_FIELDS	4096			/* Limit in the .frm file */
95 #define MAX_PARTITIONS  8192
96 
97 #define MAX_SELECT_NESTING (SELECT_NESTING_MAP_SIZE - 1)
98 
99 #define MAX_SORT_MEMORY 2048*1024
100 #define MIN_SORT_MEMORY 1024
101 
102 /* Some portable defines */
103 
104 #define STRING_BUFFER_USUAL_SIZE 80
105 
106 /* Memory allocated when parsing a statement / saving a statement */
107 #define MEM_ROOT_BLOCK_SIZE       8192
108 #define MEM_ROOT_PREALLOC         8192
109 #define TRANS_MEM_ROOT_BLOCK_SIZE 4096
110 #define TRANS_MEM_ROOT_PREALLOC   4096
111 
112 #define DEFAULT_ERROR_COUNT	64
113 #define EXTRA_RECORDS	10			/* Extra records in sort */
114 #define SCROLL_EXTRA	5			/* Extra scroll-rows. */
115 #define FIELD_NAME_USED ((uint) 32768)		/* Bit set if fieldname used */
116 #define FORM_NAME_USED	((uint) 16384)		/* Bit set if formname used */
117 #define FIELD_NR_MASK	16383			/* To get fieldnumber */
118 #define FERR		-1			/* Error from my_functions */
119 #define CREATE_MODE	0			/* Default mode on new files */
120 #define NAMES_SEP_CHAR	255			/* Char to sep. names */
121 
122 #define READ_RECORD_BUFFER	(uint) (IO_SIZE*8) /* Pointer_buffer_size */
123 #define DISK_BUFFER_SIZE	(uint) (IO_SIZE*16) /* Size of diskbuffer */
124 
125 #define FRM_VER_TRUE_VARCHAR (FRM_VER+4) /* 10 */
126 #define FRM_VER_EXPRESSSIONS (FRM_VER+5) /* 11 */
127 #define FRM_VER_CURRENT  FRM_VER_EXPRESSSIONS
128 
129 /***************************************************************************
130   Configuration parameters
131 ****************************************************************************/
132 
133 #define ACL_CACHE_SIZE		256
134 #define MAX_PASSWORD_LENGTH	32
135 #define HOST_CACHE_SIZE		128
136 #define MAX_ACCEPT_RETRY	10	// Test accept this many times
137 #define MAX_FIELDS_BEFORE_HASH	32
138 #define USER_VARS_HASH_SIZE     16
139 #define SEQUENCES_HASH_SIZE     16
140 #define TABLE_OPEN_CACHE_MIN    200
141 #define TABLE_OPEN_CACHE_DEFAULT 2000
142 #define TABLE_DEF_CACHE_DEFAULT 400
143 /**
144   We must have room for at least 400 table definitions in the table
145   cache, since otherwise there is no chance prepared
146   statements that use these many tables can work.
147   Prepared statements use table definition cache ids (table_map_id)
148   as table version identifiers. If the table definition
149   cache size is less than the number of tables used in a statement,
150   the contents of the table definition cache is guaranteed to rotate
151   between a prepare and execute. This leads to stable validation
152   errors. In future we shall use more stable version identifiers,
153   for now the only solution is to ensure that the table definition
154   cache can contain at least all tables of a given statement.
155 */
156 #define TABLE_DEF_CACHE_MIN     400
157 
158 /**
159  Maximum number of connections default value.
160  151 is larger than Apache's default max children,
161  to avoid "too many connections" error in a common setup.
162 */
163 #define MAX_CONNECTIONS_DEFAULT 151
164 
165 /*
166   Stack reservation.
167   Feel free to raise this by the smallest amount you can to get the
168   "execution_constants" test to pass.
169 */
170 #define STACK_MIN_SIZE          16000   // Abort if less stack during eval.
171 
172 #define STACK_MIN_SIZE_FOR_OPEN (1024*80)
173 #define STACK_BUFF_ALLOC        352     ///< For stack overrun checks
174 #ifndef MYSQLD_NET_RETRY_COUNT
175 #define MYSQLD_NET_RETRY_COUNT  10	///< Abort read after this many int.
176 #endif
177 
178 #define QUERY_ALLOC_BLOCK_SIZE		16384
179 #define QUERY_ALLOC_PREALLOC_SIZE   	24576
180 #define TRANS_ALLOC_BLOCK_SIZE		8192
181 #define TRANS_ALLOC_PREALLOC_SIZE	4096
182 #define RANGE_ALLOC_BLOCK_SIZE		4096
183 #define ACL_ALLOC_BLOCK_SIZE		1024
184 #define UDF_ALLOC_BLOCK_SIZE		1024
185 #define TABLE_ALLOC_BLOCK_SIZE		1024
186 #define WARN_ALLOC_BLOCK_SIZE		2048
187 #define WARN_ALLOC_PREALLOC_SIZE	1024
188 /*
189   Note that if we are using 32K or less, then TCmalloc will use a local
190   heap without locks!
191 */
192 #define SHOW_ALLOC_BLOCK_SIZE           (32768-MALLOC_OVERHEAD)
193 
194 /*
195   The following parameters is to decide when to use an extra cache to
196   optimise seeks when reading a big table in sorted order
197 */
198 #define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
199 #define MIN_ROWS_TO_USE_TABLE_CACHE	 100
200 #define MIN_ROWS_TO_USE_BULK_INSERT	 100
201 
202 /**
203   The following is used to decide if MySQL should use table scanning
204   instead of reading with keys.  The number says how many evaluation of the
205   WHERE clause is comparable to reading one extra row from a table.
206 */
207 #define TIME_FOR_COMPARE         5	//  5 compares == one read
208 #define TIME_FOR_COMPARE_IDX    20
209 
210 #define IDX_BLOCK_COPY_COST  ((double) 1 / TIME_FOR_COMPARE)
211 #define IDX_LOOKUP_COST      ((double) 1 / 8)
212 
213 /**
214   Number of comparisons of table rowids equivalent to reading one row from a
215   table.
216 */
217 #define TIME_FOR_COMPARE_ROWID  (TIME_FOR_COMPARE*100)
218 
219 /* cost1 is better that cost2 only if cost1 + COST_EPS < cost2 */
220 #define COST_EPS  0.001
221 
222 /*
223   For sequential disk seeks the cost formula is:
224     DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
225 
226   The cost of average seek
227     DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
228 */
229 #define DISK_SEEK_BASE_COST ((double)0.9)
230 
231 #define BLOCKS_IN_AVG_SEEK  128
232 
233 #define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
234 
235 
236 /**
237   Number of rows in a reference table when refereed through a not unique key.
238   This value is only used when we don't know anything about the key
239   distribution.
240 */
241 #define MATCHING_ROWS_IN_OTHER_TABLE 10
242 
243 /*
244   Subquery materialization-related constants
245 */
246 #define HEAP_TEMPTABLE_LOOKUP_COST 0.05
247 #define DISK_TEMPTABLE_LOOKUP_COST 1.0
248 #define SORT_INDEX_CMP_COST 0.02
249 
250 
251 #define COST_MAX (DBL_MAX * (1.0 - DBL_EPSILON))
252 
253 #define COST_ADD(c,d) (COST_MAX - (d) > (c) ? (c) + (d) : COST_MAX)
254 
255 #define COST_MULT(c,f) (COST_MAX / (f) > (c) ? (c) * (f) : COST_MAX)
256 
257 
258 #define MY_CHARSET_BIN_MB_MAXLEN 1
259 
260 /** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
261 #define KEY_DEFAULT_PACK_LENGTH 8
262 
263 /** Characters shown for the command in 'show processlist'. */
264 #define PROCESS_LIST_WIDTH 100
265 /* Characters shown for the command in 'information_schema.processlist' */
266 #define PROCESS_LIST_INFO_WIDTH 65535
267 
268 #define PRECISION_FOR_DOUBLE 53
269 #define PRECISION_FOR_FLOAT  24
270 
271 /* -[digits].E+## */
272 #define MAX_FLOAT_STR_LENGTH (FLT_DIG + 6)
273 /* -[digits].E+### */
274 #define MAX_DOUBLE_STR_LENGTH (DBL_DIG + 7)
275 
276 /*
277   Default time to wait before aborting a new client connection
278   that does not respond to "initial server greeting" timely
279 */
280 #define CONNECT_TIMEOUT		10
281  /* Wait 5 minutes before removing thread from thread cache */
282 #define THREAD_CACHE_TIMEOUT	5*60
283 
284 /* The following can also be changed from the command line */
285 #define DEFAULT_CONCURRENCY	10
286 #define DELAYED_LIMIT		100		/**< pause after xxx inserts */
287 #define DELAYED_QUEUE_SIZE	1000
288 #define DELAYED_WAIT_TIMEOUT	(5*60)		/**< Wait for delayed insert */
289 #define MAX_CONNECT_ERRORS	100		///< errors before disabling host
290 
291 #define LONG_TIMEOUT ((ulong) 3600L*24L*365L)
292 
293 /**
294   Maximum length of time zone name that we support (Time zone name is
295   char(64) in db). mysqlbinlog needs it.
296 */
297 #define MAX_TIME_ZONE_NAME_LENGTH       (NAME_LEN + 1)
298 
299 #if defined(__WIN__)
300 
301 #define INTERRUPT_PRIOR -2
302 #define CONNECT_PRIOR	-1
303 #define WAIT_PRIOR	0
304 #define QUERY_PRIOR	2
305 #else
306 #define INTERRUPT_PRIOR 10
307 #define CONNECT_PRIOR	9
308 #define WAIT_PRIOR	8
309 #define QUERY_PRIOR	6
310 #endif /* __WIN92__ */
311 
312 #endif /* SQL_CONST_INCLUDED */
313