InnoDB Plugin  1.0
data0type.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #ifndef data0type_h
27 #define data0type_h
28 
29 #include "univ.i"
30 
31 extern ulint data_mysql_default_charset_coll;
32 #define DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL 8
33 #define DATA_MYSQL_BINARY_CHARSET_COLL 63
34 
35 /* SQL data type struct */
36 struct dtype_t;
37 
38 /* SQL Like operator comparison types */
39 enum ib_like_t {
40  IB_LIKE_EXACT, /* e.g. STRING */
41  IB_LIKE_PREFIX, /* e.g., STRING% */
42  IB_LIKE_SUFFIX, /* e.g., %STRING */
43  IB_LIKE_SUBSTR, /* e.g., %STRING% */
44  IB_LIKE_REGEXP /* Future */
45 };
46 
47 /*-------------------------------------------*/
48 /* The 'MAIN TYPE' of a column */
49 #define DATA_MISSING 0 /* missing column */
50 #define DATA_VARCHAR 1 /* character varying of the
51  latin1_swedish_ci charset-collation; note
52  that the MySQL format for this, DATA_BINARY,
53  DATA_VARMYSQL, is also affected by whether the
54  'precise type' contains
55  DATA_MYSQL_TRUE_VARCHAR */
56 #define DATA_CHAR 2 /* fixed length character of the
57  latin1_swedish_ci charset-collation */
58 #define DATA_FIXBINARY 3 /* binary string of fixed length */
59 #define DATA_BINARY 4 /* binary string */
60 #define DATA_BLOB 5 /* binary large object, or a TEXT type;
61  if prtype & DATA_BINARY_TYPE == 0, then this is
62  actually a TEXT column (or a BLOB created
63  with < 4.0.14; since column prefix indexes
64  came only in 4.0.14, the missing flag in BLOBs
65  created before that does not cause any harm) */
66 #define DATA_INT 6 /* integer: can be any size 1 - 8 bytes */
67 #define DATA_SYS_CHILD 7 /* address of the child page in node pointer */
68 #define DATA_SYS 8 /* system column */
69 
70 /* Data types >= DATA_FLOAT must be compared using the whole field, not as
71 binary strings */
72 
73 #define DATA_FLOAT 9
74 #define DATA_DOUBLE 10
75 #define DATA_DECIMAL 11 /* decimal number stored as an ASCII string */
76 #define DATA_VARMYSQL 12 /* any charset varying length char */
77 #define DATA_MYSQL 13 /* any charset fixed length char */
78  /* NOTE that 4.1.1 used DATA_MYSQL and
79  DATA_VARMYSQL for all character sets, and the
80  charset-collation for tables created with it
81  can also be latin1_swedish_ci */
82 #define DATA_MTYPE_MAX 63 /* dtype_store_for_order_and_null_size()
83  requires the values are <= 63 */
84 /*-------------------------------------------*/
85 /* The 'PRECISE TYPE' of a column */
86 /*
87 Tables created by a MySQL user have the following convention:
88 
89 - In the least significant byte in the precise type we store the MySQL type
90 code (not applicable for system columns).
91 
92 - In the second least significant byte we OR flags DATA_NOT_NULL,
93 DATA_UNSIGNED, DATA_BINARY_TYPE.
94 
95 - In the third least significant byte of the precise type of string types we
96 store the MySQL charset-collation code. In DATA_BLOB columns created with
97 < 4.0.14 we do not actually know if it is a BLOB or a TEXT column. Since there
98 are no indexes on prefixes of BLOB or TEXT columns in < 4.0.14, this is no
99 problem, though.
100 
101 Note that versions < 4.1.2 or < 5.0.1 did not store the charset code to the
102 precise type, since the charset was always the default charset of the MySQL
103 installation. If the stored charset code is 0 in the system table SYS_COLUMNS
104 of InnoDB, that means that the default charset of this MySQL installation
105 should be used.
106 
107 When loading a table definition from the system tables to the InnoDB data
108 dictionary cache in main memory, InnoDB versions >= 4.1.2 and >= 5.0.1 check
109 if the stored charset-collation is 0, and if that is the case and the type is
110 a non-binary string, replace that 0 by the default charset-collation code of
111 this MySQL installation. In short, in old tables, the charset-collation code
112 in the system tables on disk can be 0, but in in-memory data structures
113 (dtype_t), the charset-collation code is always != 0 for non-binary string
114 types.
115 
116 In new tables, in binary string types, the charset-collation code is the
117 MySQL code for the 'binary charset', that is, != 0.
118 
119 For binary string types and for DATA_CHAR, DATA_VARCHAR, and for those
120 DATA_BLOB which are binary or have the charset-collation latin1_swedish_ci,
121 InnoDB performs all comparisons internally, without resorting to the MySQL
122 comparison functions. This is to save CPU time.
123 
124 InnoDB's own internal system tables have different precise types for their
125 columns, and for them the precise type is usually not used at all.
126 */
127 
128 #define DATA_ENGLISH 4 /* English language character string: this
129  is a relic from pre-MySQL time and only used
130  for InnoDB's own system tables */
131 #define DATA_ERROR 111 /* another relic from pre-MySQL time */
132 
133 #define DATA_MYSQL_TYPE_MASK 255 /* AND with this mask to extract the MySQL
134  type from the precise type */
135 #define DATA_MYSQL_TRUE_VARCHAR 15 /* MySQL type code for the >= 5.0.3
136  format true VARCHAR */
137 
138 /* Precise data types for system columns and the length of those columns;
139 NOTE: the values must run from 0 up in the order given! All codes must
140 be less than 256 */
141 #define DATA_ROW_ID 0 /* row id: a 48-bit integer */
142 #define DATA_ROW_ID_LEN 6 /* stored length for row id */
143 
144 #define DATA_TRX_ID 1 /* transaction id: 6 bytes */
145 #define DATA_TRX_ID_LEN 6
146 
147 #define DATA_ROLL_PTR 2 /* rollback data pointer: 7 bytes */
148 #define DATA_ROLL_PTR_LEN 7
149 
150 #define DATA_N_SYS_COLS 3 /* number of system columns defined above */
151 
152 #define DATA_FTS_DOC_ID 3 /* Used as FTS DOC ID column */
153 
154 #define DATA_SYS_PRTYPE_MASK 0xF /* mask to extract the above from prtype */
155 
156 /* Flags ORed to the precise data type */
157 #define DATA_NOT_NULL 256 /* this is ORed to the precise type when
158  the column is declared as NOT NULL */
159 #define DATA_UNSIGNED 512 /* this id ORed to the precise type when
160  we have an unsigned integer type */
161 #define DATA_BINARY_TYPE 1024 /* if the data type is a binary character
162  string, this is ORed to the precise type:
163  this only holds for tables created with
164  >= MySQL-4.0.14 */
165 /* #define DATA_NONLATIN1 2048 This is a relic from < 4.1.2 and < 5.0.1.
166  In earlier versions this was set for some
167  BLOB columns.
168 */
169 #define DATA_LONG_TRUE_VARCHAR 4096 /* this is ORed to the precise data
170  type when the column is true VARCHAR where
171  MySQL uses 2 bytes to store the data len;
172  for shorter VARCHARs MySQL uses only 1 byte */
173 /*-------------------------------------------*/
174 
175 /* This many bytes we need to store the type information affecting the
176 alphabetical order for a single field and decide the storage size of an
177 SQL null*/
178 #define DATA_ORDER_NULL_TYPE_BUF_SIZE 4
179 /* In the >= 4.1.x storage format we add 2 bytes more so that we can also
180 store the charset-collation number; one byte is left unused, though */
181 #define DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE 6
182 
183 /* Maximum multi-byte character length in bytes, plus 1 */
184 #define DATA_MBMAX 5
185 
186 /* Pack mbminlen, mbmaxlen to mbminmaxlen. */
187 #define DATA_MBMINMAXLEN(mbminlen, mbmaxlen) \
188  ((mbmaxlen) * DATA_MBMAX + (mbminlen))
189 /* Get mbminlen from mbminmaxlen. Cast the result of UNIV_EXPECT to ulint
190 because in GCC it returns a long. */
191 #define DATA_MBMINLEN(mbminmaxlen) ((ulint) \
192  UNIV_EXPECT(((mbminmaxlen) % DATA_MBMAX), \
193  1))
194 /* Get mbmaxlen from mbminmaxlen. */
195 #define DATA_MBMAXLEN(mbminmaxlen) ((ulint) ((mbminmaxlen) / DATA_MBMAX))
196 
197 /* We now support 15 bits (up to 32767) collation number */
198 #define MAX_CHAR_COLL_NUM 32767
199 
200 /* Mask to get the Charset Collation number (0x7fff) */
201 #define CHAR_COLL_MASK MAX_CHAR_COLL_NUM
202 
203 #ifndef UNIV_HOTBACKUP
204 /*********************************************************************/
207 UNIV_INLINE
208 ulint
210 /*=================*/
211  const dtype_t* type);
212 /*********************************************************************/
217 UNIV_INTERN
218 ulint
220 /*========================*/
221  ulint prtype,
222  ulint mbminmaxlen,
224  ulint prefix_len,
227  ulint data_len,
228  const char* str);
230 #endif /* !UNIV_HOTBACKUP */
231 /*********************************************************************/
235 UNIV_INTERN
236 ibool
238 /*=================*/
239  ulint mtype);
240 /*********************************************************************/
245 UNIV_INTERN
246 ibool
248 /*========================*/
249  ulint mtype,
250  ulint prtype);
251 /*********************************************************************/
257 UNIV_INTERN
258 ibool
260 /*============================*/
261  ulint mtype,
262  ulint prtype);
263 /*********************************************************************/
265 UNIV_INLINE
266 void
267 dtype_set(
268 /*======*/
269  dtype_t* type,
270  ulint mtype,
271  ulint prtype,
272  ulint len);
273 /*********************************************************************/
275 UNIV_INLINE
276 void
277 dtype_copy(
278 /*=======*/
279  dtype_t* type1,
280  const dtype_t* type2);
281 /*********************************************************************/
284 UNIV_INLINE
285 ulint
287 /*============*/
288  const dtype_t* type);
289 /*********************************************************************/
292 UNIV_INLINE
293 ulint
295 /*=============*/
296  const dtype_t* type);
297 #ifndef UNIV_HOTBACKUP
298 /*********************************************************************/
300 UNIV_INLINE
301 void
303 /*============*/
304  ulint mtype,
305  ulint prtype,
306  ulint* mbminlen,
308  ulint* mbmaxlen);
310 /*********************************************************************/
313 UNIV_INLINE
314 ulint
316 /*===================*/
317  ulint prtype);
318 /*********************************************************************/
322 UNIV_INTERN
323 ulint
325 /*==============*/
326  ulint old_prtype,
328  ulint charset_coll);
329 /*********************************************************************/
334 UNIV_INLINE
335 ibool
337 /*==========*/
338  ulint prtype);
339 #endif /* !UNIV_HOTBACKUP */
340 /*********************************************************************/
343 UNIV_INLINE
344 ulint
346 /*==========*/
347  const dtype_t* type);
348 #ifndef UNIV_HOTBACKUP
349 /*********************************************************************/
353 UNIV_INLINE
354 ulint
356 /*===============*/
357  const dtype_t* type);
358 /*********************************************************************/
362 UNIV_INLINE
363 ulint
365 /*===============*/
366  const dtype_t* type);
367 /*********************************************************************/
369 UNIV_INLINE
370 void
372 /*==================*/
373  dtype_t* type,
374  ulint mbminlen,
377  ulint mbmaxlen);
380 /*********************************************************************/
383 UNIV_INLINE
384 ulint
386 /*===============*/
387  ulint mtype,
388  ulint prtype);
389 #endif /* !UNIV_HOTBACKUP */
390 /***********************************************************************/
393 UNIV_INLINE
394 ulint
396 /*=====================*/
397  ulint mtype,
398  ulint prtype,
399  ulint len,
400  ulint mbminmaxlen,
402  ulint comp);
403 #ifndef UNIV_HOTBACKUP
404 /***********************************************************************/
407 UNIV_INLINE
408 ulint
410 /*===================*/
411  ulint mtype,
412  ulint prtype,
413  ulint len,
414  ulint mbminmaxlen);
416 /***********************************************************************/
420 UNIV_INLINE
421 ulint
423 /*===================*/
424  ulint mtype,
425  ulint len);
426 #endif /* !UNIV_HOTBACKUP */
427 /***********************************************************************/
431 UNIV_INLINE
432 ulint
434 /*====================*/
435  const dtype_t* type,
436  ulint comp);
437 #ifndef UNIV_HOTBACKUP
438 /**********************************************************************/
441 UNIV_INLINE
442 void
444 /*===============================*/
445  dtype_t* type,
446  const byte* buf);
447 /**********************************************************************/
451 UNIV_INLINE
452 void
454 /*====================================*/
455  byte* buf,
458  const dtype_t* type,
459  ulint prefix_len);
461 /**********************************************************************/
465 UNIV_INLINE
466 void
468 /*===================================*/
469  dtype_t* type,
470  const byte* buf);
472 /*********************************************************************/
475 UNIV_INLINE
476 char*
478 /*===========*/
479  unsigned mtype,
480  unsigned prtype,
481  unsigned len,
482  char* name,
483  unsigned name_sz);
485 #endif /* !UNIV_HOTBACKUP */
486 
487 /*********************************************************************/
490 UNIV_INTERN
491 ibool
493 /*===========*/
494  const dtype_t* type);
495 /*********************************************************************/
497 UNIV_INTERN
498 void
500 /*========*/
501  const dtype_t* type);
503 /* Structure for an SQL data type.
504 If you add fields to this structure, be sure to initialize them everywhere.
505 This structure is initialized in the following functions:
506 dtype_set()
507 dtype_read_for_order_and_null_size()
508 dtype_new_read_for_order_and_null_size()
509 sym_tab_add_null_lit() */
510 
511 struct dtype_t{
512  unsigned prtype:32;
519  unsigned mtype:8;
521  /* the remaining fields do not affect alphabetical ordering: */
522 
523  unsigned len:16;
531 #ifndef UNIV_HOTBACKUP
532  unsigned mbminmaxlen:5;
537 #endif /* !UNIV_HOTBACKUP */
538 };
539 
540 #ifndef UNIV_NONINL
541 #include "data0type.ic"
542 #endif
543 
544 #endif