1
/******************************************************
6
Created 1/16/1996 Heikki Tuuri
7
*******************************************************/
14
extern ulint data_mysql_default_charset_coll;
15
#define DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL 8
16
#define DATA_MYSQL_BINARY_CHARSET_COLL 63
18
/* SQL data type struct */
19
typedef struct dtype_struct dtype_t;
21
/*-------------------------------------------*/
22
/* The 'MAIN TYPE' of a column */
23
#define DATA_VARCHAR 1 /* character varying of the
24
latin1_swedish_ci charset-collation; note
25
that the MySQL format for this, DATA_BINARY,
26
DATA_VARMYSQL, is also affected by whether the
27
'precise type' contains
28
DATA_MYSQL_TRUE_VARCHAR */
29
#define DATA_CHAR 2 /* fixed length character of the
30
latin1_swedish_ci charset-collation */
31
#define DATA_FIXBINARY 3 /* binary string of fixed length */
32
#define DATA_BINARY 4 /* binary string */
33
#define DATA_BLOB 5 /* binary large object, or a TEXT type;
34
if prtype & DATA_BINARY_TYPE == 0, then this is
35
actually a TEXT column (or a BLOB created
36
with < 4.0.14; since column prefix indexes
37
came only in 4.0.14, the missing flag in BLOBs
38
created before that does not cause any harm) */
39
#define DATA_INT 6 /* integer: can be any size 1 - 8 bytes */
40
#define DATA_SYS_CHILD 7 /* address of the child page in node pointer */
41
#define DATA_SYS 8 /* system column */
43
/* Data types >= DATA_FLOAT must be compared using the whole field, not as
47
#define DATA_DOUBLE 10
48
#define DATA_DECIMAL 11 /* decimal number stored as an ASCII string */
49
#define DATA_VARMYSQL 12 /* any charset varying length char */
50
#define DATA_MYSQL 13 /* any charset fixed length char */
51
/* NOTE that 4.1.1 used DATA_MYSQL and
52
DATA_VARMYSQL for all character sets, and the
53
charset-collation for tables created with it
54
can also be latin1_swedish_ci */
55
#define DATA_MTYPE_MAX 63 /* dtype_store_for_order_and_null_size()
56
requires the values are <= 63 */
57
/*-------------------------------------------*/
58
/* The 'PRECISE TYPE' of a column */
60
Tables created by a MySQL user have the following convention:
62
- In the least significant byte in the precise type we store the MySQL type
63
code (not applicable for system columns).
65
- In the second least significant byte we OR flags DATA_NOT_NULL,
66
DATA_UNSIGNED, DATA_BINARY_TYPE.
68
- In the third least significant byte of the precise type of string types we
69
store the MySQL charset-collation code. In DATA_BLOB columns created with
70
< 4.0.14 we do not actually know if it is a BLOB or a TEXT column. Since there
71
are no indexes on prefixes of BLOB or TEXT columns in < 4.0.14, this is no
74
Note that versions < 4.1.2 or < 5.0.1 did not store the charset code to the
75
precise type, since the charset was always the default charset of the MySQL
76
installation. If the stored charset code is 0 in the system table SYS_COLUMNS
77
of InnoDB, that means that the default charset of this MySQL installation
80
When loading a table definition from the system tables to the InnoDB data
81
dictionary cache in main memory, InnoDB versions >= 4.1.2 and >= 5.0.1 check
82
if the stored charset-collation is 0, and if that is the case and the type is
83
a non-binary string, replace that 0 by the default charset-collation code of
84
this MySQL installation. In short, in old tables, the charset-collation code
85
in the system tables on disk can be 0, but in in-memory data structures
86
(dtype_t), the charset-collation code is always != 0 for non-binary string
89
In new tables, in binary string types, the charset-collation code is the
90
MySQL code for the 'binary charset', that is, != 0.
92
For binary string types and for DATA_CHAR, DATA_VARCHAR, and for those
93
DATA_BLOB which are binary or have the charset-collation latin1_swedish_ci,
94
InnoDB performs all comparisons internally, without resorting to the MySQL
95
comparison functions. This is to save CPU time.
97
InnoDB's own internal system tables have different precise types for their
98
columns, and for them the precise type is usually not used at all.
101
#define DATA_ENGLISH 4 /* English language character string: this
102
is a relic from pre-MySQL time and only used
103
for InnoDB's own system tables */
104
#define DATA_ERROR 111 /* another relic from pre-MySQL time */
106
#define DATA_MYSQL_TYPE_MASK 255 /* AND with this mask to extract the MySQL
107
type from the precise type */
108
#define DATA_MYSQL_TRUE_VARCHAR 15 /* MySQL type code for the >= 5.0.3
109
format true VARCHAR */
111
/* Precise data types for system columns and the length of those columns;
112
NOTE: the values must run from 0 up in the order given! All codes must
114
#define DATA_ROW_ID 0 /* row id: a dulint */
115
#define DATA_ROW_ID_LEN 6 /* stored length for row id */
117
#define DATA_TRX_ID 1 /* transaction id: 6 bytes */
118
#define DATA_TRX_ID_LEN 6
120
#define DATA_ROLL_PTR 2 /* rollback data pointer: 7 bytes */
121
#define DATA_ROLL_PTR_LEN 7
123
#define DATA_N_SYS_COLS 3 /* number of system columns defined above */
125
/* Flags ORed to the precise data type */
126
#define DATA_NOT_NULL 256 /* this is ORed to the precise type when
127
the column is declared as NOT NULL */
128
#define DATA_UNSIGNED 512 /* this id ORed to the precise type when
129
we have an unsigned integer type */
130
#define DATA_BINARY_TYPE 1024 /* if the data type is a binary character
131
string, this is ORed to the precise type:
132
this only holds for tables created with
134
/* #define DATA_NONLATIN1 2048 This is a relic from < 4.1.2 and < 5.0.1.
135
In earlier versions this was set for some
138
#define DATA_LONG_TRUE_VARCHAR 4096 /* this is ORed to the precise data
139
type when the column is true VARCHAR where
140
MySQL uses 2 bytes to store the data len;
141
for shorter VARCHARs MySQL uses only 1 byte */
142
/*-------------------------------------------*/
144
/* This many bytes we need to store the type information affecting the
145
alphabetical order for a single field and decide the storage size of an
147
#define DATA_ORDER_NULL_TYPE_BUF_SIZE 4
148
/* In the >= 4.1.x storage format we add 2 bytes more so that we can also
149
store the charset-collation number; one byte is left unused, though */
150
#define DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE 6
152
/*************************************************************************
153
Gets the MySQL type code from a dtype. */
156
dtype_get_mysql_type(
157
/*=================*/
158
/* out: MySQL type code; this is NOT an InnoDB
160
dtype_t* type); /* in: type struct */
161
/*************************************************************************
162
Determine how many bytes the first n characters of the given string occupy.
163
If the string is shorter than n characters, returns the number of bytes
164
the characters in the string occupy. */
167
dtype_get_at_most_n_mbchars(
168
/*========================*/
169
/* out: length of the prefix,
171
ulint prtype, /* in: precise type */
172
ulint mbminlen, /* in: minimum length of a
173
multi-byte character */
174
ulint mbmaxlen, /* in: maximum length of a
175
multi-byte character */
176
ulint prefix_len, /* in: length of the requested
177
prefix, in characters, multiplied by
178
dtype_get_mbmaxlen(dtype) */
179
ulint data_len, /* in: length of str (in bytes) */
180
const char* str); /* in: the string whose prefix
181
length is being determined */
182
/*************************************************************************
183
Checks if a data main type is a string type. Also a BLOB is considered a
187
dtype_is_string_type(
188
/*=================*/
189
/* out: TRUE if string type */
190
ulint mtype); /* in: InnoDB main data type code: DATA_CHAR, ... */
191
/*************************************************************************
192
Checks if a type is a binary string type. Note that for tables created with
193
< 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column. For
194
those DATA_BLOB columns this function currently returns FALSE. */
197
dtype_is_binary_string_type(
198
/*========================*/
199
/* out: TRUE if binary string type */
200
ulint mtype, /* in: main data type */
201
ulint prtype);/* in: precise type */
202
/*************************************************************************
203
Checks if a type is a non-binary string type. That is, dtype_is_string_type is
204
TRUE and dtype_is_binary_string_type is FALSE. Note that for tables created
205
with < 4.0.14, we do not know if a DATA_BLOB column is a BLOB or a TEXT column.
206
For those DATA_BLOB columns this function currently returns TRUE. */
209
dtype_is_non_binary_string_type(
210
/*============================*/
211
/* out: TRUE if non-binary string type */
212
ulint mtype, /* in: main data type */
213
ulint prtype);/* in: precise type */
214
/*************************************************************************
215
Sets a data type structure. */
220
dtype_t* type, /* in: type struct to init */
221
ulint mtype, /* in: main data type */
222
ulint prtype, /* in: precise type */
223
ulint len); /* in: precision of type */
224
/*************************************************************************
225
Copies a data type structure. */
230
dtype_t* type1, /* in: type struct to copy to */
231
const dtype_t* type2); /* in: type struct to copy from */
232
/*************************************************************************
233
Gets the SQL main data type. */
239
/*************************************************************************
240
Gets the precise data type. */
246
/*************************************************************************
247
Compute the mbminlen and mbmaxlen members of a data type structure. */
252
ulint mtype, /* in: main type */
253
ulint prtype, /* in: precise type (and collation) */
254
ulint* mbminlen, /* out: minimum length of a
255
multi-byte character */
256
ulint* mbmaxlen); /* out: maximum length of a
257
multi-byte character */
258
/*************************************************************************
259
Gets the MySQL charset-collation code for MySQL string types. */
262
dtype_get_charset_coll_noninline(
263
/*=============================*/
264
ulint prtype);/* in: precise data type */
265
/*************************************************************************
266
Gets the MySQL charset-collation code for MySQL string types. */
269
dtype_get_charset_coll(
270
/*===================*/
271
ulint prtype);/* in: precise data type */
272
/*************************************************************************
273
Forms a precise type from the < 4.1.2 format precise type plus the
274
charset-collation code. */
279
ulint old_prtype, /* in: the MySQL type code and the flags
280
DATA_BINARY_TYPE etc. */
281
ulint charset_coll); /* in: MySQL charset-collation code */
282
/*************************************************************************
283
Gets the type length. */
289
/*************************************************************************
290
Gets the minimum length of a character, in bytes. */
295
/* out: minimum length of a char, in bytes,
296
or 0 if this is not a character type */
297
const dtype_t* type); /* in: type */
298
/*************************************************************************
299
Gets the maximum length of a character, in bytes. */
304
/* out: maximum length of a char, in bytes,
305
or 0 if this is not a character type */
306
const dtype_t* type); /* in: type */
307
/*************************************************************************
308
Gets the padding character code for the type. */
313
/* out: padding character code, or
314
ULINT_UNDEFINED if no padding specified */
315
ulint mtype, /* in: main type */
316
ulint prtype); /* in: precise type */
317
/***************************************************************************
318
Returns the size of a fixed size data type, 0 if not a fixed size type. */
321
dtype_get_fixed_size_low(
322
/*=====================*/
323
/* out: fixed size, or 0 */
324
ulint mtype, /* in: main type */
325
ulint prtype, /* in: precise type */
326
ulint len, /* in: length */
327
ulint mbminlen, /* in: minimum length of a multibyte char */
328
ulint mbmaxlen); /* in: maximum length of a multibyte char */
329
/***************************************************************************
330
Returns the minimum size of a data type. */
333
dtype_get_min_size_low(
334
/*===================*/
335
/* out: minimum size */
336
ulint mtype, /* in: main type */
337
ulint prtype, /* in: precise type */
338
ulint len, /* in: length */
339
ulint mbminlen, /* in: minimum length of a multibyte char */
340
ulint mbmaxlen); /* in: maximum length of a multibyte char */
341
/***************************************************************************
342
Returns the maximum size of a data type. Note: types in system tables may be
343
incomplete and return incorrect information. */
346
dtype_get_max_size_low(
347
/*===================*/
348
/* out: maximum size */
349
ulint mtype, /* in: main type */
350
ulint len); /* in: length */
351
/***************************************************************************
352
Returns the ROW_FORMAT=REDUNDANT stored SQL NULL size of a type.
353
For fixed length types it is the fixed length of the type, otherwise 0. */
356
dtype_get_sql_null_size(
357
/*====================*/
358
/* out: SQL null storage size
359
in ROW_FORMAT=REDUNDANT */
360
const dtype_t* type); /* in: type */
361
/**************************************************************************
362
Reads to a type the stored information which determines its alphabetical
363
ordering and the storage size of an SQL NULL value. */
366
dtype_read_for_order_and_null_size(
367
/*===============================*/
368
dtype_t* type, /* in: type struct */
369
byte* buf); /* in: buffer for the stored order info */
370
/**************************************************************************
371
Stores for a type the information which determines its alphabetical ordering
372
and the storage size of an SQL NULL value. This is the >= 4.1.x storage
376
dtype_new_store_for_order_and_null_size(
377
/*====================================*/
378
byte* buf, /* in: buffer for
379
DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE
380
bytes where we store the info */
381
dtype_t* type, /* in: type struct */
382
ulint prefix_len);/* in: prefix length to
383
replace type->len, or 0 */
384
/**************************************************************************
385
Reads to a type the stored information which determines its alphabetical
386
ordering and the storage size of an SQL NULL value. This is the 4.1.x storage
390
dtype_new_read_for_order_and_null_size(
391
/*===================================*/
392
dtype_t* type, /* in: type struct */
393
byte* buf); /* in: buffer for stored type order info */
395
/*************************************************************************
396
Validates a data type structure. */
401
/* out: TRUE if ok */
402
dtype_t* type); /* in: type struct to validate */
403
/*************************************************************************
404
Prints a data type structure. */
409
dtype_t* type); /* in: type */
411
/* Structure for an SQL data type.
412
If you add fields to this structure, be sure to initialize them everywhere.
413
This structure is initialized in the following functions:
415
dtype_read_for_order_and_null_size()
416
dtype_new_read_for_order_and_null_size()
417
sym_tab_add_null_lit() */
420
unsigned mtype:8; /* main data type */
421
unsigned prtype:24; /* precise type; MySQL data
422
type, charset code, flags to
423
indicate nullability,
424
signedness, whether this is a
425
binary string, whether this is
426
a true VARCHAR where MySQL
427
uses 2 bytes to store the length */
429
/* the remaining fields do not affect alphabetical ordering: */
431
unsigned len:16; /* length; for MySQL data this
432
is field->pack_length(),
433
except that for a >= 5.0.3
434
type true VARCHAR this is the
435
maximum byte length of the
436
string data (in addition to
437
the string, MySQL uses 1 or 2
438
bytes to store the string length) */
440
unsigned mbminlen:2; /* minimum length of a
441
character, in bytes */
442
unsigned mbmaxlen:3; /* maximum length of a
443
character, in bytes */
447
#include "data0type.ic"