1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2021, Oracle and/or its affiliates.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation.  The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 *****************************************************************************/
26 
27 /**************************************************//**
28 @file include/data0type.h
29 Data types
30 
31 Created 1/16/1996 Heikki Tuuri
32 *******************************************************/
33 
34 #ifndef data0type_h
35 #define data0type_h
36 
37 #include "univ.i"
38 
39 extern ulint	data_mysql_default_charset_coll;
40 #define DATA_MYSQL_BINARY_CHARSET_COLL 63
41 
42 /* SQL data type struct */
43 struct dtype_t;
44 
45 /** SQL Like operator comparison types */
46 enum ib_like_t {
47 	IB_LIKE_EXACT,	/**< e.g.  STRING */
48 	IB_LIKE_PREFIX	/**< e.g., STRING% */
49 };
50 
51 /*-------------------------------------------*/
52 /* The 'MAIN TYPE' of a column */
53 #define DATA_MISSING	0	/* missing column */
54 #define	DATA_VARCHAR	1	/* character varying of the
55 				latin1_swedish_ci charset-collation; note
56 				that the MySQL format for this, DATA_BINARY,
57 				DATA_VARMYSQL, is also affected by whether the
58 				'precise type' contains
59 				DATA_MYSQL_TRUE_VARCHAR */
60 #define DATA_CHAR	2	/* fixed length character of the
61 				latin1_swedish_ci charset-collation */
62 #define DATA_FIXBINARY	3	/* binary string of fixed length */
63 #define DATA_BINARY	4	/* binary string */
64 #define DATA_BLOB	5	/* binary large object, or a TEXT type;
65 				if prtype & DATA_BINARY_TYPE == 0, then this is
66 				actually a TEXT column (or a BLOB created
67 				with < 4.0.14; since column prefix indexes
68 				came only in 4.0.14, the missing flag in BLOBs
69 				created before that does not cause any harm) */
70 #define	DATA_INT	6	/* integer: can be any size 1 - 8 bytes */
71 #define	DATA_SYS_CHILD	7	/* address of the child page in node pointer */
72 #define	DATA_SYS	8	/* system column */
73 
74 /* Data types >= DATA_FLOAT must be compared using the whole field, not as
75 binary strings */
76 
77 #define DATA_FLOAT	9
78 #define DATA_DOUBLE	10
79 #define DATA_DECIMAL	11	/* decimal number stored as an ASCII string */
80 #define	DATA_VARMYSQL	12	/* any charset varying length char */
81 #define	DATA_MYSQL	13	/* any charset fixed length char */
82 				/* NOTE that 4.1.1 used DATA_MYSQL and
83 				DATA_VARMYSQL for all character sets, and the
84 				charset-collation for tables created with it
85 				can also be latin1_swedish_ci */
86 
87 /* DATA_POINT&DATA_VAR_POINT are for standard geometry datatype 'point' and
88 DATA_GEOMETRY include all other standard geometry datatypes as described in
89 OGC standard(line_string, polygon, multi_point, multi_polygon,
90 multi_line_string, geometry_collection, geometry).
91 Currently, geometry data is stored in the standard Well-Known Binary(WKB)
92 format (http://www.opengeospatial.org/standards/sfa).
93 We use BLOB as underlying datatype for DATA_GEOMETRY and DATA_VAR_POINT
94 while CHAR for DATA_POINT */
95 #define DATA_GEOMETRY	14	/* geometry datatype of variable length */
96 /* The following two are disabled temporarily, we won't create them in
97 get_innobase_type_from_mysql_type().
98 TODO: We will enable DATA_POINT/them when we come to the fixed-length POINT
99 again. */
100 #define DATA_POINT	15	/* geometry datatype of fixed length POINT */
101 #define DATA_VAR_POINT	16	/* geometry datatype of variable length
102 				POINT, used when we want to store POINT
103 				as BLOB internally */
104 #define DATA_MTYPE_MAX	63	/* dtype_store_for_order_and_null_size()
105 				requires the values are <= 63 */
106 
107 #define DATA_MTYPE_CURRENT_MIN	DATA_VARCHAR	/* minimum value of mtype */
108 #define DATA_MTYPE_CURRENT_MAX	DATA_VAR_POINT	/* maximum value of mtype */
109 /*-------------------------------------------*/
110 /* The 'PRECISE TYPE' of a column */
111 /*
112 Tables created by a MySQL user have the following convention:
113 
114 - In the least significant byte in the precise type we store the MySQL type
115 code (not applicable for system columns).
116 
117 - In the second least significant byte we OR flags DATA_NOT_NULL,
118 DATA_UNSIGNED, DATA_BINARY_TYPE.
119 
120 - In the third least significant byte of the precise type of string types we
121 store the MySQL charset-collation code. In DATA_BLOB columns created with
122 < 4.0.14 we do not actually know if it is a BLOB or a TEXT column. Since there
123 are no indexes on prefixes of BLOB or TEXT columns in < 4.0.14, this is no
124 problem, though.
125 
126 Note that versions < 4.1.2 or < 5.0.1 did not store the charset code to the
127 precise type, since the charset was always the default charset of the MySQL
128 installation. If the stored charset code is 0 in the system table SYS_COLUMNS
129 of InnoDB, that means that the default charset of this MySQL installation
130 should be used.
131 
132 When loading a table definition from the system tables to the InnoDB data
133 dictionary cache in main memory, InnoDB versions >= 4.1.2 and >= 5.0.1 check
134 if the stored charset-collation is 0, and if that is the case and the type is
135 a non-binary string, replace that 0 by the default charset-collation code of
136 this MySQL installation. In short, in old tables, the charset-collation code
137 in the system tables on disk can be 0, but in in-memory data structures
138 (dtype_t), the charset-collation code is always != 0 for non-binary string
139 types.
140 
141 In new tables, in binary string types, the charset-collation code is the
142 MySQL code for the 'binary charset', that is, != 0.
143 
144 For binary string types and for DATA_CHAR, DATA_VARCHAR, and for those
145 DATA_BLOB which are binary or have the charset-collation latin1_swedish_ci,
146 InnoDB performs all comparisons internally, without resorting to the MySQL
147 comparison functions. This is to save CPU time.
148 
149 InnoDB's own internal system tables have different precise types for their
150 columns, and for them the precise type is usually not used at all.
151 */
152 
153 #define DATA_ENGLISH	4	/* English language character string: this
154 				is a relic from pre-MySQL time and only used
155 				for InnoDB's own system tables */
156 #define DATA_ERROR	111	/* another relic from pre-MySQL time */
157 
158 #define DATA_MYSQL_TYPE_MASK 255 /* AND with this mask to extract the MySQL
159 				 type from the precise type */
160 #define DATA_MYSQL_TRUE_VARCHAR 15 /* MySQL type code for the >= 5.0.3
161 				   format true VARCHAR */
162 
163 /* Precise data types for system columns and the length of those columns;
164 NOTE: the values must run from 0 up in the order given! All codes must
165 be less than 256 */
166 #define	DATA_ROW_ID	0	/* row id: a 48-bit integer */
167 #define DATA_ROW_ID_LEN	6	/* stored length for row id */
168 
169 #define DATA_TRX_ID	1	/* transaction id: 6 bytes */
170 #define DATA_TRX_ID_LEN	6
171 
172 #define	DATA_ROLL_PTR	2	/* rollback data pointer: 7 bytes */
173 #define DATA_ROLL_PTR_LEN 7
174 
175 #define	DATA_N_SYS_COLS 3	/* number of system columns defined above */
176 
177 #define	DATA_ITT_N_SYS_COLS	2
178 				/* number of system columns for intrinsic
179 				temporary table */
180 
181 #define DATA_FTS_DOC_ID	3	/* Used as FTS DOC ID column */
182 
183 #define DATA_SYS_PRTYPE_MASK 0xF /* mask to extract the above from prtype */
184 
185 /* Flags ORed to the precise data type */
186 #define DATA_NOT_NULL	256	/* this is ORed to the precise type when
187 				the column is declared as NOT NULL */
188 #define DATA_UNSIGNED	512	/* this id ORed to the precise type when
189 				we have an unsigned integer type */
190 #define	DATA_BINARY_TYPE 1024	/* if the data type is a binary character
191 				string, this is ORed to the precise type:
192 				this only holds for tables created with
193 				>= MySQL-4.0.14 */
194 /* #define	DATA_NONLATIN1	2048 This is a relic from < 4.1.2 and < 5.0.1.
195 				In earlier versions this was set for some
196 				BLOB columns.
197 */
198 #define DATA_GIS_MBR	2048	/* Used as GIS MBR column */
199 #define DATA_MBR_LEN	SPDIMS * 2 * sizeof(double) /* GIS MBR length*/
200 
201 #define	DATA_LONG_TRUE_VARCHAR 4096	/* this is ORed to the precise data
202 				type when the column is true VARCHAR where
203 				MySQL uses 2 bytes to store the data len;
204 				for shorter VARCHARs MySQL uses only 1 byte */
205 #define	DATA_VIRTUAL	8192	/* Virtual column */
206 
207 #define	DATA_COMPRESSED	16384	/* this is ORed to the precise data
208 				type when the column has COLUMN_FORMAT =
209 				COMPRESSED attribute*/
210 /*-------------------------------------------*/
211 
212 /* This many bytes we need to store the type information affecting the
213 alphabetical order for a single field and decide the storage size of an
214 SQL null*/
215 #define DATA_ORDER_NULL_TYPE_BUF_SIZE		4
216 /* In the >= 4.1.x storage format we add 2 bytes more so that we can also
217 store the charset-collation number; one byte is left unused, though */
218 #define DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE	6
219 
220 /* Maximum multi-byte character length in bytes, plus 1 */
221 #define DATA_MBMAX	5
222 
223 /* For DATA_POINT of dimension 2, the length of value in btree is always 25,
224 which is the summary of:
225 SRID_SIZE(4) + WKB_HEADER_SIZE(1+4) + POINT_DATA_SIZE(8*2).
226 So the length of physical record or POINT KEYs on btree are 25.
227 GIS_TODO: When we support multi-dimensions DATA_POINT, we should get the
228 length from corresponding column or index definition, instead of this MACRO
229 */
230 #define DATA_POINT_LEN	25
231 
232 /* Pack mbminlen, mbmaxlen to mbminmaxlen. */
233 #define DATA_MBMINMAXLEN(mbminlen, mbmaxlen)	\
234 	((mbmaxlen) * DATA_MBMAX + (mbminlen))
235 /* Get mbminlen from mbminmaxlen. Cast the result of UNIV_EXPECT to ulint
236 because in GCC it returns a long. */
237 #define DATA_MBMINLEN(mbminmaxlen) ((ulint) \
238                                     UNIV_EXPECT(((mbminmaxlen) % DATA_MBMAX), \
239                                                 1))
240 /* Get mbmaxlen from mbminmaxlen. */
241 #define DATA_MBMAXLEN(mbminmaxlen) ((ulint) ((mbminmaxlen) / DATA_MBMAX))
242 
243 /* For checking if a geom_type is POINT */
244 #define DATA_POINT_MTYPE(mtype) ((mtype) == DATA_POINT			\
245 				 || (mtype) == DATA_VAR_POINT)
246 
247 /* For checking if mtype is GEOMETRY datatype */
248 #define DATA_GEOMETRY_MTYPE(mtype)	(DATA_POINT_MTYPE(mtype)	\
249 					 || (mtype) == DATA_GEOMETRY)
250 
251 /* For checking if mtype is BLOB or GEOMETRY, since we use BLOB as
252 the underling datatype of GEOMETRY(not DATA_POINT) data. */
253 #define DATA_LARGE_MTYPE(mtype) ((mtype) == DATA_BLOB			\
254 				 || (mtype) == DATA_VAR_POINT		\
255 				 || (mtype) == DATA_GEOMETRY)
256 
257 /* For checking if data type is big length data type. */
258 #define DATA_BIG_LEN_MTYPE(len, mtype, extra) ((len) > 255 - (extra) || \
259 	DATA_LARGE_MTYPE(mtype))
260 
261 /* For checking if the column is a big length column. */
262 #define DATA_BIG_COL(col) DATA_BIG_LEN_MTYPE((col)->len, (col)->mtype, \
263 	prtype_get_compression_extra((col)->prtype))
264 
265 /* For checking if data type is large binary data type. */
266 #define DATA_LARGE_BINARY(mtype,prtype) ((mtype) == DATA_GEOMETRY || \
267 	((mtype) == DATA_BLOB && !((prtype) & DATA_BINARY_TYPE)))
268 
269 /* We now support 15 bits (up to 32767) collation number */
270 #define MAX_CHAR_COLL_NUM	32767
271 
272 /* Mask to get the Charset Collation number (0x7fff) */
273 #define CHAR_COLL_MASK		MAX_CHAR_COLL_NUM
274 
275 #ifndef UNIV_HOTBACKUP
276 /*********************************************************************//**
277 Gets the MySQL type code from a dtype.
278 @return MySQL type code; this is NOT an InnoDB type code! */
279 UNIV_INLINE
280 ulint
281 dtype_get_mysql_type(
282 /*=================*/
283 	const dtype_t*	type);	/*!< in: type struct */
284 /*********************************************************************//**
285 Determine how many bytes the first n characters of the given string occupy.
286 If the string is shorter than n characters, returns the number of bytes
287 the characters in the string occupy.
288 @return length of the prefix, in bytes */
289 ulint
290 dtype_get_at_most_n_mbchars(
291 /*========================*/
292 	ulint		prtype,		/*!< in: precise type */
293 	ulint		mbminmaxlen,	/*!< in: minimum and maximum length of
294 					a multi-byte character */
295 	ulint		prefix_len,	/*!< in: length of the requested
296 					prefix, in characters, multiplied by
297 					dtype_get_mbmaxlen(dtype) */
298 	ulint		data_len,	/*!< in: length of str (in bytes) */
299 	const char*	str);		/*!< in: the string whose prefix
300 					length is being determined */
301 #endif /* !UNIV_HOTBACKUP */
302 /*********************************************************************//**
303 Checks if a data main type is a string type. Also a BLOB is considered a
304 string type.
305 @return TRUE if string type */
306 ibool
307 dtype_is_string_type(
308 /*=================*/
309 	ulint	mtype);	/*!< in: InnoDB main data type code: DATA_CHAR, ... */
310 /*********************************************************************//**
311 Checks if a type is a binary string type. Note that for tables created with
312 < 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column. For
313 those DATA_BLOB columns this function currently returns FALSE.
314 @return TRUE if binary string type */
315 ibool
316 dtype_is_binary_string_type(
317 /*========================*/
318 	ulint	mtype,	/*!< in: main data type */
319 	ulint	prtype);/*!< in: precise type */
320 /*********************************************************************//**
321 Checks if a type is a non-binary string type. That is, dtype_is_string_type is
322 TRUE and dtype_is_binary_string_type is FALSE. Note that for tables created
323 with < 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column.
324 For those DATA_BLOB columns this function currently returns TRUE.
325 @return TRUE if non-binary string type */
326 ibool
327 dtype_is_non_binary_string_type(
328 /*============================*/
329 	ulint	mtype,	/*!< in: main data type */
330 	ulint	prtype);/*!< in: precise type */
331 /*********************************************************************//**
332 Sets a data type structure. */
333 UNIV_INLINE
334 void
335 dtype_set(
336 /*======*/
337 	dtype_t*	type,	/*!< in: type struct to init */
338 	ulint		mtype,	/*!< in: main data type */
339 	ulint		prtype,	/*!< in: precise type */
340 	ulint		len);	/*!< in: precision of type */
341 /*********************************************************************//**
342 Copies a data type structure. */
343 UNIV_INLINE
344 void
345 dtype_copy(
346 /*=======*/
347 	dtype_t*	type1,	/*!< in: type struct to copy to */
348 	const dtype_t*	type2);	/*!< in: type struct to copy from */
349 /*********************************************************************//**
350 Gets the SQL main data type.
351 @return SQL main data type */
352 UNIV_INLINE
353 ulint
354 dtype_get_mtype(
355 /*============*/
356 	const dtype_t*	type);	/*!< in: data type */
357 /*********************************************************************//**
358 Gets the precise data type.
359 @return precise data type */
360 UNIV_INLINE
361 ulint
362 dtype_get_prtype(
363 /*=============*/
364 	const dtype_t*	type);	/*!< in: data type */
365 #ifndef UNIV_HOTBACKUP
366 /*********************************************************************//**
367 Compute the mbminlen and mbmaxlen members of a data type structure. */
368 UNIV_INLINE
369 void
370 dtype_get_mblen(
371 /*============*/
372 	ulint	mtype,		/*!< in: main type */
373 	ulint	prtype,		/*!< in: precise type (and collation) */
374 	ulint*	mbminlen,	/*!< out: minimum length of a
375 				multi-byte character */
376 	ulint*	mbmaxlen);	/*!< out: maximum length of a
377 				multi-byte character */
378 /*********************************************************************//**
379 Gets the MySQL charset-collation code for MySQL string types.
380 @return MySQL charset-collation code */
381 UNIV_INLINE
382 ulint
383 dtype_get_charset_coll(
384 /*===================*/
385 	ulint	prtype);/*!< in: precise data type */
386 /*********************************************************************//**
387 Forms a precise type from the < 4.1.2 format precise type plus the
388 charset-collation code.
389 @return precise type, including the charset-collation code */
390 ulint
391 dtype_form_prtype(
392 /*==============*/
393 	ulint	old_prtype,	/*!< in: the MySQL type code and the flags
394 				DATA_BINARY_TYPE etc. */
395 	ulint	charset_coll);	/*!< in: MySQL charset-collation code */
396 /*********************************************************************//**
397 Determines if a MySQL string type is a subset of UTF-8.  This function
398 may return false negatives, in case further character-set collation
399 codes are introduced in MySQL later.
400 @return TRUE if a subset of UTF-8 */
401 UNIV_INLINE
402 ibool
403 dtype_is_utf8(
404 /*==========*/
405 	ulint	prtype);/*!< in: precise data type */
406 #endif /* !UNIV_HOTBACKUP */
407 /*********************************************************************//**
408 Gets the type length.
409 @return fixed length of the type, in bytes, or 0 if variable-length */
410 UNIV_INLINE
411 ulint
412 dtype_get_len(
413 /*==========*/
414 	const dtype_t*	type);	/*!< in: data type */
415 #ifndef UNIV_HOTBACKUP
416 /*********************************************************************//**
417 Gets the minimum length of a character, in bytes.
418 @return minimum length of a char, in bytes, or 0 if this is not a
419 character type */
420 UNIV_INLINE
421 ulint
422 dtype_get_mbminlen(
423 /*===============*/
424 	const dtype_t*	type);	/*!< in: type */
425 /*********************************************************************//**
426 Gets the maximum length of a character, in bytes.
427 @return maximum length of a char, in bytes, or 0 if this is not a
428 character type */
429 UNIV_INLINE
430 ulint
431 dtype_get_mbmaxlen(
432 /*===============*/
433 	const dtype_t*	type);	/*!< in: type */
434 /*********************************************************************//**
435 Sets the minimum and maximum length of a character, in bytes. */
436 UNIV_INLINE
437 void
438 dtype_set_mbminmaxlen(
439 /*==================*/
440 	dtype_t*	type,		/*!< in/out: type */
441 	ulint		mbminlen,	/*!< in: minimum length of a char,
442 					in bytes, or 0 if this is not
443 					a character type */
444 	ulint		mbmaxlen);	/*!< in: maximum length of a char,
445 					in bytes, or 0 if this is not
446 					a character type */
447 #endif /* !UNIV_HOTBACKUP */
448 /***********************************************************************//**
449 Returns the size of a fixed size data type, 0 if not a fixed size type.
450 @return fixed size, or 0 */
451 UNIV_INLINE
452 ulint
453 dtype_get_fixed_size_low(
454 /*=====================*/
455 	ulint	mtype,		/*!< in: main type */
456 	ulint	prtype,		/*!< in: precise type */
457 	ulint	len,		/*!< in: length */
458 	ulint	mbminmaxlen,	/*!< in: minimum and maximum length of a
459 				multibyte character, in bytes */
460 	ulint	comp);		/*!< in: nonzero=ROW_FORMAT=COMPACT  */
461 #ifndef UNIV_HOTBACKUP
462 /***********************************************************************//**
463 Returns the minimum size of a data type.
464 @return minimum size */
465 UNIV_INLINE
466 ulint
467 dtype_get_min_size_low(
468 /*===================*/
469 	ulint	mtype,		/*!< in: main type */
470 	ulint	prtype,		/*!< in: precise type */
471 	ulint	len,		/*!< in: length */
472 	ulint	mbminmaxlen);	/*!< in: minimum and maximum length of a
473 				multibyte character */
474 /***********************************************************************//**
475 Returns the maximum size of a data type. Note: types in system tables may be
476 incomplete and return incorrect information.
477 @return maximum size */
478 UNIV_INLINE
479 ulint
480 dtype_get_max_size_low(
481 /*===================*/
482 	ulint	mtype,		/*!< in: main type */
483 	ulint	len);		/*!< in: length */
484 #endif /* !UNIV_HOTBACKUP */
485 /***********************************************************************//**
486 Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a type.
487 For fixed length types it is the fixed length of the type, otherwise 0.
488 @return SQL null storage size in ROW_FORMAT=REDUNDANT */
489 UNIV_INLINE
490 ulint
491 dtype_get_sql_null_size(
492 /*====================*/
493 	const dtype_t*	type,	/*!< in: type */
494 	ulint		comp);	/*!< in: nonzero=ROW_FORMAT=COMPACT  */
495 #ifndef UNIV_HOTBACKUP
496 /**********************************************************************//**
497 Reads to a type the stored information which determines its alphabetical
498 ordering and the storage size of an SQL NULL value. */
499 UNIV_INLINE
500 void
501 dtype_read_for_order_and_null_size(
502 /*===============================*/
503 	dtype_t*	type,	/*!< in: type struct */
504 	const byte*	buf);	/*!< in: buffer for the stored order info */
505 /**********************************************************************//**
506 Stores for a type the information which determines its alphabetical ordering
507 and the storage size of an SQL NULL value. This is the >= 4.1.x storage
508 format. */
509 UNIV_INLINE
510 void
511 dtype_new_store_for_order_and_null_size(
512 /*====================================*/
513 	byte*		buf,	/*!< in: buffer for
514 				DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE
515 				bytes where we store the info */
516 	const dtype_t*	type,	/*!< in: type struct */
517 	ulint		prefix_len);/*!< in: prefix length to
518 				replace type->len, or 0 */
519 /**********************************************************************//**
520 Reads to a type the stored information which determines its alphabetical
521 ordering and the storage size of an SQL NULL value. This is the 4.1.x storage
522 format. */
523 UNIV_INLINE
524 void
525 dtype_new_read_for_order_and_null_size(
526 /*===================================*/
527 	dtype_t*	type,	/*!< in: type struct */
528 	const byte*	buf);	/*!< in: buffer for stored type order info */
529 
530 /*********************************************************************//**
531 Returns the type's SQL name (e.g. BIGINT UNSIGNED) from mtype,prtype,len
532 @return the SQL type name */
533 UNIV_INLINE
534 char*
535 dtype_sql_name(
536 /*===========*/
537 	unsigned	mtype,	/*!< in: mtype */
538 	unsigned	prtype,	/*!< in: prtype */
539 	unsigned	len,	/*!< in: len */
540 	char*		name,	/*!< out: SQL name */
541 	unsigned	name_sz);/*!< in: size of the name buffer */
542 
543 #endif /* !UNIV_HOTBACKUP */
544 
545 /*********************************************************************//**
546 Validates a data type structure.
547 @return TRUE if ok */
548 ibool
549 dtype_validate(
550 /*===========*/
551 	const dtype_t*	type);	/*!< in: type struct to validate */
552 /*********************************************************************//**
553 Prints a data type structure. */
554 void
555 dtype_print(
556 /*========*/
557 	const dtype_t*	type);	/*!< in: type */
558 
559 /**
560 Calculates the number of extra bytes needed for compression header
561 depending on precise column type.
562 @reval 0 if prtype does not include DATA_COMPRESSED flag
563 @reval ZIP_COLUMN_HEADER_LENGTH if prtype includes DATA_COMPRESSED flag
564 */
565 UNIV_INLINE
566 ulint
567 prtype_get_compression_extra(
568 	ulint		prtype);	/*!< in: precise type */
569 
570 /* Structure for an SQL data type.
571 If you add fields to this structure, be sure to initialize them everywhere.
572 This structure is initialized in the following functions:
573 dtype_set()
574 dtype_read_for_order_and_null_size()
575 dtype_new_read_for_order_and_null_size()
576 sym_tab_add_null_lit() */
577 
578 struct dtype_t{
579 	unsigned	prtype:32;	/*!< precise type; MySQL data
580 					type, charset code, flags to
581 					indicate nullability,
582 					signedness, whether this is a
583 					binary string, whether this is
584 					a true VARCHAR where MySQL
585 					uses 2 bytes to store the length */
586 	unsigned	mtype:8;	/*!< main data type */
587 
588 	/* the remaining fields do not affect alphabetical ordering: */
589 
590 	unsigned	len:16;		/*!< length; for MySQL data this
591 					is field->pack_length(),
592 					except that for a >= 5.0.3
593 					type true VARCHAR this is the
594 					maximum byte length of the
595 					string data (in addition to
596 					the string, MySQL uses 1 or 2
597 					bytes to store the string length) */
598 #ifndef UNIV_HOTBACKUP
599 	unsigned	mbminmaxlen:5;	/*!< minimum and maximum length of a
600 					character, in bytes;
601 					DATA_MBMINMAXLEN(mbminlen,mbmaxlen);
602 					mbminlen=DATA_MBMINLEN(mbminmaxlen);
603 					mbmaxlen=DATA_MBMINLEN(mbminmaxlen) */
604 #endif /* !UNIV_HOTBACKUP */
605 };
606 
607 #ifndef UNIV_NONINL
608 #include "data0type.ic"
609 #endif
610 
611 #endif
612