drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
data0type.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/**************************************************/
25
26#pragma once
27#ifndef data0type_h
28#define data0type_h
29
30#include "univ.i"
31
32extern ulint data_mysql_default_charset_coll;
33#define DATA_MYSQL_LATIN1_SWEDISH_CHARSET_COLL 8
34#define DATA_MYSQL_BINARY_CHARSET_COLL 63
35
36/* SQL data type struct */
37typedef struct dtype_struct dtype_t;
38
39/*-------------------------------------------*/
40/* The 'MAIN TYPE' of a column */
41#define DATA_VARCHAR 1 /* character varying of the
42 latin1_swedish_ci charset-collation; note
43 that the MySQL format for this, DATA_BINARY,
44 DATA_VARMYSQL, is also affected by whether the
45 'precise type' contains
46 DATA_MYSQL_TRUE_VARCHAR */
47#define DATA_CHAR 2 /* fixed length character of the
48 latin1_swedish_ci charset-collation */
49#define DATA_FIXBINARY 3 /* binary string of fixed length */
50#define DATA_BINARY 4 /* binary string */
51#define DATA_BLOB 5 /* binary large object, or a TEXT type;
52 if prtype & DATA_BINARY_TYPE == 0, then this is
53 actually a TEXT column (or a BLOB created
54 with < 4.0.14; since column prefix indexes
55 came only in 4.0.14, the missing flag in BLOBs
56 created before that does not cause any harm) */
57#define DATA_INT 6 /* integer: can be any size 1 - 8 bytes */
58#define DATA_SYS_CHILD 7 /* address of the child page in node pointer */
59#define DATA_SYS 8 /* system column */
60
61/* Data types >= DATA_FLOAT must be compared using the whole field, not as
62binary strings */
63
64#define DATA_FLOAT 9
65#define DATA_DOUBLE 10
66#define DATA_DECIMAL 11 /* decimal number stored as an ASCII string */
67#define DATA_VARMYSQL 12 /* any charset varying length char */
68#define DATA_MYSQL 13 /* any charset fixed length char */
69 /* NOTE that 4.1.1 used DATA_MYSQL and
70 DATA_VARMYSQL for all character sets, and the
71 charset-collation for tables created with it
72 can also be latin1_swedish_ci */
73#define DATA_MTYPE_MAX 63 /* dtype_store_for_order_and_null_size()
74 requires the values are <= 63 */
75/*-------------------------------------------*/
76/* The 'PRECISE TYPE' of a column */
77/*
78Tables created by a MySQL user have the following convention:
79
80- In the least significant byte in the precise type we store the MySQL type
81code (not applicable for system columns).
82
83- In the second least significant byte we OR flags DATA_NOT_NULL,
84DATA_UNSIGNED, DATA_BINARY_TYPE.
85
86- In the third least significant byte of the precise type of string types we
87store the MySQL charset-collation code. In DATA_BLOB columns created with
88< 4.0.14 we do not actually know if it is a BLOB or a TEXT column. Since there
89are no indexes on prefixes of BLOB or TEXT columns in < 4.0.14, this is no
90problem, though.
91
92Note that versions < 4.1.2 or < 5.0.1 did not store the charset code to the
93precise type, since the charset was always the default charset of the MySQL
94installation. If the stored charset code is 0 in the system table SYS_COLUMNS
95of InnoDB, that means that the default charset of this MySQL installation
96should be used.
97
98When loading a table definition from the system tables to the InnoDB data
99dictionary cache in main memory, InnoDB versions >= 4.1.2 and >= 5.0.1 check
100if the stored charset-collation is 0, and if that is the case and the type is
101a non-binary string, replace that 0 by the default charset-collation code of
102this MySQL installation. In short, in old tables, the charset-collation code
103in the system tables on disk can be 0, but in in-memory data structures
104(dtype_t), the charset-collation code is always != 0 for non-binary string
105types.
106
107In new tables, in binary string types, the charset-collation code is the
108MySQL code for the 'binary charset', that is, != 0.
109
110For binary string types and for DATA_CHAR, DATA_VARCHAR, and for those
111DATA_BLOB which are binary or have the charset-collation latin1_swedish_ci,
112InnoDB performs all comparisons internally, without resorting to the MySQL
113comparison functions. This is to save CPU time.
114
115InnoDB's own internal system tables have different precise types for their
116columns, and for them the precise type is usually not used at all.
117*/
118
119#define DATA_ENGLISH 4 /* English language character string: this
120 is a relic from pre-MySQL time and only used
121 for InnoDBs own system tables */
122#define DATA_ERROR 111 /* another relic from pre-MySQL time */
123
124#define DATA_MYSQL_TYPE_MASK 255 /* AND with this mask to extract the MySQL
125 type from the precise type */
126#if defined(BUILD_DRIZZLE)
127# define DATA_MYSQL_TRUE_VARCHAR 7 /* Drizzle type code for true VARCHAR */
128#else
129# define DATA_MYSQL_TRUE_VARCHAR 15 /* MySQL type code for the >= 5.0.3
130 format true VARCHAR */
131#endif
132
133/* Precise data types for system columns and the length of those columns;
134NOTE: the values must run from 0 up in the order given! All codes must
135be less than 256 */
136#define DATA_ROW_ID 0 /* row id: a 48-bit integer */
137#define DATA_ROW_ID_LEN 6 /* stored length for row id */
138
139#define DATA_TRX_ID 1 /* transaction id: 6 bytes */
140#define DATA_TRX_ID_LEN 6
141
142#define DATA_ROLL_PTR 2 /* rollback data pointer: 7 bytes */
143#define DATA_ROLL_PTR_LEN 7
144
145#define DATA_N_SYS_COLS 3 /* number of system columns defined above */
146
147#define DATA_SYS_PRTYPE_MASK 0xF /* mask to extract the above from prtype */
148
149/* Flags ORed to the precise data type */
150#define DATA_NOT_NULL 256 /* this is ORed to the precise type when
151 the column is declared as NOT NULL */
152#define DATA_UNSIGNED 512 /* this id ORed to the precise type when
153 we have an unsigned integer type */
154#define DATA_BINARY_TYPE 1024 /* if the data type is a binary character
155 string, this is ORed to the precise type:
156 this only holds for tables created with
157 >= MySQL-4.0.14 */
158/* #define DATA_NONLATIN1 2048 This is a relic from < 4.1.2 and < 5.0.1.
159 In earlier versions this was set for some
160 BLOB columns.
161*/
162#define DATA_LONG_TRUE_VARCHAR 4096 /* this is ORed to the precise data
163 type when the column is true VARCHAR where
164 MySQL uses 2 bytes to store the data len;
165 for shorter VARCHARs MySQL uses only 1 byte */
166/*-------------------------------------------*/
167
168/* This many bytes we need to store the type information affecting the
169alphabetical order for a single field and decide the storage size of an
170SQL null*/
171#define DATA_ORDER_NULL_TYPE_BUF_SIZE 4
172/* In the >= 4.1.x storage format we add 2 bytes more so that we can also
173store the charset-collation number; one byte is left unused, though */
174#define DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE 6
175
176/* Maximum multi-byte character length in bytes, plus 1 */
177#define DATA_MBMAX 5
178
179/* Pack mbminlen, mbmaxlen to mbminmaxlen. */
180#define DATA_MBMINMAXLEN(mbminlen, mbmaxlen) \
181 ((mbmaxlen) * DATA_MBMAX + (mbminlen))
182/* Get mbminlen from mbminmaxlen. Cast the result of UNIV_EXPECT to ulint
183because in GCC it returns a long. */
184#define DATA_MBMINLEN(mbminmaxlen) ((ulint) \
185 UNIV_EXPECT(((mbminmaxlen) % DATA_MBMAX), \
186 1))
187/* Get mbmaxlen from mbminmaxlen. */
188#define DATA_MBMAXLEN(mbminmaxlen) ((ulint) ((mbminmaxlen) / DATA_MBMAX))
189
190#ifndef UNIV_HOTBACKUP
191/*********************************************************************/
194UNIV_INLINE
195ulint
197/*=================*/
198 const dtype_t* type);
199/*********************************************************************/
204UNIV_INTERN
205ulint
207/*========================*/
208 ulint prtype,
209 ulint mbminmaxlen,
211 ulint prefix_len,
214 ulint data_len,
215 const char* str);
217#endif /* !UNIV_HOTBACKUP */
218/*********************************************************************/
222UNIV_INTERN
223ibool
225/*=================*/
226 ulint mtype);
227/*********************************************************************/
232UNIV_INTERN
233ibool
235/*========================*/
236 ulint mtype,
237 ulint prtype);
238/*********************************************************************/
244UNIV_INTERN
245ibool
247/*============================*/
248 ulint mtype,
249 ulint prtype);
250/*********************************************************************/
252UNIV_INLINE
253void
255/*======*/
256 dtype_t* type,
257 ulint mtype,
258 ulint prtype,
259 ulint len);
260/*********************************************************************/
262UNIV_INLINE
263void
265/*=======*/
266 dtype_t* type1,
267 const dtype_t* type2);
268/*********************************************************************/
271UNIV_INLINE
272ulint
274/*============*/
275 const dtype_t* type);
276/*********************************************************************/
279UNIV_INLINE
280ulint
282/*=============*/
283 const dtype_t* type);
284#ifndef UNIV_HOTBACKUP
285/*********************************************************************/
287UNIV_INLINE
288void
290/*============*/
291 ulint mtype,
292 ulint prtype,
293 ulint* mbminlen,
295 ulint* mbmaxlen);
297/*********************************************************************/
300UNIV_INLINE
301ulint
303/*===================*/
304 ulint prtype);
305/*********************************************************************/
309UNIV_INTERN
310ulint
312/*==============*/
313 ulint old_prtype,
315 ulint charset_coll);
316/*********************************************************************/
321UNIV_INLINE
322ibool
324/*==========*/
325 ulint prtype);
326#endif /* !UNIV_HOTBACKUP */
327/*********************************************************************/
330UNIV_INLINE
331ulint
333/*==========*/
334 const dtype_t* type);
335#ifndef UNIV_HOTBACKUP
336/*********************************************************************/
340UNIV_INLINE
341ulint
343/*===============*/
344 const dtype_t* type);
345/*********************************************************************/
349UNIV_INLINE
350ulint
352/*===============*/
353 const dtype_t* type);
354/*********************************************************************/
356UNIV_INLINE
357void
359/*==================*/
360 dtype_t* type,
361 ulint mbminlen,
364 ulint mbmaxlen);
367/*********************************************************************/
370UNIV_INLINE
371ulint
373/*===============*/
374 ulint mtype,
375 ulint prtype);
376#endif /* !UNIV_HOTBACKUP */
377/***********************************************************************/
380UNIV_INLINE
381ulint
383/*=====================*/
384 ulint mtype,
385 ulint prtype,
386 ulint len,
387 ulint mbminmaxlen,
389 ulint comp);
390#ifndef UNIV_HOTBACKUP
391/***********************************************************************/
394UNIV_INLINE
395ulint
397/*===================*/
398 ulint mtype,
399 ulint prtype,
400 ulint len,
401 ulint mbminmaxlen);
403/***********************************************************************/
407UNIV_INLINE
408ulint
410/*===================*/
411 ulint mtype,
412 ulint len);
413#endif /* !UNIV_HOTBACKUP */
414/***********************************************************************/
418UNIV_INLINE
419ulint
421/*====================*/
422 const dtype_t* type,
423 ulint comp);
424#ifndef UNIV_HOTBACKUP
425/**********************************************************************/
428UNIV_INLINE
429void
431/*===============================*/
432 dtype_t* type,
433 const byte* buf);
434/**********************************************************************/
438UNIV_INLINE
439void
441/*====================================*/
442 byte* buf,
445 const dtype_t* type,
446 ulint prefix_len);
448/**********************************************************************/
452UNIV_INLINE
453void
455/*===================================*/
456 dtype_t* type,
457 const byte* buf);
458#endif /* !UNIV_HOTBACKUP */
459
460/*********************************************************************/
463UNIV_INTERN
464ibool
466/*===========*/
467 const dtype_t* type);
468/*********************************************************************/
470UNIV_INTERN
471void
473/*========*/
474 const dtype_t* type);
475
476/* Structure for an SQL data type.
477If you add fields to this structure, be sure to initialize them everywhere.
478This structure is initialized in the following functions:
479dtype_set()
480dtype_read_for_order_and_null_size()
481dtype_new_read_for_order_and_null_size()
482sym_tab_add_null_lit() */
483
484struct dtype_struct{
485 unsigned mtype:8;
486 unsigned prtype:24;
488
493
494 /* the remaining fields do not affect alphabetical ordering: */
495
496 unsigned len:16;
504#ifndef UNIV_HOTBACKUP
505 unsigned mbminmaxlen:5;
510#endif /* !UNIV_HOTBACKUP */
511};
512
513#ifndef UNIV_NONINL
514#include "data0type.ic"
515#endif
516
517#endif
UNIV_INLINE ibool dtype_is_utf8(ulint prtype)
UNIV_INLINE void dtype_get_mblen(ulint mtype, ulint prtype, ulint *mbminlen, ulint *mbmaxlen)
UNIV_INLINE ulint dtype_get_fixed_size_low(ulint mtype, ulint prtype, ulint len, ulint mbminmaxlen, ulint comp)
UNIV_INLINE ulint dtype_get_len(const dtype_t *type)
UNIV_INLINE void dtype_set(dtype_t *type, ulint mtype, ulint prtype, ulint len)
UNIV_INTERN ibool dtype_is_non_binary_string_type(ulint mtype, ulint prtype)
Definition data0type.cc:134
UNIV_INLINE void dtype_new_store_for_order_and_null_size(byte *buf, const dtype_t *type, ulint prefix_len)
UNIV_INLINE ulint dtype_get_min_size_low(ulint mtype, ulint prtype, ulint len, ulint mbminmaxlen)
UNIV_INLINE ulint dtype_get_prtype(const dtype_t *type)
UNIV_INLINE void dtype_new_read_for_order_and_null_size(dtype_t *type, const byte *buf)
UNIV_INTERN ulint dtype_form_prtype(ulint old_prtype, ulint charset_coll)
Definition data0type.cc:154
UNIV_INLINE ulint dtype_get_max_size_low(ulint mtype, ulint len)
UNIV_INLINE void dtype_set_mbminmaxlen(dtype_t *type, ulint mbminlen, ulint mbmaxlen)
UNIV_INLINE ulint dtype_get_mtype(const dtype_t *type)
UNIV_INLINE ulint dtype_get_sql_null_size(const dtype_t *type, ulint comp)
UNIV_INLINE ulint dtype_get_charset_coll(ulint prtype)
UNIV_INLINE void dtype_read_for_order_and_null_size(dtype_t *type, const byte *buf)
UNIV_INTERN ibool dtype_is_binary_string_type(ulint mtype, ulint prtype)
Definition data0type.cc:111
UNIV_INTERN ulint dtype_get_at_most_n_mbchars(ulint prtype, ulint mbminmaxlen, ulint prefix_len, ulint data_len, const char *str)
Definition data0type.cc:49
UNIV_INLINE void dtype_copy(dtype_t *type1, const dtype_t *type2)
UNIV_INTERN ibool dtype_is_string_type(ulint mtype)
Definition data0type.cc:90
UNIV_INLINE ulint dtype_get_pad_char(ulint mtype, ulint prtype)
UNIV_INLINE ulint dtype_get_mbminlen(const dtype_t *type)
UNIV_INTERN void dtype_print(const dtype_t *type)
Definition data0type.cc:195
UNIV_INLINE ulint dtype_get_mbmaxlen(const dtype_t *type)
UNIV_INLINE ulint dtype_get_mysql_type(const dtype_t *type)
UNIV_INTERN ibool dtype_validate(const dtype_t *type)
Definition data0type.cc:171
unsigned mtype
Definition data0type.h:461
unsigned mbminmaxlen
Definition data0type.h:481
unsigned len
Definition data0type.h:472
unsigned prtype
Definition data0type.h:462